Tip

For an interactive online version click here: Binder badge

Build a Wflow Sediment model#

This notebook demonstrates how to prepare a Wflow Sediment model 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.

HydroMT CLI build interface#

Lets first check if the Wflow sediment model is recognized by HydroMT

[1]:
# this should return "wflow, wflow_sediment"
!hydromt --models
hydroMT model plugins: wflow (v0.2.1.dev0), wflow_sediment (v0.2.1.dev0)

Using the HydroMT build API we can setup a complete model from scratch. Let’s get an overview of all the available options:

[2]:
!hydromt build --help
Usage: hydromt build [OPTIONS] MODEL MODEL_ROOT REGION

  Build models from scratch.

  Example usage:
  --------------

  To build a wflow model for a subbasin using and point coordinates snapped to cells with stream order >= 4
  hydromt build wflow /path/to/model_root "{'subbasin': [-7.24, 62.09], 'strord': 4}" -i /path/to/wflow_config.ini -d deltares_data -d /path/to/data_catalog.yml -v

  To build a sfincs model based on a bbox
  hydromt build sfincs /path/to/model_root "{'bbox': [4.6891,52.9750,4.9576,53.1994]}" -i /path/to/sfincs_config.ini -d /path/to/data_catalog.yml -v

Options:
  -r, --res FLOAT             Model resolution in model src.
  --build-base / --build-all  Deprecated!
  --opt TEXT                  Method specific keyword arguments, see the
                              method documentation of the specific model for
                              more information about the arguments.
  -i, --config PATH           Path to hydroMT configuration file, for the
                              model specific implementation.
  -d, --data TEXT             Path to local yaml data catalog file OR name of
                              predefined data catalog.
  --dd, --deltares-data       Shortcut to add the "deltares_data" catalog
  -q, --quiet                 Decrease verbosity.
  -v, --verbose               Increase verbosity.
  --help                      Show this message and exit.

Model setup configuration#

The ini-file contains the model setup configuration and determines which methods are used to prepare the different components of a Wflow Sediment 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 methods).

We will load the default wflow sediment build ini file for inspection:

[3]:
fn_ini = "wflow_sediment_build.ini"
with open(fn_ini, "r") as f:
    txt = f.read()
print(txt)
[global]
data_libs        = []               # add optional paths to data yml files

[setup_config]                      # options parsed to wflow ini file <section>.<option>
starttime = 2010-01-01T00:00:00
endtime = 2010-03-31T00:00:00
timestepsecs = 86400

[setup_basemaps]
hydrography_fn   = merit_hydro      # source hydrography data {merit_hydro, merit_hydro_1k}
basin_index_fn   = merit_hydro_index # source of basin index corresponding to hydrography_fn
upscale_method   = ihu              # upscaling method for flow direction data, by default 'ihu'

[setup_rivers]
hydrography_fn   = merit_hydro      # source hydrography data, should correspond to hydrography_fn in setup_basemaps
river_geom_fn    = rivers_lin2019_v1 # river source data with river width and bankfull discharge
river_upa        = 30               # minimum upstream area threshold for the river map [km2]
rivdph_method    = powlaw           # method to estimate depth {'powlaw', 'manning', 'gvf'}
min_rivdph       = 1                # minimum river depth [m]
min_rivwth       = 30               # minimum river width [m]
slope_len        = 2000             # length over which tp calculate river slope [m]
smooth_len       = 5000             # length over which to smooth river depth and river width [m]

[setup_reservoirs]
reservoirs_fn    = hydro_reservoirs # source for reservoirs based on GRAND: {hydro_reservoirs}; None to skip
min_area         = 1.0              # minimum lake area to consider [km2]
priority_jrc     = True             # if True then JRC data from hydroengine is used to calculate some reservoir attributes instead of the GRanD and HydroLAKES db.

[setup_lakes]
lakes_fn         = hydro_lakes      # source for lakes based on hydroLAKES: {hydro_lakes}; None to skip
min_area         = 1.0              # minimum reservoir area to consider [km2]

[setup_riverbedsed]
bedsed_mapping_fn = None             # path to a mapping csv file from streamorder to river bed particles characteristics

[setup_lulcmaps]
lulc_fn          = globcover        # source for lulc maps: {globcover, vito, corine}

[setup_laimaps]
lai_fn           = modis_lai        # source for LAI: {modis_lai}

[setup_canopymaps]
canopy_fn        = simard           # source for vegetation canopy height: {simard}

[setup_soilmaps]
soil_fn          = soilgrids        # source for soilmaps: {soilgrids}
usleK_method     = renard           # method to compute the USLE K factor: {renard, epic}

[setup_hydrodem]                 # adds hydrologically conditioned elevation FloodplainZ

[setup_gauges]
gauges_fn        = grdc             # If not None add gaugemap. Either a path or known gauges_fn: {grdc}
snap_to_river    = True             # If True snaps gauges from source to river
derive_subcatch  = False            # if True derive subcatch map based on gauges.

