This notebook demonstrates how to prepare Wflow model from scratch using the command line interace (CLI).
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.
Lets first check if the Wflow model is recognized by HydroMT
# this should return "wflow, wflow_sediment"
# as well as the generic HydroMT models "grid_model, lumped_model, network_model, (mesh_model)"
!hydromt --models
Using the HydroMT build API we can setup a complete model from scratch. Let's get an overview of all the available options:
!hydromt build --help
# NOTE: copy this line (without !) to your shell for more direct feedback
# NOTE: as of hydromt version 0.7.0 the region argument is optional and should be preceded by -r or --region
# NOTE: the resolution argument has been removed since hydromt v0.7.0 and can now only be configured from .ini file under the setup_basemap header
!hydromt build wflow "./wflow_test_base" -r "{'subbasin': [12.2051, 45.8331], 'strord': 4, 'bounds': [11.70, 45.35, 12.95, 46.70]}" -v -d artifact_data
The example above means the following: run hydromt build with:
wflow
: i.e. build a Wflow model./wflow_test_base
: output model folder-r "{'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-vv
: give some extra verbosity (2 * v) to display feedback on screen. Now debug messages are provided.NOTE: As we did not specify a model configuration, only the base maps (topography and hydrography) have been setup using default parameters. To build a complete model we need the use a configuraton ini-file.
The ini-file contains the model setup configuration and determines which methods are used to prepare the different components of a Wflow model and in which order and optionally sets non-default arguments for each method. This configuration is passed to HydroMT using -i <path_to_ini_file>
. We have prepared several example ini-files which are available in the model repository examples folder and from the docs (building a model).
Each header as shown between [...]
(e.g. [setup_basemaps]
) corresponds to a model method. All model methods are explained in the docs (model components).
We will load the default wflow build ini file for inspection:
fn_ini = "wflow_build.ini"
with open(fn_ini, "r") as f:
txt = f.read()
print(txt)
The <...>_fn
arguments correspond to a data source from the DataCatalog
which is based on a yml-file with references to the data paths/urls and how the data should be read. This file can be provided to hydromt using -d <path_to_yml_file>
.
By default, the pre-defined artifact_data
catalog containing some example data for the Piave basin will be downloaded to ~/.hydromt_data/
which is also used for this example. An overview of the available example data is provided here
This example data is a based on the data which is available from the Deltares p-drive.
If you have acces to this drive, a pre-configured catalog file can be loaded using the -d deltares_data
pre-defined catalog.
More background how to write a data catalog yml file can be found in the HydroMT core docs
# NOTE: copy this line (without !) to your shell for more direct feedback
!hydromt build wflow "./wflow_test_full" -r "{'subbasin': [12.2051, 45.8331], 'strord': 4, 'bounds': [11.70, 45.35, 12.95, 46.70]}" -i wflow_build.ini -d artifact_data -vv
With this example we build a complete Wflow model including forcing. Compared to the previous hydromt build we have added:
-i wflow_build.ini
: setup configuration file including all components to build and their argumentsNext 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 model. In addition several geometry (.geojson) files are saved in the staticgeoms folder. Finally, the setup process is logged in the hydromt.log file.
import os
root = "wflow_test_full"
for path, _, files in os.walk(root):
print(path)
for name in files:
if name.endswith(".xml"):
continue
print(f" - {name}")