{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Hazard Overlay\n", "This tutorial guides you through performing a hazard overlay with a network using RA2CE.\n", "It assumes you already have a road network. If not, please first complete the [Network tutorial](network)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Hazard Map\n", "A hazard map is geospatial data representing the extent and severity of a hazard in a specific area. RA2CE supports raster formats such as GeoTIFF.\n", "\n", "> **Note:** RA2CE is hazard agnostic: any hazard that can be represented in a raster format (flood, landslide, wildfire) can be used." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## What is hazard overlay?\n", "The road network is represented as links and nodes, and the hazard map as a raster grid. By overlaying the network onto the hazard map, each road segment is assigned hazard values from the intersecting cells. This allows RA2CE to quantify network exposure and supports risk assessment and accessibility studies." ] }, { "cell_type": "code", "execution_count": null, "id": "8fba20ba", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Step 1. Import the Required Packages" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "import geopandas as gpd\n", "\n", "from ra2ce.network.network_config_data.enums.aggregate_wl_enum import AggregateWlEnum\n", "from ra2ce.network.network_config_data.network_config_data import (\n", " NetworkSection, NetworkConfigData, HazardSection, CleanupSection\n", ")\n", "from ra2ce.network.network_config_data.enums.source_enum import SourceEnum\n", "from ra2ce.ra2ce_handler import Ra2ceHandler\n", "\n", "# Root project directory\n", "root_dir = Path('data', 'hazard_overlay')\n", "network_path = root_dir / \"network\"\n", "hazard_path = root_dir / \"hazard\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Step 2. Define Network and Hazard Sections\n", "Specify the network and hazard map sections in the configuration. Provide the CRS of the hazard map and select an aggregation method for hazard values." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Define the network section\n", "network_section = NetworkSection(\n", " source=SourceEnum.SHAPEFILE,\n", " primary_file=network_path.joinpath(\"base_shapefile.shp\"),\n", " save_gpkg=True\n", ")\n", "\n", "# Define the hazard section\n", "hazard_section = HazardSection(\n", " hazard_map=[hazard_path.joinpath(\"max_flood_depth.tif\")],\n", " aggregate_wl=AggregateWlEnum.MEAN,\n", " hazard_crs=\"EPSG:32736\",\n", ")\n", "\n", "# Build the full configuration\n", "network_config_data = NetworkConfigData(\n", " root_path=root_dir,\n", " static_path=root_dir.joinpath('static'),\n", " network=network_section,\n", " hazard=hazard_section\n", ")" ] }, { "cell_type": "markdown", "id": "2afce395", "metadata": {}, "source": [ "The network is segment by default into 100m segments. This can be modified using the attribute `segmentation_length` from [CleanupSection](../api/ra2ce.network.network_config_data.html#ra2ce.network.network_config_data.network_config_data.CleanupSection){.api-ref}." ] }, { "cell_type": "code", "execution_count": null, "id": "17c243a7", "metadata": {}, "outputs": [], "source": [ "# Define the network section\n", "network_section = CleanupSection(\n", " segmentation_length=1000 # in meters\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Step 3. Initialize and Configure RA2CE\n", "Generate both the base network and the overlaid hazard network. Results will be stored in `static/output_graph`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "handler = Ra2ceHandler.from_config(network=network_config_data, analysis=None)\n", "handler.configure()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Step 4. Inspect Hazard Overlay Results\n", "Once the analysis is complete, hazard overlay results are stored in the `output_graph` folder. Files containing `_hazard` hold the overlay results for each road segment. For example, `EV1_ma` represents the maximum flood depth for Event 1." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "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.head()" ] } ], "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.11.13" } }, "nbformat": 4, "nbformat_minor": 5 }