hydromt_wflow.components.WflowForcingComponent#
Summary of Methods and Attributes#
Component class |
Methods |
Attributes |
|---|---|---|
|
|
- class WflowForcingComponent(model: Model, *, filename: str = 'inmaps.nc', region_component: str | None = None, region_filename: str = 'staticgeoms/forcing_region.geojson')[source]#
Bases:
GridComponentWflow forcing component.
This class is used for setting, creating, writing, and reading the Wflow forcing. The forcing component data stored in the
dataproperty 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_forcinganddir_input. If not found uses the default pathinmaps.ncin 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 hydromtforcingdictionary.- 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
filenamepath 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
Falseunless 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.
- property bounds: Tuple[float, float, float, float] | None#
Returns the bounding box of the model grid.
- 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.
- property model: Model#
Return the model object this component is associated with.
- property region: GeoDataFrame | None#
Provide access to the underlying GeoDataFrame data of the model region.
- property root: ModelRoot#
Return the root of the model this component is associated with.
- 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.