hydromt_delwaq.components.DemissionForcingComponent#

Summary of Methods and Attributes#

class hydromt_delwaq.components.DemissionForcingComponent(model: Model, *, filename: str = 'dynamicdata/{name}.dat', region_component: str | None = None)[source]#

Bases: DelwaqForcingComponent

Demission forcing component.

Class used for setting, creating, writing, and reading the Demission forcing. The forcing 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 DelwaqForcingComponent.

Parameters:
  • model (Model) – HydroMT model instance

  • filename (str, optional) – Default path relative to the root where the forcing file(s) will be read and written. By default “dynamicdata/{name}.dat”.

  • region_component (str, optional) – The name of the region component to use as reference for this component’s region. If None, the region will be set to the grid extent.

write(filename: str = 'dynamicdata/{name}.dat', write_nc: bool = False)[source]#

Write forcing at <root/fn> in binary format.

Can also write a netcdf copy if write_nc is True. The output files are:

  • hydrology.bin binary file containing the hydrology data.

  • sediment.dat binary file containing the sediment data.

  • climate.dat binary file containing the climate data.

Parameters:
  • fn (str, optional) – filename relative to model root and should contain a {name} placeholder, by default ‘dynamicdata/{name}.dat’

  • write_nc (bool, optional) – If True, write a NetCDF copy of the forcing data, by default False.

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.

read(filename: str = 'dynamicdata/{name}.dat')#

Read netcdf copy of the forcing if exists at <root/filename>.

Parameters:

filename (str, optional) – filename relative to model root and should contain a {name} placeholder, by default ‘dynamicdata/{name}.dat’

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.

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

Test if two forcing 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 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.