Model#

Model class#

High-level methods#

Model([root, components, mode, data_libs, ...])

General and basic API for models in HydroMT.

Model.read([components])

Read provided components from disk.

Model.write([components])

Write provided components to disk with defaults.

Model.write_data_catalog([root, ...])

Write the data catalog to data_lib_path.

General methods#

Model.build(*[, write])

Single method to build a model from scratch based on settings in steps.

Model.update(*[, model_out, write, steps, ...])

Single method to update a model based the settings in steps.

Model.get_component(name)

Get a component from the model.

Model.add_component(name, component)

Add a component to the model.

Model.test_equal(other)

Test if two models are equal, based on their components.

Model attributes#

Model.data_catalog

DataCatalog for data access

Model.crs

Returns coordinate reference system embedded in region.

Model.root

Model root

Model.region

Return the model's region component.

Model.components

ModelRoot#

ModelRoot(path[, mode])

A class to handle model roots in a cross platform manner.

Attributes#

ModelRoot.mode

The mode of the model this object belongs to.

ModelRoot.is_writing_mode()

Test whether we are in writing mode or not.

ModelRoot.is_reading_mode()

Test whether we are in reading mode or not.

ModelRoot.is_override_mode()

Test whether we are in override mode or not.

General Methods#

ModelRoot.set(path[, mode])

Set the path of the root, and create the necessary loggers.

Model components#

ModelComponent#

Note that the base ModelComponent attributes and methods are available to all model components.

components.ModelComponent(model)

Abstract base class for ModelComponent.

components.ModelComponent.model

Return the model object this component is associated with.

components.ModelComponent.data_catalog

Return the data catalog of the model this component is associated with.

components.ModelComponent.read()

Read the file(s) into the component.

components.ModelComponent.write()

Write the component to file(s).

components.ModelComponent.root

Return the root of the model this component is associated with.

SpatialModelComponent#

components.SpatialModelComponent(model, *[, ...])

Base spatial model component for GIS components.

components.SpatialModelComponent.model

Return the model object this component is associated with.

components.SpatialModelComponent.data_catalog

Return the data catalog of the model this component is associated with.

components.SpatialModelComponent.root

Return the root of the model this component is associated with.

components.SpatialModelComponent.crs

Provide access to the CRS of the model region.

components.SpatialModelComponent.bounds

Return the total bounds of the model region.

components.SpatialModelComponent.region

Provide access to the underlying GeoDataFrame data of the model region.

Plugin developer methods

components.SpatialModelComponent._region_data

Implement this property in order to provide the region.

components.SpatialModelComponent.write_region(*)

Write the model region to file.

components.SpatialModelComponent.test_equal(other)

Test if two components are equal.

ConfigComponent#

components.ConfigComponent(model, *[, ...])

A component to manage configuration files for model simulations/settings.

components.ConfigComponent.model

Return the model object this component is associated with.

components.ConfigComponent.data_catalog

Return the data catalog of the model this component is associated with.

components.ConfigComponent.root

Return the root of the model this component is associated with.

components.ConfigComponent.data

Model config values.

components.ConfigComponent.write([path])

Write model config at <root>/{path}.

components.ConfigComponent.read([path])

Read model config at <root>/{path}.

components.ConfigComponent.create([template])

Create a new config file based on a template file.

components.ConfigComponent.update(data)

Set the config dictionary at key(s) with values.

components.ConfigComponent.set(key, value)

Update the config dictionary at key(s) with values.

components.ConfigComponent.get_value(key[, ...])

Get a config value at key(s).

components.ConfigComponent.test_equal(other)

Test if two components are equal.

GeomsComponent#

components.GeomsComponent(model, *[, ...])

A component to manage geo-spatial geometries.

components.GeomsComponent.model

Return the model object this component is associated with.

components.GeomsComponent.data_catalog

Return the data catalog of the model this component is associated with.

components.GeomsComponent.root

Return the root of the model this component is associated with.

components.GeomsComponent.data

