API#
SFINCS Model class#
The hydromt_sfincs.SfincsModel class is the main entry point to read, write, build, and update SFINCS models using HydroMT.
It uses the functionalities provided by the reusable components defined in the hydromt_sfincs.components module.
|
SFINCS model class. |
Methods#
Read SfincsModel from disk. |
|
|
Write SfincsModel to disk. |
|
Single method to build a model from scratch based on settings in steps. |
|
Single method to update a model based the settings in steps. |
Plot methods#
|
Create basemap plot. |
|
Plot model timeseries forcing. |
Attributes#
Model root |
|
Returns the model crs |
|
Returns the geometry of the active model cells. |
|
Returns the bounding box in WGS 84 of the model grid. |
Components#
The hydromt_sfincs.components module defines reusable data container classes
that represent configuration, grid, geometries, boundary conditions, outputs,
and other model data.
Configuration#
" Class to read and write SFINCS configuration files (sfincs.inp). |
|
Return the Pydantic SfincsConfigVariables object. |
|
Read a text file with the sfincs configuration from the root folder and populate the SfincsConfigVariables. |
|
Write the SfincsConfigVariables to a text file in the root folder of the model. |
|
Update attributes using a dictionary or keyword arguments. |
|
Update the grid properties from the configuration. |
|
|
Get the value for a specific key with validation check. |
|
Set a value for a specific key with validation using Pydantic's model_validate. |
Return the absolute file path for a given 'key'. |
|
SFINCS configuration variables with defaults matching sfincs_input.f90. |
Grid#
The regular-grid component’s data property contains the complete gridded
dataset. The individual grid components (for example, elevation, mask, and
roughness) also provide a data property, but that property exposes only the
layer or layers relevant to that component. These are component-specific views
of data stored on the shared grid; they are not separate data stores. To add or
replace a layer, use the parent grid’s set() method.
The grid reads and writes the cell index, mask, and elevation maps. Other
component-owned maps are read and written by their components through the
grid’s internal layer I/O methods. When SfincsGrid.write() is called with
write_components=True, it also calls the owning components’ write()
methods. Regular-grid infiltration layers are stored in their configured
binary map files; subgrid tables are managed by the subgrid component.
|
Regular grid component of the SfincsModel class. |
Model static gridded data as xarray.Dataset. |
|
Read SFINCS binary grid files and save to data attribute. |
|
Write SFINCS grid to binary files including map index file. |
|
|
Create a regular grid for the SfincsModel. |
Create a regular grid for the SfincsModel based on a region. |
|
Read SFINCS binary maps into data, one file per variable. |
|
Write variables from data as SFINCS binary maps, one file per variable. |
|
|
Read one of the grid variables of the SFINCS model map from a binary file. |
|
Write one of the grid variables of the SFINCS model map to a binary file. |
SFINCS Elevation Component. |
|
Return only the available elevation layer from the model grid. |
|
Interpolate topobathy (dep) data to the model grid. |
|
|
SFINCS Mask Component. |
Return only the available mask layer from the model grid. |
|
Create an integer mask with inactive (mask=0) and active (mask=1) cells, optionally bounded by several criteria. |
|
Set boundary cells in the model mask. |
|
SFINCS Roughness Component. |
|
Return only the available roughness layers from the model grid. |
|
Read the manning roughness map from its own binary file. |
|
Write the manning roughness map to its own binary file. |
|
Setup model manning roughness map (manningfile) from gridded manning data or a combinataion of gridded land-use/land-cover map and manning roughness mapping table. |
|
SFINCS infiltration component for regular grids. |
|
Return only the available infiltration layers from the model grid. |
|
Read the infiltration layers from their own files. |
|
Write each regular-grid infiltration layer to its own binary file. |
|
|
Create a uniform constant infiltration rate in model config. |
Create spatially varying constant infiltration rate. |
|
Create Curve Number infiltration without recovery. |
|
|
Create Curve Number infiltration from land use and HSG. |
|
Create Curve Number infiltration with recovery. |
Estimate Green-Ampt infiltration from HSG and optional landuse. |
|
|
Create Green-Ampt infiltration from final parameter maps. |
Estimate Horton infiltration from HSG and optional landuse. |
|
|
Create Horton infiltration from final parameter maps. |
SFINCS Initial Conditions Component. |
|
Return only the available initial-condition layers from the grid. |
|
Read the initial water level map from its own binary file. |
|
Write the initial water level map to its own binary file. |
|
Setup spatially varying initial water level (inifile). |
|
SFINCS Storage Volume Component. |
|
Return only the available storage volume layers from the model grid. |
|
Read the storage volume map from its own binary file. |
|
Write the storage volume map to its own binary file. |
|
Create storage volume. |
|
|
SFINCS Subgrid Table Component. |
Model static gridded data as xarray.Dataset. |
|
Load subgrid table from file for a regular grid with given mask. |
|
Write subgrid table to file for a regular grid with given mask. |
|
Create method for subgrid tables based on a list of elevation and Manning's roughness datasets. |
Quadtree#
The quadtree grid’s data property contains the complete mesh dataset.
Individual quadtree components expose their relevant layer or layers through
their own data properties. These are component-specific views of data
stored on the shared quadtree grid, not separate data stores; use the parent
grid’s set() method to add or replace a layer. The component views retain
the mesh topology.
The mask, elevation, and any quadtree-specific variables are stored in the main
quadtree file (qtrfile). Other component-owned variables are written to
standalone UGRID netCDF files by their components. Calling
SfincsQuadtreeGrid.write() with write_components=True also invokes those
component writers. Quadtree infiltration, including bucket variables, is
stored in inffile; inftype identifies the flavor. The subgrid table is
managed separately by its subgrid component.
Quadtree grid component attached to an |
|
Model static mesh data. |
|
Reads a quadtree netcdf file and stores it in the QuadtreeGrid object. |
|
Read face variables from a standalone UGRID netcdf file into data. |
|
Write face variables to a standalone UGRID netcdf file. |
|
Writes a quadtree SFINCS netcdf file. |
|
Build the Quadtree grid. |
|
|
Setup a quadtree grid from a region. |
Elevation stored as |
|
Return only elevation, retaining the mesh even before it is created. |
|
Ensure the parent grid is loaded, including elevation in |
|
Leave elevation persistence in |
|
Interpolate topobathy (z) data to the model grid. |
|
|
|
Mask stored in the shared quadtree grid. |
|
Return only this mask, retaining the parent mesh. |
|
Ensure the parent grid is loaded, including masks in |
|
Leave mask persistence in |
|
Setup active model cells. |
|
|
Set boundary cells in the model mask. |
Return only roughness layers, retaining the parent mesh. |
|
Read the manning roughness layer from its own file. |
|
Write the manning roughness layer to its own file. |
|
Interpolate roughness (Manning's n) data to the model grid. |
|
SFINCS infiltration component for quadtree grids. |
|
Return only infiltration layers, retaining the parent mesh. |
|
Read the infiltration layers from their own file. |
|
Write the infiltration layers to their own file. |
|
|
Create a uniform constant infiltration rate in model config. |
|
Create spatially varying constant infiltration rate. |
|
Create Curve Number infiltration without recovery for quadtree grids. |
|
Create Curve Number infiltration from land use and HSG. |
|
Create Curve Number infiltration with recovery for quadtree grids. |
|
Estimate Green-Ampt infiltration from HSG and optional landuse. |
|
Create Green-Ampt infiltration from final parameter maps. |
|
Estimate Horton infiltration from HSG and optional landuse. |
|
Create Horton infiltration from final parameter maps. |
|
Estimate bucket infiltration from HSG and optional landuse. |
|
Create bucket infiltration from final parameter maps. |
|
Create a spatially varying constant run-off coefficient. |
SFINCS initial conditions component for quadtree grids. |
|
Return only initial-condition layers, retaining the parent mesh. |
|
Read the initial water level layer from its own file. |
|
Write the initial water level layer to its own file. |
|
|
Setup spatially varying initial water level (ncinifile). |
|
Setup spatially varying initial water level (ncinifile). |
SFINCS storage volume component for quadtree grids. |
|
Return only storage volume layers, retaining the parent mesh. |
|
Read the storage volume layer from its own file. |
|
Write the storage volume layer to its own file. |
|
Setup storage volume. |
|
Read SFINCS subgrid table ( |
|
Write SFINCS subgrid table ( |
|
Build SFINCS subgrid table for quadtree grid |
|
Return only this mask, retaining the parent mesh. |
|
Setup active model snapwave mask and add boundaries. |
|
|
Setup active model cells. |
|
Set boundary cells in the model mask. |
Geometries#
SFINCS Observation Points Component. |
|
Observation point data, returned as a GeoDataFrame. |
|
Read SFINCS observation points (.obs) file. |
|
Write SFINCS observation points (.obs) file, and set obsfile in config (if it was not already set) |
|
Create model observation point locations. |
|
SFINCS Cross-Sections Component. |
|
Cross-section lines data, returned as a GeoDataFrame. |
|
Read ascii SFINCS cross-sections (.crs) file. |
|
Write ascii SFINCS cross-sections (.crs) file, and set crsfile in config (if it was not already set). |
|
Create model cross-sections (old name: setup_observation_lines) |
|
SFINCS thin dams geometry component. |
|
Thin dam data, returned as a GeoDataFrame. |
|
Read SFINCS thin dams (.thd) file. |
|
Write SFINCS thin dams (.thd) file, and set thdfile in config (if it was not already set) |
|
Create model thin dams (old name: setup_structures). |
|
SFINCS weir geometry component. |
|
Weirs lines data, returned as a GeoDataFrame. |
|
Read SFINCS weir (.weir) file. |
|
Write SFINCS weir (.weir) file, and set weirfile in config (if it was not already set). |
|
Create model weir lines (old name: setup_structures). |
|
SFINCS drainage structures component. |
|
Drainage structures data, returns geopandas.GeoDataFrame |
|
Read SFINCS drainage structures (.drn) file. |
|
Write SFINCS drainage structures (.drn) file, and make sure drnfile is in config (if it was not already set). |
|
Create drainage structures such as pumps, culverts, valves, or gates (old name: setup_drainage_structures). |
Forcing#
Water level boundary component for SFINCS models. |
|
Get the internal xarray dataset/dataarray containing point timeseries and geometry information. |
|
Read SFINCS boundary conditions (.bnd, .bzs, .bca files) or netcdf file. |
|
Write SFINCS boundary conditions (.bnd, .bzs, .bca files) or netcdf file. |
|
Setup waterlevel forcing. |
|
|
Applies time series boundary conditions for each point Create numpy datetime64 array for time series with python datetime.datetime objects |
|
Generates boundary time series file from astronomical components |
|
Get boundary points from waterlevel boundary cells of mask in grid or quadtree grid. |
Discharge point component for SFINCS models. |
|
Get the internal xarray dataset/dataarray containing point timeseries and geometry information. |
|
Read SFINCS discharge points (.dis, .src files) or netcdf file. |
|
Write SFINCS discharges (.src, .dis files) or netcdf file. |
|
Setup discharge forcing. |
|
|
Applies time series discharges for each point Create numpy datetime64 array for time series with python datetime.datetime objects |
SFINCS precipitation forcing. |
|
Meteo data. |
|
Read precipitation data from file. |
|
Write meteo data to file. |
|
Setup precipitation forcing from a gridded spatially varying data source. |
|
|
Setup spatially uniform precipitation forcing (precip). |
Meteo data. |
|
Read meteo data from file. |
|
Write meteo data to file. |
|
Setup pressure forcing from a gridded spatially varying data source. |
|
Meteo data. |
|
|
Read meteo data from file. |
Write meteo data to file. |
|
|
Setup wind forcing from a gridded spatially varying data source. |
Setup spatially uniform wind forcing (wind). |
|
This class contains functions to create and manage river inflow/outflow points in the SFINCS model. |
|
River geometry data. |
|
Read the file(s) into the component. |
|
Write the river inflow data to a gis-file. |
|
Setup discharge (src) points where a river enters the model domain. |
Output#
SFINCS model output component. |
SFINCS workflows#
|
Merge a list of data arrays by reprojecting these to a common destination grid and combine valid values. |
|
Return merged data from two data arrays. |
|
Burn rivers with a rectangular cross profile into a DEM. |
|
Snaps point locations to grid cell with smallest difference in upstream area within wdw around the original location if the local cell does not meet the error criteria. |
|
Returns the locations where a river flows in (inflow=True) or out (inflow=False) of the model gdf_mask. |
Returns the centerline of rivers based on a flow direction raster data (da_flwdir). |
Infiltration#
Estimation maths only; these take already-read arrays and tables and return SFINCS parameter maps. Reading data and writing config is done by the infiltration components.
|
Return Ksat as float32 with nodata and negative values set to NaN. |
|
Normalize single- and dual-HSG classes to the requested convention. |
|
Convert curve numbers to potential maximum soil moisture retention S. |
Map land-use and HSG classes to curve numbers. |
|
|
Adjust CN-II values to a requested antecedent moisture condition. |
|
Estimate SCS curve-number-with-recovery parameters. |
Estimate spatially varying constant infiltration from Ksat and land use. |
|
|
Estimate Green-Ampt parameters from HSG classes and optional Ksat. |
|
Estimate Green-Ampt parameters from soil classes, Ksat, and land use. |
|
Estimate Horton parameters from HSG classes and optional Ksat. |
|
Estimate Horton parameters from soil classes, Ksat, and land use. |
|
Estimate bucket parameters from HSG classes and optional Ksat. |
|
Estimate bucket parameters from soil classes, Ksat, and land use. |
Flood map downscaling#
Create a downscaled floodmap for (model) region. |
|
Cell-space WSE dilation pre-step — works on both quadtree and regular grids. |
|
Add the velocity head v²/(2g) to zsmax (Bernoulli correction). |
|
Remove disconnected flooding from a downscaled depth raster. |
|
|
Make a Cloud Optimized GeoTIFF (COG) file with the corresponding indices of the SFINCS grid cells to the high-resolution DEM COG. |
|
Write a Cloud Optimized GeoTIFF (COG) with merged topobathy data. |
SFINCS low-level methods#
Input/Output methods#
|
Read binary map. |
|
Write binary map file. |
|
Read binary map index file. |
|
Write flat index of binary map file. |
Read ascii map |
|
|
Write ascii map |
|
Read ascii timeseries files such as sfincs.bzs, sfincs.dis and sfincs.precip. |
|
Write pandas.DataFrame to fixed width ascii timeseries files such as sfincs.bzs, sfincs.dis and sfincs.precip. |
|
Read sfincs xy files and parse to GeoDataFrame. |
|
Write geopandas.GeoDataFrame with Point geometries to point xy files. |
|
Read xyn files. |
|
Write xyn files, for example observation points with names. |
Read structure files to list of dictionaries. |
|
|
Write list of structure dictionaries to file |
|
Read drainage structure files to geodataframe. |
|
Write structure files from list of dictionaries. |
|
Read sfincs_map.nc staggered grid netcdf files and parse to two hydromt.RasterDataset objects: one with face and one with edge variables. |
|
Read sfincs_his.nc point timeseries netcdf file and parse to hydromt.GeoDataset object. |
Utilities#
|
Checks and/or parses datetime from a string, default sfincs datetime string format |
|
Convert GeoDataFrame[LineString] to list of structure dictionaries |
|
Convert list of structure dictionaries to GeoDataFrame[LineString] |
|
Convert GeoDataFrame[Polygon] to list of structure dictionaries |
|
Convert list of structure dictionaries to GeoDataFrame[Polygon] |
|
Get bounds of vectorized mask as GeoDataFrame. |
|
Convert a boolean mask to a GeoDataFrame of polygons. |
|
Returns the origin (x0, y0), shape (mmax, nmax) and rotation of the rotated grid fitted to the minimum rotated rectangle around the area of interest (pol). |
Visualization#
|
Create basemap plot. |
|
Plot model timeseries forcing. |