[setup_constant_pars]               # constant parameters values
c_Bagnold = 0.0000175
eros_expo = 1.5
eros_ov = 0.9
eros_spl_EUROSEM = 2.0
exp_Bagnold = 1.4
ResTrapEff = 1.0

Setup Wflow Sediment model from scratch#

[4]:
# NOTE: copy this line (without !) to your shell for more direct feedback
!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
2022-08-10 11:48:29,757 - build - log - DEBUG - Writing log messages to new file /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_test_sediment/hydromt.log.
2022-08-10 11:48:29,758 - build - log - INFO - HydroMT version: 0.5.1.dev
2022-08-10 11:48:29,758 - build - main - INFO - Building instance of wflow_sediment model at /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_test_sediment.
2022-08-10 11:48:29,758 - build - main - INFO - User settings:
2022-08-10 11:48:29,766 - build - model_plugins - DEBUG - Loaded model plugin 'wflow_sediment = hydromt_wflow.wflow_sediment.WflowSedimentModel' (0.2.1.dev0)
2022-08-10 11:48:29,766 - build - model_api - INFO - Initializing wflow_sediment model from hydromt_wflow (v0.2.1.dev0).
2022-08-10 11:48:29,766 - build - model_api - ERROR - missing required argument cfdict for setup_config
2022-08-10 11:48:29,766 - build - model_api - DEBUG - Setting model config options.
2022-08-10 11:48:29,769 - build - model_api - DEBUG - Default config read from /usr/share/miniconda/envs/hydromt-wflow/lib/python3.9/site-packages/hydromt_wflow/data/wflow_sediment/wflow_sediment.toml
2022-08-10 11:48:29,769 - build - model_api - INFO - setup_basemaps.region: {'subbasin': [12.2051, 45.8331], 'strord': 4, 'bounds': [11.7, 45.35, 12.95, 46.7]}
2022-08-10 11:48:29,769 - build - model_api - INFO - setup_basemaps.res: 0.00833
2022-08-10 11:48:29,769 - build - model_api - INFO - setup_basemaps.hydrography_fn: merit_hydro
2022-08-10 11:48:29,769 - build - model_api - INFO - setup_basemaps.basin_index_fn: merit_hydro_index
2022-08-10 11:48:29,769 - build - model_api - INFO - setup_basemaps.upscale_method: ihu
2022-08-10 11:48:29,769 - build - wflow - INFO - Preparing base hydrography basemaps.
2022-08-10 11:48:29,872 - build - data_catalog - INFO - Reading data catalog artifact_data v0.0.6 from archive
2022-08-10 11:48:29,872 - build - data_catalog - INFO - Parsing data catalog from /home/runner/.hydromt_data/artifact_data/v0.0.6/data_catalog.yml
2022-08-10 11:48:29,938 - build - data_catalog - INFO - DataCatalog: Getting merit_hydro RasterDataset raster data from /home/runner/.hydromt_data/artifact_data/v0.0.6/merit_hydro/{variable}.tif
2022-08-10 11:48:30,060 - build - basin_mask - DEBUG - Parsed region (kind=subbasin): {'strord': 4, 'bounds': [11.7, 45.35, 12.95, 46.7], 'xy': [12.2051, 45.8331]}
2022-08-10 11:48:33,533 - build - basin_mask - INFO - subbasin bbox: [11.7750, 45.8042, 12.7450, 46.6900]
2022-08-10 11:48:33,605 - build - wflow - DEBUG - Adding basins vector to staticgeoms.
2022-08-10 11:48:33,605 - build - basemaps - DEBUG - Mask in dataset assumed to represent subbasins.
2022-08-10 11:48:33,606 - build - basemaps - DEBUG - (Sub)basin at original resolution has 664756 cells.
2022-08-10 11:48:33,742 - build - basemaps - DEBUG - Burn subbasin outlet in upstream area data.
2022-08-10 11:48:33,780 - build - basemaps - INFO - Upscale flow direction data: 10x, ihu method.
2022-08-10 11:48:48,514 - build - basemaps - DEBUG - Derive stream order.
2022-08-10 11:48:48,728 - build - basemaps - DEBUG - Map shape: (106, 116); active cells: 6637.
2022-08-10 11:48:48,728 - build - basemaps - DEBUG - Outlet coordinates (1/1): (12.20750,45.83583).
2022-08-10 11:48:48,795 - build - wflow - DEBUG - Adding region vector to staticgeoms.
2022-08-10 11:48:48,799 - build - model_api - INFO - setup_rivers.hydrography_fn: merit_hydro
2022-08-10 11:48:48,799 - build - model_api - INFO - setup_rivers.river_geom_fn: rivers_lin2019_v1
2022-08-10 11:48:48,799 - build - model_api - INFO - setup_rivers.river_upa: 30
2022-08-10 11:48:48,799 - build - model_api - INFO - setup_rivers.rivdph_method: powlaw
2022-08-10 11:48:48,799 - build - model_api - INFO - setup_rivers.slope_len: 2000
2022-08-10 11:48:48,799 - build - model_api - INFO - setup_rivers.min_rivlen_ratio: 0.1
2022-08-10 11:48:48,799 - build - model_api - INFO - setup_rivers.min_rivdph: 1
2022-08-10 11:48:48,799 - build - model_api - INFO - setup_rivers.min_rivwth: 30
2022-08-10 11:48:48,799 - build - model_api - INFO - setup_rivers.smooth_len: 5000
2022-08-10 11:48:48,799 - build - model_api - INFO - setup_rivers.rivman_mapping_fn: /usr/share/miniconda/envs/hydromt-wflow/lib/python3.9/site-packages/hydromt_wflow/data/wflow/N_river_mapping.csv
2022-08-10 11:48:48,799 - build - wflow - INFO - Preparing river maps.
2022-08-10 11:48:48,799 - build - data_catalog - INFO - DataCatalog: Getting merit_hydro RasterDataset raster data from /home/runner/.hydromt_data/artifact_data/v0.0.6/merit_hydro/{variable}.tif
2022-08-10 11:48:48,884 - build - rasterdataset - DEBUG - RasterDataset: Clip with geom - [11.778, 45.807, 12.745, 46.690]
2022-08-10 11:48:48,898 - build - river - DEBUG - Set river mask (min uparea: 30 km2) and prepare flow dirs.
2022-08-10 11:48:49,068 - build - river - DEBUG - Derive river length.
2022-08-10 11:48:54,686 - build - river - DEBUG - Derive river slope.
2022-08-10 11:48:55,289 - build - river - DEBUG - Derive rivwth from hydrography dataset.
2022-08-10 11:48:55,327 - build - landuse - INFO - Deriving N_River using average resampling (nodata=-999.0).
2022-08-10 11:48:55,338 - build - data_catalog - INFO - DataCatalog: Getting rivers_lin2019_v1 GeoDataFrame vector data from /home/runner/.hydromt_data/artifact_data/v0.0.6/rivers_lin2019_v1.gpkg
2022-08-10 11:48:55,339 - build - geodataframe - INFO - GeoDataFrame: Read vector data and clip to geom (epsg:4326) [11.778, 45.807, 12.745, 46.690].
2022-08-10 11:48:55,550 - build - river - DEBUG - Derive ['rivwth', 'qbankfull'] from shapefile.
2022-08-10 11:48:55,639 - build - river - DEBUG - Valid for 381/655 river cells (max dist: 392 m).
2022-08-10 11:48:57,523 - build - wflow - DEBUG - Adding rivers vector to staticgeoms.
2022-08-10 11:48:58,218 - build - model_api - INFO - setup_reservoirs.reservoirs_fn: hydro_reservoirs
2022-08-10 11:48:58,218 - build - model_api - INFO - setup_reservoirs.min_area: 1.0
2022-08-10 11:48:58,219 - build - model_api - INFO - setup_reservoirs.priority_jrc: True
2022-08-10 11:48:58,219 - build - wflow - INFO - Preparing reservoir maps.
2022-08-10 11:48:58,219 - build - data_catalog - INFO - DataCatalog: Getting hydro_reservoirs GeoDataFrame vector data from /home/runner/.hydromt_data/artifact_data/v0.0.6/hydro_reservoirs.gpkg
2022-08-10 11:48:58,221 - build - geodataframe - INFO - GeoDataFrame: Read vector data and clip to geom (epsg:4326) [11.775, 45.804, 12.745, 46.690].
2022-08-10 11:48:58,248 - build - geodataframe - DEBUG - GeoDataFrame: Convert units for 5 columns.
2022-08-10 11:48:58,252 - build - wflow - WARNING - No reservoirs of sufficient size found within region! Skipping reservoir procedures!
2022-08-10 11:48:58,252 - build - model_api - INFO - setup_lakes.lakes_fn: hydro_lakes
2022-08-10 11:48:58,252 - build - model_api - INFO - setup_lakes.min_area: 1.0
2022-08-10 11:48:58,252 - build - wflow - INFO - Preparing lake maps.
2022-08-10 11:48:58,252 - build - data_catalog - INFO - DataCatalog: Getting hydro_lakes GeoDataFrame vector data from /home/runner/.hydromt_data/artifact_data/v0.0.6/hydro_lakes.gpkg
2022-08-10 11:48:58,254 - build - geodataframe - INFO - GeoDataFrame: Read vector data and clip to geom (epsg:4326) [11.775, 45.804, 12.745, 46.690].
2022-08-10 11:48:58,275 - build - geodataframe - DEBUG - GeoDataFrame: Convert units for 1 columns.
2022-08-10 11:48:58,277 - build - wflow - INFO - 1 lake(s) of sufficient size found within region.
2022-08-10 11:48:58,284 - build - waterbodies - DEBUG - Setting lake outlet map based maximum upstream area.
2022-08-10 11:48:58,346 - build - model_api - INFO - setup_riverbedsed.bedsed_mapping_fn: None
2022-08-10 11:48:58,346 - build - wflow_sediment - INFO - Preparing riverbedsed parameter maps.
2022-08-10 11:48:58,354 - build - landuse - INFO - Deriving D50_River using average resampling (nodata=-999.0).
2022-08-10 11:48:58,364 - build - landuse - INFO - Deriving ClayF_River using average resampling (nodata=-999.0).
2022-08-10 11:48:58,374 - build - landuse - INFO - Deriving SiltF_River using average resampling (nodata=-999.0).
2022-08-10 11:48:58,384 - build - landuse - INFO - Deriving SandF_River using average resampling (nodata=-999.0).
2022-08-10 11:48:58,394 - build - landuse - INFO - Deriving GravelF_River using average resampling (nodata=-999.0).
2022-08-10 11:48:58,410 - build - model_api - INFO - setup_lulcmaps.lulc_fn: globcover
2022-08-10 11:48:58,410 - build - model_api - INFO - setup_lulcmaps.lulc_mapping_fn: None
2022-08-10 11:48:58,410 - build - model_api - INFO - setup_lulcmaps.lulc_vars: ['landuse', 'Cov_River', 'Kext', 'N', 'PathFrac', 'Sl', 'Swood', 'USLE_C', 'WaterFrac']
2022-08-10 11:48:58,410 - build - wflow - INFO - Preparing LULC parameter maps.
2022-08-10 11:48:58,410 - build - data_catalog - INFO - DataCatalog: Getting globcover RasterDataset raster data from /home/runner/.hydromt_data/artifact_data/v0.0.6/globcover.tif
2022-08-10 11:48:58,424 - build - rasterdataset - DEBUG - RasterDataset: Clip with geom - [11.778, 45.807, 12.745, 46.690]
2022-08-10 11:48:58,441 - build - landuse - INFO - Deriving landuse using nearest resampling (nodata=230).
2022-08-10 11:48:58,481 - build - landuse - INFO - Deriving Cov_River using average resampling (nodata=-999.0).
2022-08-10 11:48:58,520 - build - landuse - INFO - Deriving Kext using average resampling (nodata=-999.0).
2022-08-10 11:48:58,560 - build - landuse - INFO - Deriving N using average resampling (nodata=-999.0).
2022-08-10 11:48:58,599 - build - landuse - INFO - Deriving PathFrac using average resampling (nodata=-999.0).
2022-08-10 11:48:58,639 - build - landuse - INFO - Deriving Sl using average resampling (nodata=-999.0).
2022-08-10 11:48:58,679 - build - landuse - INFO - Deriving Swood using average resampling (nodata=-999.0).
2022-08-10 11:48:58,718 - build - landuse - INFO - Deriving USLE_C using average resampling (nodata=-999.0).
2022-08-10 11:48:58,757 - build - landuse - INFO - Deriving WaterFrac using average resampling (nodata=-999.0).
2022-08-10 11:48:58,809 - build - model_api - INFO - setup_laimaps.lai_fn: modis_lai
2022-08-10 11:48:58,809 - build - wflow - INFO - Preparing LAI maps.
2022-08-10 11:48:58,809 - build - data_catalog - INFO - DataCatalog: Getting modis_lai RasterDataset netcdf data from /home/runner/.hydromt_data/artifact_data/v0.0.6/modis_lai.nc
2022-08-10 11:48:58,819 - build - rasterdataset - DEBUG - RasterDataset: Clip with geom - [11.778, 45.807, 12.745, 46.690]
2022-08-10 11:48:58,830 - build - rasterdataset - DEBUG - RasterDataset: Convert units for 1 variables.
2022-08-10 11:48:58,835 - build - landuse - INFO - Deriving LAI using average resampling (nodata=nan).
2022-08-10 11:48:58,883 - build - model_api - INFO - setup_canopymaps.canopy_fn: simard
2022-08-10 11:48:58,884 - build - wflow_sediment - INFO - Preparing canopy height map.
2022-08-10 11:48:58,884 - build - data_catalog - INFO - DataCatalog: Getting simard RasterDataset raster data from /home/runner/.hydromt_data/artifact_data/v0.0.6/simard.tif
2022-08-10 11:48:58,897 - build - rasterdataset - DEBUG - RasterDataset: Clip with geom - [11.778, 45.807, 12.745, 46.690]
2022-08-10 11:48:58,937 - build - model_api - INFO - setup_soilmaps.soil_fn: soilgrids
2022-08-10 11:48:58,937 - build - model_api - INFO - setup_soilmaps.usleK_method: renard
2022-08-10 11:48:58,937 - build - wflow_sediment - INFO - Preparing soil parameter maps.
2022-08-10 11:48:58,938 - build - data_catalog - INFO - DataCatalog: Getting soilgrids RasterDataset raster data from /home/runner/.hydromt_data/artifact_data/v0.0.6/soilgrids/{variable}.tif
2022-08-10 11:48:59,352 - build - rasterdataset - DEBUG - RasterDataset: Clip with geom - [11.778, 45.807, 12.745, 46.690]
2022-08-10 11:48:59,372 - build - rasterdataset - DEBUG - RasterDataset: Convert units for 21 variables.
2022-08-10 11:48:59,820 - build - soilgrids - INFO - Interpolate NAN values for PercentClay
2022-08-10 11:48:59,841 - build - soilgrids - INFO - Interpolate NAN values for PercentSilt
2022-08-10 11:48:59,861 - build - soilgrids - INFO - Interpolate NAN values for PercentOC
2022-08-10 11:48:59,887 - build - soilgrids - INFO - Interpolate NAN values for ErosK
2022-08-10 11:48:59,917 - build - soilgrids - INFO - Interpolate NAN values for USLE_K
2022-08-10 11:48:59,928 - build - model_api - INFO - setup_hydrodem.elevtn_map: wflow_dem
2022-08-10 11:48:59,928 - build - model_api - INFO - setup_hydrodem.river_routing: local-inertial
2022-08-10 11:48:59,928 - build - model_api - INFO - setup_hydrodem.land_routing: kinematic-wave
2022-08-10 11:48:59,928 - build - wflow - INFO - Preparing hydrodem_avg map for routing.
2022-08-10 11:48:59,928 - build - wflow - INFO - Preparing hydrodem_avg_D8 map for routing.
2022-08-10 11:48:59,958 - build - flw - INFO - Condition elevation to D8 flow directions.
2022-08-10 11:49:03,577 - build - wflow - DEBUG - Update wflow config model.river_routing="local-inertial"
2022-08-10 11:49:03,577 - build - wflow - DEBUG - Update wflow config model.land_routing="kinematic-wave"
2022-08-10 11:49:03,577 - build - main - ERROR - 'land'
Traceback (most recent call last):
  File "/usr/share/miniconda/envs/hydromt-wflow/lib/python3.9/site-packages/hydromt/cli/main.py", line 193, in build
    mod.build(region, res, opt=opt)
  File "/usr/share/miniconda/envs/hydromt-wflow/lib/python3.9/site-packages/hydromt/models/model_api.py", line 187, in build
    self._run_log_method(method, **opt[method])
  File "/usr/share/miniconda/envs/hydromt-wflow/lib/python3.9/site-packages/hydromt/models/model_api.py", line 124, in _run_log_method
    return func(*args, **kwargs)
  File "/usr/share/miniconda/envs/hydromt-wflow/lib/python3.9/site-packages/hydromt_wflow/wflow.py", line 475, in setup_hydrodem
    self.config["state"]["lateral"]["land"].pop("qx", None)
