API reference#

SFINCS model class#

Initialize#

SfincsModel(root, mode, config_fn, ...[, logger])

The SFINCS model class (SfincsModel) contains methods to read, write, setup and edit SFINCS models.

Setup components#

SfincsModel.setup_config(**cfdict)

Update config with a dictionary.

SfincsModel.setup_region(region[, ...])

Set the region of interest of the model.

SfincsModel.setup_grid(x0, y0, dx, dy, nmax, ...)

Setup a regular or quadtree grid.

SfincsModel.setup_grid_from_region(region[, ...])

Setup a regular or quadtree grid from a region.

SfincsModel.setup_dep(datasets_dep[, ...])

Interpolate topobathy (dep) data to the model grid.

SfincsModel.setup_mask_active([mask, ...])

Setup active model cells.

SfincsModel.setup_mask_bounds([btype, ...])

Set boundary cells in the model mask.

SfincsModel.setup_manning_roughness([...])

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.

SfincsModel.setup_constant_infiltration([...])

Setup spatially varying constant infiltration rate (qinffile).

SfincsModel.setup_cn_infiltration(cn[, ...])

Setup model potential maximum soil moisture retention map (scsfile) from gridded curve number map.

SfincsModel.setup_cn_infiltration_with_ks(...)

Setup model the Soil Conservation Service (SCS) Curve Number (CN) files for SFINCS including recovery term based on the soil saturation

SfincsModel.setup_subgrid(datasets_dep[, ...])

Setup method for subgrid tables based on a list of elevation and Manning's roughness datasets.

SfincsModel.setup_river_inflow([rivers, ...])

Setup discharge (src) points where a river enters the model domain.

SfincsModel.setup_river_outflow([rivers, ...])

Setup open boundary cells (mask=3) where a river flows out of the model domain.

SfincsModel.setup_observation_points(locations)

Setup model observation point locations.

SfincsModel.setup_observation_lines(locations)

Setup model observation lines (cross-sections) to monitor discharges.

SfincsModel.setup_structures(structures, stype)

Setup thin dam or weir structures.

SfincsModel.setup_drainage_structures(structures)

Setup drainage structures.

SfincsModel.setup_storage_volume(storage_locs)

Setup storage volume.

SfincsModel.setup_waterlevel_forcing([...])

Setup waterlevel forcing.

SfincsModel.setup_waterlevel_bnd_from_mask([...])

Setup waterlevel boundary (bnd) points along model waterlevel boundary (msk=2).

SfincsModel.setup_discharge_forcing([...])

Setup discharge forcing.

SfincsModel.setup_discharge_forcing_from_grid(...)

Setup discharge forcing based on a gridded discharge dataset.

SfincsModel.setup_precip_forcing([...])

Setup spatially uniform precipitation forcing (precip).

SfincsModel.setup_precip_forcing_from_grid(precip)

Setup precipitation forcing from a gridded spatially varying data source.

SfincsModel.setup_pressure_forcing_from_grid(press)

Setup pressure forcing from a gridded spatially varying data source.

SfincsModel.setup_wind_forcing([timeseries, ...])

Setup spatially uniform wind forcing (wind).

SfincsModel.setup_wind_forcing_from_grid(wind)

Setup pressure forcing from a gridded spatially varying data source.

SfincsModel.setup_tiles([path, region, ...])

Create both index and topobathy tiles in webmercator format.

Plot methods#

SfincsModel.plot_basemap([fn_out, variable, ...])

Create basemap plot.

SfincsModel.plot_forcing([fn_out, forcings])

Plot model timeseries forcing.

Attributes#

SfincsModel.region

Returns the geometry of the active model cells.

SfincsModel.mask

Returns model mask

SfincsModel.crs

Returns the model crs

SfincsModel.res

Returns the resolution of the model grid.

SfincsModel.root

Path to model folder.

SfincsModel.config

Model configuration.

SfincsModel.grid

Model static gridded data as xarray.Dataset.

SfincsModel.geoms

Model geometries.

SfincsModel.forcing

Model forcing.

SfincsModel.states

Model states.

SfincsModel.results

Model results.

High level methods#

SfincsModel.read([epsg])

Read the complete model schematization and configuration from file.

SfincsModel.write()

Write the complete model schematization and configuration to file.

SfincsModel.build([region, write, opt])

Single method to build a model from scratch based on settings in opt.

SfincsModel.update([model_out, write, opt, ...])

Single method to update a model based the settings in opt.

SfincsModel.set_root(root[, mode])

Initialize the model root.

Low level methods#

SfincsModel.update_grid_from_config()

Update grid properties based on config (sfincs.inp) attributes

SfincsModel.update_spatial_attrs()

Update geospatial config (sfincs.inp) attributes based on grid

SfincsModel.set_forcing_1d([df_ts, ...])

Set 1D forcing time series for 'bzs' or 'dis' boundary conditions.

SfincsModel.get_model_time()

Return (tstart, tstop) tuple with parsed model start and end time

General methods#

SfincsModel.setup_config(**cfdict)

Update config with a dictionary.

SfincsModel.get_config(*args[, fallback, ...])

Get a config value at key(s).

SfincsModel.set_config(*args)

Update the config dictionary at key(s) with values.

SfincsModel.read_config([config_fn, epsg])

Parse config from SFINCS input file.

SfincsModel.write_config([config_fn])

Write config to <root/config_fn>

SfincsModel.set_grid(data[, name])

Add data to grid.

SfincsModel.read_grid([data_vars])

Read SFINCS binary grid files and save to grid attribute.

SfincsModel.write_grid([data_vars])

