.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_auto_examples/run_module/plot_run_module.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__auto_examples_run_module_plot_run_module.py: .. _run_module_example: Run module ========== In this example we demonstrate how to use AequilibraE's run module using Sioux Falls example. .. GENERATED FROM PYTHON SOURCE LINES 11-15 .. admonition:: References * :doc:`../../run_module` * :ref:`parameters_run` .. GENERATED FROM PYTHON SOURCE LINES 17-21 .. seealso:: Several functions, methods, classes and modules are used in this example: * :attr:`aequilibrae.Project.run` .. GENERATED FROM PYTHON SOURCE LINES 23-32 .. code-block:: Python # Imports from os.path import join from tempfile import gettempdir from uuid import uuid4 from aequilibrae.examples import create_example .. GENERATED FROM PYTHON SOURCE LINES 34-40 .. code-block:: Python # Let's create the Sioux Falls example in an arbitrary folder. folder = join(gettempdir(), uuid4().hex) project = create_example(folder) .. GENERATED FROM PYTHON SOURCE LINES 41-46 First, let's check the matrix information using ``matrix_summary()``. This method provides us useful information such as the matrix total, minimum and maximum values in the array, and the number of non-empty pairs in the matrix. Notice that the matrix summary is presented for each matrix core. .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python project.run["matrix_summary"]() .. rst-class:: sphx-glr-script-out .. code-block:: none {'skims.omx': {'distance_blended': {'total': np.float64(6725.294972629576), 'min': np.float64(0.0), 'max': np.float64(27.000048290421308), 'nnz': np.int64(552)}, 'time_final': {'total': np.float64(13600.90095750823), 'min': np.float64(0.0), 'max': np.float64(46.66452630996126), 'nnz': np.int64(552)}}, 'demand.omx': {'matrix': {'total': np.float64(360600.0), 'min': np.float64(0.0), 'max': np.float64(4400.0), 'nnz': np.int64(528)}}, 'demand_mc.omx': {'car': {'total': np.float64(271266.6324170904), 'min': np.float64(0.0), 'max': np.float64(3414.160702028352), 'nnz': np.int64(528)}, 'motorcycle': {'total': np.float64(89819.0708124364), 'min': np.float64(0.0), 'max': np.float64(1237.9652821904103), 'nnz': np.int64(528)}, 'trucks': {'total': np.float64(90235.57459796841), 'min': np.float64(0.0), 'max': np.float64(1318.3068496025667), 'nnz': np.int64(528)}}} .. GENERATED FROM PYTHON SOURCE LINES 49-51 If our matrices folder is empty, instead of a nested dictionary of data, AequilibraE run would return an empty dictionary. .. GENERATED FROM PYTHON SOURCE LINES 53-54 Let's create a graph for mode `car`. .. GENERATED FROM PYTHON SOURCE LINES 54-56 .. code-block:: Python mode = "c" .. GENERATED FROM PYTHON SOURCE LINES 57-60 .. code-block:: Python network = project.road.build_network() graph = network.build_graph(mode=mode, cost="distance", skimming=["distance"], block_centroid_flows=False) .. GENERATED FROM PYTHON SOURCE LINES 61-64 The network mapping describes the source topology. Building with compact=True can reduce the routing counts without changing the source mapping. .. GENERATED FROM PYTHON SOURCE LINES 64-72 .. code-block:: Python { "network_num_links": network.mapping.link_count, "network_num_nodes": network.mapping.node_count, "num_zones": graph.num_zones, "graph_num_links": graph.num_links, "graph_num_nodes": graph.num_nodes, } .. rst-class:: sphx-glr-script-out .. code-block:: none {'network_num_links': 76, 'network_num_nodes': 24, 'num_zones': 24, 'graph_num_links': 76, 'graph_num_nodes': 24} .. GENERATED FROM PYTHON SOURCE LINES 73-76 Let's add a ``create_delaunay`` function to our ``run/__init__.py`` file. This function replicates the example in which we :ref:`create Delaunay lines `. .. GENERATED FROM PYTHON SOURCE LINES 76-86 .. code-block:: Python func_string = """ def create_delaunay(project, source: str, name: str, matrix_core: str, result_name: str, overwrite: bool=False):\n \tfrom aequilibrae.utils.create_delaunay_network import DelaunayAnalysis\n \tmatrix = project.matrices\n \tmat = matrix.get_matrix(name, subset=[matrix_core])\n \tda = DelaunayAnalysis(project)\n \tda.create_network(source, overwrite)\n \tda.assign_matrix(mat, result_name)\n """ .. GENERATED FROM PYTHON SOURCE LINES 87-91 .. code-block:: Python with open(join(folder, "run", "__init__.py"), "a") as file: file.write("\n") file.write(func_string) .. GENERATED FROM PYTHON SOURCE LINES 92-93 Now we add new parameters to our model .. GENERATED FROM PYTHON SOURCE LINES 93-102 .. code-block:: Python p = project.project_parameters p.parameters["run"]["create_delaunay"] = {} p.parameters["run"]["create_delaunay"]["source"] = "zones" p.parameters["run"]["create_delaunay"]["name"] = "demand.omx" p.parameters["run"]["create_delaunay"]["matrix_core"] = "matrix" p.parameters["run"]["create_delaunay"]["result_name"] = "my_run_module_example" p.write_back() .. GENERATED FROM PYTHON SOURCE LINES 103-104 And we run the function .. GENERATED FROM PYTHON SOURCE LINES 104-106 .. code-block:: Python project.run["create_delaunay"]() .. rst-class:: sphx-glr-script-out .. code-block:: none Equilibrium Assignment : 0%| | 0/250 [00:00
scenario year table_name reference_table procedure procedure_id procedure_report timestamp description
0 None None my_run_module_example links Delaunay assignment 372aa478e31b4c498411ad388dc50ac8 "{\"setup\": \"{'Algorithm': 'all-or-nothing',... 2026-11-19 08:27:40.733467


