Skip to content

Instantly share code, notes, and snippets.

@shakythesherpa
shakythesherpa / crawl.py
Last active August 29, 2015 14:07 — forked from csytan/crawl.py
import csv
import json
import os
import time
import urllib
def load(**kwargs):
url = 'http://booths.nigeriaelections.org/getStuff.php'
@shakythesherpa
shakythesherpa / README.md
Last active August 29, 2015 14:07 — forked from tmcw/README.md
try:
import simplejson as json
except:
import json
import re
import requests
dir_url = 'http://api.tiles.mapbox.com/v3/modilabs/maps.json'
map_data = json.load(requests.get(dir_url).text)
nmis_exp = re.compile("Nigeria|nigeria|nmis")
import subprocess
import sys, re
MERC = '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs'
infile = sys.argv[1]
info_output = subprocess.Popen(['gdalinfo', infile], stdout=subprocess.PIPE).communicate()[0]
size_is_re = re.compile('Size is (?P<width>\d+), (?P<height>\d+)')
size_is = filter(lambda x: x, map(lambda x: size_is_re.match(x), info_output.split('\n')))
from lxml import etree
import urllib2
import urlparse
import sys
# Prevents this script from failing when output is piped
# to another process
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE,SIG_DFL)

Download and convert data from NYC open data portal

curl -o nynta.zip "https://nycopendata.socrata.com/api/geospatial/cpf4-rkhq?method=export&format=Shapefile"
cd nynta_12c

ogr2ogr can't deal with the projection directly. Replace content of nynta.prj with the following projection string:

PROJCS["NAD_1983_StatePlane_New_York_Long_Island_FIPS_3104_Feet",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["lambert_conformal_conic_2sp"],PARAMETER["False_Easting",984250.0],PARAMETER["False_Northing",0.0],PARAMETER["longitude_of_center",-74.0],PARAMETER["Standard_Parallel_1",40.66666666666666],PARAMETER["Standard_Parallel_2",41.03333333333333],PARAMETER["latitude_of_center",40.16666666666666],UNIT["Foot_US",0.3048006096012192]]

#a simple network-based SIR model written in Python
#Jon Zelner
#University of Michigan
#October 20, 2009
#import this file (networkSIRWithClasses) to use the model components
#or run as 'python networkSIRWithClasses.py' to do sample runs
import igraph
import random
#a simple object-based SIR model written in Python
#Jon Zelner
#University of Michigan
#October 20, 2009
#import 'sirWithClasses' to use the components of this model as you wish
#or just run this script as 'python sirWithClasses.py' to do a sample model run
import random
import heapq