HydroMT-SFINCS | Example 01B
Example: Build a SFINCS quadtree model from Python
Create a locally refined grid, add model data and write a complete quadtree model.
In this example a simple SFINCS compound flood model will be made, using the underlying Python functions of HydroMT-SFINCS to build a model.
The model is situated in Northern Italy, where a small selection of topography and bathymetry data has already been made available for you to try the examples.
[1]:
import os
import geopandas as gpd
from pathlib import Path
from datetime import datetime
from hydromt_sfincs import SfincsModel, DATADIR
from hydromt import log
This example shows how to build a SFINCS model containing elevation data and spatially varying roughness (together processed into subgrid tables), and add simple water level boundary conditions.
In case you want to adjust this example to build a SFINCS model anywhere else in the world, you will have to add your own datasets to HydroMT’s data catalog. For more info on that, check-out:
💡 Note: Before you begin
This example uses the bundled Northern Italy data and OpenStreetMap coastline catalog. For another location, configure your own data catalog and provide a suitable refinement polygon.
Steps followed in this notebook to build your SFINCS quadtree model:
Initialize the logger.
Initialize the SfincsModel class, data library and output folder.
Create a quadtree grid with coastline refinement.
Add elevation to the quadtree grid.
Create the active and inactive cell mask.
Add water-level and outflow boundaries.
Cut inactive cells from the quadtree grid.
Add spatially varying roughness.
Create quadtree subgrid-derived tables.
Add water-level time-series forcing.
Inspect the model and boundary conditions.
Write the model to disk.
Let’s get started!
0. Initialize the logger#
Initialize logging and choose the level of detail for the messages written to the notebook and log file.
[2]:
model_root = "tmp_sfincs_quadtree"
# Initialize logging, the lower the log level number, the more verbose (more info) the output
# NOTSET=0-9, DEBUG=10, INFO=20, WARNING=30, ERROR=40, CRITICAL=50
log.initialize_logging()
log.set_log_level(log_level=20)
# Add file handler to log to a file
log_file = Path(model_root) / "hydromt_sfincs.log"
logger = log._add_filehandler(log_file)
2026-11-18 08:37:25,452 - hydromt - log - INFO - HydroMT version: 1.4.1
1. Initialize SfincsModel class, set data library and output folder:#
Before we can use all the tools provided by HydroMT-SFINCS, we have to initialize the SfincsModel instance. This creates a shortcut to all the model components and methods to read, write and create these components. Furthermore, when initializing the model, we can specify which data catalog we use and where the model is/will be stored (the root).
[3]:
# Initialize SfincsModel Python class with the artifact data catalog which contains publically available data for North Italy
sf = SfincsModel(
data_libs=["artifact_data"], # specify which data libraries to use
root=model_root, # specify the root directory for the model
mode="w", # specify the mode for opening the model (r=read only, r+=append, w=write,
write_gis=True, # specify whether to write GIS data
)
2026-11-18 08:37:25,496 - hydromt.data_catalog.data_catalog - data_catalog - INFO - Reading data catalog artifact_data latest
2026-11-18 08:37:25,497 - hydromt.data_catalog.data_catalog - data_catalog - INFO - Parsing data catalog from /home/runner/.hydromt/artifact_data/v1.0.0/data_catalog.yml
2026-11-18 08:37:26,053 - hydromt.model.model - model - INFO - Initializing sfincs model from hydromt_sfincs (v2.0.0.dev0).
2. Create a quadtree grid with coastline refinement#
A quadtree grid starts at a base resolution and refines only selected areas. This example creates a 500 m buffer around the OpenStreetMap coastline and refines the cells in that polygon. Refinement level 1 halves the 50 m base cell size to 25 m; level 2 would refine it to 12.5 m.
[4]:
# first we obtain the region and the corresponding OSM coastlines
region = {"geom": "data/region.geojson"}
gdf_region = sf.data_catalog.get_geodataframe(region["geom"]).to_crs("EPSG:4326")
gdf_osm = sf.data_catalog.get_geodataframe(
"osm_coastlines", bbox=tuple(gdf_region.total_bounds)
)
# then we create a buffer around the OSM coastlines and prepare the refinement GeoDataFrame
gdf_osm_line = gdf_osm.to_crs("EPSG:32633").boundary
gdf_osm_buffer = gdf_osm_line.buffer(200)
gdf_refinement = gpd.GeoDataFrame(
geometry=[gdf_osm_buffer.union_all()], crs="EPSG:32633"
)
# assign the refinement level to the buffered region
gdf_refinement["refinement_level"] = 1
2026-11-18 08:37:26,058 - hydromt.data_catalog.sources.data_source - data_source - INFO - Reading region.geojson GeoDataFrame data from /home/runner/work/hydromt_sfincs/hydromt_sfincs/docs/_examples/data/region.geojson
2026-11-18 08:37:26,068 - hydromt.data_catalog.sources.data_source - data_source - INFO - Reading osm_coastlines GeoDataFrame data from /home/runner/.hydromt/artifact_data/latest/osm_coastlines.gpkg
[5]:
sf.quadtree_grid.create_from_region(
region=region,
res=50,
rotated=True,
crs=32633,
refinement_polygons=gdf_refinement,
)
2026-11-18 08:37:26,116 - hydromt.data_catalog.data_catalog - data_catalog - WARNING - overwriting data source 'region.geojson' with provider user and version _UNSPECIFIED_.
2026-11-18 08:37:26,117 - hydromt.data_catalog.sources.data_source - data_source - INFO - Reading region.geojson GeoDataFrame data from /home/runner/work/hydromt_sfincs/hydromt_sfincs/docs/_examples/data/region.geojson
Refining ...
Time elapsed : 0.2284092903137207 s
Finding neighbors ...
Time elapsed : 0.003653287887573242 s
Setting neighbors left and below ...
Time elapsed : 0.04389810562133789 s
Getting uv points ...
Time elapsed : 0.02378249168395996 s
Making XUGrid ...
Got rid of duplicates in 0.1023 seconds
Made XUGrid in 0.0004 seconds
The resulting quadtree grid and refinement-level layer are available on the model.
[6]:
fig, ax = sf.plot_basemap(
variable="level",
plot_region=True,
plot_bounds=False,
bmap="sat",
zoomlevel=12,
)
gdf_refinement.boundary.plot(ax=ax, color="purple", linewidth=1, linestyle="--")
[6]:
<GeoAxes: title={'center': 'SFINCS level map'}, xlabel='x [m] - WGS 84 / UTM zone 33N', ylabel='y [m]'>
3. Add elevation to the quadtree grid#
Probably the most important datasets to create a proper SFINCS model are the digital elevation models (DEMs). However, often there are different datasets for describing the elevation on land, topography, and below water, bathymetry. HydroMT-SFINCS provides functionality to merge these different datasets onto the model grid.
[7]:
# In this example we want to combine 2 elevation datasets, merit_hydro as elevation and gebco as bathymetry, in that order.
# NOTE: from the 1st dataset (merit_hydro) only elevation above ("zmin":0.001) meters is used;
# the 2nd elevation dataset (gebco) is used where the 1st dataset returned nodata values
elevation_list = [{"elevation": "merit_hydro", "zmin": 0.001}, {"elevation": "gebco"}]
# Add depth information to modelgrid based on these chosen datasets
sf.quadtree_elevation.create(elevation_list=elevation_list, buffer_cells=1)
# Make a plot of the merged topobathy, here colour limits are set between an elevation of -5 to 5 meters
_ = sf.plot_basemap(
variable="z", plot_region=True, plot_bounds=False, bmap="sat", zoomlevel=12
)
2026-11-18 08:37:29,243 - hydromt.data_catalog.sources.data_source - data_source - INFO - Reading merit_hydro RasterDataset data from /home/runner/.hydromt/artifact_data/latest/merit_hydro/{variable}.tif
2026-11-18 08:37:29,278 - hydromt.data_catalog.sources.data_source - data_source - INFO - Reading gebco RasterDataset data from /home/runner/.hydromt/artifact_data/latest/gebco.tif
2026-11-18 08:37:29,308 - hydromt.data_catalog.sources.data_source - data_source - INFO - Reading merit_hydro RasterDataset data from /home/runner/.hydromt/artifact_data/latest/merit_hydro/{variable}.tif
2026-11-18 08:37:29,339 - hydromt.data_catalog.sources.data_source - data_source - INFO - Reading gebco RasterDataset data from /home/runner/.hydromt/artifact_data/latest/gebco.tif
2026-11-18 08:37:29,396 - hydromt.hydromt_sfincs.components.quadtree.quadtree_elevation - quadtree_elevation - WARNING - Interpolate elevation at 2 cells
2026-11-18 08:37:29,439 - hydromt.hydromt_sfincs.components.quadtree.quadtree_elevation - quadtree_elevation - WARNING - Interpolate elevation at 1 cells
2026-11-18 08:37:29,471 - hydromt.model.components.mesh - mesh - WARNING - Replacing mesh parameter: z
4. Make mask of active and inactive quadtree cells:#
The next step of building a SFINCS model is to create a mask. First we generate a mask of active (msk=1) and inactive cells (msk=0), determining in which cells of your computational grid water levels will be computed.
For more info about the msk-file, click here.
[8]:
# Defining your active cells can be based on multiple criteria, here we only specify a minimum elevation of -5 meters,
# meaning all cells above -5 are considered to be active. Check-out the method documentation for more options.
sf.quadtree_mask.create_active(zmin=-5)
# # Make a plot of the mask file
_ = sf.plot_basemap(
variable="mask", plot_region=False, plot_bounds=False, bmap="sat", zoomlevel=12
)
2026-11-18 08:37:31,772 - hydromt.hydromt_sfincs.components.quadtree.quadtree_mask - quadtree_mask - INFO - Building mask ...
2026-11-18 08:37:31,773 - hydromt.hydromt_sfincs.components.quadtree.quadtree_mask - quadtree_mask - INFO - Build new mask for: sfincs ...
2026-11-18 08:37:31,819 - hydromt.model.components.mesh - mesh - WARNING - Replacing mesh parameter: mask
⚠️ Note: Mask cleanup
For quadtree models, the fill_area and drop_area arguments are not available
5. Update mask with water level boundary cells - including use of polygons:#
In SFINCS you can specify cells where you want to force offshore water levels (mask=2). To determine these cells, there are again multiple criteria to use, such as elevation or user-defined-polygons.
[9]:
# Here we add water level cells along the coastal boundary, for cells up to an elevation of -5 meters
sf.quadtree_mask.create_boundary(
btype="waterlevel",
zmax=-5,
reset_bounds=True,
)
# Make a plot of the mask file
fig, ax = sf.plot_basemap(
variable="mask", plot_region=False, plot_bounds=False, bmap="sat", zoomlevel=12
)
2026-11-18 08:37:33,999 - hydromt.model.components.mesh - mesh - WARNING - Replacing mesh parameter: mask
💡 Note: Boundary mask
As shown in the plot, msk=2 values (red line) have been added along the coastal boundary.
reset_bounds=True means you start without existing boundary cells of that type. With reset_bounds=False (the default), you build on existing boundary cells, if available.
6. Cut inactive cells from the quadtree grid#
After creating the mask and boundary cells, remove inactive cells from the mesh before continuing with model preprocessing. The unstructured nature of the quadtree grids allows for removing unnecessary cells, making the pre-processing and running more efficient.
⚠️ Note: Quadtree grid update
cut_inactive_cells() updates the grid in place and returns None; call it without assigning its result.
[10]:
sf.quadtree_grid.cut_inactive_cells()
Removing inactive cells ...
Finding neighbors ...
Time elapsed : 0.0029265880584716797 s
Setting neighbors left and below ...
Time elapsed : 0.03464841842651367 s
Getting uv points ...
Time elapsed : 0.018932104110717773 s
Making XUGrid ...
Got rid of duplicates in 0.0759 seconds
Made XUGrid in 0.0002 seconds
7. Add spatially varying roughness data:#
Next to the elevation, the roughness is also an important input dataset for the SFINCS model. Typically, the mannings’ n roughness coefficients are derived based on landuse/landcover data and a conversion table.
[11]:
# Some reclass tables are available in the hydromt_sfincs DATADIR
# e.g. vito_mapping.csv for vito_2015 landuse classification
reclass_table = os.path.join(DATADIR, "lulc", "vito_mapping.csv")
# use the river manning raster in combination with vito_2015 land to derive the manning roughness file
roughness_list = [{"lulc": "vito_2015", "reclass_table": reclass_table}]
sf.quadtree_roughness.create(
roughness_list=roughness_list,
manning_land=0.04,
manning_sea=0.02,
rgh_lev_land=0, # the minimum elevation of the land
)
_ = sf.plot_basemap(variable="manning", plot_bounds=False, bmap="sat", zoomlevel=12)
2026-11-18 08:37:36,089 - hydromt.data_catalog.sources.data_source - data_source - INFO - Reading vito_2015 RasterDataset data from /home/runner/.hydromt/artifact_data/latest/vito.tif
2026-11-18 08:37:36,100 - hydromt.data_catalog.sources.data_source - data_source - INFO - Reading vito_mapping.csv DataFrame data from /home/runner/work/hydromt_sfincs/hydromt_sfincs/hydromt_sfincs/data/lulc/vito_mapping.csv
2026-11-18 08:37:36,104 - hydromt.gis.raster - raster - WARNING - The nodata value None is not in the reclass table.None will be used for the params.
2026-11-18 08:37:36,130 - hydromt.hydromt_sfincs.components.quadtree.quadtree_roughness - quadtree_roughness - INFO - Filled 0 remaining cells in manning with depth-based roughness.
8. Make quadtree subgrid-derived tables:#
Subgrid derived tables are used to better capture the elevation and roughness of your domain, to either improve your results, or to allow you to run on a courser grid resolution (means faster simulation). For more info about subgrid tables, click here.
You as user can specify multiple settings about how the subgrid derived tables should be made.
Every single grid cell of the flux grid of the size inp.dx by inp.dy is defined into subgrid pixels (default nr_subgrid_pixels = 20). For every subgrid pixel the topobathy data is loaded, ideally this consists of high-resolution DEM datasets that you specify as user.
In this example with dx=dy=50m, having nr_subgrid_pixels = 20 means we are loading data onto a 2.5 m subpixel grid However, the input data of Gebco and Merit_hydro is way coarser, therefore let’s set the ratio to 6 for now.
⚠️ Note: Subgrid tables
The subgrid tables replace the elevation and roughness data that we prepared before.
For the subgrid tables, we again provide the elevation datasets, and roughness datasets. Additonally, we can provide river datasets that are used to burn in rivers into the elevation and roughness maps.
[12]:
# Repeat elevation and roughness sets for clarity
elevation_list = [{"elevation": "merit_hydro", "zmin": 0.001}, {"elevation": "gebco"}]
# Roughness sets
roughness_list = [{"lulc": "vito_2015", "reclass_table": reclass_table}]
sf.quadtree_subgrid.create(
elevation_list=elevation_list,
roughness_list=roughness_list,
nr_subgrid_pixels=6,
write_dep_tif=True,
write_man_tif=True,
)
# NOTE: we turned on that the merged topobathy of the different (high-res) datasets is written to a geotiff
2026-11-18 08:37:37,906 - hydromt.data_catalog.sources.data_source - data_source - INFO - Reading merit_hydro RasterDataset data from /home/runner/.hydromt/artifact_data/latest/merit_hydro/{variable}.tif
2026-11-18 08:37:37,935 - hydromt.data_catalog.sources.data_source - data_source - INFO - Reading gebco RasterDataset data from /home/runner/.hydromt/artifact_data/latest/gebco.tif
2026-11-18 08:37:37,963 - hydromt.data_catalog.sources.data_source - data_source - INFO - Reading merit_hydro RasterDataset data from /home/runner/.hydromt/artifact_data/latest/merit_hydro/{variable}.tif
2026-11-18 08:37:37,990 - hydromt.data_catalog.sources.data_source - data_source - INFO - Reading gebco RasterDataset data from /home/runner/.hydromt/artifact_data/latest/gebco.tif
2026-11-18 08:37:38,018 - hydromt.data_catalog.sources.data_source - data_source - INFO - Reading vito_2015 RasterDataset data from /home/runner/.hydromt/artifact_data/latest/vito.tif
2026-11-18 08:37:38,029 - hydromt.data_catalog.data_catalog - data_catalog - WARNING - overwriting data source 'vito_mapping.csv' with provider user and version _UNSPECIFIED_.
2026-11-18 08:37:38,029 - hydromt.data_catalog.sources.data_source - data_source - INFO - Reading vito_mapping.csv DataFrame data from /home/runner/work/hydromt_sfincs/hydromt_sfincs/hydromt_sfincs/data/lulc/vito_mapping.csv
2026-11-18 08:37:38,033 - hydromt.gis.raster - raster - WARNING - The nodata value None is not in the reclass table.None will be used for the params.
2026-11-18 08:37:38,036 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2026-11-18 08:37:38,036 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Building subgrid tables for SFINCS Quadtree model ...
Building subgrid tables for SFINCS Quadtree model ...
2026-11-18 08:37:38,079 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2026-11-18 08:37:38,080 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Processing level 1 of 2 ...
Processing level 1 of 2 ...
2026-11-18 08:37:38,081 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Number of regular cells in a block : 333
Number of regular cells in a block : 333
2026-11-18 08:37:38,081 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Number of blocks in n direction : 1
Number of blocks in n direction : 1
2026-11-18 08:37:38,081 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Number of blocks in m direction : 1
Number of blocks in m direction : 1
2026-11-18 08:37:38,082 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Grid size of flux grid : dx= 50.000000000000654, dy= 50.00000000000095
Grid size of flux grid : dx= 50.000000000000654, dy= 50.00000000000095
2026-11-18 08:37:38,082 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Grid size of subgrid pixels : dx= 8.333333333333442, dy= 8.333333333333492
Grid size of subgrid pixels : dx= 8.333333333333442, dy= 8.333333333333492
2026-11-18 08:37:38,082 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - --------------------------------------------------------------
--------------------------------------------------------------
2026-11-18 08:37:38,082 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Processing block 1 of 1 ...
Processing block 1 of 1 ...
2026-11-18 08:37:38,091 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Number of cells in this block : 18314
Number of cells in this block : 18314
2026-11-18 08:37:38,092 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Getting bathy/topo ...
Getting bathy/topo ...
2026-11-18 08:37:38,207 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Processing cells ...
Processing cells ...
2026-11-18 08:37:44,083 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - --------------------------------------------------------------
--------------------------------------------------------------
2026-11-18 08:37:44,083 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Processing U/V points in block 1 of 1 ...
Processing U/V points in block 1 of 1 ...
2026-11-18 08:37:44,134 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Number of U/V points in this block: 35994
Number of U/V points in this block: 35994
2026-11-18 08:37:44,135 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Getting bathy/topo ...
Getting bathy/topo ...
2026-11-18 08:37:44,357 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Processing U/V points ...
Processing U/V points ...
2026-11-18 08:37:48,212 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - cog - INFO - Building 2 overviews with average
2026-11-18 08:37:48,239 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - cog - INFO - Building 2 overviews with average
2026-11-18 08:37:48,254 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2026-11-18 08:37:48,255 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Processing level 2 of 2 ...
Processing level 2 of 2 ...
2026-11-18 08:37:48,255 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Number of regular cells in a block : 333
Number of regular cells in a block : 333
2026-11-18 08:37:48,256 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Number of blocks in n direction : 1
Number of blocks in n direction : 1
2026-11-18 08:37:48,256 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Number of blocks in m direction : 2
Number of blocks in m direction : 2
2026-11-18 08:37:48,256 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Grid size of flux grid : dx= 25.000000000000327, dy= 25.000000000000476
Grid size of flux grid : dx= 25.000000000000327, dy= 25.000000000000476
2026-11-18 08:37:48,257 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Grid size of subgrid pixels : dx= 4.166666666666721, dy= 4.166666666666746
Grid size of subgrid pixels : dx= 4.166666666666721, dy= 4.166666666666746
2026-11-18 08:37:48,257 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - --------------------------------------------------------------
--------------------------------------------------------------
2026-11-18 08:37:48,257 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Processing block 1 of 2 ...
Processing block 1 of 2 ...
2026-11-18 08:37:48,261 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Number of cells in this block : 6371
Number of cells in this block : 6371
2026-11-18 08:37:48,262 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Getting bathy/topo ...
Getting bathy/topo ...
2026-11-18 08:37:48,339 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Processing cells ...
Processing cells ...
2026-11-18 08:37:48,351 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - --------------------------------------------------------------
--------------------------------------------------------------
2026-11-18 08:37:48,351 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Processing block 2 of 2 ...
Processing block 2 of 2 ...
2026-11-18 08:37:48,355 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Number of cells in this block : 3112
Number of cells in this block : 3112
2026-11-18 08:37:48,355 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Getting bathy/topo ...
Getting bathy/topo ...
2026-11-18 08:37:48,406 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Processing cells ...
Processing cells ...
2026-11-18 08:37:48,416 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - --------------------------------------------------------------
--------------------------------------------------------------
2026-11-18 08:37:48,417 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Processing U/V points in block 1 of 2 ...
Processing U/V points in block 1 of 2 ...
2026-11-18 08:37:48,441 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Number of U/V points in this block: 13117
Number of U/V points in this block: 13117
2026-11-18 08:37:48,442 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Getting bathy/topo ...
Getting bathy/topo ...
2026-11-18 08:37:48,601 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Processing U/V points ...
Processing U/V points ...
2026-11-18 08:37:48,741 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - --------------------------------------------------------------
--------------------------------------------------------------
2026-11-18 08:37:48,741 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Processing U/V points in block 2 of 2 ...
Processing U/V points in block 2 of 2 ...
2026-11-18 08:37:48,760 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Number of U/V points in this block: 6395
Number of U/V points in this block: 6395
2026-11-18 08:37:48,760 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Getting bathy/topo ...
Getting bathy/topo ...
2026-11-18 08:37:48,852 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Processing U/V points ...
Processing U/V points ...
2026-11-18 08:37:48,920 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - cog - INFO - Building 3 overviews with average
2026-11-18 08:37:48,966 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - cog - INFO - Building 3 overviews with average
2026-11-18 08:37:49,006 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2026-11-18 08:37:49,007 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - Time elapsed: 11.0 seconds
Time elapsed: 11.0 seconds
2026-11-18 08:37:49,007 - hydromt.hydromt_sfincs.components.quadtree.quadtree_subgrid - subgrid_quadtree_builder - INFO - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
⚠️ Note: Subgrid processing time
If you have a very large domain with more than a million cells and very high-resolution datasets (e.g. 1 m), this step might take minutes to hours.
But the good news: when finished successfully, you can run very accurate SFINCS simulations quickly. The point of the subgrid functionality is that, by deriving tables from high-resolution elevation data, you can get more accurate results, run on a coarser grid (and therefore faster), or both.
The generated quadtree subgrid data are available through sf.quadtree_subgrid.data and are included when the model is written.
9. Add water level time-series as forcing:#
There are many ways to add water level boundary conditions to the SFINCS model. We introduce one in the example below, check out the WaterLevel component for more options:
🌐 Using a geodataset (presented here)
The simplest option.
Contains time series of water levels at specific points.
Often generated by other models, such as the GTSM model.
[13]:
# Change period of model simulation time, specified in yyyymmdd HHMMSS, to match with the available water level data
sf.config.update(
{
"tref": datetime(2010, 2, 5),
"tstart": datetime(2010, 2, 5),
"tstop": datetime(2010, 2, 7),
}
)
# From geodataset
sf.water_level.create(geodataset="gtsmv3_eu_era5")
2026-11-18 08:37:49,012 - hydromt.hydromt_sfincs.components.config.config - config - INFO - Updating 3 attributes in model config.
2026-11-18 08:37:49,037 - hydromt.data_catalog.sources.data_source - data_source - INFO - Reading gtsmv3_eu_era5 GeoDataset data from /home/runner/.hydromt/artifact_data/latest/gtsmv3_eu_era5.nc
10. Inspect the model and boundary conditions#
To inspect the added boundary conditions, we can again use the plotting functionality of HydroMT-SFINCS. When the boundary conditions are related to boundary points (water levels and waves), these locations can be visualzied with SfincsModel.plot_basemap(plot_geoms=True). Nonetheless, the actual timeseries of the boundary conditions can be visualized with SfincsModel.plot_forcing().
[14]:
# plot basemap, in this case boundary points should be added (and plotted because of plot_geoms=True)
sf.plot_basemap(
variable="z", plot_geoms=True, plot_bounds=False, bmap="sat", zoomlevel=12
)
[14]:
(<Figure size 600x303.495 with 2 Axes>,
<GeoAxes: title={'center': 'SFINCS z map'}, xlabel='x [m] - WGS 84 / UTM zone 33N', ylabel='y [m]'>)
And the boundary conditions timeseries:
[15]:
sf.plot_forcing()
[15]:
(<Figure size 600x300 with 1 Axes>,
[<Axes: title={'center': 'SFINCS waterlevel forcing (bzs)'}, ylabel='waterlevel\n[m+ref]'>])
11. Write the quadtree model input to disk#
By now we have made all basic SFINCS spatial layers and added simple water level boundary conditions. We are ready to write the model to disk, and run the model.
[16]:
# write all model files to disk
sf.write()
We always recommend to run the SFINCS model with normal conditions first to check model performance (we don’t expect flooding under normal conditions). To run this basic model, you could progress to the notebook:
If you noticed something strange in your results, or want to increase the complexity of your model (e.g. more realistic boundary conditions), you can update your model. This is demonstrated in the following notebooks:
💡 Note: Model building is iterative
Combining the different notebooks in this tutorial series allows you to build more complex models step by step.