.. GENERATED FROM PYTHON SOURCE LINES 121-122 Let's check what our Delaunay lines look like! .. GENERATED FROM PYTHON SOURCE LINES 122-125 .. code-block:: Python import geopandas as gpd .. GENERATED FROM PYTHON SOURCE LINES 126-127 Let's retrieve the results .. GENERATED FROM PYTHON SOURCE LINES 127-129 .. code-block:: Python results = project.results.get_results("my_run_module_example").set_index("link_id") .. GENERATED FROM PYTHON SOURCE LINES 130-136 .. code-block:: Python with project.db_connection as conn: links = gpd.read_postgis( "SELECT link_id, st_asBinary(geometry) geometry FROM delaunay_network", conn, geom_col="geometry", crs=4326 ) links.set_index("link_id", inplace=True) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/aequilibrae/aequilibrae/docs/source/examples/run_module/plot_run_module.py:134: Pandas4Warning: The inplace keyword in GeoDataFrame.set_index is deprecated and will be removed in a future version (PDEP-8). See https://pandas.pydata.org/docs/dev/whatsnew/v3.1.0.html#deprecation-inplace for more details. links.set_index("link_id", inplace=True) .. GENERATED FROM PYTHON SOURCE LINES 137-140 .. code-block:: Python df = links.join(results) max_vol = df.matrix_tot.max() .. GENERATED FROM PYTHON SOURCE LINES 141-142 And finally plot the data .. GENERATED FROM PYTHON SOURCE LINES 142-144 .. code-block:: Python df.plot(linewidth=5 * df["matrix_tot"] / max_vol, color="blue") .. image-sg:: /_auto_examples/run_module/images/sphx_glr_plot_run_module_001.png :alt: plot run module :srcset: /_auto_examples/run_module/images/sphx_glr_plot_run_module_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 145-147 .. code-block:: Python project.close() .. GENERATED FROM PYTHON SOURCE LINES 148-150 Pipeline image credits to `Data-pipeline icons created by Vectors Tank - Flaticon `_ .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.264 seconds) .. _sphx_glr_download__auto_examples_run_module_plot_run_module.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_run_module.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_run_module.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_run_module.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_