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_variables attribute. write() skips those layers unless called with write_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 component read() methods ensure this grid is loaded. Their write() methods are no-ops; persistence is handled here. Component data properties expose only their relevant layers; this grid remains the full dataset and the destination for set() calls.

Initialize 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:

str

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 instance

  • filename (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

bounds

Returns the bounding box of the model grid.

coordinates

Return the coordinates of the cell-centers the regular grid.

crs

Return the coordinate reference system of the regular grid.

data

Model static gridded data as xarray.Dataset.

data_catalog

Return the data catalog of the model this component is associated with.

edges

Return the coordinates of the cell-edges the regular grid.

empty_mask

Return mask with only inactive cells

indices

Return active-cell indices in SFINCS (south-to-north) order.

mask

Return the mask of the regular grid.

model

Return the model object this component is associated with.

name_in_model

Find the name of the component in the parent model components.

region

Return the active region of the regular grid.

res

Returns the resolution of the model grid.

root

Return the root of the model this component is associated with.

transform

Return the affine transform of the regular grid.