import%20marimo%0A%0A__generated_with%20%3D%20%220.23.13%22%0Aapp%20%3D%20marimo.App()%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Park%20Accessibility%20from%20OSM%20Data%0A%0A%20%20%20%20Calculate%20park%20accessibility%20for%20London%20using%20OpenStreetMap%20polygon%20data.%0A%0A%20%20%20%20This%20recipe%20uses%20the%20high-level%20%5B%60CityNetwork%60%5D(https%3A%2F%2Fcityseer.benchmarkurbanism.com%2Fapi%2Fnetwork)%20class%2C%20whose%20%5B%60from_osm%60%5D(https%3A%2F%2Fcityseer.benchmarkurbanism.com%2Fapi%2Fnetwork%23from_osm)%20constructor%20wraps%20the%20OSM%20download%2C%20cleaning%2C%20and%20network%20preparation%20behind%20a%20single%20call.%0A%0A%20%20%20%20Network%20data%20%C2%A9%20%5BOpenStreetMap%5D(https%3A%2F%2Fwww.openstreetmap.org%2Fcopyright)%20contributors%2C%20available%20under%20the%20Open%20Database%20Licence.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20from%20cityseer.network%20import%20CityNetwork%0A%20%20%20%20from%20cityseer.tools%20import%20io%0A%20%20%20%20from%20osmnx%20import%20features%0A%0A%20%20%20%20return%20CityNetwork%2C%20features%2C%20io%2C%20plt%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20To%20start%2C%20create%20the%20network%20from%20a%20buffered%20point%20polygon%20using%20the%20%60from_osm%60%20constructor.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(CityNetwork%2C%20io)%3A%0A%20%20%20%20lng%2C%20lat%20%3D%20-0.13396079424572427%2C%2051.51371088849723%0A%20%20%20%20buffer%20%3D%201500%0A%20%20%20%20poly_wgs%2C%20_epsg_code%20%3D%20io.buffered_point_poly(lng%2C%20lat%2C%20buffer)%0A%20%20%20%20cn%20%3D%20CityNetwork.from_osm(poly_wgs)%0A%20%20%20%20return%20cn%2C%20poly_wgs%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Prepare%20the%20parks%20GeoDataFrame%20by%20downloading%20the%20data%20from%20OpenStreetMap.%20The%20%60osmnx%60%20%5B%60features_from_polygon%60%5D(https%3A%2F%2Fosmnx.readthedocs.io%2Fen%2Fstable%2Fuser-reference.html%23osmnx.features.features_from_polygon)%20works%20well%20for%20this%20purpose.%20In%20this%20instance%2C%20we%20are%20specifically%20targeting%20features%20that%20are%20labelled%20as%20a%20%60leisure%60%20type%20of%20%60park%60.%20You%20can%20use%20the%20same%20idea%20to%20extract%20other%20features%20or%20land%20use%20types.%0A%0A%20%20%20%20It%20is%20important%20to%20convert%20the%20derivative%20GeoDataFrame%20to%20the%20same%20CRS%20as%20the%20network.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cn%2C%20features%2C%20poly_wgs)%3A%0A%20%20%20%20data_gdf%20%3D%20features.features_from_polygon(poly_wgs%2C%20tags%3D%7B%22leisure%22%3A%20%5B%22park%22%5D%7D)%0A%20%20%20%20data_gdf%20%3D%20data_gdf.to_crs(cn.crs)%0A%20%20%20%20%23%20reset%20index%0A%20%20%20%20data_gdf%20%3D%20data_gdf.reset_index(level%3D0%2C%20drop%3DTrue)%0A%0A%20%20%20%20data_gdf%0A%20%20%20%20return%20(data_gdf%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Once%20the%20data%20has%20been%20prepared%2C%20use%20the%20%5B%60compute_accessibilities%60%5D(https%3A%2F%2Fcityseer.benchmarkurbanism.com%2Fapi%2Fnetwork%23compute_accessibilities)%20method%20to%20compute%20accessibilities.%20The%20method%20accepts%20polygon%20geometries%20directly%2C%20assigning%20each%20polygon%20to%20the%20nearby%20network%20nodes.%20The%20%60landuse_column_label%60%20and%20the%20target%20accessibility%20keys%20should%20correspond%20to%20the%20data%20in%20the%20input%20GeoDataFrame.%20Use%20the%20%60max_netw_assign_dist%60%20parameter%20to%20configure%20the%20distance%20for%20network%20assignment.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cn%2C%20data_gdf)%3A%0A%20%20%20%20%23%20compute%20park%20accessibility%0A%20%20%20%20distances%20%3D%20%5B100%2C%20200%2C%20400%2C%20800%5D%0A%20%20%20%20_cn%2C%20data_gdf_1%20%3D%20cn.compute_accessibilities(%0A%20%20%20%20%20%20%20%20data_gdf%2C%0A%20%20%20%20%20%20%20%20landuse_column_label%3D%22leisure%22%2C%0A%20%20%20%20%20%20%20%20accessibility_keys%3D%5B%22park%22%5D%2C%0A%20%20%20%20%20%20%20%20distances%3Ddistances%2C%0A%20%20%20%20)%0A%20%20%20%20nodes_gdf_1%20%3D%20cn.to_geopandas()%0A%20%20%20%20return%20data_gdf_1%2C%20nodes_gdf_1%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20output%20columns%20are%20named%20%60cc_%7Bkey%7D_%7Bdistance%7D%60%2C%20where%20the%20keys%20correspond%20to%20the%20input%20accessibility%20keys%20and%20the%20distances%20to%20the%20input%20distances.%20By%20default%20the%20counts%20are%20unweighted%3B%20pass%20a%20%60decay_fn%60%20expression%20such%20as%20%60%22exp(-4%20*%20p)%22%60%20for%20distance-weighted%20counts.%20A%20further%20%60cc_%7Bkey%7D_nearest_max_%7Bdistance%7D%60%20column%20gives%20the%20distance%20to%20the%20nearest%20instance%20of%20each%20landuse.%0A%0A%20%20%20%20Standard%20GeoPandas%20functionality%20can%20be%20used%20to%20explore%2C%20visualise%2C%20or%20save%20the%20results.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(nodes_gdf_1)%3A%0A%20%20%20%20nodes_gdf_1.columns%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(data_gdf_1%2C%20nodes_gdf_1%2C%20plt)%3A%0A%20%20%20%20fig%2C%20ax%20%3D%20plt.subplots(1%2C%201%2C%20figsize%3D(7%2C%207)%2C%20dpi%3D150)%0A%20%20%20%20_g%20%3D%20nodes_gdf_1.copy()%0A%20%20%20%20%23%20distance-to-nearest%3A%20lower%20is%20better%2C%20so%20invert%20the%20rank%20to%20draw%20the%20closest%20streets%20boldest%0A%20%20%20%20_g%5B%22_r%22%5D%20%3D%201%20-%20_g%5B%22cc_park_nearest_max_800%22%5D.rank(pct%3DTrue)%0A%20%20%20%20_g%20%3D%20_g.sort_values(%22_r%22)%0A%20%20%20%20_g.plot(ax%3Dax%2C%20color%3Dplt.get_cmap(%22OrRd%22)(_g%5B%22_r%22%5D)%2C%20linewidth%3D0.15%20%2B%202.25%20*%20_g%5B%22_r%22%5D)%0A%20%20%20%20data_gdf_1.plot(color%3D%22%23cccccc%22%2C%20edgecolor%3D%22%23bbbbbb%22%2C%20ax%3Dax)%0A%20%20%20%20ax.set_title(%22Distance%20to%20nearest%20park%2C%20800%20m%20max%22%2C%20loc%3D%22left%22)%0A%20%20%20%20ax.set_axis_off()%0A%20%20%20%20fig.tight_layout()%0A%20%20%20%20fig%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Conclusion%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20This%20notebook%20computed%20park%20accessibility%20from%20OSM%20polygon%20features%20in%20London%2C%20showing%20that%20%60CityNetwork.compute_accessibilities%60%20handles%20polygon%20geometries%20as%20well%20as%20points%20by%20assigning%20them%20to%20multiple%20nearby%20network%20nodes.%20The%20nearest-distance%20and%20count%20outputs%20reveal%20how%20park%20proximity%20varies%20across%20the%20street%20network.%0A%0A%20%20%20%20**Next%20steps%3A**%20To%20compute%20mixed%20land-use%20diversity%2C%20see%20%5BMixed%20Uses%5D(https%3A%2F%2Fcityseer.benchmarkurbanism.com%2Fexamples%2Faccessibility%2Fgpd-mixed-uses).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
8b56c49373edb90797d44fc5e19e8521