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.

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.

__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.

clear_datashader_dataframe()

Clears the datashader dataframe

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_tiles(root, region[, ...])

Create index tiles for a region.

finish_write()

Finish the write functionality after cleanup was called for all components in the model.

get_datashader_dataframe()

Create a datashader-friendly DataFrame for the regular grid.

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([data_vars])

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([data_vars])

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

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.