KeyError: 'land'
Traceback (most recent call last):
  File "/usr/share/miniconda/envs/hydromt-wflow/bin/hydromt", line 8, in <module>
    sys.exit(main())
  File "/usr/share/miniconda/envs/hydromt-wflow/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/share/miniconda/envs/hydromt-wflow/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/share/miniconda/envs/hydromt-wflow/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/share/miniconda/envs/hydromt-wflow/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/share/miniconda/envs/hydromt-wflow/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/share/miniconda/envs/hydromt-wflow/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/share/miniconda/envs/hydromt-wflow/lib/python3.9/site-packages/hydromt/cli/main.py", line 193, in build
    mod.build(region, res, opt=opt)
  File "/usr/share/miniconda/envs/hydromt-wflow/lib/python3.9/site-packages/hydromt/models/model_api.py", line 187, in build
    self._run_log_method(method, **opt[method])
  File "/usr/share/miniconda/envs/hydromt-wflow/lib/python3.9/site-packages/hydromt/models/model_api.py", line 124, in _run_log_method
    return func(*args, **kwargs)
  File "/usr/share/miniconda/envs/hydromt-wflow/lib/python3.9/site-packages/hydromt_wflow/wflow.py", line 475, in setup_hydrodem
    self.config["state"]["lateral"]["land"].pop("qx", None)
