hydromt_wflow.components.WflowForcingComponent#

Summary of Methods and Attributes#

class WflowForcingComponent(model: Model, *, filename: str = 'inmaps.nc', region_component: str | None = None, region_filename: str = 'staticgeoms/forcing_region.geojson')[source]#

Bases: GridComponent

Wflow forcing component.

This class is used for setting, creating, writing, and reading the Wflow 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.

read(**kwargs)[source]#

Read forcing model data at root/dir_input/filename.

Checks the path of the file in the config toml using both input.path_forcing and dir_input. If not found uses the default path inmaps.nc in the root folder.

If several files are used using ‘*’ in input.path_forcing, all corresponding files are read and merged into one xarray dataset before being split to one xarray DataArray per forcing variable in the hydromt forcing dictionary.

Parameters:

**kwargs (dict) – Additional keyword arguments to be passed to the read_nc method.

write(*, filename: str | None = None, output_frequency: str | None = None, time_chunk: int = 1, time_units='days since 1900-01-01T00:00:00', decimals: int = 2, overwrite: bool = False, **kwargs) None[source]#

Write forcing model data.

If no filename path is provided and path_forcing from the wflow toml exists, the following default filenames are used:

  • Default name format (with downscaling): inmaps_sourcePd_sourceTd_methodPET_freq_startyear_endyear.nc

  • Default name format (no downscaling): inmaps_sourceP_sourceT_methodPET_freq_startyear_endyear.nc

Key-word arguments are passed to write_nc()

Parameters:
  • filename (str, optional) – Filepath to write the forcing data to, either absolute or relative to the model root. If None, the default filename will be used.

  • output_frequency (str, optional) – The frequency of the files being written. If e.g. ‘3M’ (3 months) is specified then files are written with a maximum of 3 months worth of data. By default None

  • time_chunk (int, optional) – The chunk size for the time dimension when writing the forcing data. By default 1.

  • time_units (str, optional) – Common time units when writing several netcdf forcing files. By default “days since 1900-01-01T00:00:00”.

  • decimals (int, optional) – Number of decimals to use when writing the forcing data. By default 2.

  • overwrite (bool, optional) – Whether to overwrite existing files. Default is False unless the model is in w+ mode (FORCED_WRITE).

  • **kwargs (dict) – Additional keyword arguments to be passed to the write_nc method.

set(data: DataArray | Dataset, name: str | None = None)[source]#

Add data to forcing.

All layers in data must have identical spatial coordinates to existing forcing and staticmaps.

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

  • 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

clip()[source]#

Clip the forcing component to the region of the region component.

If no region component is set, the forcing component is clipped to its own extent.

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

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

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.