hydromt_sfincs.components.grid.SfincsGrid#
- class hydromt_sfincs.components.grid.SfincsGrid(model: SfincsModel)[source]#
Regular grid component of the SfincsModel class.
This class implements reading and writing of SFINCS binary grid files, as well as methods to create a regular grid for a region of interest.
The data for all gridded variables is stored in the data attribute as an xarray Dataset. However, the creation of new data layers,, such as elevation or roughness, is done in separate model component classes, such as SfincsElevation or SfincsRoughness.
Layer ownership#
A component may claim the layers it is responsible for through a
grid_variablesattribute.write()skips those layers unless called withwrite_components=True; the component writes them itself through_write_layers().read()loads the mask and elevation; component-owned layers are read by their respective components.This grid always owns the cell index file (
sfincs.ind), the mask and the elevation, since every other binary map is indexed against them. Mask and elevation componentread()methods ensure this grid is loaded. Theirwrite()methods are no-ops; persistence is handled here. Componentdataproperties expose only their relevant layers; this grid remains the full dataset and the destination forset()calls.See also
SfincsElevation,SfincsMask,SfincsRoughness,SfincsInfiltration,SfincsStorageVolume,SfincsInitialConditionsInitialize a GridComponent.
- param model:
HydroMT model instance
- type model:
Model- param filename:
The path to use for reading and writing of component data by default. By default “grid/grid.nc”.
- type filename:
- param region_component:
The name of the region component to use as reference for this component’s region. If provided, the region is not written to disk. If None, the region will be set to the grid extent. Note that the create method only works if the region_component is None. For add_data_from_* methods, the other region_component should be a reference to another grid component for correct reprojection.
- type region_component:
str, optional- param region_filename:
The path to use for writing the region data to a file. By default “grid/grid_region.geojson”. If None, the region is not written to disk.
- type region_filename:
Optional[str] =
"grid/grid_region.geojson",
- __init__(model: SfincsModel)[source]#
Initialize a GridComponent.
- Parameters:
model (
Model) – HydroMT model instancefilename (
str) – The path to use for reading and writing of component data by default. By default “grid/grid.nc”.region_component (
str, optional) – The name of the region component to use as reference for this component’s region. If provided, the region is not written to disk. If None, the region will be set to the grid extent. Note that the create method only works if the region_component is None. For add_data_from_* methods, the other region_component should be a reference to another grid component for correct reprojection.region_filename (Optional[str] =
"grid/grid_region.geojson",) – The path to use for writing the region data to a file. By default “grid/grid_region.geojson”. If None, the region is not written to disk.
Methods
__init__(model)Initialize a GridComponent.
close()Clean up all open datasets.
create(x0, y0, dx, dy, nmax, mmax, rotation, ...)Create a regular grid for the SfincsModel.
create_from_region(region[, res, crs, ...])Create a regular grid for the SfincsModel based on a region.
create_index_cog(filename, filename_topobathy)Write a COG raster mapping each pixel to a grid cell index.
create_topobathy_cog(filename, elevation_list)Write a COG raster sampling the model topobathy.
finish_write()Finish the write functionality after cleanup was called for all components in the model.
get_indices_at_points(x, y)get_mask_layer(mask, *args)Get the proper mask layer based on itself or a layer in a Dataset.
ind(mask)Return indices of active cells in mask.
read([read_components])Read SFINCS binary grid files and save to data attribute.
read_ind([ind_fn])Read indices of active cells in mask from binary file.
read_map(map_fn, ind[, dtype, mv, name])Read one of the grid variables of the SFINCS model map from a binary file.
set(data[, name, mask, force_sn])Add data to grid.
test_equal(other)Test if two components are equal.
to_gdf()Return a GeoDataFrame with a geometry for each grid line.
update_config_from_grid()Update config (sfincs.inp) attributes based on grid properties
update_grid_from_config()Update grid properties based on config (sfincs.inp) attributes
write([write_components])Write SFINCS grid to binary files including map index file.
write_ind(mask[, ind_fn])Write indices of active cells in mask to binary file.
write_map(map_fn, data, mask[, dtype])Write one of the grid variables of the SFINCS model map to a binary file.
write_region([filename, to_wgs84, ...])Write the model region to file.
Attributes
boundsReturns the bounding box of the model grid.
coordinatesReturn the coordinates of the cell-centers the regular grid.
crsReturn the coordinate reference system of the regular grid.
Model static gridded data as xarray.Dataset.
data_catalogReturn the data catalog of the model this component is associated with.
edgesReturn the coordinates of the cell-edges the regular grid.
empty_maskReturn mask with only inactive cells
indicesReturn active-cell indices in SFINCS (south-to-north) order.
maskReturn the mask of the regular grid.
modelReturn the model object this component is associated with.
name_in_modelFind the name of the component in the parent model components.
regionReturn the active region of the regular grid.
resReturns the resolution of the model grid.
rootReturn the root of the model this component is associated with.
transformReturn the affine transform of the regular grid.