Skip to content

Instantly share code, notes, and snippets.

View fscottfoti's full-sized avatar

Fletcher Foti fscottfoti

View GitHub Profile
from monary import Monary
import numpy as np, pandas as pd
import time
mon = Monary()
columns = ['x','y','shape_area','zone_id','county_id','parcel_id']
t1 = time.time()
numpy_arrays = mon.query('bayarea','parcels',{},columns,['float32']*len(columns))
df = np.matrix(numpy_arrays).transpose()
df = pd.DataFrame(df, columns=columns)
print time.time()-t1
@fscottfoti
fscottfoti / gist:1cec32e70a60e440ebce
Last active August 29, 2015 14:01
Is patsy slow or am I doing something wrong?
{
"metadata": {
"name": "",
"signature": "sha256:0cf6cb9492bf54a87341cd63b1eaa77ad1a76608073d08f68c5c2d41d7568686"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@fscottfoti
fscottfoti / bayarea_simulation1
Last active August 29, 2015 14:04
inaugural urbansim simulation run
{
"metadata": {
"name": "",
"signature": "sha256:3687bfe6e588cba4b1013e657e1f62b803fc49a204d980923fc3bdb31ced8c99"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@fscottfoti
fscottfoti / network_data_convert.py
Last active August 29, 2015 14:05
This is the code required to convert the network from the old pickled format to just storing the networks as dataframes in an hdf5 file (pandas style)
import pandas as pd
import cPickle
import sys
args = sys.argv[1:]
assert len(args) == 2, "go.py <infile.jar> <outfile.h5>"
d = cPickle.load(open(args[0]))
nodes = pd.DataFrame(d['nodes'], index=d['nodeids'])
{
"metadata": {
"name": "",
"signature": "sha256:1cb19ce6c787115025feeb23df2dc82b4547224d32a0d8f2dfc941418962d417"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@fscottfoti
fscottfoti / gist:c44799407d0793cc715b
Created February 12, 2015 22:29
Parking Simulations
import models
import time
import urbansim.sim.simulation as sim
import sys
print "Started", time.ctime()
print "Run number", sim.get_injectable("run_number")
in_year, out_year = 2010, 2040
try:
@fscottfoti
fscottfoti / gist:bac96177b2fb70248675
Created March 9, 2015 20:35
drive along portion of mode choice spec
description filter expression other coeff
Drive alone - Unavailable sovAvailable==0 -999
Drive alone - Unavailable for zero auto households autos==0 1 -999
Drive alone - Unavailable for persons less than 16 age<16 1 -999
Drive alone - Unavailable for joint tours tourCategoryJoint==1 1 -999
Drive alone - Unavailable if didn't drive to work
@fscottfoti
fscottfoti / gist:ddc7c7ad3b0f6c337ac5
Created July 13, 2015 20:46
Change CRS of Pandana network
import pyproj
import pandas as pd
s = pd.HDFStore('osm_bayarea.h5', "r")
s2 = pd.HDFStore('osm_bayarea4326.h5', "w")
s2["edges"] = s["edges"]
po = s["nodes"]
print po.describe()
@fscottfoti
fscottfoti / geomid1.py
Last active September 25, 2015 16:59
def make_key(row):
return "cx="+(row.centroidx/10).round(0).astype('str') + \
", cy=" + (row.centroidy/10).round(0).astype('str') + \
", ar=" + (row.area/25).round(0).astype('str') + \
", l=" + (row.length/10).round(0).astype('str') + \
", bbminx=" + (row.minx/2).round(0).astype('str') + \
", bbmaxy=" + (row.maxy/2).round(0).astype('str')
df["new_geom_id"] = df.apply(make_key, axis=1)
from sklearn.neighbors import KDTree
def nearest_neighbor(df1, df2):
kdt = KDTree(df1.as_matrix())
distances, indexes = kdt.query(df2.as_matrix(), k=1, return_distance=True)
return pd.Series(distances.flatten(), index=df1.index.values[indexes.flatten()])
import sys
import pandas as pd