Final Project Demo¶
CSCI E-29 Advanced Python for Data Science
Filip Wodnicki
8 May 2021
Transit + OSMnx¶
Setup¶
from final_project.network import Network, TransitNetwork, WalkNetwork, MultiNetwork
import osmnx as ox
NOLA_WALK = "data/nola_walking_network.graphml"
NOLA_TRANSIT = "data/nola_transit_network.pickle"
NOLA_MULTI = "data/nola_combined_network.pickle"
Route details
Google Maps- De La Salle High School to Superior Seafood & Oyster Bar
pt1 = dls = (29.928048784077454, -90.11423725461219)
mid = (29.925781685210005, -90.10771821332047)
pt2 = sso = (29.926284495505136, -90.10223516437942)
Walking Network¶
Load¶
W = WalkNetwork.load(NOLA_WALK)
[nodes] = W.nearest_k_nodes(X=dls[1], Y=dls[0], k=350) # TODO tie-in
sub = WalkNetwork(W.G.subgraph(nodes))
/Users/filip/code/harvard/adv_python/final_project/2021sp-final-project-filipwodnicki/final_project/utilities.py:91: FutureWarning: Support for multi-dimensional indexing (e.g. `obj[:, None]`) is deprecated and will be removed in a future version. Convert to a numpy array before indexing instead.
nn = nodes.index[pos]
sub.edges_with_nodes_df
| source | target | geometry | oneway | osmid | length | highway | access | name | tunnel | maxspeed | lanes | id_source | y_source | x_source | id_target | y_target | x_target | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 116033548 | 116033554 | NaN | False | 24925491 | 106.574 | residential | NaN | La Salle Street | NaN | NaN | NaN | 116033548 | 29.933939 | -90.107333 | 116033554 | 29.933979 | -90.108438 |
| 1 | 116033548 | 115992065 | NaN | False | 37606457 | 107.614 | residential | NaN | Upperline Street | NaN | NaN | NaN | 116033548 | 29.933939 | -90.107333 | 115992065 | 29.932972 | -90.107378 |
| 2 | 116033554 | 115992066 | NaN | False | 24882806 | 107.785 | residential | NaN | Robert Street | NaN | NaN | NaN | 116033554 | 29.933979 | -90.108438 | 115992066 | 29.933011 | -90.108492 |
| 3 | 116033554 | 116001710 | NaN | False | 24882806 | 54.309 | residential | NaN | Robert Street | NaN | NaN | NaN | 116033554 | 29.933979 | -90.108438 | 116001710 | 29.934466 | -90.108408 |
| 4 | 116033554 | 115991911 | NaN | False | 24925491 | 90.741 | residential | NaN | La Salle Street | NaN | NaN | NaN | 116033554 | 29.933979 | -90.108438 | 115991911 | 29.934016 | -90.109379 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 1209 | 116100838 | 116074751 | NaN | False | 24882806 | 107.743 | residential | NaN | Robert Street | NaN | NaN | NaN | 116100838 | 29.929116 | -90.108681 | 116074751 | 29.930083 | -90.108626 |
| 1210 | 116090624 | 116036590 | NaN | False | 12704792 | 93.615 | residential | NaN | Coliseum Street | NaN | NaN | NaN | 116090624 | 29.924282 | -90.118204 | 116036590 | 29.924469 | -90.119151 |
| 1211 | 116090624 | 116072496 | NaN | False | 12704792 | 93.978 | residential | NaN | Coliseum Street | NaN | NaN | NaN | 116090624 | 29.924282 | -90.118204 | 116072496 | 29.924089 | -90.117254 |
| 1212 | 116090624 | 115988603 | NaN | False | 249575188 | 103.839 | residential | NaN | Nashville Avenue | NaN | NaN | NaN | 116090624 | 29.924282 | -90.118204 | 115988603 | 29.925190 | -90.117953 |
| 1213 | 116090624 | 116020118 | NaN | False | 249575188 | 104.225 | residential | NaN | Nashville Avenue | NaN | NaN | NaN | 116090624 | 29.924282 | -90.118204 | 116020118 | 29.923370 | -90.118455 |
1214 rows × 18 columns
Visualize¶
m = sub.mapper
m
Make this Notebook Trusted to load map: File -> Trust Notebook
Transit Network¶
T = TransitNetwork.load(NOLA_TRANSIT)
[nodes] = T.nearest_k_nodes(X=dls[1], Y=dls[0], k=350) # TODO tie-in
subgraph = T.G.subgraph(nodes)
sub = TransitNetwork(subgraph)
/Users/filip/code/anaconda3/envs/trox/lib/python3.8/site-packages/pyproj/crs/crs.py:53: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
return _prepare_from_string(" ".join(pjargs))
/Users/filip/code/harvard/adv_python/final_project/2021sp-final-project-filipwodnicki/final_project/utilities.py:91: FutureWarning: Support for multi-dimensional indexing (e.g. `obj[:, None]`) is deprecated and will be removed in a future version. Convert to a numpy array before indexing instead.
nn = nodes.index[pos]
Load¶
T.edges_with_nodes_df
| source | target | length | mode | id_source | y_source | x_source | id_target | y_target | x_target | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0DKDI_1 | 0DKDI_1621 | 65.00 | transit | 0DKDI_1 | 29.960899 | -90.057160 | 0DKDI_1621 | 29.959530 | -90.059121 |
| 1 | 0DKDI_10 | 0DKDI_2414 | 38.00 | transit | 0DKDI_10 | 29.981920 | -90.099770 | 0DKDI_2414 | 29.980568 | -90.097750 |
| 2 | 0DKDI_100 | 0DKDI_101 | 45.25 | transit | 0DKDI_100 | 29.967506 | -90.070652 | 0DKDI_101 | 29.965828 | -90.072156 |
| 3 | 0DKDI_1000 | 0DKDI_1001 | 24.00 | transit | 0DKDI_1000 | 29.933720 | -90.007404 | 0DKDI_1001 | 29.932630 | -90.004961 |
| 4 | 0DKDI_1001 | 0DKDI_1002 | 15.00 | transit | 0DKDI_1001 | 29.932630 | -90.004961 | 0DKDI_1002 | 29.931773 | -90.003101 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 2525 | 0DKDI_1086 | 0DKDI_1094 | 109.00 | transit | 0DKDI_1086 | 29.944505 | -90.072171 | 0DKDI_1094 | 29.942753 | -90.072815 |
| 2526 | 0DKDI_601 | 0DKDI_574 | 21.00 | transit | 0DKDI_601 | 30.047577 | -89.961712 | 0DKDI_574 | 30.048694 | -89.962924 |
| 2527 | 0DKDI_1077 | 0DKDI_2077 | 36.00 | transit | 0DKDI_1077 | 29.948406 | -90.071035 | 0DKDI_2077 | 29.947405 | -90.071277 |
| 2528 | 0DKDI_1094 | 0DKDI_2068 | 84.00 | transit | 0DKDI_1094 | 29.942753 | -90.072815 | 0DKDI_2068 | 29.940531 | -90.074438 |
| 2529 | 0DKDI_2367 | 0DKDI_2368 | 29.00 | transit | 0DKDI_2367 | 29.961847 | -90.115889 | 0DKDI_2368 | 29.964390 | -90.120874 |
2530 rows × 10 columns
Visualize¶
sub.mapper
Make this Notebook Trusted to load map: File -> Trust Notebook
Combine!¶
Visualize Multi-Network¶
WT = MultiNetwork.combine(walk=W, transit=T)
/Users/filip/code/anaconda3/envs/trox/lib/python3.8/site-packages/pyproj/crs/crs.py:53: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
return _prepare_from_string(" ".join(pjargs))
/Users/filip/code/harvard/adv_python/final_project/2021sp-final-project-filipwodnicki/final_project/utilities.py:91: FutureWarning: Support for multi-dimensional indexing (e.g. `obj[:, None]`) is deprecated and will be removed in a future version. Convert to a numpy array before indexing instead.
nn = nodes.index[pos]
[nodes] = WT.nearest_k_nodes(X=mid[1], Y=mid[0], k=350) # TODO tie-in
subgraph = WT.G.subgraph(nodes)
sub = MultiNetwork(subgraph)
/Users/filip/code/anaconda3/envs/trox/lib/python3.8/site-packages/pyproj/crs/crs.py:53: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
return _prepare_from_string(" ".join(pjargs))
/Users/filip/code/harvard/adv_python/final_project/2021sp-final-project-filipwodnicki/final_project/utilities.py:91: FutureWarning: Support for multi-dimensional indexing (e.g. `obj[:, None]`) is deprecated and will be removed in a future version. Convert to a numpy array before indexing instead.
nn = nodes.index[pos]
m = sub.mapper
m
Make this Notebook Trusted to load map: File -> Trust Notebook
Routing¶
route = WT.get_shortest_pair(pt1, pt2, k=1)[0]
ox.plot_route_folium(WT.G, route, route_map=m, color="magenta")
/Users/filip/code/anaconda3/envs/trox/lib/python3.8/site-packages/pyproj/crs/crs.py:53: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
return _prepare_from_string(" ".join(pjargs))
/Users/filip/code/harvard/adv_python/final_project/2021sp-final-project-filipwodnicki/final_project/utilities.py:91: FutureWarning: Support for multi-dimensional indexing (e.g. `obj[:, None]`) is deprecated and will be removed in a future version. Convert to a numpy array before indexing instead.
nn = nodes.index[pos]
/Users/filip/code/anaconda3/envs/trox/lib/python3.8/site-packages/pyproj/crs/crs.py:53: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
return _prepare_from_string(" ".join(pjargs))
/Users/filip/code/harvard/adv_python/final_project/2021sp-final-project-filipwodnicki/final_project/utilities.py:91: FutureWarning: Support for multi-dimensional indexing (e.g. `obj[:, None]`) is deprecated and will be removed in a future version. Convert to a numpy array before indexing instead.
nn = nodes.index[pos]
/Users/filip/code/anaconda3/envs/trox/lib/python3.8/site-packages/pyproj/crs/crs.py:53: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
return _prepare_from_string(" ".join(pjargs))
Make this Notebook Trusted to load map: File -> Trust Notebook
route
[115997964,
116009085,
116009082,
'0DKDI_1335',
'0DKDI_836',
'0DKDI_839',
'0DKDI_846',
'0DKDI_850',
'0DKDI_858',
'0DKDI_863',
3344161313]