{ "cells": [ { "cell_type": "markdown", "id": "9a73590b", "metadata": {}, "source": [ "## Build a Wflow sediment model" ] }, { "cell_type": "markdown", "id": "ee510c6e", "metadata": {}, "source": [ "This notebook demonstrates how to prepare a **Wflow sediment** model using the command line interace (CLI)." ] }, { "cell_type": "markdown", "id": "6b96aa15", "metadata": {}, "source": [ "All lines in this notebook which start with `!` are executed from the command line. Within the notebook environment the logging messages are shown after completion. You can also copy these lines and paste these in your shell to get more direct feedback." ] }, { "cell_type": "markdown", "id": "451c8168", "metadata": {}, "source": [ "### hydroMT CLI build interface" ] }, { "cell_type": "markdown", "id": "2c70853e", "metadata": {}, "source": [ "Lets first check if the Wflow sediment model is recognized by hydromt" ] }, { "cell_type": "code", "execution_count": null, "id": "40470302", "metadata": {}, "outputs": [], "source": [ "# this should return \"wflow, wflow_sediment\"\n", "!hydromt --models" ] }, { "cell_type": "markdown", "id": "7d9b5a20", "metadata": {}, "source": [ "Using the **hydromt build** API we can setup a complete model from scratch. Let's get an overview of all the available options:" ] }, { "cell_type": "code", "execution_count": null, "id": "1d39e4a1", "metadata": {}, "outputs": [], "source": [ "!hydromt build --help" ] }, { "cell_type": "markdown", "id": "ebd31242", "metadata": {}, "source": [ "### Model setup configuration" ] }, { "cell_type": "markdown", "id": "fb8282c9", "metadata": {}, "source": [ "The ini-file contains the model setup configuration and determines which components are build and in which order and optionally sets non-default arguments for each component. This configuration is passed to hydromt using `-i `. We have prepared several example ini-files which are available in the model repository [examples folder](https://github.com/Deltares/hydromt_wflow/tree/main/examples) and from the [docs(build_configuration)](https://deltares.github.io/hydromt_wflow/latest/user_guide/wflow/build_configuration.html). \n", "\n", "Each header as shown between `[...]` (e.g. `[setup_basemaps]`) corresponds to a model component. All model components are explained in the [docs(model_components)](https://deltares.github.io/hydromt_wflow/latest/user_guide/wflow/components.html). " ] }, { "cell_type": "markdown", "id": "cc3fd44d", "metadata": {}, "source": [ "We will load the default wflow sediment build ini file for inspection:" ] }, { "cell_type": "code", "execution_count": null, "id": "e88d4aed", "metadata": {}, "outputs": [], "source": [ "fn_ini = 'wflow_sediment_build.ini'\n", "with open(fn_ini, 'r') as f:\n", " txt = f.read()\n", "print(txt)" ] }, { "cell_type": "markdown", "id": "12860ed2", "metadata": {}, "source": [ "### Setup wflow sediment model from scratch" ] }, { "cell_type": "code", "execution_count": null, "id": "hundred-trailer", "metadata": { "scrolled": true }, "outputs": [], "source": [ "# NOTE: copy this line (without !) to your shell for more direct feedback\n", "!hydromt build wflow_sediment \"./wflow_test_sediment\" \"{'subbasin': [12.2051, 45.8331], 'strord': 4, 'bounds': [11.70, 45.35, 12.95, 46.70]}\" -r 0.00833 -i wflow_sediment_build.ini -vv" ] }, { "cell_type": "markdown", "id": "b31e92d2", "metadata": {}, "source": [ "The example above means the following: run **hydromt build** with:\n", "\n", "* `wflow_sediment` : i.e. build a wflow sediment model\n", "* `./wflow_test_sediment` : output model folder\n", "* `\"{'subbasin': [12.2051, 45.8331], 'strord': 4, 'bounds': [11.70, 45.35, 12.95, 46.70]}\"` : derive a subbasin with its outlet at the given x,y coordinates and within the given bounds [xmin, ymin, xmax, ymax] (WGS84) snapped to a river with minimum stream order (strord) of 4. All *REGION* options are described in the [docs](https://deltares.github.io/hydromt/latest/user_guide/cli.html#region-options)\n", "* `-r 0.0083333` : build the model at a 30 arc sec (~1km) resolution\n", "* `-i wflow_sediment_build.ini` : setup configuration file using\n", "* `-vv` : give some extra verbosity (2 * v) to display feedback on screen. Now debug messages are provided.\n" ] }, { "cell_type": "markdown", "id": "2eed76e4", "metadata": {}, "source": [ "Next we check which files have been created. The model root should contain two netcdf (.nc) files, one for the staticmaps and one for the forcing data, a wflow configuration (.toml) file. These files are sufficient to run the wflow sediment model. In addition several geometry (.geojson) files are saved in the *staticgeoms* folder. Finally, the setup process is logged in the hydromt.log file. " ] }, { "cell_type": "code", "execution_count": null, "id": "wireless-style", "metadata": {}, "outputs": [], "source": [ "import os\n", "root = 'wflow_test_sediment'\n", "for path, _, files in os.walk(root):\n", " print(path)\n", " for name in files:\n", " if name.endswith('.xml'):\n", " continue\n", " print(f' - {name}')" ] }, { "cell_type": "markdown", "id": "adef7fa1", "metadata": {}, "source": [ "### Visualize and/or inspect model schematization" ] }, { "cell_type": "markdown", "id": "20ce9df3", "metadata": {}, "source": [ "You can (copy and) adapt the following example notebooks in order to visualize your Wflow sediment model: \n", "\n", "* The **wflow plot** example notebook contains scripts to visualize your model\n", "* The **wflow nc to raster files** example notebook contains scripts to write the nc model files to a netcdf which can be used to inspect (and modify) the model layers in e.g. QGIS." ] }, { "cell_type": "markdown", "id": "01f1186a", "metadata": {}, "source": [ "### Add Wflow sediment layers to an existing Wflow model" ] }, { "cell_type": "markdown", "id": "6ca56c32", "metadata": {}, "source": [ "If you already have a hydrological **Wflow** model and you want to extend it in order to include **sediment** as well, then you do not need to build the wflow_sediment from scratch. You can instead **update** the wflow model with the additional components needed by wflow_sediment. \n", "\n", "These components are available in the template **wflow_extend_sediment.ini**:" ] }, { "cell_type": "code", "execution_count": null, "id": "fd79d798", "metadata": {}, "outputs": [], "source": [ "fn_ini = 'wflow_extend_sediment.ini'\n", "with open(fn_ini, 'r') as f:\n", " txt = f.read()\n", "print(txt)" ] }, { "cell_type": "markdown", "id": "7bd19d2b", "metadata": {}, "source": [ "Let's update the hydrological **Wflow** model available from our example for the Piave subbasin:" ] }, { "cell_type": "code", "execution_count": null, "id": "12142c2c", "metadata": {}, "outputs": [], "source": [ "# NOTE: copy this line (without !) to your shell for more direct feedback\n", "!hydromt update wflow_sediment \"wflow_piave_subbasin\" -o \"./wflow_test_extend_sediment\" -i wflow_extend_sediment.ini -vv" ] }, { "cell_type": "markdown", "id": "7e64ec0c", "metadata": {}, "source": [ "The example above means the following: run **hydromt update** with:\n", "\n", "* `wflow_sediment` : i.e. update a wflow_sediment model (in our case a wflow model but with wflow_sediment components)\n", "* `wflow_piave_subbasin` : hydrological wflow model folder\n", "* `-o \"./wflow_test_extend_sediment\"`: output combined wflow hydrology+sediment models\n", "* `-i wflow_extend_sediment.ini` : setup configuration file containing wflow sediment specific components\n", "* `-vv` : give some extra verbosity (2 * v) to display feedback on screen. Now debug messages are provided." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.9.2" } }, "nbformat": 4, "nbformat_minor": 5 }