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[, ...])

This component sets 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(qinf)

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_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_structures(structures, stype)

Setup thin dam or weir structures.

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(timeseries)

Setup spatially uniform precipitation forcing (precip).

SfincsModel.setup_precip_forcing_from_grid([...])

Setup precipitation 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])

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.

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.get_rivbank_dz(gdf_riv, da_msk, da_hnd)

Return river bank height estimated as from height above nearest drainage (HAND) values adjecent to river cells.

workflows.get_river_bathymetry(ds, flwdir[, ...])

Estimate river bedlevel zb using gradually varying flow (gvf), manning's equation (manning) or a power-law relation (powlaw) rivdph_method.

workflows.burn_river_zb(gdf_riv, da_elv, da_msk)

Burn bedlevels from gdf_riv (column zb) into the DEM da_elv at river cells indicated in da_msk.

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_boundary_points(region, res)

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

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, crs])

utils.read_geoms(fn)

Read structure files to list of dictionaries.

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

Write list of structure dictionaries to file

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