Skip to content

Instantly share code, notes, and snippets.

View fscottfoti's full-sized avatar

Fletcher Foti fscottfoti

View GitHub Profile
@fscottfoti
fscottfoti / .babelrc
Created August 20, 2023 19:42 — forked from camerondavison/.babelrc
apache arrow from python to javascript
{
"presets": [
"@babel/preset-env",
]
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
We can make this file beautiful and searchable if this error is corrected: It looks like row 3 should actually have 25 columns, instead of 22. in line 2.
geometry,county_id,apn,land_use_type_id,res_type,land_value,improvement_value,year_assessed,year_built,building_sqft,non_residential_sqft,residential_units,stories,tax_exempt,condo_identifier,imputation_flag,development_type_id,calc_area,parcel_id,zone_id,general_plan_name,city,priority,x,y
"POLYGON ((-122.3990274713002 37.79395382339768, -122.3993259511759 37.79391578933188, -122.3993538562597 37.79405130905006, -122.3990561343018 37.79408924715813, -122.3990274713002 37.79395382339768))",San Francisco,0237046,MIXED,,555469.0,225936.0,,1907.0,8250.0,8250.0,0.0,2.0,0.0, ,_,ME,405.240852503,893634,1.0,DOWNTOWN- OFFICE-350-S,San Francisco,1.0,-122.399190847,37.7940025136
"POLYGON ((-122.3964937400307 37.79335498674916, -122.397325320222 37.79271016640127, -122.3974696743914 37.79341132542675, -122.3965299855578 37.79353105082634, -122.3964937400307 37.79335498674916))",San Francisco,0264004,MIPS,,79131319.0,83209623.0,,2005.0,570000.0,570000.0,0.0,32.0,0.0, ,_,,4134.37730242,893997,1.0,DOWNTOWN- OFFICE-400-S,Sa
"""
Steps to install environment
1)
Get Anaconda (python with includes packages) and install it
https://www.continuum.io/downloads
2)
Get network file and put it in the same directory as this file
http://urbanforecast.com/data/2015_06_01_osm_bayarea4326.h5
@fscottfoti
fscottfoti / export3.py
Created March 23, 2016 21:32
script to turn parcels into binary h5 file
from pymongo import MongoClient
from bson.objectid import ObjectId
import json
import time
from string import join
import pandas as pd
import cPickle
MONGO = True
JURIS = None
@fscottfoti
fscottfoti / link_nodes.py
Created February 24, 2016 22:42
a good start at linking gtfs nodes to osm nodes
// Copyright (c) 2012 Sutoiku, Inc.
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE O
@fscottfoti
fscottfoti / ipf.py
Created October 27, 2015 20:33
ipf, yea! see elsewhere for description of ipf.
# this should be fairly self explanitory if you know ipf
# seed_matrix is your best bet at the totals, col_marginals are
# observed column marginals and row_marginals is the same for rows
def simple_ipf(seed_matrix, col_marginals, row_marginals, tolerance=1, cnt=0):
assert np.absolute(row_marginals.sum() - col_marginals.sum()) < 5.0
# first normalize on columns
ratios = col_marginals / seed_matrix.sum(axis=0)
seed_matrix *= ratios
closeness = np.absolute(row_marginals - seed_matrix.sum(axis=1)).sum()
@fscottfoti
fscottfoti / model.py
Created October 20, 2015 21:54
pandana example POI query
def make_network(name, weight_col, max_distance):
st = pd.HDFStore(os.path.join(misc.data_dir(), name), "r")
nodes, edges = st.nodes, st.edges
net = pdna.Network(nodes["x"], nodes["y"], edges["from"], edges["to"],
edges[[weight_col]])
net.precompute(max_distance)
return net
@orca.step('local_pois')
def local_pois(settings):
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