Skip to content

Instantly share code, notes, and snippets.

View simonkassel's full-sized avatar

Simon Kassel simonkassel

View GitHub Profile
import os
import argparse
from gdal import Open
from gdalconst import GA_ReadOnly
from shutil import copyfile
def main(tif_directory, all_labels):
tif_directory_contents = os.listdir(tif_directory)
This file has been truncated, but you can view the full file.
[{"GEOID.msa":10180,"name":"Abilene, TX","year":2006,"category":"bus","total_expenses":1067426,"revenue_miles":433499,"revenue_hours":30754,"upt":506631,"fares":201795,"average_speed":14.0957,"avg_fare":0.3983,"farebox_recovery":0.189},{"GEOID.msa":10180,"name":"Abilene, TX","year":2006,"category":"other","total_expenses":1300467,"revenue_miles":618718,"revenue_hours":43670,"upt":110747,"fares":93789,"average_speed":14.168,"avg_fare":0.8469,"farebox_recovery":0.0721},{"GEOID.msa":10180,"name":"Abilene, TX","year":2007,"category":"bus","total_expenses":1042242,"revenue_miles":435929,"revenue_hours":30702,"upt":485752,"fares":217336,"average_speed":14.1987,"avg_fare":0.4474,"farebox_recovery":0.2085},{"GEOID.msa":10180,"name":"Abilene, TX","year":2007,"category":"other","total_expenses":1472836,"revenue_miles":631823,"revenue_hours":47605,"upt":110546,"fares":98383,"average_speed":13.2722,"avg_fare":0.89,"farebox_recovery":0.0668},{"GEOID.msa":10180,"name":"Abilene, TX","year":2008,"category":"bus","total_expen
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
var pts = [{"x":348,"y":673},{"x":431,"y":663},{"x":264,"y":604},{"x":373,"y":610},{"x":466,"y":607},{"x":148,"y":562},{"x":143,"y":525},{"x":227,"y":533},{"x":348,"y":570},{"x":552,"y":551},{"x":582,"y":553},{"x":65,"y":432},{"x":111,"y":425},{"x":231,"y":491},{"x":282,"y":477},{"x":346,"y":453},{"x":377,"y":411},{"x":440,"y":473},{"x":503,"y":492},{"x":522,"y":490},{"x":531,"y":446},{"x":563,"y":419},{"x":643,"y":399},{"x":698,"y":402},{"x":38,"y":384},{"x":99,"y":333},{"x":137,"y":342},{"x":214,"y":390},{"x":275,"y":325},{"x":425,"y":388},{"x":441,"y":358},{"x":495,"y":335},{"x":545,"y":316},{"x":634,"y":365},{"x":698,"y":370},{"x":2,"y":267},{"x":48,"y":235},{"x":78,"y":297},{"x":124,"y":293},{"x":197,"y":207},{"x":218,"y":297},{"x":236,"y":241},{"x":298,"y":271},{"x":345,"y":239},{"x":388,"y":287},{"x":420,"y":223},{"x":454,"y":213},{"x":585,"y":268},{"x":774,"y":284},{"x":289,"y":188},{"x":331,"y":145},{"x":442,"y":122},{"x":451,"y":183},{"x":517,"y":132},{"x":537,"y":155},{"x":570,"y":132},{"x":622,"y"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file has been truncated, but you can view the full file.
{
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [
{
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# First create a data frame of just the year 2009, removing neighborhoods
# that we gave an NA value for pctChange due to on insufficient sale volume
sf.2009 <- sf.summarized[which(sf.summarized$SaleYr == 2009), ] %>% na.omit()
# Then create the scatterplot using neighborhood name labels instead of points
change_scatterplot <- ggplot(sf.2009, aes(x = pctChange, y = medianPrice, label = Neighborhood)) +
geom_label(data = sf.2009[which(!sf.2009$pctChange %in% topPctChange),],
aes(label = Neighborhood), fill = "grey20", size = 2, color = "white") +
geom_label(data = sf.2009[which(sf.2009$pctChange %in% topPctChange),],
aes(label = Neighborhood, fill = Neighborhood), size = 2, color = "white") +
# Create a locator map for these neighborhoods
sampleNeighborhoods <- ggmap(basemap) +
geom_polygon(data = neighb.tidy, aes(x = long, y = lat, group = group),
colour = NA, fill="black", alpha = 1) +
geom_polygon(data = neighb.tidy[which(neighb.tidy$Neighborhood %in% sfForTimeSeries$Neighborhood), ],
aes(x = long, y = lat, group = group, fill = Neighborhood),
colour = "black") +
coord_map() +
scale_fill_manual(values=palette_9_colors)+
mapTheme() +
# First some data wrangling:
# We will create a list of the 8 highest percentages
topPctChange <- unique(sf.summarized$pctChange) %>% sort(decreasing = TRUE) %>% head(8)
# Check out what those are:
topPctChange
# We'll use these percentages to subset our neighborhoods data frame
sfForTimeSeries <- sf.summarized[which(sf.summarized$pctChange %in% topPctChange), ]