hydromt_wflow.components.WflowStatesComponent#

Summary of Methods and Attributes#

class WflowStatesComponent(model: Model, *, filename: str = 'instate/instates.nc', region_component: str | None = None, region_filename: str | None = 'staticgeoms/states_region.geojson')[source]#

Bases: GridComponent

ModelComponent class for Wflow states.

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

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

Set the states data.

Parameters:
  • data (xr.Dataset or xr.DataArray) – The states data to set/add.

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

drop_vars(names: list[str], errors: str = 'raise')[source]#

Drop variables from the states.

This method is a wrapper around the xarray.Dataset.drop_vars method.

Parameters:
  • names (list of str) – List of variable names to drop from the states.

  • errors (str, optional {raise, ignore}) – How to handle errors. If ‘raise’, raises a ValueError error if any of the variable passed are not in the dataset. If ‘ignore’, any given names that are in the dataset are dropped and no error is raised.

clip(reservoir_name: str = 'reservoir_area_id', reservoir_states: list[str] = [])[source]#

Clip the states component to the region of the region component.

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

Parameters:
  • reservoir_name (str, optional) – Name of the reservoir id variable in the region component, by default “reservoir_area_id”

  • reservoir_states (list of str, optional) – List of state names in the wflow model states to be treated as reservoirs. These states are removed if empty after clipping.

read()[source]#

Read states at <root/dir_input/state.path_input>.

Checks the path of the file in the config toml using both state.path_input and dir_input. If not found uses the default path instate/instates.nc in the root folder.

Parameters:

filename (str or Path, optional) – A path relative to the root where the states file will be read from. By default ‘instate/instates.nc’.

write(filename: str | None = None)[source]#

Write states at <root/dir_input/state.path_input> in model ready format.

Checks the path of the file in the config toml using both state.path_input and dir_input. If not found uses the default path instate/instates.nc in the root folder. If filename is provided, it will be used and config state.path_input will be updated accordingly.

Parameters:

filename (str or Path, optional) – Name of the states file, relative to model root and dir_input if any. By default None to use the name as defined in the model config file.

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

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