hydromt_delwaq.components.DelwaqStaticdataComponent#

Summary of Methods and Attributes#

class hydromt_delwaq.components.DelwaqStaticdataComponent(model: Model, *, filename: str = 'staticdata/{name}.dat', region_filename: str = 'geoms/region.geojson')[source]#

Bases: GridComponent

Delwaq staticdata component.

Inherits from the HydroMT-core GridComponent model-component. It is used for setting, creating, writing, and reading static and cyclic data for a Delwaq model on a regular grid. The component data, stored in the data property of this class, is of the hydromt.gis.raster.RasterDataset type which is an extension of xarray.Dataset for regular grid.

Initialize a DelwaqStaticdataComponent.

Parameters:
  • model (Model) – HydroMT model instance

  • filename (str) – The path to use for reading and writing of component data by default. By default “staticdata/{name}.dat”.

  • region_filename (str) – The path to use for reading and writing of the region data by default. By default “geoms/region.geojson”.

read(filename: str = 'staticdata/{name}.dat', **kwargs)[source]#

Read staticdata at <root/fn> and parse to xarray.

For now, this function only allows to read the netcdf copy of the grid.

Parameters:

filename (str, optional) – filename relative to model root and should contain a {name} placeholder, by default ‘staticdata/{name}.dat’. For the netcdf file, the placeholder will be replaced by the name staticdata.

write(filename: str = 'staticdata/{name}.dat')[source]#

Write grid at <root/fn> in NetCDF and binary format.

Parameters:

fn (str, optional) – filename relative to model root and should contain a {name} placeholder, by default ‘staticdata/{name}.dat’. For the netcdf file, the placeholder will be replaced by the name staticdata.

write_monitoring(monpoints, monareas)[source]#

Write monitoring files and config in ASCII format.

Input:
  • monpoints - xr.DataArray of monitoring points location

  • monareas - xr.DataArray of monitoring areas location

test_equal(other: ModelComponent) tuple[bool, dict[str, str]][source]#

Test if two staticdata components are equal.

Checks the model component type as well as the data variables and their values.

Parameters:

other (ModelComponent) – The component to compare against.

Returns:

True if the components are equal, and a dict with the associated errors per property checked.

Return type:

tuple[bool, Dict[str, str]]

property bounds: Tuple[float, float, float, float] | None#

Returns the bounding box of the model grid.

close() None#

Clean up all open datasets. Method to be called before finish_write.

property crs: CRS | None#

Returns coordinate reference system embedded in the model grid.

property data: Dataset#

Model static gridded data as xarray.Dataset.

property data_catalog: DataCatalog#

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

finish_write()#

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

All DeferredFileClose objects can overwrite any lazy loaded files now.

static get_mask_layer(mask: str | DataArray | None, *args) DataArray | None#

Get the proper mask layer based on itself or a layer in a Dataset.

Parameters:
  • mask (str | xr.DataArray | None) – The mask itself or the name of the mask layer in another dataset.

  • *args (list) – These have to be xarray Datasets in which the mask (as a string) can be present

property model: Model#

Return the model object this component is associated with.

property name_in_model: str#

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

property region: GeoDataFrame | None#

Provide access to the underlying GeoDataFrame data of the model region.

property res: Tuple[float, float] | None#

Returns the resolution of the model grid.

property root: ModelRoot#

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

set(data: DataArray | Dataset | ndarray, name: str | None = None, mask: str | DataArray | None = None, force_sn: bool = False)#

Add data to grid.

All layers of grid must have identical spatial coordinates.

Parameters:
  • data (xarray.DataArray or xarray.Dataset) – new map layer to add to grid

  • name (str, optional) – Name of new map layer, this is used to overwrite the name of a DataArray and ignored if data is a Dataset

  • mask (xr.DataArray, optional) – Name of the mask layer in the grid (self) or data, or directly the mask layer to use. Should be a DataArray where .raster.nodata is used to define the mask. If None or not present as a layer, no masking is applied.

  • force_sn (bool, optional, default=False) – If True, the y-axis is oriented such that increasing y values go from South to North. If False, incoming data is used as is.

property transform: Affine | None#

Returns spatial transform of the model grid.

write_region(filename: str | None = None, *, to_wgs84: bool = False, to_file_kwargs: dict[str, Any] | None = None) None#

Write the model region to file.

The region is an auxiliary file that is often not required by the model, but can be useful for getting data from the data catalog. Plugin implementors may choose to write this file on write for a specific component.

Parameters:
  • filename (str, optional) – The filename to write the region to. If None, the filename provided at initialization is used.

  • to_wgs84 (bool) – If True, the region is reprojected to WGS84 before writing.

  • to_file_kwargs (dict, optional) – Additional keyword arguments passed to the geopandas.GeoDataFrame.to_file function.