{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# RA2CE feature: Single link losses analysis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Single link losses Analysis" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "c:\\Users\\hauth\\anaconda3\\envs\\ra2ce_env\\lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "source": [ "from pathlib import Path\n", "from ra2ce.ra2ce_handler import Ra2ceHandler\n", "import geopandas as gpd\n", "\n", "# Import config data\n", "root_dir = Path(\"data\", \"single_link_losses\")\n", "assert root_dir.exists()\n", "\n", "# Load network data.\n", "from ra2ce.network.network_config_data.network_config_data_reader import NetworkConfigDataReader\n", "_network_config_data = NetworkConfigDataReader().read(root_dir.joinpath(\"network.ini\"))\n", "\n", "# Load analysis data.\n", "from ra2ce.analysis.analysis_config_data.analysis_config_data_reader import AnalysisConfigDataReader\n", "_analysis_config_data = AnalysisConfigDataReader().read(root_dir.joinpath(\"analysis.ini\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Modify the analysis config data with custom properties" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from ra2ce.analysis.analysis_config_data.analysis_config_data import AnalysisSectionLosses\n", "\n", "# Modify the first analysis (assuming it's the only one)\n", "_found_analysis: AnalysisSectionLosses = _analysis_config_data.analyses[0]\n", "_input_analysis_path = root_dir.joinpath(\"input_analysis_data\")\n", "_found_analysis.traffic_intensities_file = _input_analysis_path.joinpath(\"traffic_intensities.csv\")\n", "_found_analysis.resilience_curves_file = _input_analysis_path.joinpath(\"resilience_curve.csv\")\n", "_found_analysis.values_of_time_file = _input_analysis_path.joinpath(\"values_of_time.csv\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Configure network" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's have a look first at the hazard overlay to locate the road segments for which losses will be expected. We run only the network configuration." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "handler = Ra2ceHandler.from_config(_network_config_data, _analysis_config_data)\n", "handler.configure()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hazard_output = root_dir / \"static\" / \"output_graph\" / \"base_graph_hazard_edges.gpkg\"\n", "hazard_gdf = gpd.read_file(hazard_output, driver = \"GPKG\")\n", "hazard_gdf.explore(column=\"EV1_ma\", cmap = \"viridis\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Run losses analysis" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "c:\\Users\\hauth\\anaconda3\\envs\\ra2ce_env\\lib\\site-packages\\geopandas\\geodataframe.py:1543: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " super().__setitem__(key, value)\n" ] }, { "data": { "text/plain": [ "[AnalysisResultWrapper(analysis_result= ID u v key EV1_fr EV1_ma \\\n", " 0 86 2 42 0 0.014318 1.369213 \n", " 1 30 29 31 0 0.079975 0.345044 \n", " 2 100 30 82 0 0.100808 0.654458 \n", " 3 85 42 73 0 0.027676 0.409945 \n", " 4 264 46 51 0 0.002634 0.766717 \n", " .. ... ... ... ... ... ... \n", " 225 253 153 156 0 0.000000 0.000000 \n", " 226 246 154 155 0 0.000000 0.000000 \n", " 227 249 154 156 0 0.000000 0.000000 \n", " 228 248 156 157 0 0.000000 0.000000 \n", " 229 257 157 158 0 0.000000 0.000000 \n", " \n", " alt_nodes alt_time avgspeed \\\n", " 0 [2, 0, 11, 12, 10, 7, 6, 9, 75, 121, 118, 5, 3... 0.099722 59.0 \n", " 1 [29, 30, 82, 31] 0.009356 59.0 \n", " 2 [30, 29, 31, 82] 0.005288 30.0 \n", " 3 nan NaN 60.0 \n", " 4 [46, 48, 47, 160, 51] 0.008829 60.0 \n", " .. ... ... ... \n", " 225 [153, 155, 154, 156] 0.000933 60.0 \n", " 226 [154, 156, 153, 155] 0.000933 60.0 \n", " 227 [154, 155, 153, 156] 0.001217 60.0 \n", " 228 [156, 154, 89, 157] 0.003383 60.0 \n", " 229 nan NaN 60.0 \n", " \n", " bridge ... node_A node_B rfid rfid_c time vlh_business_EV1_ma \\\n", " 0 yes ... 2 42 125 127 0.043763 433.125000 \n", " 1 yes ... 29 31 91 93 0.003898 5.156250 \n", " 2 yes ... 30 82 233 241 0.007967 -40.781250 \n", " 3 yes ... 42 73 208 216 0.016917 46.375000 \n", " 4 nan ... 46 51 151 153 0.002183 39.785156 \n", " .. ... ... ... ... ... ... ... ... \n", " 225 nan ... 153 156 448 458 0.000500 0.000000 \n", " 226 nan ... 154 155 447 457 0.000500 0.000000 \n", " 227 nan ... 154 156 449 459 0.000217 0.000000 \n", " 228 nan ... 156 157 452 462 0.002950 0.000000 \n", " 229 nan ... 157 158 454 464 0.025067 0.000000 \n", " \n", " vlh_commute_EV1_ma vlh_freight_EV1_ma vlh_other_EV1_ma vlh_EV1_ma_total \n", " 0 303.333333 5775.000000 5133.333333 11644.791667 \n", " 1 3.750000 5.000000 35.833333 49.739583 \n", " 2 -18.437500 -81.250000 -106.250000 -246.718750 \n", " 3 51.187500 24.500000 210.000000 332.062500 \n", " 4 13.125000 80.208333 69.270833 202.389323 \n", " .. ... ... ... ... \n", " 225 0.000000 0.000000 0.000000 0.000000 \n", " 226 0.000000 0.000000 0.000000 0.000000 \n", " 227 0.000000 0.000000 0.000000 0.000000 \n", " 228 0.000000 0.000000 0.000000 0.000000 \n", " 229 0.000000 0.000000 0.000000 0.000000 \n", " \n", " [230 rows x 27 columns], analysis=)]" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "handler.run_analysis()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's inspect the results of the analysis. For every segment in the network, the losses are expressed in vehicle loss hour (vlh) for all the types of trip defined in the input files: business, commute, freight and other." ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IDuvkeyEV1_frEV1_maalt_nodesalt_timeavgspeedbridge...node_Brfidrfid_ctimevlh_business_EV1_mavlh_commute_EV1_mavlh_freight_EV1_mavlh_other_EV1_mavlh_EV1_ma_totalgeometry
08624200.0143181.369213[2, 0, 11, 12, 10, 7, 6, 9, 75, 121, 118, 5, 3...0.09972259.0yes...421251270.043763433.125000303.3333335775.0000005133.33333311644.791667LINESTRING (34.86702 -19.83164, 34.86711 -19.8...
130293100.0799750.345044[29, 30, 82, 31]0.00935659.0yes...3191930.0038985.1562503.7500005.00000035.83333349.739583LINESTRING (34.83997 -19.83592, 34.84019 -19.8...
2100308200.1008080.654458[30, 29, 31, 82]0.00528830.0yes...822332410.007967-40.781250-18.437500-81.250000-106.250000-246.718750LINESTRING (34.84149 -19.83431, 34.84137 -19.8...
385427300.0276760.409945nanNaN60.0yes...732082160.01691746.37500051.18750024.500000210.000000332.062500LINESTRING (34.87145 -19.82349, 34.87126 -19.8...
4264465100.0026340.766717[46, 48, 47, 160, 51]0.00882960.0nan...511511530.00218339.78515613.12500080.20833369.270833202.389323LINESTRING (34.85650 -19.83019, 34.85714 -19.8...
\n", "

5 rows × 27 columns

\n", "
" ], "text/plain": [ " ID u v key EV1_fr EV1_ma \\\n", "0 86 2 42 0 0.014318 1.369213 \n", "1 30 29 31 0 0.079975 0.345044 \n", "2 100 30 82 0 0.100808 0.654458 \n", "3 85 42 73 0 0.027676 0.409945 \n", "4 264 46 51 0 0.002634 0.766717 \n", "\n", " alt_nodes alt_time avgspeed \\\n", "0 [2, 0, 11, 12, 10, 7, 6, 9, 75, 121, 118, 5, 3... 0.099722 59.0 \n", "1 [29, 30, 82, 31] 0.009356 59.0 \n", "2 [30, 29, 31, 82] 0.005288 30.0 \n", "3 nan NaN 60.0 \n", "4 [46, 48, 47, 160, 51] 0.008829 60.0 \n", "\n", " bridge ... node_B rfid rfid_c time vlh_business_EV1_ma \\\n", "0 yes ... 42 125 127 0.043763 433.125000 \n", "1 yes ... 31 91 93 0.003898 5.156250 \n", "2 yes ... 82 233 241 0.007967 -40.781250 \n", "3 yes ... 73 208 216 0.016917 46.375000 \n", "4 nan ... 51 151 153 0.002183 39.785156 \n", "\n", " vlh_commute_EV1_ma vlh_freight_EV1_ma vlh_other_EV1_ma vlh_EV1_ma_total \\\n", "0 303.333333 5775.000000 5133.333333 11644.791667 \n", "1 3.750000 5.000000 35.833333 49.739583 \n", "2 -18.437500 -81.250000 -106.250000 -246.718750 \n", "3 51.187500 24.500000 210.000000 332.062500 \n", "4 13.125000 80.208333 69.270833 202.389323 \n", "\n", " geometry \n", "0 LINESTRING (34.86702 -19.83164, 34.86711 -19.8... \n", "1 LINESTRING (34.83997 -19.83592, 34.84019 -19.8... \n", "2 LINESTRING (34.84149 -19.83431, 34.84137 -19.8... \n", "3 LINESTRING (34.87145 -19.82349, 34.87126 -19.8... \n", "4 LINESTRING (34.85650 -19.83019, 34.85714 -19.8... \n", "\n", "[5 rows x 27 columns]" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "analysis_output_folder = root_dir / \"output\" / \"single_link_losses\" # specify path to output folder\n", "\n", "losses_gdf = gpd.read_file(analysis_output_folder/\"beira_single_losses.gpkg\") #specify the name of the geopackage holding your results (can be found in the analysis output folder)\n", "losses_gdf.head() #display the attributes of the file" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The map below displays the total loss for all trip types per link" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "losses_roads_map = losses_gdf.explore(column='vlh_EV1_ma_total', tiles=\"CartoDB positron\",)\n", "display(losses_roads_map)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "ra2ce_env", "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.10.13" } }, "nbformat": 4, "nbformat_minor": 2 }