Model geometries.

components.GeomsComponent.region

Provide access to the underlying GeoDataFrame data of the model region.

components.GeomsComponent.write([filename, ...])

Write model geometries to a vector file (by default GeoJSON) at <root>/<filename>.

components.GeomsComponent.read([filename])

Read model geometries files at <root>/<filename>.

components.GeomsComponent.set(geom, name)

Add data to the geom component.

components.GeomsComponent.test_equal(other)

Test if two GeomsComponents are equal.

TablesComponent#

components.TablesComponent(model[, filename])

TablesComponent contains data as a dictionary of pandas.DataFrame.

components.TablesComponent.model

Return the model object this component is associated with.

components.TablesComponent.data_catalog

Return the data catalog of the model this component is associated with.

components.TablesComponent.root

Return the root of the model this component is associated with.

components.TablesComponent.data

Model tables.

components.TablesComponent.write([filename])

Write tables at provided or default filepath if none is provided.

components.TablesComponent.read([filename])

Read tables at provided or default filepath if none is provided.

components.TablesComponent.set(tables[, name])

Add (a) table(s) <pandas.DataFrame> to model.

components.TablesComponent.test_equal(other)

Test if two components are equal.

DatasetsComponent#

components.DatasetsComponent(model[, filename])

A component to manage collections of Xarray objects.

components.DatasetsComponent.model

Return the model object this component is associated with.

components.DatasetsComponent.data_catalog

Return the data catalog of the model this component is associated with.

components.DatasetsComponent.root

Return the root of the model this component is associated with.

components.DatasetsComponent.data

Model data in the form of xarray objects.

components.DatasetsComponent.write([...])

Write dictionary of xarray.Dataset and/or xarray.DataArray to netcdf files.

components.DatasetsComponent.read([...])

Read model dataset files at <root>/<filename>.

components.DatasetsComponent.set(data[, ...])

Add data to the xarray component.

components.DatasetsComponent.test_equal(other)

Test if two DatasetsComponents are equal.

SpatialDatasetsComponent#

components.SpatialDatasetsComponent(model, ...)

A component to manage collection of geospatial xarray objects.

components.SpatialDatasetsComponent.model

Return the model object this component is associated with.

components.SpatialDatasetsComponent.data_catalog

Return the data catalog of the model this component is associated with.

components.SpatialDatasetsComponent.root

Return the root of the model this component is associated with.

components.SpatialDatasetsComponent.data

Model data in the form of xarray objects.

components.SpatialDatasetsComponent.region

Provide access to the underlying GeoDataFrame data of the model region.

components.SpatialDatasetsComponent.write([...])

Write dictionary of xarray.Dataset and/or xarray.DataArray to netcdf files.

components.SpatialDatasetsComponent.read([...])

Read model dataset files at <root>/<filename>.

components.SpatialDatasetsComponent.add_raster_data_from_raster_reclass(...)

HYDROMT CORE METHOD: Add data variable(s) to datasets component by reclassifying the data in raster_filename based on reclass_table_filename.

components.SpatialDatasetsComponent.add_raster_data_from_rasterdataset(...)

HYDROMT CORE METHOD: Add data variable(s) from raster_filename to datasets component.

components.SpatialDatasetsComponent.set(data)

Add data to the xarray component.

components.SpatialDatasetsComponent.test_equal(other)

Test if two DatasetsComponents are equal.

GridComponent#

components.GridComponent(model, *[, ...])

ModelComponent class for grid components.

components.GridComponent.model

Return the model object this component is associated with.

components.GridComponent.data_catalog

Return the data catalog of the model this component is associated with.

components.GridComponent.root

Return the root of the model this component is associated with.

components.GridComponent.res

Returns the resolution of the model grid.

components.GridComponent.transform

Returns spatial transform of the model grid.

components.GridComponent.crs

Returns coordinate reference system embedded in the model grid.

components.GridComponent.bounds

Returns the bounding box of the model grid.

components.GridComponent.region

Provide access to the underlying GeoDataFrame data of the model region.

components.GridComponent.data

Model static gridded data as xarray.Dataset.

components.GridComponent.write([filename, ...])

Write model grid data to netcdf file at <root>/<fn>.

components.GridComponent.read([filename, ...])

Read model grid data at <root>/<fn> and add to grid property.

components.GridComponent.create_from_region(...)

HYDROMT CORE METHOD: Create a 2D regular grid or reads an existing grid.

components.GridComponent.add_data_from_constant(...)

HYDROMT CORE METHOD: Adds data to grid component based on a constant value.

components.GridComponent.add_data_from_rasterdataset(...)

HYDROMT CORE METHOD: Add data variable(s) from raster_data to grid component.

components.GridComponent.add_data_from_raster_reclass(...)

HYDROMT CORE METHOD: Add data variable(s) to grid component by reclassifying the data in raster_data based on reclass_table_data.

components.GridComponent.add_data_from_geodataframe(...)

HYDROMT CORE METHOD: Add data variable(s) to grid component by rasterizing the data from vector_data.

components.GridComponent.set(data[, name])

Add data to grid.

components.GridComponent.test_equal(other)

Test if two components are equal.

MeshComponent#

components.MeshComponent(model, *[, ...])

ModelComponent class for mesh components.

components.MeshComponent.model

Return the model object this component is associated with.

components.MeshComponent.data_catalog

Return the data catalog of the model this component is associated with.

components.MeshComponent.root

Return the root of the model this component is associated with.

components.MeshComponent.data

Model static mesh data.

components.MeshComponent.crs

Returns model mesh crs.

components.MeshComponent.bounds

Returns model mesh bounds.

components.MeshComponent.region

Provide access to the underlying GeoDataFrame data of the model region.

components.MeshComponent.mesh_names

List of grid names in mesh.

components.MeshComponent.mesh_grids

Dictionary of grid names and Ugrid topologies in mesh.

components.MeshComponent.mesh_datasets

Dictionnary of grid names and corresponding UgridDataset topology and data variables in mesh.

components.MeshComponent.mesh_gdf

Returns dict of geometry of grids in mesh as a gpd.GeoDataFrame.

components.MeshComponent.write([filename, ...])

Write model grid data to a netCDF file at <root>/<filename>.

components.MeshComponent.read([filename, crs])

Read model mesh data at <root>/<filename> and add to mesh property.

components.MeshComponent.create_2d_from_region(...)

HYDROMT CORE METHOD: Create an 2D unstructured mesh or reads an existing 2D mesh according UGRID conventions.

components.MeshComponent.add_2d_data_from_rasterdataset(...)

HYDROMT CORE METHOD: Add data variable(s) from raster_filename to 2D grid_name in mesh object.

components.MeshComponent.add_2d_data_from_raster_reclass(...)

HYDROMT CORE METHOD: Add data variable(s) to 2D grid_name in mesh object by reclassifying the data in raster_filename based on reclass_table_filename.

components.MeshComponent.set(data, *[, ...])

Add data to mesh.

components.MeshComponent.get_mesh(grid_name)

Return a specific grid topology from mesh based on grid_name.

VectorComponent#

components.VectorComponent(model, *[, ...])

ModelComponent class for vector components.

components.VectorComponent.data

Model vector (polygon) data.

components.VectorComponent.geometry

Returns the geometry of the model vector as gpd.GeoSeries.

components.VectorComponent.index_dim

Returns the index dimension of the vector.

components.VectorComponent.crs

Returns coordinate reference system embedded in the vector.

components.VectorComponent.model

Return the model object this component is associated with.

components.VectorComponent.data_catalog

Return the data catalog of the model this component is associated with.

components.VectorComponent.root

Return the root of the model this component is associated with.

components.VectorComponent.read(*[, ...])

Read model vector from combined netcdf and geojson file.

components.VectorComponent.write(*[, ...])

Write model vector to combined netcdf and geojson files.

components.VectorComponent.set([data, name, ...])

Add data to vector.

components.VectorComponent.test_equal(other)

Test if two components are equal.

Model Processes#

Grid#

processes.grid.create_grid_from_region(region, *)

Create a 2D regular grid or reads an existing grid.

processes.grid.create_rotated_grid_from_geom(...)

Create a rotated grid based on a geometry.

processes.grid.grid_from_constant(grid_like, ...)

Prepare a grid based on a constant value.

processes.grid.grid_from_rasterdataset(...)

Prepare data by resampling ds to grid_like.

processes.grid.grid_from_raster_reclass(...)

Prepare data variable(s) resampled to grid_like object by reclassifying the data in da based on reclass_table.

processes.grid.grid_from_geodataframe(...[, ...])

Prepare data variable(s) resampled to grid_like object by rasterizing the data from gdf.

processes.grid.rotated_grid(pol, res[, ...])

Return the origin (x0, y0), shape (mmax, nmax) and rotation of the rotated grid.

Mesh#

processes.mesh.create_mesh2d_from_region(...)

HYDROMT CORE METHOD: Create an 2D unstructured mesh or reads an existing 2D mesh according UGRID conventions.

processes.mesh.create_mesh2d_from_mesh(uds, ...)

Create a 2D mesh from another mesh.

processes.mesh.create_mesh2d_from_geom(geom, ...)

Create a regular 2D mesh from a boundary geometry.

processes.mesh.mesh2d_from_rasterdataset(ds, ...)

Resamples data in ds to mesh2d.

processes.mesh.mesh2d_from_raster_reclass(da, ...)

Resample data to mesh2d grid by reclassifying the data in da based on df_vars.

Region#

processes.region.parse_region_basin(region, ...)

Parse a basin /subbasin / interbasin region and return the GeoDataFrame.

processes.region.parse_region_bbox(region, *)

Parse a region of kind bbox and return the GeoDataFrame.

processes.region.parse_region_geom(region, *)

Parse a region and return the GeoDataFrame.

processes.region.parse_region_grid(region, ...)

Parse a region of kind grid and return the corresponding xarray object.

processes.region.parse_region_other_model(region)

Parse a region with a model path and return that whole Model in read mode.

processes.region.parse_region_mesh(region)

Parse a region with a mesh path and return that mesh in read mode.

Basin mask#

processes.basin_mask.get_basin_geometry(ds)

Return a geometry of the (sub)(inter)basin(s).

River bathymetry#

processes.rivers.river_width(gdf_stream, ...)

Return average river width along a segment based on a river mask raster.

processes.rivers.river_depth(data, method[, ...])

Derive river depth estimates based bankfull discharge.

Meteo#

processes.meteo.precip(precip, da_like[, ...])

Return the lazy reprojection of precipitation to model.

processes.meteo.temp(temp, dem_model[, ...])

Return lazy reprojection of temperature to model grid.

processes.meteo.press(press, dem_model[, ...])

Return lazy reprojection of pressure to model grid.

processes.meteo.pet(ds, temp, dem_model[, ...])

Determine reference evapotranspiration.

processes.meteo.wind(da_model[, wind, ...])

Return lazy reprojection of wind speed to model grid.

processes.meteo.press_correction(dem_model)

Pressure correction based on elevation lapse_rate.

processes.meteo.temp_correction(dem[, ...])

Temperature correction based on elevation data.

processes.meteo.resample_time(da, freq[, ...])

Resample data to destination frequency.

processes.meteo.delta_freq(da_or_freq, ...)

Return relative difference between dataset mean timestep and destination freq.

processes.meteo.pet_debruin(temp, press, ...)

Determine De Bruin (2016) reference evapotranspiration.

processes.meteo.pet_makkink(temp, press, k_in)

Determnines Makkink reference evapotranspiration.

processes.meteo.pm_fao56(temp, temp_max, ...)

Estimate daily reference evapotranspiration (ETo).