6) UNA Workflows
In the previous section, we learned how to create the pairing table, and use it to loop over multiple pairs of origins and destinations. In this section, we will learn how to use the standarized UNA workflows to accomplish the same objective with fewer lines of code. We first need to import the workflow module
[2]:
from madina.una.workflows import betweenness_flow_simulation
This workflow takes the following inputs:
Data folder that contains the raw data.
Pairing Table similar to the one prepared in the previous section, saved as a csv file. More instructions on preparing the data and creating the pairing table can be found in the documentation: https://madinadocs.readthedocs.io/en/latest/ped_flow.html
if the network and origin/destination data is placed in a folder Cities/Somerville/Data, Once the Pairing table is prepared and saved as “Pairings.csv” in the same folder, the following function can be used to replicate the same process introdiced in the previous section. iterating over pairs in the pairing tabble, loading layers, creating networks, handling origins and destinations, calculating the betweenness, saving the result back to the network file.
This function workflow provides additional advantages:
Better logging and reporting of progress
Producing specifically styled maps for each flow
concise definition for reproducibility, and for use as part of a repititive scenario analysis process
[3]:
betweenness_flow_simulation(
city_name="Somerville",
num_cores=8,
)
total time | seconds elapsed | flow_name | event
0.0000 | 0.000000 | --- | SIMULATION STARTED: VERSION: 0.0.14, RELEASE DATEL 2023-02-06
0.0090 | 0.008977 | --- | 3.11.0 | packaged by conda-forge | (main, Oct 25 2022, 06:12:32) [MSC v.1929 64 bit (AMD64)]
0.0150 | 0.006030 | --- | Dependencies: Geopandas:0.12.2, Shapely:2.0.1, Pandas:1.5.3, Numpy:1.24.2, NetworkX:3.0
6.5430 | 6.528032 | --- | network FIle Loaded, Projection: EPSG:26986
9.9336 | 3.390516 | (1/7) Somerville_Bus_Subway_Geometric | network topology created
9.9800 | 0.046448 | (1/7) Somerville_Bus_Subway_Geometric | Bus file bus.geojson Loaded, Projection: EPSG:26986
9.9961 | 0.016122 | (1/7) Somerville_Bus_Subway_Geometric | Subway file subway.geojson Loaded, Projection: EPSG:26986
10.0383 | 0.042168 | (1/7) Somerville_Bus_Subway_Geometric | Origins and Destinations Inserted.
10.3497 | 0.311376 | (1/7) Somerville_Bus_Subway_Geometric | NetworkX Graphs Created.
17.9439 | 7.594271 | (1/7) Somerville_Bus_Subway_Geometric | Betweenness estimated.
34.4812 | 16.537227 | (1/7) Somerville_Bus_Subway_Geometric | Output saved
38.4672 | 3.985988 | (2/7) Somerville_Bus_Subway | network topology created
38.5200 | 0.052830 | (2/7) Somerville_Bus_Subway | Origins and Destinations Inserted.
38.9359 | 0.415891 | (2/7) Somerville_Bus_Subway | NetworkX Graphs Created.
47.0344 | 8.098509 | (2/7) Somerville_Bus_Subway | Betweenness estimated.
63.5214 | 16.487052 | (2/7) Somerville_Bus_Subway | Output saved
69.8316 | 6.310132 | (3/7) Somerville_Homes_Subway | Homes file homes.geojson Loaded, Projection: EPSG:26986
71.0967 | 1.265091 | (3/7) Somerville_Homes_Subway | Origins and Destinations Inserted.
71.5631 | 0.466475 | (3/7) Somerville_Homes_Subway | NetworkX Graphs Created.
188.2780 | 116.714844 | (3/7) Somerville_Homes_Subway | Betweenness estimated.
217.2007 | 28.922733 | (3/7) Somerville_Homes_Subway | Output saved
218.2923 | 1.091600 | (4/7) Somerville_Jobs_Subway | Jobs file jobs.geojson Loaded, Projection: EPSG:26986
218.5310 | 0.238644 | (4/7) Somerville_Jobs_Subway | Origins and Destinations Inserted.
219.0316 | 0.500631 | (4/7) Somerville_Jobs_Subway | NetworkX Graphs Created.
241.3644 | 22.332830 | (4/7) Somerville_Jobs_Subway | Betweenness estimated.
259.9120 | 18.547570 | (4/7) Somerville_Jobs_Subway | Output saved
260.4366 | 0.524604 | (5/7) Somerville_Amenities_Amenities | Amenities file amenities.geojson Loaded, Projection: EPSG:26986
260.6092 | 0.172577 | (5/7) Somerville_Amenities_Amenities | Origins and Destinations Inserted.
262.1261 | 1.516915 | (5/7) Somerville_Amenities_Amenities | NetworkX Graphs Created.
870.9422 | 608.816114 | (5/7) Somerville_Amenities_Amenities | Betweenness estimated.
889.3239 | 18.381677 | (5/7) Somerville_Amenities_Amenities | Output saved
889.6070 | 0.283090 | (6/7) Somerville_CensusBlock_Parks | CensusBlock file CensusBlock.geojson Loaded, Projection: EPSG:26986
889.6429 | 0.035907 | (6/7) Somerville_CensusBlock_Parks | Parks file parks.geojson Loaded, Projection: EPSG:26986
889.7646 | 0.121704 | (6/7) Somerville_CensusBlock_Parks | Origins and Destinations Inserted.
890.2892 | 0.524612 | (6/7) Somerville_CensusBlock_Parks | NetworkX Graphs Created.
983.9523 | 93.663156 | (6/7) Somerville_CensusBlock_Parks | Betweenness estimated.
999.3091 | 15.356737 | (6/7) Somerville_CensusBlock_Parks | Output saved
999.3360 | 0.026928 | (7/7) Somerville_Institutions_Subway | Institutions file institutions.geojson Loaded, Projection: EPSG:26986
999.3599 | 0.023938 | (7/7) Somerville_Institutions_Subway | Origins and Destinations Inserted.
999.6542 | 0.294211 | (7/7) Somerville_Institutions_Subway | NetworkX Graphs Created.
1008.9593 | 9.305191 | (7/7) Somerville_Institutions_Subway | Betweenness estimated.
1025.0003 | 16.040985 | (7/7) Somerville_Institutions_Subway | Output saved
1034.8252 | 9.824885 | --- | Simulation Output saved: ALL DONE
Similarly, you can run the accessibility workflow, using the provided Somerville example data and access_pairings.csv
[1]:
from madina.una.workflows import KNN_accessibility
KNN_accessibility(
city_name="Somerville",
pairings_file="access_pairings.csv",
num_cores=8,
)
total time | seconds elapsed | flow_name | event
0.0000 | 0.000000 | --- | SIMULATION STARTED: VERSION: 0.0.14, RELEASE DATEL 2023-02-06
0.0075 | 0.007532 | --- | 3.11.0 | packaged by conda-forge | (main, Oct 25 2022, 06:12:32) [MSC v.1929 64 bit (AMD64)]
0.0075 | 0.000000 | --- | Dependencies: Geopandas:0.12.2, Shapely:2.0.1, Pandas:1.5.3, Numpy:1.24.2, NetworkX:3.0
6.8013 | 6.793734 | (1/7) Homes_to_Subway | network FIle Loaded, Projection: EPSG:26986
10.4698 | 3.668578 | (1/7) Homes_to_Subway | network topology created
16.0008 | 5.530913 | (1/7) Homes_to_Subway | Homes file homes.geojson Loaded, Projection: EPSG:26986
16.0175 | 0.016761 | (1/7) Homes_to_Subway | Subway file subway.geojson Loaded, Projection: EPSG:26986
17.2508 | 1.233300 | (1/7) Homes_to_Subway | Origins and Destinations Inserted.
17.6356 | 0.384745 | (1/7) Homes_to_Subway | NetworkX Graphs Created.
93.0068 | 75.371214 | (1/7) Homes_to_Subway | accissibility calculated.
93.0965 | 0.089759 | (2/7) Homes_to_Bus | Bus file bus.geojson Loaded, Projection: EPSG:26986
94.6913 | 1.594767 | (2/7) Homes_to_Bus | Origins and Destinations Inserted.
95.4942 | 0.802854 | (2/7) Homes_to_Bus | NetworkX Graphs Created.
181.9056 | 86.411463 | (2/7) Homes_to_Bus | accissibility calculated.
185.5998 | 3.694154 | (3/7) Homes_to_Jobs | Jobs file jobs.geojson Loaded, Projection: EPSG:26986
189.9097 | 4.309914 | (3/7) Homes_to_Jobs | Origins and Destinations Inserted.
196.0949 | 6.185255 | (3/7) Homes_to_Jobs | NetworkX Graphs Created.
336.5469 | 140.451927 | (3/7) Homes_to_Jobs | accissibility calculated.
338.7605 | 2.213600 | (4/7) Homes_to_Amenities | Amenities file amenities.geojson Loaded, Projection: EPSG:26986
342.7391 | 3.978646 | (4/7) Homes_to_Amenities | Origins and Destinations Inserted.
345.1482 | 2.409051 | (4/7) Homes_to_Amenities | NetworkX Graphs Created.
452.4969 | 107.348709 | (4/7) Homes_to_Amenities | accissibility calculated.
452.5727 | 0.075798 | (5/7) Homes_to_Institutions | Institutions file institutions.geojson Loaded, Projection: EPSG:26986
454.2472 | 1.674520 | (5/7) Homes_to_Institutions | Origins and Destinations Inserted.
454.9237 | 0.676495 | (5/7) Homes_to_Institutions | NetworkX Graphs Created.
551.7782 | 96.854521 | (5/7) Homes_to_Institutions | accissibility calculated.
551.9837 | 0.205451 | (6/7) Homes_to_Parks | Parks file parks.geojson Loaded, Projection: EPSG:26986
555.2841 | 3.300421 | (6/7) Homes_to_Parks | Origins and Destinations Inserted.
557.6138 | 2.329717 | (6/7) Homes_to_Parks | NetworkX Graphs Created.
650.1986 | 92.584788 | (6/7) Homes_to_Parks | accissibility calculated.
650.2455 | 0.046875 | (7/7) Homes_to_Schools | Schools file schools.geojson Loaded, Projection: EPSG:26986
651.5218 | 1.276381 | (7/7) Homes_to_Schools | Origins and Destinations Inserted.
652.5903 | 1.068479 | (7/7) Homes_to_Schools | NetworkX Graphs Created.
747.2607 | 94.670420 | (7/7) Homes_to_Schools | accissibility calculated.
763.8196 | 16.558825 | --- | Output saved: ALL DONE