{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 6) UNA Workflows\n", "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" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from madina.una.workflows import betweenness_flow_simulation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This workflow takes the following inputs:\n", "* Data folder that contains the raw data. \n", "* Pairing Table similar to the one prepared in the previous section, saved as a csv file. \n", "More instructions on preparing the data and creating the pairing table can be found in the documentation:\n", "https://madinadocs.readthedocs.io/en/latest/ped_flow.html\n", "\n", "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.\n", "\n", "This function workflow provides additional advantages:\n", "* Better logging and reporting of progress\n", "* Producing specifically styled maps for each flow\n", "* concise definition for reproducibility, and for use as part of a repititive scenario analysis process" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "total time | seconds elapsed | flow_name | event\n", " 0.0000 | 0.000000 | --- | SIMULATION STARTED: VERSION: 0.0.14, RELEASE DATEL 2023-02-06\n", " 0.0090 | 0.008977 | --- | 3.11.0 | packaged by conda-forge | (main, Oct 25 2022, 06:12:32) [MSC v.1929 64 bit (AMD64)]\n", " 0.0150 | 0.006030 | --- | Dependencies: Geopandas:0.12.2, Shapely:2.0.1, Pandas:1.5.3, Numpy:1.24.2, NetworkX:3.0\n", " 6.5430 | 6.528032 | --- | network FIle Loaded, Projection: EPSG:26986\n", " 9.9336 | 3.390516 | (1/7) Somerville_Bus_Subway_Geometric | network topology created\n", " 9.9800 | 0.046448 | (1/7) Somerville_Bus_Subway_Geometric | Bus file bus.geojson Loaded, Projection: EPSG:26986\n", " 9.9961 | 0.016122 | (1/7) Somerville_Bus_Subway_Geometric | Subway file subway.geojson Loaded, Projection: EPSG:26986\n", " 10.0383 | 0.042168 | (1/7) Somerville_Bus_Subway_Geometric | Origins and Destinations Inserted.\n", " 10.3497 | 0.311376 | (1/7) Somerville_Bus_Subway_Geometric | NetworkX Graphs Created.\n", " 17.9439 | 7.594271 | (1/7) Somerville_Bus_Subway_Geometric | Betweenness estimated.\n", " 34.4812 | 16.537227 | (1/7) Somerville_Bus_Subway_Geometric | Output saved\n", " 38.4672 | 3.985988 | (2/7) Somerville_Bus_Subway | network topology created\n", " 38.5200 | 0.052830 | (2/7) Somerville_Bus_Subway | Origins and Destinations Inserted.\n", " 38.9359 | 0.415891 | (2/7) Somerville_Bus_Subway | NetworkX Graphs Created.\n", " 47.0344 | 8.098509 | (2/7) Somerville_Bus_Subway | Betweenness estimated.\n", " 63.5214 | 16.487052 | (2/7) Somerville_Bus_Subway | Output saved\n", " 69.8316 | 6.310132 | (3/7) Somerville_Homes_Subway | Homes file homes.geojson Loaded, Projection: EPSG:26986\n", " 71.0967 | 1.265091 | (3/7) Somerville_Homes_Subway | Origins and Destinations Inserted.\n", " 71.5631 | 0.466475 | (3/7) Somerville_Homes_Subway | NetworkX Graphs Created.\n", " 188.2780 | 116.714844 | (3/7) Somerville_Homes_Subway | Betweenness estimated.\n", " 217.2007 | 28.922733 | (3/7) Somerville_Homes_Subway | Output saved\n", " 218.2923 | 1.091600 | (4/7) Somerville_Jobs_Subway | Jobs file jobs.geojson Loaded, Projection: EPSG:26986\n", " 218.5310 | 0.238644 | (4/7) Somerville_Jobs_Subway | Origins and Destinations Inserted.\n", " 219.0316 | 0.500631 | (4/7) Somerville_Jobs_Subway | NetworkX Graphs Created.\n", " 241.3644 | 22.332830 | (4/7) Somerville_Jobs_Subway | Betweenness estimated.\n", " 259.9120 | 18.547570 | (4/7) Somerville_Jobs_Subway | Output saved\n", " 260.4366 | 0.524604 | (5/7) Somerville_Amenities_Amenities | Amenities file amenities.geojson Loaded, Projection: EPSG:26986\n", " 260.6092 | 0.172577 | (5/7) Somerville_Amenities_Amenities | Origins and Destinations Inserted.\n", " 262.1261 | 1.516915 | (5/7) Somerville_Amenities_Amenities | NetworkX Graphs Created.\n", " 870.9422 | 608.816114 | (5/7) Somerville_Amenities_Amenities | Betweenness estimated.\n", " 889.3239 | 18.381677 | (5/7) Somerville_Amenities_Amenities | Output saved\n", " 889.6070 | 0.283090 | (6/7) Somerville_CensusBlock_Parks | CensusBlock file CensusBlock.geojson Loaded, Projection: EPSG:26986\n", " 889.6429 | 0.035907 | (6/7) Somerville_CensusBlock_Parks | Parks file parks.geojson Loaded, Projection: EPSG:26986\n", " 889.7646 | 0.121704 | (6/7) Somerville_CensusBlock_Parks | Origins and Destinations Inserted.\n", " 890.2892 | 0.524612 | (6/7) Somerville_CensusBlock_Parks | NetworkX Graphs Created.\n", " 983.9523 | 93.663156 | (6/7) Somerville_CensusBlock_Parks | Betweenness estimated.\n", " 999.3091 | 15.356737 | (6/7) Somerville_CensusBlock_Parks | Output saved\n", " 999.3360 | 0.026928 | (7/7) Somerville_Institutions_Subway | Institutions file institutions.geojson Loaded, Projection: EPSG:26986\n", " 999.3599 | 0.023938 | (7/7) Somerville_Institutions_Subway | Origins and Destinations Inserted.\n", " 999.6542 | 0.294211 | (7/7) Somerville_Institutions_Subway | NetworkX Graphs Created.\n", " 1008.9593 | 9.305191 | (7/7) Somerville_Institutions_Subway | Betweenness estimated.\n", " 1025.0003 | 16.040985 | (7/7) Somerville_Institutions_Subway | Output saved\n", " 1034.8252 | 9.824885 | --- | Simulation Output saved: ALL DONE\n" ] } ], "source": [ "betweenness_flow_simulation(\n", " city_name=\"Somerville\",\n", " num_cores=8,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Similarly, you can run the accessibility workflow, using the provided Somerville example data and `access_pairings.csv`" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "total time | seconds elapsed | flow_name | event\n", " 0.0000 | 0.000000 | --- | SIMULATION STARTED: VERSION: 0.0.14, RELEASE DATEL 2023-02-06\n", " 0.0075 | 0.007532 | --- | 3.11.0 | packaged by conda-forge | (main, Oct 25 2022, 06:12:32) [MSC v.1929 64 bit (AMD64)]\n", " 0.0075 | 0.000000 | --- | Dependencies: Geopandas:0.12.2, Shapely:2.0.1, Pandas:1.5.3, Numpy:1.24.2, NetworkX:3.0\n", " 6.8013 | 6.793734 | (1/7) Homes_to_Subway | network FIle Loaded, Projection: EPSG:26986\n", " 10.4698 | 3.668578 | (1/7) Homes_to_Subway | network topology created\n", " 16.0008 | 5.530913 | (1/7) Homes_to_Subway | Homes file homes.geojson Loaded, Projection: EPSG:26986\n", " 16.0175 | 0.016761 | (1/7) Homes_to_Subway | Subway file subway.geojson Loaded, Projection: EPSG:26986\n", " 17.2508 | 1.233300 | (1/7) Homes_to_Subway | Origins and Destinations Inserted.\n", " 17.6356 | 0.384745 | (1/7) Homes_to_Subway | NetworkX Graphs Created.\n", " 93.0068 | 75.371214 | (1/7) Homes_to_Subway | accissibility calculated.\n", " 93.0965 | 0.089759 | (2/7) Homes_to_Bus | Bus file bus.geojson Loaded, Projection: EPSG:26986\n", " 94.6913 | 1.594767 | (2/7) Homes_to_Bus | Origins and Destinations Inserted.\n", " 95.4942 | 0.802854 | (2/7) Homes_to_Bus | NetworkX Graphs Created.\n", " 181.9056 | 86.411463 | (2/7) Homes_to_Bus | accissibility calculated.\n", " 185.5998 | 3.694154 | (3/7) Homes_to_Jobs | Jobs file jobs.geojson Loaded, Projection: EPSG:26986\n", " 189.9097 | 4.309914 | (3/7) Homes_to_Jobs | Origins and Destinations Inserted.\n", " 196.0949 | 6.185255 | (3/7) Homes_to_Jobs | NetworkX Graphs Created.\n", " 336.5469 | 140.451927 | (3/7) Homes_to_Jobs | accissibility calculated.\n", " 338.7605 | 2.213600 | (4/7) Homes_to_Amenities | Amenities file amenities.geojson Loaded, Projection: EPSG:26986\n", " 342.7391 | 3.978646 | (4/7) Homes_to_Amenities | Origins and Destinations Inserted.\n", " 345.1482 | 2.409051 | (4/7) Homes_to_Amenities | NetworkX Graphs Created.\n", " 452.4969 | 107.348709 | (4/7) Homes_to_Amenities | accissibility calculated.\n", " 452.5727 | 0.075798 | (5/7) Homes_to_Institutions | Institutions file institutions.geojson Loaded, Projection: EPSG:26986\n", " 454.2472 | 1.674520 | (5/7) Homes_to_Institutions | Origins and Destinations Inserted.\n", " 454.9237 | 0.676495 | (5/7) Homes_to_Institutions | NetworkX Graphs Created.\n", " 551.7782 | 96.854521 | (5/7) Homes_to_Institutions | accissibility calculated.\n", " 551.9837 | 0.205451 | (6/7) Homes_to_Parks | Parks file parks.geojson Loaded, Projection: EPSG:26986\n", " 555.2841 | 3.300421 | (6/7) Homes_to_Parks | Origins and Destinations Inserted.\n", " 557.6138 | 2.329717 | (6/7) Homes_to_Parks | NetworkX Graphs Created.\n", " 650.1986 | 92.584788 | (6/7) Homes_to_Parks | accissibility calculated.\n", " 650.2455 | 0.046875 | (7/7) Homes_to_Schools | Schools file schools.geojson Loaded, Projection: EPSG:26986\n", " 651.5218 | 1.276381 | (7/7) Homes_to_Schools | Origins and Destinations Inserted.\n", " 652.5903 | 1.068479 | (7/7) Homes_to_Schools | NetworkX Graphs Created.\n", " 747.2607 | 94.670420 | (7/7) Homes_to_Schools | accissibility calculated.\n", " 763.8196 | 16.558825 | --- | Output saved: ALL DONE\n" ] } ], "source": [ "from madina.una.workflows import KNN_accessibility\n", "\n", "KNN_accessibility(\n", " city_name=\"Somerville\",\n", " pairings_file=\"access_pairings.csv\",\n", " num_cores=8,\n", ")" ] } ], "metadata": { "kernelspec": { "display_name": "madina_dev", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.0" } }, "nbformat": 4, "nbformat_minor": 2 }