KeyError: 'land'
malloc(): unsorted double linked list corrupted
Aborted (core dumped)

The example above means the following: run hydromt build with:

  • wflow_sediment : i.e. build a wflow sediment model

  • ./wflow_test_sediment : output model folder

  • "{'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

  • -r 0.0083333 : build the model at a 30 arc sec (~1km) resolution

  • -i wflow_sediment_build.ini : setup configuration file using

  • -vv : give some extra verbosity (2 * v) to display feedback on screen. Now debug messages are provided.

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.

[5]:
import os

root = "wflow_test_sediment"
for path, _, files in os.walk(root):
    print(path)
    for name in files:
        if name.endswith(".xml"):
            continue
        print(f" - {name}")
wflow_test_sediment
 - hydromt.log
wflow_test_sediment/run_default
wflow_test_sediment/instate
wflow_test_sediment/staticgeoms

Visualize and/or inspect model schematization#

You can (copy and) adapt the following example notebooks in order to visualize your Wflow Sediment model:

  • The wflow plot example notebook contains scripts to visualize your model

  • 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.

Add Wflow Sediment layers to an existing Wflow model#

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.

These components are available in the template wflow_extend_sediment.ini:

[6]:
fn_ini = "wflow_extend_sediment.ini"
with open(fn_ini, "r") as f:
    txt = f.read()