Write SFINCS grid to binary files including map index file.

SfincsModel.read_subgrid()

Read SFINCS subgrid file and add to subgrid attribute.

SfincsModel.write_subgrid()

Write SFINCS subgrid file.

SfincsModel.set_geoms(geom, name)

Add data to the geoms attribute.

SfincsModel.read_geoms()

Read geometry files and save to geoms attribute.

SfincsModel.write_geoms([data_vars])

Write geoms to bnd/src/obs xy files and thd/weir structure files.

SfincsModel.set_forcing(data[, name, ...])

Add data to forcing attribute.

SfincsModel.read_forcing([data_vars])

Read forcing files and save to forcing attribute.

SfincsModel.write_forcing([data_vars])

Write forcing to ascii or netcdf (netampr) files.

SfincsModel.set_states(data[, name, ...])

Add data to states attribute.

SfincsModel.read_states()

Read waterlevel state (zsini) from binary file and save to states attribute.

SfincsModel.write_states()

Write waterlevel state (zsini) to binary map file.

SfincsModel.set_results(data[, name, ...])

Add data to results attribute.

SfincsModel.read_results([chunksize, drop, ...])

Read results from sfincs_map.nc and sfincs_his.nc and save to the results attribute.

SFINCS workflows#

workflows.merge_multi_dataarrays(da_list[, ...])

Merge a list of data arrays by reprojecting these to a common destination grid and combine valid values.

workflows.merge_dataarrays(da1, da2[, ...])

Return merged data from two data arrays.

workflows.burn_river_rect(da_elv, gdf_riv[, ...])

Burn rivers with a rectangular cross profile into a DEM.

workflows.snap_discharge(ds, gdf[, wdw, ...])

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.

workflows.river_source_points(gdf_riv, gdf_mask)

Returns the locations where a river flows in (inflow=True) or out (inflow=False) of the model gdf_mask.

workflows.river_centerline_from_hydrography(...)

Returns the centerline of rivers based on a flow direction raster data (da_flwdir).

workflows.landuse

Landuse related workflows for SFINCS.

workflows.cn_to_s(da_cn[, da_mask, nodata])

Convert Curve Numbers to potential maximum soil moisture retention S [inch].

workflows.create_topobathy_tiles(root, ...)

Create webmercator topobathy tiles for a given region.

workflows.downscale_floodmap_webmercator(...)

Create a downscaled floodmap for (model) region in webmercator tile format

SFINCS low-level methods#

Input/Output methods#

utils.read_binary_map(fn, ind, shape[, mv, ...])

Read binary map.

utils.write_binary_map(fn, data, msk[, dtype])

Write binary map file.

utils.read_binary_map_index(fn_ind)

Read binary map index file.

utils.write_binary_map_index(fn_ind, msk)

Write flat index of binary map file.

utils.read_ascii_map(fn)

Read ascii map

utils.write_ascii_map(fn, data[, fmt])

Write ascii map

utils.read_timeseries(fn, tref)

Read ascii timeseries files such as sfincs.bzs, sfincs.dis and sfincs.precip.

utils.write_timeseries(fn, df, tref[, fmt])

Write pandas.DataFrame to fixed width ascii timeseries files such as sfincs.bzs, sfincs.dis and sfincs.precip.

utils.read_xy(fn[, crs])

Read sfincs xy files and parse to GeoDataFrame.

utils.write_xy(fn, gdf[, fmt])

Write geopandas.GeoDataFrame with Point geometries to point xy files.

utils.read_xyn(fn[, crs])

utils.write_xyn([fn, gdf, fmt])

utils.read_geoms(fn)

Read structure files to list of dictionaries.

utils.write_geoms(fn, feats[, stype, fmt, fmt_z])

Write list of structure dictionaries to file

utils.read_drn(fn[, crs])

Read drainage structure files to geodataframe.

utils.write_drn(fn, gdf_drainage[, fmt])

Write structure files from list of dictionaries.

utils.read_sfincs_map_results(fn_map, ds_like)

Read sfincs_map.nc staggered grid netcdf files and parse to two hydromt.RasterDataset objects: one with face and one with edge variables.

utils.read_sfincs_his_results(fn_his[, crs, ...])

Read sfincs_his.nc point timeseries netcdf file and parse to hydromt.GeoDataset object.

Utilities#

utils.parse_datetime(dt[, format])

Checks and/or parses datetime from a string, default sfincs datetime string format

utils.gdf2linestring(gdf)

Convert GeoDataFrame[LineString] to list of structure dictionaries

utils.linestring2gdf(feats[, crs])

Convert list of structure dictionaries to GeoDataFrame[LineString]

utils.gdf2polygon(gdf)

Convert GeoDataFrame[Polygon] to list of structure dictionaries

utils.polygon2gdf(feats[, crs, zmin, zmax])

Convert list of structure dictionaries to GeoDataFrame[Polygon]

utils.get_bounds_vector(da_msk)

Get bounds of vectorized mask as GeoDataFrame.

utils.mask2gdf(da_mask[, option])

Convert a boolean mask to a GeoDataFrame of polygons.

utils.rotated_grid(pol, res[, dec_origin, ...])

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#

plots.plot_basemap(ds, geoms[, variable, ...])

Create basemap plot.

plots.plot_forcing(forcing, **kwargs)

Plot model timeseries forcing.

utils.downscale_floodmap(zsmax, dep[, hmin, ...])

Create a downscaled floodmap for (model) region.

workflows.downscale_floodmap_webmercator(...)

Create a downscaled floodmap for (model) region in webmercator tile format