{ "cells": [ { "cell_type": "markdown", "id": "118165e7", "metadata": { "papermill": { "duration": 0.002758, "end_time": "2025-06-18T09:40:36.082150", "exception": false, "start_time": "2025-06-18T09:40:36.079392", "status": "completed" }, "tags": [] }, "source": [ "# Combined pluvial and fluvial flood risk" ] }, { "cell_type": "markdown", "id": "c50e1894", "metadata": { "papermill": { "duration": 0.002359, "end_time": "2025-06-18T09:40:36.087124", "exception": false, "start_time": "2025-06-18T09:40:36.084765", "status": "completed" }, "tags": [] }, "source": [ "This example shows a workflow to derive pluvial and fluvial flood risk using the Wflow, SFINCS and Delft-FIAT models. The goal of the example is to show **how to combine different event sets** in the workflow. Note that both types of flood risk are assessed independently. Additional statistical analysis are needed to derive compound flood risk estimates. For more details about each step we refer the user to the pluvial flood risk or fluvial flood risk examples." ] }, { "cell_type": "code", "execution_count": 1, "id": "8bac2d94", "metadata": { "execution": { "iopub.execute_input": "2025-06-18T09:40:36.092525Z", "iopub.status.busy": "2025-06-18T09:40:36.092365Z", "iopub.status.idle": "2025-06-18T09:40:40.692237Z", "shell.execute_reply": "2025-06-18T09:40:40.691707Z" }, "papermill": { "duration": 4.6036, "end_time": "2025-06-18T09:40:40.693117", "exception": false, "start_time": "2025-06-18T09:40:36.089517", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO - log - hydroflows version: 0.1.0\n" ] } ], "source": [ "# Import packages\n", "from pathlib import Path\n", "\n", "from hydroflows import Workflow, WorkflowConfig\n", "from hydroflows.log import setuplog\n", "from hydroflows.methods import discharge, fiat, rainfall, sfincs, wflow\n", "from hydroflows.methods.utils.example_data import fetch_data\n", "\n", "logger = setuplog(level=\"INFO\")" ] }, { "cell_type": "code", "execution_count": 2, "id": "99d8e2a4", "metadata": { "execution": { "iopub.execute_input": "2025-06-18T09:40:40.699972Z", "iopub.status.busy": "2025-06-18T09:40:40.699130Z", "iopub.status.idle": "2025-06-18T09:40:40.702421Z", "shell.execute_reply": "2025-06-18T09:40:40.701956Z" }, "papermill": { "duration": 0.007198, "end_time": "2025-06-18T09:40:40.703232", "exception": false, "start_time": "2025-06-18T09:40:40.696034", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "# Define case name and root directory\n", "name = \"pluvial_fluvial_hazard\"\n", "pwd = Path().resolve() # Get the current file location\n", "case_root = Path(pwd, \"cases\", name) # output directory\n", "pwd_rel = \"../../\"" ] }, { "cell_type": "markdown", "id": "67ade9ab", "metadata": { "papermill": { "duration": 0.002517, "end_time": "2025-06-18T09:40:40.708379", "exception": false, "start_time": "2025-06-18T09:40:40.705862", "status": "completed" }, "tags": [] }, "source": [ "## Workflow inputs" ] }, { "cell_type": "code", "execution_count": 3, "id": "e258ce82", "metadata": { "execution": { "iopub.execute_input": "2025-06-18T09:40:40.714345Z", "iopub.status.busy": "2025-06-18T09:40:40.714037Z", "iopub.status.idle": "2025-06-18T09:44:19.826401Z", "shell.execute_reply": "2025-06-18T09:44:19.825901Z" }, "papermill": { "duration": 219.116293, "end_time": "2025-06-18T09:44:19.827349", "exception": false, "start_time": "2025-06-18T09:40:40.711056", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Downloading file 'global-data.tar.gz' from 'doi:10.5281/zenodo.14967510/global-data.tar.gz' to '/home/runner/.cache/hydroflows'.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Untarring contents of '/home/runner/.cache/hydroflows/global-data.tar.gz' to '/home/runner/.cache/hydroflows/global-data'\n" ] } ], "source": [ "# Fetch the global build data\n", "cache_dir = fetch_data(data=\"global-data\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "46abecd2", "metadata": { "execution": { "iopub.execute_input": "2025-06-18T09:44:19.833928Z", "iopub.status.busy": "2025-06-18T09:44:19.833719Z", "iopub.status.idle": "2025-06-18T09:44:19.837349Z", "shell.execute_reply": "2025-06-18T09:44:19.836973Z" }, "papermill": { "duration": 0.007791, "end_time": "2025-06-18T09:44:19.838095", "exception": false, "start_time": "2025-06-18T09:44:19.830304", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "config = WorkflowConfig(\n", " # general settings\n", " region=Path(pwd, \"data/build/region.geojson\"),\n", " catalog_path=Path(cache_dir, \"data_catalog.yml\"),\n", " plot_fig=True,\n", " start_date=\"2014-01-01\",\n", " end_date=\"2021-12-31\",\n", " # sfincs settings\n", " hydromt_sfincs_config=Path(pwd, \"hydromt_config/sfincs_config.yml\"),\n", " sfincs_exe=Path(pwd, \"bin/sfincs_v2.1.1/sfincs.exe\"),\n", " subgrid_output=True,\n", " src_points_output=True,\n", " # wflow settings\n", " hydromt_wflow_config=Path(pwd, \"hydromt_config/wflow_config.yml\"),\n", " wflow_exe=Path(pwd, \"bin/wflow_v0.8.1/bin/wflow_cli.exe\"),\n", " # fiat settings\n", " hydromt_fiat_config=Path(pwd, \"hydromt_config/fiat_config.yml\"),\n", " fiat_exe=Path(pwd, \"bin/fiat_v0.2.1/fiat.exe\"),\n", " risk=True,\n", " # design events settings\n", " rps=[5, 10, 25],\n", ")\n" ] }, { "cell_type": "markdown", "id": "af445632", "metadata": { "papermill": { "duration": 0.002539, "end_time": "2025-06-18T09:44:19.843241", "exception": false, "start_time": "2025-06-18T09:44:19.840702", "status": "completed" }, "tags": [] }, "source": [ "## Create the workflow" ] }, { "cell_type": "code", "execution_count": 5, "id": "51a1919d", "metadata": { "execution": { "iopub.execute_input": "2025-06-18T09:44:19.849037Z", "iopub.status.busy": "2025-06-18T09:44:19.848876Z", "iopub.status.idle": "2025-06-18T09:44:19.851502Z", "shell.execute_reply": "2025-06-18T09:44:19.851128Z" }, "papermill": { "duration": 0.00637, "end_time": "2025-06-18T09:44:19.852172", "exception": false, "start_time": "2025-06-18T09:44:19.845802", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "# create and empty workflow\n", "wf = Workflow(config=config, name=name, root=case_root)" ] }, { "cell_type": "markdown", "id": "0f927744", "metadata": { "papermill": { "duration": 0.002615, "end_time": "2025-06-18T09:44:19.857423", "exception": false, "start_time": "2025-06-18T09:44:19.854808", "status": "completed" }, "tags": [] }, "source": [ "### Build models\n", "\n", "In this section we build a model cascade and make sure these are configured correctly for offline coupling, i.e. Wflow exports discharge at the right locations and Delft-FIAT uses the same ground elevation as SFINCS. Note that you can also skip these steps and use your own models instead." ] }, { "cell_type": "code", "execution_count": 6, "id": "dea0ce67", "metadata": { "execution": { "iopub.execute_input": "2025-06-18T09:44:19.863434Z", "iopub.status.busy": "2025-06-18T09:44:19.863273Z", "iopub.status.idle": "2025-06-18T09:44:19.869912Z", "shell.execute_reply": "2025-06-18T09:44:19.869390Z" }, "papermill": { "duration": 0.010522, "end_time": "2025-06-18T09:44:19.870571", "exception": false, "start_time": "2025-06-18T09:44:19.860049", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/plain": [ "Rule(id=sfincs_build, method=sfincs_build, runs=1)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Build SFINCS model\n", "sfincs_build = sfincs.SfincsBuild(\n", " region=wf.get_ref(\"$config.region\"),\n", " config=wf.get_ref(\"$config.hydromt_sfincs_config\"),\n", " sfincs_root=\"models/sfincs\",\n", " catalog_path=wf.get_ref(\"$config.catalog_path\"),\n", " plot_fig=wf.get_ref(\"$config.plot_fig\"),\n", " subgrid_output=wf.get_ref(\"$config.subgrid_output\"),\n", " src_points_output=wf.get_ref(\"$config.src_points_output\"),\n", ")\n", "wf.create_rule(sfincs_build, rule_id=\"sfincs_build\")" ] }, { "cell_type": "code", "execution_count": 7, "id": "330ec56f", "metadata": { "execution": { "iopub.execute_input": "2025-06-18T09:44:19.876703Z", "iopub.status.busy": "2025-06-18T09:44:19.876547Z", "iopub.status.idle": "2025-06-18T09:44:19.880787Z", "shell.execute_reply": "2025-06-18T09:44:19.880416Z" }, "papermill": { "duration": 0.008198, "end_time": "2025-06-18T09:44:19.881586", "exception": false, "start_time": "2025-06-18T09:44:19.873388", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/plain": [ "Rule(id=wflow_build, method=wflow_build, runs=1)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Wflow build\n", "wflow_build = wflow.WflowBuild(\n", " region=sfincs_build.output.sfincs_region,\n", " wflow_root=\"models/wflow\",\n", " config=wf.get_ref(\"$config.hydromt_wflow_config\"),\n", " catalog_path=wf.get_ref(\"$config.catalog_path\"),\n", " gauges=sfincs_build.output.sfincs_src_points,\n", " plot_fig=wf.get_ref(\"$config.plot_fig\"),\n", ")\n", "wf.create_rule(wflow_build, rule_id=\"wflow_build\")\n" ] }, { "cell_type": "code", "execution_count": 8, "id": "dcc4edc3", "metadata": { "execution": { "iopub.execute_input": "2025-06-18T09:44:19.887995Z", "iopub.status.busy": "2025-06-18T09:44:19.887811Z", "iopub.status.idle": "2025-06-18T09:44:19.892332Z", "shell.execute_reply": "2025-06-18T09:44:19.891860Z" }, "papermill": { "duration": 0.008673, "end_time": "2025-06-18T09:44:19.893091", "exception": false, "start_time": "2025-06-18T09:44:19.884418", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/plain": [ "Rule(id=fiat_build, method=fiat_build, runs=1)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Fiat build\n", "fiat_build = fiat.FIATBuild(\n", " region=sfincs_build.output.sfincs_region,\n", " ground_elevation=sfincs_build.output.sfincs_subgrid_dep,\n", " fiat_root=\"models/fiat\",\n", " catalog_path=wf.get_ref(\"$config.catalog_path\"),\n", " config=wf.get_ref(\"$config.hydromt_fiat_config\"),\n", ")\n", "wf.create_rule(fiat_build, rule_id=\"fiat_build\")\n" ] }, { "cell_type": "markdown", "id": "d4bf4400", "metadata": { "papermill": { "duration": 0.002921, "end_time": "2025-06-18T09:44:19.899034", "exception": false, "start_time": "2025-06-18T09:44:19.896113", "status": "completed" }, "tags": [] }, "source": [ "### Derive fluvial design events from Wflow\n", "\n", "In this section we derive fluvial design events for each Wflow output gauge location." ] }, { "cell_type": "code", "execution_count": 9, "id": "f5ffc25a", "metadata": { "execution": { "iopub.execute_input": "2025-06-18T09:44:19.905690Z", "iopub.status.busy": "2025-06-18T09:44:19.905286Z", "iopub.status.idle": "2025-06-18T09:44:19.912650Z", "shell.execute_reply": "2025-06-18T09:44:19.912119Z" }, "papermill": { "duration": 0.011569, "end_time": "2025-06-18T09:44:19.913483", "exception": false, "start_time": "2025-06-18T09:44:19.901914", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO - wildcards - Added wildcard 'fluvial_events' with values: ['q_event_rp005', 'q_event_rp010', 'q_event_rp025']\n" ] }, { "data": { "text/plain": [ "Rule(id=fluvial_events, method=fluvial_design_events, runs=1, expand=['fluvial_events'])" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Update forcing\n", "wflow_update = wflow.WflowUpdateForcing(\n", " wflow_toml=wflow_build.output.wflow_toml,\n", " catalog_path=wf.get_ref(\"$config.catalog_path\"),\n", " start_time=wf.get_ref(\"$config.start_date\"),\n", " end_time=wf.get_ref(\"$config.end_date\"),\n", " output_dir=wflow_build.output.wflow_toml.parent/\"simulations\"/\"default\"\n", ")\n", "wf.create_rule(wflow_update, rule_id=\"wflow_update\")\n", "\n", "# Run wflow\n", "wflow_run = wflow.WflowRun(\n", " wflow_toml=wflow_update.output.wflow_out_toml,\n", " wflow_bin=wf.get_ref(\"$config.wflow_exe\"),\n", ")\n", "wf.create_rule(wflow_run, rule_id=\"wflow_run\")\n", "\n", "# Generate fluvial events\n", "fluvial_events = discharge.FluvialDesignEvents(\n", " discharge_nc=wflow_run.output.wflow_output_timeseries,\n", " rps=wf.get_ref(\"$config.rps\"),\n", " wildcard=\"fluvial_events\",\n", " event_root=\"data/events\",\n", " index_dim=\"Q_gauges_bounds\",\n", ")\n", "wf.create_rule(fluvial_events, rule_id=\"fluvial_events\")" ] }, { "cell_type": "markdown", "id": "50fc25bb", "metadata": { "papermill": { "duration": 0.00415, "end_time": "2025-06-18T09:44:19.922066", "exception": false, "start_time": "2025-06-18T09:44:19.917916", "status": "completed" }, "tags": [] }, "source": [ "### Derive pluvial design events\n", "\n", "Here we derive pluvial design events from ERA5 rainfall timeseries data." ] }, { "cell_type": "code", "execution_count": 10, "id": "3605ab33", "metadata": { "execution": { "iopub.execute_input": "2025-06-18T09:44:19.928872Z", "iopub.status.busy": "2025-06-18T09:44:19.928533Z", "iopub.status.idle": "2025-06-18T09:44:19.934514Z", "shell.execute_reply": "2025-06-18T09:44:19.934046Z" }, "papermill": { "duration": 0.010149, "end_time": "2025-06-18T09:44:19.935190", "exception": false, "start_time": "2025-06-18T09:44:19.925041", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO - wildcards - Added wildcard 'pluvial_events' with values: ['p_event_rp005', 'p_event_rp010', 'p_event_rp025']\n" ] }, { "data": { "text/plain": [ "Rule(id=pluvial_events, method=pluvial_design_events, runs=1, expand=['pluvial_events'])" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Pluvial events\n", "pluvial_data = rainfall.GetERA5Rainfall(\n", " region=sfincs_build.output.sfincs_region,\n", " output_dir=\"data/era5\",\n", " start_date=wf.get_ref(\"$config.start_date\"),\n", " end_date=wf.get_ref(\"$config.end_date\"),\n", ")\n", "wf.create_rule(pluvial_data, rule_id=\"pluvial_data\")\n", "\n", "# Actual derivation of events based on precip\n", "pluvial_events = rainfall.PluvialDesignEvents(\n", " precip_nc=pluvial_data.output.precip_nc,\n", " rps=wf.get_ref(\"$config.rps\"),\n", " wildcard=\"pluvial_events\",\n", " event_root=\"data/events\",\n", ")\n", "wf.create_rule(pluvial_events, rule_id=\"pluvial_events\")" ] }, { "cell_type": "markdown", "id": "aa6b2590", "metadata": { "papermill": { "duration": 0.003114, "end_time": "2025-06-18T09:44:19.941569", "exception": false, "start_time": "2025-06-18T09:44:19.938455", "status": "completed" }, "tags": [] }, "source": [ "### Combine event sets\n", "\n", "In order to run the SFINCS model for all events (pluvial and fluvial) and the Delft-FIAT model for both event sets, we need to combine all events into a new ``{all_events}`` wildcard and create a new ``{event_set}`` wildcard for both event sets." ] }, { "cell_type": "code", "execution_count": 11, "id": "8f9816d6", "metadata": { "execution": { "iopub.execute_input": "2025-06-18T09:44:19.948673Z", "iopub.status.busy": "2025-06-18T09:44:19.948394Z", "iopub.status.idle": "2025-06-18T09:44:19.952349Z", "shell.execute_reply": "2025-06-18T09:44:19.951895Z" }, "papermill": { "duration": 0.008402, "end_time": "2025-06-18T09:44:19.953138", "exception": false, "start_time": "2025-06-18T09:44:19.944736", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO - wildcards - Added wildcard 'all_events' with values: ['p_event_rp005', 'p_event_rp010', 'p_event_rp025', 'q_event_rp005', 'q_event_rp010', 'q_event_rp025']\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "INFO - wildcards - Added wildcard 'event_set' with values: ['fluvial_design_events', 'pluvial_design_events']\n" ] } ], "source": [ "# Combine fluvial and pluvial events into one set in order to run SFINCS for all in parallel\n", "all_events = wf.wildcards.get(\"pluvial_events\") + wf.wildcards.get(\"fluvial_events\")\n", "wf.wildcards.set(\"all_events\", all_events)\n", "\n", "# Set the combined event_set of both fluvial and pluvial\n", "wf.wildcards.set(\"event_set\", [\"fluvial_design_events\", \"pluvial_design_events\"])" ] }, { "cell_type": "markdown", "id": "dd2c325a", "metadata": { "papermill": { "duration": 0.00317, "end_time": "2025-06-18T09:44:19.959543", "exception": false, "start_time": "2025-06-18T09:44:19.956373", "status": "completed" }, "tags": [] }, "source": [ "### Derive flood hazard\n", "\n", "Here we update, run, and postprocess SFINCS for all events (combined pluvial and fluvial)" ] }, { "cell_type": "code", "execution_count": 12, "id": "a5eac82e", "metadata": { "execution": { "iopub.execute_input": "2025-06-18T09:44:19.966667Z", "iopub.status.busy": "2025-06-18T09:44:19.966363Z", "iopub.status.idle": "2025-06-18T09:44:19.974369Z", "shell.execute_reply": "2025-06-18T09:44:19.973971Z" }, "papermill": { "duration": 0.012357, "end_time": "2025-06-18T09:44:19.975076", "exception": false, "start_time": "2025-06-18T09:44:19.962719", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/plain": [ "Rule(id=sfincs_post, method=sfincs_postprocess, runs=6, repeat=['all_events'])" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Updating, running and postprocessing SFINCS model for combined events\n", "sfincs_update = sfincs.SfincsUpdateForcing(\n", " sfincs_inp=sfincs_build.output.sfincs_inp,\n", " event_yaml=\"data/events/{all_events}.yml\",\n", " output_dir=sfincs_build.output.sfincs_inp.parent/\"simulations\"/\"{all_events}\"\n", ")\n", "wf.create_rule(sfincs_update, rule_id=\"sfincs_update\")\n", "\n", "# Run SFINCS model\n", "sfincs_run = sfincs.SfincsRun(\n", " sfincs_inp=sfincs_update.output.sfincs_out_inp,\n", " sfincs_exe=wf.get_ref(\"$config.sfincs_exe\"),\n", ")\n", "wf.create_rule(sfincs_run, rule_id=\"sfincs_run\")\n", "\n", "# Postprocesses SFINCS results\n", "sfincs_post = sfincs.SfincsPostprocess(\n", " sfincs_map=sfincs_run.output.sfincs_map,\n", " event_name=\"{all_events}\",\n", ")\n", "wf.create_rule(sfincs_post, rule_id=\"sfincs_post\")" ] }, { "cell_type": "markdown", "id": "db54ee9d", "metadata": { "papermill": { "duration": 0.003246, "end_time": "2025-06-18T09:44:19.981594", "exception": false, "start_time": "2025-06-18T09:44:19.978348", "status": "completed" }, "tags": [] }, "source": [ "### Derive flood risk\n", "\n", "Here we calculate flood risk separately for each event set (fluvial and pluvial)." ] }, { "cell_type": "code", "execution_count": 13, "id": "1d42bc91", "metadata": { "execution": { "iopub.execute_input": "2025-06-18T09:44:19.988720Z", "iopub.status.busy": "2025-06-18T09:44:19.988581Z", "iopub.status.idle": "2025-06-18T09:44:19.995425Z", "shell.execute_reply": "2025-06-18T09:44:19.995035Z" }, "papermill": { "duration": 0.011257, "end_time": "2025-06-18T09:44:19.996141", "exception": false, "start_time": "2025-06-18T09:44:19.984884", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/plain": [ "Rule(id=fiat_visualize, method=fiat_visualize, runs=2, repeat=['event_set'])" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Update hazard\n", "fiat_update = fiat.FIATUpdateHazard(\n", " fiat_cfg=fiat_build.output.fiat_cfg,\n", " event_set_yaml=\"data/events/{event_set}.yml\",\n", " map_type=\"water_level\",\n", " hazard_maps=sfincs_post.output.sfincs_zsmax,\n", " risk=wf.get_ref(\"$config.risk\"),\n", " output_dir=fiat_build.output.fiat_cfg.parent/\"simulations\"/\"{event_set}\"\n", ")\n", "wf.create_rule(fiat_update, rule_id=\"fiat_update\")\n", "\n", "# Run FIAT\n", "fiat_run = fiat.FIATRun(\n", " fiat_cfg=fiat_update.output.fiat_out_cfg,\n", " fiat_exe=wf.get_ref(\"$config.fiat_exe\"),\n", ")\n", "wf.create_rule(fiat_run, rule_id=\"fiat_run\")\n", "\n", "# Visualize Fiat \n", "fiat_visualize = fiat.FIATVisualize(\n", " fiat_cfg=fiat_update.output.fiat_out_cfg,\n", " fiat_output_csv=fiat_run.output.fiat_out_csv,\n", " spatial_joins_cfg=fiat_build.output.spatial_joins_cfg, # aggregation level for visualization\n", " output_dir=\"output/risk\"\n", ")\n", "wf.create_rule(fiat_visualize, rule_id=\"fiat_visualize\")" ] }, { "cell_type": "markdown", "id": "58e15ed0", "metadata": { "papermill": { "duration": 0.003323, "end_time": "2025-06-18T09:44:20.002859", "exception": false, "start_time": "2025-06-18T09:44:19.999536", "status": "completed" }, "tags": [] }, "source": [ "## Visualize and execute the workflow\n", "\n", "To inspect the workflow we can plot the rulegraph which shows all rules their dependencies.\n", "The nodes are colored based on the type, for instance the red nodes show the result rules.\n" ] }, { "cell_type": "code", "execution_count": 14, "id": "83c2c41b", "metadata": { "execution": { "iopub.execute_input": "2025-06-18T09:44:20.010349Z", "iopub.status.busy": "2025-06-18T09:44:20.010031Z", "iopub.status.idle": "2025-06-18T09:44:20.044495Z", "shell.execute_reply": "2025-06-18T09:44:20.044077Z" }, "papermill": { "duration": 0.038941, "end_time": "2025-06-18T09:44:20.045196", "exception": false, "start_time": "2025-06-18T09:44:20.006255", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "pluvial_fluvial_hazard\n", "\n", "\n", "\n", "sfincs_build\n", "\n", "sfincs_build\n", " runs=1\n", "\n", "\n", "\n", "pluvial_data\n", "\n", "pluvial_data\n", " runs=1\n", "\n", "\n", "\n", "sfincs_build->pluvial_data\n", "\n", "\n", "\n", "\n", "\n", "fiat_build\n", "\n", "fiat_build\n", " runs=1\n", "\n", "\n", "\n", "sfincs_build->fiat_build\n", "\n", "\n", "\n", "\n", "\n", "wflow_build\n", "\n", "wflow_build\n", " runs=1\n", "\n", "\n", "\n", "sfincs_build->wflow_build\n", "\n", "\n", "\n", "\n", "\n", "sfincs_update\n", "\n", "sfincs_update\n", " runs=6\n", " repeat=['all_events']\n", "\n", "\n", "\n", "sfincs_build->sfincs_update\n", "\n", "\n", "\n", "\n", "\n", "pluvial_events\n", "\n", "pluvial_events\n", " runs=1\n", " expand=['pluvial_events']\n", "\n", "\n", "\n", "pluvial_data->pluvial_events\n", "\n", "\n", "\n", "\n", "\n", "pluvial_events->sfincs_update\n", "\n", "\n", "\n", "\n", "\n", "fiat_update\n", "\n", "fiat_update\n", " runs=2\n", " repeat=['event_set']\n", " reduce=['all_events']\n", "\n", "\n", "\n", "pluvial_events->fiat_update\n", "\n", "\n", "\n", "\n", "\n", "fiat_build->fiat_update\n", "\n", "\n", "\n", "\n", "\n", "fiat_visualize\n", "\n", "fiat_visualize\n", " runs=2\n", " repeat=['event_set']\n", "\n", "\n", "\n", "fiat_build->fiat_visualize\n", "\n", "\n", "\n", "\n", "\n", "wflow_update\n", "\n", "wflow_update\n", " runs=1\n", "\n", "\n", "\n", "wflow_build->wflow_update\n", "\n", "\n", "\n", "\n", "\n", "wflow_run\n", "\n", "wflow_run\n", " runs=1\n", "\n", "\n", "\n", "wflow_update->wflow_run\n", "\n", "\n", "\n", "\n", "\n", "fluvial_events\n", "\n", "fluvial_events\n", " runs=1\n", " expand=['fluvial_events']\n", "\n", "\n", "\n", "wflow_run->fluvial_events\n", "\n", "\n", "\n", "\n", "\n", "fluvial_events->sfincs_update\n", "\n", "\n", "\n", "\n", "\n", "fluvial_events->fiat_update\n", "\n", "\n", "\n", "\n", "\n", "sfincs_run\n", "\n", "sfincs_run\n", " runs=6\n", " repeat=['all_events']\n", "\n", "\n", "\n", "sfincs_update->sfincs_run\n", "\n", "\n", "\n", "\n", "\n", "sfincs_post\n", "\n", "sfincs_post\n", " runs=6\n", " repeat=['all_events']\n", "\n", "\n", "\n", "sfincs_run->sfincs_post\n", "\n", "\n", "\n", "\n", "\n", "sfincs_post->fiat_update\n", "\n", "\n", "\n", "\n", "\n", "fiat_run\n", "\n", "fiat_run\n", " runs=2\n", " repeat=['event_set']\n", "\n", "\n", "\n", "fiat_update->fiat_run\n", "\n", "\n", "\n", "\n", "\n", "fiat_update->fiat_visualize\n", "\n", "\n", "\n", "\n", "\n", "fiat_run->fiat_visualize\n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# plot the rulegraph using graphviz\n", "wf.plot_rulegraph(filename=\"rulegraph.svg\", plot_rule_attrs=True)" ] }, { "cell_type": "code", "execution_count": 15, "id": "49160eb2", "metadata": { "execution": { "iopub.execute_input": "2025-06-18T09:44:20.053480Z", "iopub.status.busy": "2025-06-18T09:44:20.053326Z", "iopub.status.idle": "2025-06-18T09:44:20.063549Z", "shell.execute_reply": "2025-06-18T09:44:20.063192Z" }, "papermill": { "duration": 0.015209, "end_time": "2025-06-18T09:44:20.064272", "exception": false, "start_time": "2025-06-18T09:44:20.049063", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO - workflow - Dryrun rule 1/14: sfincs_build (1 runs)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "INFO - workflow - Dryrun rule 2/14: pluvial_data (1 runs)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "INFO - workflow - Dryrun rule 3/14: pluvial_events (1 runs)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "INFO - workflow - Dryrun rule 4/14: fiat_build (1 runs)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "INFO - workflow - Dryrun rule 5/14: wflow_build (1 runs)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "INFO - workflow - Dryrun rule 6/14: wflow_update (1 runs)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "INFO - workflow - Dryrun rule 7/14: wflow_run (1 runs)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "INFO - workflow - Dryrun rule 8/14: fluvial_events (1 runs)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "INFO - workflow - Dryrun rule 9/14: sfincs_update (6 runs)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "INFO - workflow - Dryrun rule 10/14: sfincs_run (6 runs)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "INFO - workflow - Dryrun rule 11/14: sfincs_post (6 runs)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "INFO - workflow - Dryrun rule 12/14: fiat_update (2 runs)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "INFO - workflow - Dryrun rule 13/14: fiat_run (2 runs)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "INFO - workflow - Dryrun rule 14/14: fiat_visualize (2 runs)\n" ] } ], "source": [ "# Test the workflow\n", "wf.dryrun()" ] }, { "cell_type": "markdown", "id": "a41f8377", "metadata": { "papermill": { "duration": 0.00478, "end_time": "2025-06-18T09:44:20.073191", "exception": false, "start_time": "2025-06-18T09:44:20.068411", "status": "completed" }, "tags": [] }, "source": [ "The workflow can be executed using HydroFlows or a workflow engine. \n", "To run the workflow in HydroFlows use ``wf.run()``. \n", "To run the workflow with SnakeMake (preferred) use ``wf.to_snakemake()`` to create a snakemake file, see below.\n", "You can then use the Snakemake CLI to execute the workflow, see the [snakemake documentation](https://snakemake.readthedocs.io/en/stable/executing/cli.html)" ] }, { "cell_type": "code", "execution_count": 16, "id": "38a05756", "metadata": { "execution": { "iopub.execute_input": "2025-06-18T09:44:20.082158Z", "iopub.status.busy": "2025-06-18T09:44:20.081972Z", "iopub.status.idle": "2025-06-18T09:44:20.098449Z", "shell.execute_reply": "2025-06-18T09:44:20.098040Z" }, "papermill": { "duration": 0.021789, "end_time": "2025-06-18T09:44:20.099126", "exception": false, "start_time": "2025-06-18T09:44:20.077337", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "cases/pluvial_fluvial_hazard:\n", "- Snakefile\n", "- rulegraph.svg\n", "- Snakefile.config.yml\n" ] } ], "source": [ "# Write the workflow to a Snakefile\n", "wf.to_snakemake()\n", "\n", "# show the files in the case directory\n", "print(f\"{wf.root.relative_to(pwd)}:\")\n", "for f in wf.root.iterdir():\n", " print(f\"- {f.name}\")" ] }, { "cell_type": "code", "execution_count": 17, "id": "f5ad6bcb", "metadata": { "execution": { "iopub.execute_input": "2025-06-18T09:44:20.108053Z", "iopub.status.busy": "2025-06-18T09:44:20.107865Z", "iopub.status.idle": "2025-06-18T09:44:20.110387Z", "shell.execute_reply": "2025-06-18T09:44:20.109927Z" }, "papermill": { "duration": 0.007951, "end_time": "2025-06-18T09:44:20.111181", "exception": false, "start_time": "2025-06-18T09:44:20.103230", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "# uncomment to run the workflow with snakemake\n", "# import subprocess\n", "# subprocess.run([\"snakemake\", \"-c\", \"1\"], cwd=wf.root)" ] } ], "metadata": { "kernelspec": { "display_name": "full", "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.12" }, "papermill": { "default_parameters": {}, "duration": 225.52844, "end_time": "2025-06-18T09:44:20.831293", "environment_variables": {}, "exception": null, "input_path": "/home/runner/work/HydroFlows/HydroFlows/docs/../examples/pluvial_fluvial_risk.ipynb", "output_path": "/home/runner/work/HydroFlows/HydroFlows/docs/_examples/pluvial_fluvial_risk.ipynb", "parameters": {}, "start_time": "2025-06-18T09:40:35.302853", "version": "2.6.0" } }, "nbformat": 4, "nbformat_minor": 5 }