print(txt)
[global]
data_libs        = []               # add optional paths to data yml files

[setup_config]
# model.dolake = True               # uncomment if there are lakes in the wflow model
# model.doreservoir = True          # uncomment if there are reservoirs in the wflow model

[setup_riverbedsed]
bedsed_mapping_fn   = None             # path to a mapping csv file from streamorder to river bed particles characteristics

[setup_lulcmaps]
lulc_fn          = globcover        # source for lulc maps: {globcover, vito, corine}

[setup_canopymaps]
canopy_fn        = simard           # source for vegetation canopy height: {simard}

[setup_soilmaps]
soil_fn          = soilgrids        # source for soilmaps: {soilgrids}
usleK_method     = renard           # method to compute the USLE K factor: {renard, epic}

[setup_gauges]
gauges_fn        = grdc             # If not None add gaugemap. Either a path or known gauges_fn: {grdc}
snap_to_river    = True             # If True snaps gauges from source to river
derive_subcatch  = False            # if True derive subcatch map based on gauges.

[setup_constant_pars]               # constant parameters values
c_Bagnold = 0.0000175
eros_expo = 1.5
eros_ov = 0.9
eros_spl_EUROSEM = 2.0
exp_Bagnold = 1.4
ResTrapEff = 1.0

Let’s update the hydrological Wflow model available from our example for the Piave subbasin:

