Before you get started, note that this notebook requires the osm branch of geopandas to be installed. This is all still fairly experimental functionality in geopandas, and thus should still be considered experimental here as well (utils.py is not fully unit tested). On the other hand, the actual POI queries in Pandana are unit tested and can be considered ready for release.
In [ ]:
%load_ext autoreload
%autoreload 2
import pandas as pd
import numpy as np
import pandana as pdna
from pandana import utils
import geopandas.io.osm as osm
%matplotlib inline
In [ ]:
store = pd.HDFStore('osm_bayarea.h5', "r")
net=pdna.Network(store.nodes["x"],
store.nodes["y"],
store.edges["from"],
store.edges["to"],
store.edges[["weight"]])
# make sure you have enough categories for your score
net.init_pois(num_categories=10, max_dist=2400, max_pois=10)
bbox = [-122.8662,37.1373,-121.4798,38.2158] # san francisco
In [ ]:
from scipy.special import expit
def dist_to_contrib(dist):
dist = dist.astype('float') / 2400 # now varies from 0 to 1
dist = (dist * -10) + 5
return expit(dist)
In [ ]:
s = utils.anything_score(
net,
{
"shop=supermarket": [3.0],
"amenity=restaurant": [.75, .45, .25, .25, .225, .225, .225, .225, .2, .2],
"shop=convenience": [.5, .45, .4, .35, .3],
"amenity=cafe": [1.25, .75],
"amenity=bank": [1.0],
"leisure=park": [1.0],
"amenity=school": [1.0],
"amenity=library": [1.0],
"amenity=bar": [1.0]
},
2400,
dist_to_contrib, # decay function to apply to distance
bbox
)
print s.describe()
In [ ]:
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('png')
out_bbox = utils.bbox_convert([-122.539365,37.693047,-122.347698,37.816069],
from_epsg=4326, to_epsg=3740)
net.plot(s, bbox=out_bbox, scheme="diverging", color="BrBG")
In [ ]: