Supporting functionalities#
Supporting functions and (GIS) methods are the engine of HydroMT. Methods provide the low-level functionality, only accessible through the Python interface, to do the required processing of common data types such as grid and vector data.
HydroMT also provides higher-level processes that combine multiple methods to accomplish common tasks. These processes are used in the HydroMT model components to prepare model input data, but can also be used directly through the Python API. You can find which model processes are available in the model processes documentation
HydroMT provides a wide range of supporting functionalities, including:
RasterDataset#
Some powerful functionality that HydroMT uses is exposed in the gis module. In this
module xarray accessors are located. These
allow for powerful new methods on top of xarray Dataset and DataArray classes.
HydroMT RasterDataset builds on top of these accessors to
work with raster data. Available methods include reprojection, resampling, transforming,
interpolating nodata or zonal statistics. And properties such as crs, bounds, or resolution .
To access these methods in python, first load a xarray Dataset or DataArray, for example
using the HydroMT get_rasterdataset method
and use the raster accessor following by the method or attribute you want to use.
All available methods and properties are documented in the raster API documentation.
import hydromt
# Load a raster dataset from the data catalog
cat = hydromt.DataCatalog('path_to_your_catalog.yml')
ds = cat.get_rasterdataset('your_raster_key')
# Use the raster accessor to reproject the dataset
ds_reprojected = ds.raster.reproject(dst_crs='EPSG:4326', method="nearest")
# Get the bounds of the dataset
bounds = ds.raster.bounds
print(bounds)
For more example, you can check the working with raster data notebook.
GeoDataset#
Some powerful functionality that HydroMT uses is exposed in the gis module. In this
module xarray accessors are located. These
allow for powerful new methods on top of xarray Dataset and DataArray classes.
HydroMT GeoDataset builds on top of these accessors to work
with geospatial vector data (N-dim point/line/polygon geometry). Available methods include
reprojection, transforming, updating geometry or converting to geopandas.GeoDataFrame to
access further GIS methods. And properties such as crs, bounds or geometry.
To access these methods in python, first load a xarray Dataset or DataArray, for example
using the HydroMT get_geodataset method
and use the vector accessor following by the method or attribute you want to use.
All available methods and properties are documented in the GeoDataset API documentation.
import hydromt
# Load a geodataset from the data catalog
cat = hydromt.DataCatalog('path_to_your_catalog.yml')
gds = cat.get_geodataset('your_geodataset_key')
# Use the vector accessor to reproject the geodataset
gds_reprojected = gds.vector.to_crs(dst_crs='EPSG:4326')
# Convert to geopandas GeoDataFrame
gdf = gds.vector.geometry
print(gdf.head())
For more example, you can check the working with geodataset notebook.
Flow directions#
PyFlwDir contains a series of
methods to work with gridded DEM and flow direction datasets. The gis.flw module
builds on top of this and provides hydrological methods for raster DEM and flow direction data. For
example, calculate flow direction, flow accumulation, stream network, catchments, or
reproject hydrography.
Available methods are listed in the flow directions API documentation.
You can find examples of how to use these methods in the working with flow direction notebook.
Statistical methods#
HydroMT stats.skills module provides different statistical functions to compare model results with observations.
They include:
Absolute and percentual bias
Nash-Sutcliffe model Efficiency (NSE) and log Nash-Sutcliffe model Efficiency (log-NSE)
Various versions of the Kling-Gupta model Efficiency (KGE)
Coefficient of determination (R-squared)
Mean Squared Error (MSE) and Root Mean Squared Error (RMSE)
The full list is available in the skills statistics API.
As HydroMT provides methods to easily read the model results, applying a skill statistic just takes a few lines of code and can be applied directly across all observation locations in your model.
from hydromt.stats import nashsutcliffe
from hydromt_wflow import WflowModel
import xarray as xr
# read model results
# NOTE: the name of the results depends on the wflow run configuration (toml file)
mod = WflowModel(root=r'/path/to/wflow_model/root', mode='r')
sim = mod.results['Q_gauges_grdc']
# read observations
obs = xr.open_dataset(r'/path/to/grdc_obs.nc')
# calculate skill statistic
nse = nashsutcliffe(sim, obs)
Extreme Value Analysis#
HydroMT stats.extremes module provides different functions to perform Extreme Value Analysis (EVA) on hydrological data.
They include full extreme value analysis or sub methods to get peaks, fit extremes or get return values.
The full list is available in the extreme value analysis API.
You can find examples of how to use these methods in the extreme value analysis notebook.