[7]:
# NOTE: copy this line (without !) to your shell for more direct feedback
!hydromt update wflow_sediment "wflow_piave_subbasin" -o "./wflow_test_extend_sediment" -i wflow_extend_sediment.ini -vv
2022-08-10 11:49:06,679 - update - log - DEBUG - Writing log messages to new file /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_test_extend_sediment/hydromt.log.
2022-08-10 11:49:06,679 - update - log - INFO - HydroMT version: 0.5.1.dev
2022-08-10 11:49:06,680 - update - main - INFO - Updating wflow_sediment model at /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_piave_subbasin (r).
2022-08-10 11:49:06,680 - update - main - INFO - Output dir: /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_test_extend_sediment
2022-08-10 11:49:06,680 - update - main - INFO - User settings:
2022-08-10 11:49:06,686 - update - model_plugins - DEBUG - Loaded model plugin 'wflow_sediment = hydromt_wflow.wflow_sediment.WflowSedimentModel' (0.2.1.dev0)
2022-08-10 11:49:06,686 - update - log - DEBUG - Writing log messages to new file /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_piave_subbasin/hydromt.log.
2022-08-10 11:49:06,687 - update - model_api - INFO - Initializing wflow_sediment model from hydromt_wflow (v0.2.1.dev0).
2022-08-10 11:49:06,687 - update - model_api - ERROR - Model config file not found at /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_piave_subbasin/wflow_sediment.toml
2022-08-10 11:49:06,687 - update - model_api - ERROR - Model config file not found at /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_piave_subbasin/wflow_sediment.toml
2022-08-10 11:49:06,687 - update - wflow - INFO - Read staticmaps from /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_piave_subbasin/staticmaps.nc
2022-08-10 11:49:06,820 - update - wflow - INFO - Reading model intbl files.
2022-08-10 11:49:06,820 - update - model_api - ERROR - Model config file not found at /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_piave_subbasin/wflow_sediment.toml
2022-08-10 11:49:06,820 - update - wflow - INFO - Reading model staticgeom files.
2022-08-10 11:49:06,902 - update - model_api - ERROR - Model config file not found at /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_piave_subbasin/wflow_sediment.toml
2022-08-10 11:49:06,903 - update - wflow - INFO - Read forcing from /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_piave_subbasin/inmaps.nc
2022-08-10 11:49:06,911 - update - wflow - INFO - Model read
2022-08-10 11:49:06,911 - update - log - DEBUG - Appending log messages to file /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_test_extend_sediment/hydromt.log.
2022-08-10 11:49:06,937 - update - model_api - ERROR - missing required argument cfdict for setup_config
2022-08-10 11:49:06,937 - update - model_api - INFO - setup_riverbedsed.bedsed_mapping_fn: None
2022-08-10 11:49:06,937 - update - wflow_sediment - INFO - Preparing riverbedsed parameter maps.
2022-08-10 11:49:06,947 - update - landuse - INFO - Deriving D50_River using average resampling (nodata=-999.0).
2022-08-10 11:49:06,958 - update - landuse - INFO - Deriving ClayF_River using average resampling (nodata=-999.0).
2022-08-10 11:49:06,968 - update - landuse - INFO - Deriving SiltF_River using average resampling (nodata=-999.0).
2022-08-10 11:49:06,978 - update - landuse - INFO - Deriving SandF_River using average resampling (nodata=-999.0).
2022-08-10 11:49:06,988 - update - landuse - INFO - Deriving GravelF_River using average resampling (nodata=-999.0).
2022-08-10 11:49:07,012 - update - model_api - INFO - setup_lulcmaps.lulc_fn: globcover
2022-08-10 11:49:07,012 - update - model_api - INFO - setup_lulcmaps.lulc_mapping_fn: None
2022-08-10 11:49:07,012 - update - model_api - INFO - setup_lulcmaps.lulc_vars: ['landuse', 'Cov_River', 'Kext', 'N', 'PathFrac', 'Sl', 'Swood', 'USLE_C', 'WaterFrac']
2022-08-10 11:49:07,012 - update - wflow - INFO - Preparing LULC parameter maps.
2022-08-10 11:49:07,033 - update - data_catalog - INFO - Reading data catalog artifact_data v0.0.6 from archive
2022-08-10 11:49:07,034 - update - data_catalog - INFO - Parsing data catalog from /home/runner/.hydromt_data/artifact_data/v0.0.6/data_catalog.yml
2022-08-10 11:49:07,090 - update - data_catalog - INFO - DataCatalog: Getting globcover RasterDataset raster data from /home/runner/.hydromt_data/artifact_data/v0.0.6/globcover.tif
2022-08-10 11:49:07,113 - update - rasterdataset - DEBUG - RasterDataset: Clip with geom - [11.775, 45.808, 12.742, 46.692]
2022-08-10 11:49:07,132 - update - landuse - INFO - Deriving landuse using nearest resampling (nodata=230).
2022-08-10 11:49:07,173 - update - landuse - INFO - Deriving Cov_River using average resampling (nodata=-999.0).
2022-08-10 11:49:07,212 - update - landuse - INFO - Deriving Kext using average resampling (nodata=-999.0).
2022-08-10 11:49:07,252 - update - landuse - INFO - Deriving N using average resampling (nodata=-999.0).
2022-08-10 11:49:07,292 - update - landuse - INFO - Deriving PathFrac using average resampling (nodata=-999.0).
2022-08-10 11:49:07,332 - update - landuse - INFO - Deriving Sl using average resampling (nodata=-999.0).
2022-08-10 11:49:07,372 - update - landuse - INFO - Deriving Swood using average resampling (nodata=-999.0).
2022-08-10 11:49:07,411 - update - landuse - INFO - Deriving USLE_C using average resampling (nodata=-999.0).
2022-08-10 11:49:07,451 - update - landuse - INFO - Deriving WaterFrac using average resampling (nodata=-999.0).
2022-08-10 11:49:07,517 - update - model_api - INFO - setup_canopymaps.canopy_fn: simard
2022-08-10 11:49:07,517 - update - wflow_sediment - INFO - Preparing canopy height map.
2022-08-10 11:49:07,520 - update - data_catalog - INFO - DataCatalog: Getting simard RasterDataset raster data from /home/runner/.hydromt_data/artifact_data/v0.0.6/simard.tif
2022-08-10 11:49:07,534 - update - rasterdataset - DEBUG - RasterDataset: Clip with geom - [11.775, 45.808, 12.742, 46.692]
2022-08-10 11:49:07,580 - update - model_api - INFO - setup_soilmaps.soil_fn: soilgrids
2022-08-10 11:49:07,581 - update - model_api - INFO - setup_soilmaps.usleK_method: renard
2022-08-10 11:49:07,581 - update - wflow_sediment - INFO - Preparing soil parameter maps.
2022-08-10 11:49:07,584 - update - data_catalog - INFO - DataCatalog: Getting soilgrids RasterDataset raster data from /home/runner/.hydromt_data/artifact_data/v0.0.6/soilgrids/{variable}.tif
2022-08-10 11:49:08,008 - update - rasterdataset - DEBUG - RasterDataset: Clip with geom - [11.775, 45.808, 12.742, 46.692]
2022-08-10 11:49:08,027 - update - rasterdataset - DEBUG - RasterDataset: Convert units for 21 variables.
2022-08-10 11:49:08,473 - update - soilgrids - INFO - Interpolate NAN values for PercentClay
2022-08-10 11:49:08,490 - update - soilgrids - INFO - Interpolate NAN values for PercentSilt
2022-08-10 11:49:08,507 - update - soilgrids - INFO - Interpolate NAN values for PercentOC
2022-08-10 11:49:08,534 - update - soilgrids - INFO - Interpolate NAN values for ErosK
2022-08-10 11:49:08,555 - update - soilgrids - INFO - Interpolate NAN values for USLE_K
2022-08-10 11:49:08,572 - update - model_api - INFO - setup_gauges.gauges_fn: grdc
2022-08-10 11:49:08,572 - update - model_api - INFO - setup_gauges.source_gdf: None
2022-08-10 11:49:08,572 - update - model_api - INFO - setup_gauges.snap_to_river: True
2022-08-10 11:49:08,572 - update - model_api - INFO - setup_gauges.mask: None
2022-08-10 11:49:08,572 - update - model_api - INFO - setup_gauges.derive_subcatch: False
2022-08-10 11:49:08,573 - update - model_api - INFO - setup_gauges.derive_outlet: True
2022-08-10 11:49:08,573 - update - model_api - INFO - setup_gauges.basename: None
2022-08-10 11:49:08,573 - update - model_api - INFO - setup_gauges.update_toml: True
2022-08-10 11:49:08,573 - update - model_api - INFO - setup_gauges.gauge_toml_header: None
2022-08-10 11:49:08,573 - update - model_api - INFO - setup_gauges.gauge_toml_param: None
2022-08-10 11:49:08,573 - update - wflow - INFO - Gauges locations set based on river outlets.
2022-08-10 11:49:09,310 - update - wflow - INFO - Gauges map based on catchment river outlets added.
2022-08-10 11:49:09,310 - update - data_catalog - INFO - DataCatalog: Getting grdc GeoDataFrame csv data from /home/runner/.hydromt_data/artifact_data/v0.0.6/grdc.csv
2022-08-10 11:49:09,313 - update - geodataframe - INFO - GeoDataFrame: Read csv data and clip to geom (epsg:4326) [11.775, 45.804, 12.745, 46.690].
2022-08-10 11:49:09,326 - update - wflow - INFO - 3 grdc gauge locations found within domain
2022-08-10 11:49:10,172 - update - model_api - DEBUG - Default config read from /usr/share/miniconda/envs/hydromt-wflow/lib/python3.9/site-packages/hydromt_wflow/data/wflow_sediment/wflow_sediment.toml
2022-08-10 11:49:10,172 - update - wflow - INFO - Gauges map from grdc added.
2022-08-10 11:49:10,172 - update - model_api - INFO - setup_constant_pars.dtype: float32
2022-08-10 11:49:10,172 - update - model_api - INFO - setup_constant_pars.nodata: -999
2022-08-10 11:49:10,172 - update - model_api - INFO - setup_constant_pars.c_Bagnold: 1.75e-05
2022-08-10 11:49:10,172 - update - model_api - INFO - setup_constant_pars.eros_expo: 1.5
2022-08-10 11:49:10,172 - update - model_api - INFO - setup_constant_pars.eros_ov: 0.9
2022-08-10 11:49:10,172 - update - model_api - INFO - setup_constant_pars.eros_spl_EUROSEM: 2.0
2022-08-10 11:49:10,172 - update - model_api - INFO - setup_constant_pars.exp_Bagnold: 1.4
2022-08-10 11:49:10,172 - update - model_api - INFO - setup_constant_pars.ResTrapEff: 1.0
2022-08-10 11:49:10,198 - update - wflow - INFO - Write model data to /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_test_extend_sediment
2022-08-10 11:49:10,202 - update - model_api - INFO - Writing model config to /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_test_extend_sediment/wflow_sediment.toml
2022-08-10 11:49:10,329 - update - wflow - INFO - Write staticmaps to /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_test_extend_sediment/staticmaps.nc
2022-08-10 11:49:10,869 - update - wflow - INFO - Writing model staticgeom to file.
2022-08-10 11:49:11,051 - update - wflow - INFO - Write forcing file
2022-08-10 11:49:11,062 - update - wflow - WARNING - Not all dates found in precip_fn changing starttime to 2010-02-02 00:00:00 and endtime to 2010-02-10 00:00:00 in the toml.
2022-08-10 11:49:11,062 - update - model_api - INFO - Writing model config to /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_test_extend_sediment/wflow_sediment.toml
2022-08-10 11:49:11,074 - update - wflow - INFO - Process forcing; saving to /home/runner/work/hydromt_wflow/hydromt_wflow/docs/_examples/wflow_test_extend_sediment/inmaps.nc
[########################################] | 100% Completed | 101.54 ms

The example above means the following: run hydromt update with:

  • wflow_sediment : i.e. update a wflow_sediment model (in our case a wflow model but with wflow_sediment components)

  • wflow_piave_subbasin : hydrological wflow model folder

  • -o "./wflow_test_extend_sediment": output combined wflow hydrology+sediment models

  • -i wflow_extend_sediment.ini : setup configuration file containing wflow sediment specific components

  • -vv : give some extra verbosity (2 * v) to display feedback on screen. Now debug messages are provided.