hydromt_wflow.components.WflowStaticmapsComponent#
Summary of Methods and Attributes#
Component class |
Methods |
Attributes |
|---|---|---|
|
|
- class WflowStaticmapsComponent(model: Model, *, filename: str = 'staticmaps.nc', region_filename: str = 'staticgeoms/region.geojson')[source]#
Bases:
GridComponentWflow staticmaps component.
Inherits from the HydroMT-core GridComponent model-component. It is used for setting, creating, writing, and reading static and cyclic data for a Wflow model on a regular grid. The 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 staticmaps model data.
Checks the path of the file in the config toml using both
input.path_staticanddir_input. If not found uses the default pathstaticmaps.ncin the root folder. Key-word arguments are passed to_read_nc()- Parameters:
**kwargs (dict) – Additional keyword arguments to be passed to the read_nc method.
- write(filename: str | None = None, **kwargs)[source]#
Write staticmaps model data.
Checks the path of the file in the config toml using both
input.path_staticanddir_input. If not found uses the default pathstaticmaps.ncin the root folder.If filename is supplied, the config will be updated.
Key-word arguments are passed to
_write_nc()- Parameters:
- set(data: DataArray | Dataset, name: str | None = None)[source]#
Add data to the staticmaps.
All layers of grid must have identical spatial coordinates. If basin data is available the grid will be masked to that upon setting.
The first fix is when data with a time axis is being added. Since Wflow.jl v0.7.3, cyclic data at different lengths (12, 365, 366) is supported, as long as the dimension name starts with “time”. In this function, a check is done if a time axis with that exact shape is already present in the grid object, and will use that dimension (and its name) to set the data. If a time dimension does not yet exist with that shape, it is created following the format “time_{length_data}”.
The other fix is that when the model is updated with a different number of layers, this is not automatically updated correctly. With this fix, the old layer dimension is removed (including all associated data), and the new data is added with the correct “layer” dimension.
- Parameters:
data (xr.DataArray | xr.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
- drop_vars(names: list[str], errors: str = 'raise')[source]#
Drop variables from the grid.
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 grid.
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(region: dict, inverse_clip: bool = False, crs: int = 4326, basins_name: str = 'subcatchment', flwdir_name: str = 'local_drain_direction', reservoir_name: str = 'reservoir_area_id', reservoir_maps: list[str] = [], **kwargs)[source]#
Clip staticmaps to region.
Staticmaps are clipped to the region defined in the region argument. If inverse_clip is True, the upstream part of the model is removed instead of the subbasin itself. After clipping, the flow direction map is re-derived to ensure that all edges of the clipped model are pits. If reservoir maps are present in the staticmaps but no reservoirs are present in the clipped model, these maps are removed from the staticmaps.
Note that the outlets are not re-derived in this function and should be done separately using WflowBaseModel.setup_outlets.
- Parameters:
region (dict) – The region to clip to.
inverse_clip (bool, optional) – Flag to perform “inverse clipping”: removing an upstream part of the model instead of the subbasin itself, by default False
crs (int, optional) – Default crs of the model in case it cannot be read.
basins_name (str, optional) – Name of the basin/subbasin variable in the staticmaps data, by default “subcatchment”
flwdir_name (str, optional) – Name of the flow direction variable in the staticmaps data, by default “local_drain_direction”
reservoir_name (str, optional) – Name of the reservoir id variable in the staticmaps data, by default “reservoir_area_id”
reservoir_maps (list of str, optional) – List of map names in the wflow model grid to be treated as reservoirs. These maps are removed if empty after clipping.
**kwargs (dict) – Additional keyword arguments passed to
clip_geom()
- update_names(**rename)[source]#
Map the names of the data variables to new ones.
This method however does not change the new names in the config file. To update config file entries, you can use it together with the WflowBaseModel.setup_config method.
- Parameters:
rename (dict, optional) – Keyword arguments that map the old names to the new names. So < old-name > = < new-name >.
- 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.
- 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.