API reference#

Command Line Interface#

hydromt

Main command line interface of HydroMT.

hydromt build

Build a model.

hydromt update

Update an existing model.

hydromt clip

Clip/Extract a submodel from an existing model.

hydromt export

Export data extract from a data catalog.

hydromt check

Check if data catalog or configuration file are valid.

Data#

Data catalog#

General#

data_catalog.DataCatalog(data_libs, fallback_lib)

Base class for the data catalog object.

data_catalog.DataCatalog.get_source(source)

Return a data source.

data_catalog.DataCatalog.iter_sources([...])

Return a flat list of all available data sources.

data_catalog.DataCatalog.sources

Returns dictionary of DataAdapter sources.

data_catalog.DataCatalog.keys

Returns list of data source names.

data_catalog.DataCatalog.predefined_catalogs

Return all predefined catalogs.

data_catalog.DataCatalog.to_dict([...])

Export the data catalog to a dictionary.

data_catalog.DataCatalog.to_dataframe([...])

Return data catalog summary as DataFrame.

data_catalog.DataCatalog.to_yml(path[, ...])

Write data catalog to yaml format.

data_catalog.DataCatalog.export_data(data_root)

Export a data slice of each dataset and a data_catalog.yml file to disk.

data_catalog.DataCatalog.get_source_bbox(source)

Retrieve the bounding box and crs of the source.

data_catalog.DataCatalog.get_source_time_range(source)

Detect the temporal range of the dataset.

Add data sources#

data_catalog.DataCatalog.add_source(source, ...)

Add a new data source to the data catalog.

data_catalog.DataCatalog.update(**kwargs)

Add data sources to library or update them.

data_catalog.DataCatalog.from_predefined_catalogs(name)

Add data sources from a predefined data catalog.

data_catalog.DataCatalog.from_archive(urlpath)

Read and cache a data archive including a data_catalog.yml file.

data_catalog.DataCatalog.from_yml(urlpath[, ...])

Add data sources based on yaml file.

data_catalog.DataCatalog.from_dict(data_dict)

Add data sources based on dictionary.

data_catalog.DataCatalog.set_predefined_catalogs([...])

Initialise the predefined catalogs.

Get data#

data_catalog.DataCatalog.get_rasterdataset(...)

Return a clipped, sliced and unified RasterDataset.

data_catalog.DataCatalog.get_geodataset(...)

Return a clipped, sliced and unified GeoDataset.

data_catalog.DataCatalog.get_geodataframe(...)

Return a clipped and unified GeoDataFrame (vector).

data_catalog.DataCatalog.get_dataframe(data_like)

Return a unified and sliced DataFrame.

data_catalog.DataCatalog.get_dataset(data_like)

Return a clipped, sliced and unified Dataset.

DataAdapter#

General#

data_adapter.DataAdapter(path[, driver, ...])

General Interface to data source for HydroMT.

data_adapter.DataAdapter.summary()

Return a dictionary summary of the data adapter.

data_adapter.DataAdapter.to_dict()

Return a dictionary view of the data source.

RasterDataset#

data_adapter.RasterDatasetAdapter(path[, ...])

Implementation for the RasterDatasetAdapter.

data_adapter.RasterDatasetAdapter.summary()

Return a dictionary summary of the data adapter.

data_adapter.RasterDatasetAdapter.get_data([...])

Return a clipped, sliced and unified RasterDataset.

data_adapter.RasterDatasetAdapter.to_dict()

Return a dictionary view of the data source.

data_adapter.RasterDatasetAdapter.to_file(...)

Save a data slice to file.

data_adapter.RasterDatasetAdapter.get_bbox([...])

Return the bounding box and espg code of the dataset.

data_adapter.RasterDatasetAdapter.get_time_range([...])

Detect the time range of the dataset.

data_adapter.RasterDatasetAdapter.detect_bbox([ds])

Detect the bounding box and crs of the dataset.

data_adapter.RasterDatasetAdapter.detect_time_range([ds])

Detect the temporal range of the dataset.

data_adapter.RasterDatasetAdapter.to_stac_catalog([...])

Convert a rasterdataset into a STAC Catalog representation.

GeoDataset#

data_adapter.GeoDatasetAdapter(path[, ...])

DatasetAdapter for GeoDatasets.

data_adapter.GeoDatasetAdapter.summary()

Return a dictionary summary of the data adapter.

data_adapter.GeoDatasetAdapter.get_data([...])

Return a clipped, sliced and unified GeoDataset.

data_adapter.GeoDatasetAdapter.to_dict()

Return a dictionary view of the data source.

data_adapter.GeoDatasetAdapter.to_file(...)

Save a data slice to file.

data_adapter.GeoDatasetAdapter.get_bbox([detect])

Return the bounding box and espg code of the dataset.

data_adapter.GeoDatasetAdapter.get_time_range([...])

Detect the time range of the dataset.

data_adapter.GeoDatasetAdapter.detect_bbox([ds])

Detect the bounding box and crs of the dataset.

data_adapter.GeoDatasetAdapter.detect_time_range([ds])

Detect the temporal range of the dataset.

data_adapter.GeoDatasetAdapter.to_stac_catalog([...])

Convert a geodataset into a STAC Catalog representation.

GeoDataFrame#

data_adapter.GeoDataFrameAdapter(path[, ...])

The Geodataframe adapter implementation.

data_adapter.GeoDataFrameAdapter.summary()

Return a dictionary summary of the data adapter.

data_adapter.GeoDataFrameAdapter.get_data([...])

Return a clipped and unified GeoDataFrame (vector).

data_adapter.GeoDataFrameAdapter.to_dict()

Return a dictionary view of the data source.

data_adapter.GeoDataFrameAdapter.to_file(...)

Save a data slice to file.

data_adapter.GeoDataFrameAdapter.get_bbox([...])

Return the bounding box and espg code of the dataset.

data_adapter.GeoDataFrameAdapter.detect_bbox([gdf])

Detect the bounding box and crs of the dataset.

data_adapter.GeoDataFrameAdapter.to_stac_catalog([...])

Convert a geodataframe into a STAC Catalog representation.

DataFrame#

data_adapter.DataFrameAdapter(path[, ...])

DataAdapter implementation for Pandas Dataframes.

data_adapter.DataFrameAdapter.summary()

Return a dictionary summary of the data adapter.

data_adapter.DataFrameAdapter.get_data([...])

Return a DataFrame.

data_adapter.DataFrameAdapter.to_dict()

Return a dictionary view of the data source.

data_adapter.DataFrameAdapter.to_file(...[, ...])

Save a dataframe slice to a file.

data_adapter.DataFrameAdapter.to_stac_catalog([...])

Convert a dataframe into a STAC Catalog representation.

Dataset#

data_adapter.DatasetAdapter(path[, driver, ...])

DatasetAdapter for non-spatial n-dimensional data.

data_adapter.DatasetAdapter.summary()

Return a dictionary summary of the data adapter.

data_adapter.DatasetAdapter.get_data([...])

Return a clipped, sliced and unified Dataset.

data_adapter.DatasetAdapter.to_dict()

Return a dictionary view of the data source.

data_adapter.DatasetAdapter.to_file(...[, ...])

Save a dataset slice to file.

data_adapter.DatasetAdapter.to_stac_catalog([...])

Convert a dataset into a STAC Catalog representation.

Models#

Discovery#

ModelCatalog()

The model catalogue provides access to plugins and their Model classes.

Model#

Note that the base Model attributes and methods are available to all models.

Model(root, mode, config_fn, data_libs[, logger])

General and basic API for models in HydroMT.

High level methods#

Model.read([components])

Read the complete model schematization and configuration from model files.

Model.write([components])

Write the complete model schematization and configuration to model files.

Model.build([region, write, opt])

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

Model.update([model_out, write, opt, ...])

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

Model.set_root(root[, mode])

Initialize the model root.

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

Write the data catalog to data_lib_fn.

Model attributes#

Model.crs

Returns coordinate reference system embedded in region.

Model.region

Returns the geometry of the model area of interest.

Model.root

Path to model folder.

Model.api

Model components and attributes#

Model.config

Model configuration.

Model.maps

Model maps.

Model.geoms

Model geometries.

Model.forcing

Model forcing.

Model.states

Model states.

Model.results

Model results.

General methods#

Model.get_config(*args[, fallback, abs_path])

Get a config value at key(s).

Model.set_config(*args)

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

Model.read_config([config_fn])

Parse config from file.

Model.write_config([config_name, config_root])

Write config to <root/config_fn>.

Model.set_maps(data[, name, split_dataset])

Add raster data to the maps component.

Model.read_maps([fn])

Read model map at <root>/<fn> and add to maps component.

Model.write_maps([fn])

Write maps to netcdf file at <root>/<fn>.

Model.set_geoms(geom, name)

Add data to the geoms attribute.

Model.read_geoms([fn])

Read model geometries files at <root>/<fn> and add to geoms property.

Model.write_geoms([fn, to_wgs84])

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

Model.set_forcing(data[, name, split_dataset])

Add data to forcing attribute.

Model.read_forcing([fn])

Read forcing at <root>/<fn> and add to forcing property.

Model.write_forcing([fn])

Write forcing to netcdf file at <root>/<fn>.

Model.set_states(data[, name, split_dataset])

Add data to states attribute.

Model.read_states([fn])

Read states at <root>/<fn> and add to states property.

Model.write_states([fn])

Write states to netcdf file at <root>/<fn>.

Model.set_results(data[, name, split_dataset])

Add data to results attribute.

Model.read_results([fn])

Read results at <root>/<fn> and add to results property.

Model.read_nc(fn[, mask_and_scale, ...])

Read netcdf files at <root>/<fn> and return as dict of xarray.Dataset.

Model.write_nc(nc_dict, fn[, ...])

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

Setup methods#

Model.setup_config(**cfdict)

Update config with a dictionary.

Model.setup_region(region[, hydrography_fn, ...])

Set the region of interest of the model.

Model.setup_maps_from_rasterdataset(raster_fn)

HYDROMT CORE METHOD: Add data variable(s) from raster_fn to maps object.

Model.setup_maps_from_raster_reclass(...[, ...])

HYDROMT CORE METHOD: Add data variable(s) to maps object by reclassifying the data in raster_fn based on reclass_table_fn.

GridModel#

GridModel(root, mode, config_fn, data_libs)

Model class Grid Model for gridded models in HydroMT.

Components and attributes#

GridModel.grid

Model static gridded data as xarray.Dataset.

GridModel.crs

Returns coordinate reference system embedded in the model grid.

GridModel.region

Returns the geometry of the model area of interest.

General methods#

GridModel.set_grid(data[, name])

Add data to grid.

GridModel.read_grid([fn])

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

GridModel.write_grid([fn, gdal_compliant, ...])

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

Setup methods#

GridModel.setup_config(**cfdict)

Update config with a dictionary.

GridModel.setup_region(region[, ...])

Set the region of interest of the model.

GridModel.setup_maps_from_rasterdataset(...)

HYDROMT CORE METHOD: Add data variable(s) from raster_fn to maps object.

GridModel.setup_maps_from_raster_reclass(...)

HYDROMT CORE METHOD: Add data variable(s) to maps object by reclassifying the data in raster_fn based on reclass_table_fn.

GridModel.setup_grid(region[, res, crs, ...])

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

GridModel.setup_grid_from_constant(constant, ...)

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

GridModel.setup_grid_from_rasterdataset(...)

HYDROMT CORE METHOD: Add data variable(s) from raster_fn to grid object.

GridModel.setup_grid_from_raster_reclass(...)

HYDROMT CORE METHOD: Add data variable(s) to grid object by reclassifying the data in raster_fn based on reclass_table_fn.

GridModel.setup_grid_from_geodataframe(vector_fn)

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

VectorModel#

VectorModel(root, mode, config_fn, data_libs)

Model class Vector Model for vector (polygons) models in HydroMT.

Components and attributes#

VectorModel.vector

Model vector (polygon) data.

VectorModel.crs

Returns coordinate reference system embedded in region.

VectorModel.region

Returns the geometry of the model area of interest.

General methods#

VectorModel.set_vector([data, name, ...])

Add data to vector.

VectorModel.read_vector([fn, fn_geom])

Read model vector from combined netcdf and geojson file.

VectorModel.write_vector([fn, fn_geom, ...])

Write model vector to combined netcdf and geojson files.

Setup methods#

VectorModel.setup_config(**cfdict)

Update config with a dictionary.

VectorModel.setup_region(region[, ...])

Set the region of interest of the model.

VectorModel.setup_maps_from_rasterdataset(...)

HYDROMT CORE METHOD: Add data variable(s) from raster_fn to maps object.

VectorModel.setup_maps_from_raster_reclass(...)

HYDROMT CORE METHOD: Add data variable(s) to maps object by reclassifying the data in raster_fn based on reclass_table_fn.

MeshModel#

MeshModel(root, mode, config_fn, data_libs)

Model class Mesh Model for mesh models in HydroMT.

Components and attributes#

MeshModel.mesh

Model static mesh data.

MeshModel.mesh_names

List of grid names in mesh.

MeshModel.mesh_grids

Dictionnary of grid names and Ugrid topologies in mesh.

MeshModel.mesh_datasets

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

MeshModel.mesh_gdf

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

MeshModel.crs

Returns model mesh crs.

MeshModel.region

Returns geometry of region of the model area of interest based on mesh total bounds.

MeshModel.bounds

Returns model mesh bounds.

General methods#

MeshModel.set_mesh(data[, name, grid_name, ...])

Add data to mesh.

MeshModel.get_mesh(grid_name[, include_data])

Return a specific grid topology from mesh based on grid_name.

MeshModel.read_mesh([fn, crs])

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

MeshModel.write_mesh([fn, ...])

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

Setup methods#

MeshModel.setup_config(**cfdict)

Update config with a dictionary.

MeshModel.setup_region(region[, ...])

Set the region of interest of the model.

MeshModel.setup_mesh2d(region[, res, crs, ...])

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

MeshModel.setup_mesh2d_from_rasterdataset(...)

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

MeshModel.setup_mesh2d_from_raster_reclass(...)

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

MeshModel.setup_maps_from_rasterdataset(...)

HYDROMT CORE METHOD: Add data variable(s) from raster_fn to maps object.

MeshModel.setup_maps_from_raster_reclass(...)

HYDROMT CORE METHOD: Add data variable(s) to maps object by reclassifying the data in raster_fn based on reclass_table_fn.

Workflows#

Grid#

workflows.grid.grid_from_constant(grid_like, ...)

Prepare a grid based on a constant value.

workflows.grid.grid_from_rasterdataset(...)

Prepare data by resampling ds to grid_like.

workflows.grid.grid_from_raster_reclass(...)

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

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

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

Mesh#

workflows.mesh.create_mesh2d(region[, res, ...])

Create an 2D unstructured mesh or reads an existing 2D mesh.

workflows.mesh.mesh2d_from_rasterdataset(ds, ...)

Resamples data in ds to mesh2d.

workflows.mesh.mesh2d_from_raster_reclass(da, ...)

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

Basin mask#

workflows.basin_mask.get_basin_geometry(ds)

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

workflows.basin_mask.parse_region(region[, ...])

Check and return parsed region arguments.

River bathymetry#

workflows.rivers.river_width(gdf_stream, ...)

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

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

Derive river depth estimates based bankfull discharge.

Forcing#

Data handling#

workflows.forcing.precip(precip, da_like[, ...])

Return the lazy reprojection of precipitation to model.

workflows.forcing.temp(temp, dem_model[, ...])

Return lazy reprojection of temperature to model grid.

workflows.forcing.press(press, dem_model[, ...])

Return lazy reprojection of pressure to model grid.

workflows.forcing.pet(ds, temp, dem_model[, ...])

Determine reference evapotranspiration.

workflows.forcing.wind(da_model[, wind, ...])

Return lazy reprojection of wind speed to model grid.

Correction methods#

workflows.forcing.press_correction(dem_model)

Pressure correction based on elevation lapse_rate.

workflows.forcing.temp_correction(dem[, ...])

Temperature correction based on elevation data.

Time resampling methods#

workflows.forcing.resample_time(da, freq[, ...])

Resample data to destination frequency.

workflows.forcing.delta_freq(da_or_freq, ...)

Return relative difference between dataset mean timestep and destination freq.

Computation methods#

PET

workflows.forcing.pet_debruin(temp, press, ...)

Determine De Bruin (2016) reference evapotranspiration.

workflows.forcing.pet_makkink(temp, press, k_in)

Determnines Makkink reference evapotranspiration.

workflows.forcing.pm_fao56(temp, temp_max, ...)

Estimate daily reference evapotranspiration (ETo).

Reading/writing methods#

Reading methods#

io.open_raster(filename[, mask_nodata, ...])

Open a gdal-readable file with rasterio based on.

io.open_mfraster(paths[, chunks, concat, ...])

Open multiple gdal-readable files as single Dataset with geospatial attributes.

io.open_raster_from_tindex(fn_tindex[, ...])

Read and merge raster tiles.

io.open_vector(fn[, driver, crs, dst_crs, ...])

Open fiona-compatible geometry, csv, parquet, excel or xy file and parse it.

io.open_vector_from_table(fn[, driver, ...])

Read point geometry files from csv, parquet, xy or excel table files.

io.open_geodataset(fn_locs[, fn_data, ...])

Open and combine geometry location GIS file and timeseries file in a xr.Dataset.

io.open_timeseries_from_table(fn[, name, ...])

Open timeseries csv or parquet file and parse to xarray.DataArray.

Raster writing methods#

DataArray.raster.to_xyz_tiles(root, ...[, ...])

Export rasterdataset to tiles in a xyz structure.

DataArray.raster.to_slippy_tiles(root[, ...])

Produce tiles in /zoom/x/y.<ext> structure (EPSG:3857).

DataArray.raster.to_raster(raster_path[, ...])

Write DataArray object to a gdal-writable raster file.

Dataset.raster.to_mapstack(root[, driver, ...])

Write the Dataset object to one gdal-writable raster files per variable.

Raster methods#

High level methods#

merge.merge(data_arrays[, dst_crs, ...])

Merge multiple tiles to a single DataArray.

raster.full(coords[, nodata, dtype, name, ...])

Return a full DataArray based on a geospatial coords dictionary.

raster.full_like(other[, nodata, lazy])

Return a full object with the same grid and geospatial attributes as other.

raster.full_from_transform(transform, shape)

Return a full DataArray based on a geospatial transform and shape.

DataArray.raster.from_numpy(data, transform)

Transform a 2D/3D numpy array into a DataArray with geospatial attributes.

Dataset.raster.from_numpy(data_vars, transform)

Transform multiple numpy arrays to a Dataset object.

Attributes#

DataArray.raster.attrs

Return dictionary of spatial attributes.

DataArray.raster.crs

Return horizontal Coordinate Reference System.

DataArray.raster.bounds

Return the bounds (xmin, ymin, xmax, ymax) of the object.

DataArray.raster.transform

Return the affine transform of the object.

DataArray.raster.res

Return resolution (x, y) tuple.

DataArray.raster.rotation

Return rotation of grid (degrees).

DataArray.raster.origin

Return origin of grid (x0, y0) tuple.

DataArray.raster.nodata

Nodata value of the DataArray.

DataArray.raster.dims

Return tuple of geospatial dimensions names.

DataArray.raster.coords

Return dict of geospatial dimensions coordinates.

DataArray.raster.dim0

Return the non geospatial dimension name.

DataArray.raster.y_dim

Return the y dimension name.

DataArray.raster.x_dim

Return the x dimension name.

DataArray.raster.xcoords

Return the x coordinates.

DataArray.raster.ycoords

Return the y coordinates.

DataArray.raster.shape

Return shape of geospatial dimension (height, width).

DataArray.raster.size

Return size of geospatial grid.

DataArray.raster.width

Return the width of the object (x dimension size).

DataArray.raster.height

Return the height of the object (y dimension size).

DataArray.raster.internal_bounds

Return the internal bounds (left, bottom, right, top) the object.

DataArray.raster.box

Return GeoDataFrame() of bounding box.

General methods#

DataArray.raster.set_crs([input_crs, write_crs])

Set the Coordinate Reference System.

DataArray.raster.set_spatial_dims([x_dim, y_dim])

Set the geospatial dimensions of the object.

DataArray.raster.reset_spatial_dims_attrs([...])

Reset spatial dimension names and attributes.

DataArray.raster.identical_grid(other)

Return True if other has an same grid as object (crs, transform, shape).

DataArray.raster.aligned_grid(other)

Check if other grid aligns with object grid (crs, resolution, origin).

DataArray.raster.gdal_compliant([...])

Update attributes to get GDAL compliant NetCDF files.

DataArray.raster.idx_to_xy(idx[, mask, ...])

Return x,y coordinates at linear index.

DataArray.raster.xy_to_idx(xs, ys[, mask, ...])

Return linear index of x, y coordinates.

DataArray.raster.rowcol(xs, ys[, mask, ...])

Return row, col indices of x, y coordinates.

DataArray.raster.xy(r, c[, mask, ...])

Return x,y coordinates at cell center of row, col indices.

DataArray.raster.flipud()

Return raster flipped along y dimension.

DataArray.raster.area_grid([dtype])

Return the grid cell area [m2].

DataArray.raster.density_grid()

Return the density in [unit/m2] of raster(s).

DataArray.raster.reclassify(reclass_table[, ...])

Reclass columns in df from raster map (DataArray).

Nodata handling and interpolation#

DataArray.raster.set_nodata([nodata, logger])

Set the nodata value as CF compliant attribute of the DataArray.

DataArray.raster.mask_nodata([fill_value])

Mask nodata values with fill_value (default np.nan).

DataArray.raster.interpolate_na([method, ...])

Interpolate missing data.

Clip#

DataArray.raster.clip(xslice, yslice)

Clip object based on slices.

DataArray.raster.clip_bbox(bbox[, align, ...])

Clip object based on a bounding box.

DataArray.raster.clip_mask(da_mask[, mask])

Clip object to region with mask values greater than zero.

DataArray.raster.clip_geom(geom[, align, ...])

Clip object to bounding box of the geometry.

Reproject#

DataArray.raster.reproject([dst_crs, ...])

Reproject a DataArray with geospatial coordinates.

DataArray.raster.reindex2d(index[, dst_nodata])

Return reprojected DataArray object based on simple reindexing.

DataArray.raster.reproject_like(other[, method])

Reproject a object to match the grid of other.

DataArray.raster.transform_bounds(dst_crs[, ...])

Transform bounds from object to destination CRS.

DataArray.raster.nearest_index([dst_crs, ...])

Prepare nearest index mapping for reprojection of a gridded timeseries file.

Transform#

DataArray.raster.rasterize(gdf[, col_name, ...])

Return an object with input geometry values burned in.

DataArray.raster.rasterize_geometry(gdf[, ...])

Return an object with the fraction of the grid cells covered by geometry.

DataArray.raster.geometry_mask(gdf[, ...])

Return a grid with True values where shapes overlap pixels.

DataArray.raster.vectorize([connectivity])

Return geometry of grouped pixels with the same value in a DataArray object.

DataArray.raster.vector_grid([geom_type])

Return a vector representation of the grid.

Sampling and zonal stats#

DataArray.raster.sample(gdf[, wdw])

Sample from map at point locations with optional window around the points.

DataArray.raster.zonal_stats(gdf, stats[, ...])

Calculate zonal statistics of raster samples aggregated for geometries.

Low level methods#

gis_utils.axes_attrs(crs)

Provide CF-compliant variable names and metadata for axes.

gis_utils.meridian_offset(ds[, bbox])

Shift data along the x-axis of global datasets to avoid issues along the 180 meridian.

GeoDataset methods#

High level methods#

DataArray.vector.from_gdf(gdf, data[, ...])

Parse GeoDataFrame object with point geometries to DataArray.

DataArray.vector.to_gdf([reducer])

Return geopandas GeoDataFrame with Point geometry.

DataArray.vector.from_netcdf(path[, ...])

Read netcdf file or convert xr.DataArray as GeoDataArray.

DataArray.vector.to_netcdf(path[, ...])

Export geodataset vectordata to an ogr compliant netCDF4 file.

Dataset.vector.from_gdf(gdf[, data_vars, ...])

Create Dataset with geospatial coordinates.

Dataset.vector.to_gdf([reducer])

Return geopandas GeoDataFrame with Point geometry.

Dataset.vector.from_netcdf(path[, ...])

Create GeoDataset from ogr compliant netCDF4 file or xr.Dataset.

Dataset.vector.to_netcdf(path[, ...])

Export geodataset vectordata to an ogr compliant netCDF4 file.

Attributes#

DataArray.vector.attrs

Return dictionary of spatial attributes.

DataArray.vector.crs

Return horizontal Coordinate Reference System.

DataArray.vector.index_dim

Index dimension name.

DataArray.vector.time_dim

Time dimension name.

DataArray.vector.x_name

Name of x coordinate; only for point geometries in xy format.

DataArray.vector.y_name

Name of y coordinate; only for point geometries in xy format.

DataArray.vector.geom_name

Name of geometry coordinate; only for 'wkt' and 'geom' formats.

DataArray.vector.geom_type

Return geometry type.

DataArray.vector.geom_format

Name of geometry coordinate; only for 'wkt' and 'geom' formats.

DataArray.vector.index

Return the index values.

DataArray.vector.bounds

Return the bounds (xmin, ymin, xmax, ymax) of the object.

DataArray.vector.size

Return the length of the index array.

DataArray.vector.sindex

Return the spatial index of the geometry.

DataArray.vector.geometry

Return the geometry of the dataset or array as GeoSeries.

Dataset.vector.attrs

Return dictionary of spatial attributes.

Dataset.vector.crs

Return horizontal Coordinate Reference System.

Dataset.vector.index_dim

Index dimension name.

Dataset.vector.time_dim

Time dimension name.

Dataset.vector.x_name

Name of x coordinate; only for point geometries in xy format.

Dataset.vector.y_name

Name of y coordinate; only for point geometries in xy format.

Dataset.vector.geom_name

Name of geometry coordinate; only for 'wkt' and 'geom' formats.

Dataset.vector.geom_type

Return geometry type.

Dataset.vector.geom_format

Name of geometry coordinate; only for 'wkt' and 'geom' formats.

Dataset.vector.index

Return the index values.

Dataset.vector.bounds

Return the bounds (xmin, ymin, xmax, ymax) of the object.

Dataset.vector.size

Return the length of the index array.

Dataset.vector.sindex

Return the spatial index of the geometry.

Dataset.vector.geometry

Return the geometry of the dataset or array as GeoSeries.

Conversion#

DataArray.vector.ogr_compliant([reducer])

Create a Dataset/Array which is understood by OGR.

DataArray.vector.update_geometry([geometry, ...])

Update the geometry in the Dataset/Array with a new geometry.

DataArray.vector.to_geom([geom_name])

Convert Dataset/ DataArray with xy or wkt geometries to shapely Geometries.

DataArray.vector.to_xy([x_name, y_name])

Convert Dataset/ DataArray with Point geometries to x,y structure.

DataArray.vector.to_wkt([ogr_compliant, reducer])

Convert geometries in Dataset/DataArray to wkt strings.

Dataset.vector.ogr_compliant([reducer])

Create a Dataset/Array which is understood by OGR.

Dataset.vector.update_geometry([geometry, ...])

Update the geometry in the Dataset/Array with a new geometry.

Dataset.vector.to_geom([geom_name])

Convert Dataset/ DataArray with xy or wkt geometries to shapely Geometries.

Dataset.vector.to_xy([x_name, y_name])

Convert Dataset/ DataArray with Point geometries to x,y structure.

Dataset.vector.to_wkt([ogr_compliant, reducer])

Convert geometries in Dataset/DataArray to wkt strings.

General methods#

DataArray.vector.set_crs([input_crs, write_crs])

Set the Coordinate Reference System.

DataArray.vector.set_spatial_dims([...])

Set the spatial and index dimensions of the object.

Dataset.vector.set_crs([input_crs, write_crs])

Set the Coordinate Reference System.

Dataset.vector.set_spatial_dims([geom_name, ...])

Set the spatial and index dimensions of the object.

Clip#

DataArray.vector.clip_bbox(bbox[, crs, buffer])

Select point locations to bounding box.

DataArray.vector.clip_geom(geom[, predicate])

Select all geometries that intersect with the input geometry.

Dataset.vector.clip_bbox(bbox[, crs, buffer])

Select point locations to bounding box.

Dataset.vector.clip_geom(geom[, predicate])

Select all geometries that intersect with the input geometry.

Reproject#

DataArray.vector.to_crs(dst_crs)

Transform spatial coordinates to a new coordinate reference system.

Dataset.vector.to_crs(dst_crs)

Transform spatial coordinates to a new coordinate reference system.

Flow direction methods#

These methods are based on the pyflwdir library. For more flow direction based methods visit the pyflwdir docs.

flw.flwdir_from_da(da[, ftype, check_ftype, ...])

Parse dataarray to flow direction raster object.

flw.d8_from_dem(da_elv[, gdf_stream, ...])

Derive D8 flow directions grid from an elevation grid.

flw.reproject_hydrography_like(ds_hydro, da_elv)

Reproject flow direction and upstream area data to the da_elv crs and grid.

flw.upscale_flwdir(ds, flwdir, scale_ratio)

Upscale flow direction network to lower resolution.

flw.stream_map(ds[, stream])

Return a stream mask DataArray.

flw.basin_map(ds, flwdir[, xy, idxs, ...])

Return a (sub)basin map, with unique non-zero IDs for each subbasin.

flw.gauge_map(ds[, idxs, xy, ids, stream, ...])

Return map with unique gauge IDs.

flw.outlet_map(da_flw[, ftype])

Return a mask of basin outlets/pits from a flow direction raster.

flw.clip_basins(ds, flwdir, xy[, flwdir_name])

Clip a dataset to a subbasin.

flw.dem_adjust(da_elevtn, da_flwdir[, ...])

Return hydrologically conditioned elevation.

General GIS methods#

Raster#

gis_utils.create_vrt(vrt_path[, files, ...])

Create a .vrt file from a list op raster datasets.

gis_utils.spread2d(da_obs[, da_mask, ...])

Return values of da_obs spreaded to cells with nodata value within da_mask.

gis_utils.reggrid_area(lats, lons)

Return the cell area [m2] for a regular grid based on its cell centres lat, lon.

gis_utils.cellarea(lat[, xres, yres])

Return the area [m2] of cell based on its center latitude and resolution in degrees.

gis_utils.cellres(lat[, xres, yres])

Return the cell (x, y) resolution [m].

CRS and transform#

gis_utils.parse_crs(crs[, bbox])

gis_utils.utm_crs(bbox)

Return wkt string of nearest UTM projects.

gis_utils.affine_to_coords(transform, shape)

Return a raster axis with pixel center coordinates based on the transform.

Vector#

gis_utils.filter_gdf(gdf[, geom, bbox, crs, ...])

Filter GeoDataFrame geometries based on geometry mask or bounding box.

gis_utils.nearest(gdf1, gdf2)

Return the index of and distance [m] to the nearest geometry.

gis_utils.nearest_merge(gdf1, gdf2[, ...])

Merge attributes of gdf2 with the nearest feature of gdf1.

Statistics and Extreme Value Analysis#

Statistics and performance metrics#

stats.skills.bias(sim, obs[, dim])

Return the bias between two time series.

stats.skills.percentual_bias(sim, obs[, dim])

Return the percentual bias between two time series.

stats.skills.volumetric_error(sim, obs[, dim])

Return the volumetric error between two time series.

stats.skills.nashsutcliffe(sim, obs[, dim])

Return the Nash-Sutcliffe model efficiency.

stats.skills.lognashsutcliffe(sim, obs[, ...])

Return the log Nash-Sutcliffe model efficiency.

stats.skills.pearson_correlation(sim, obs[, dim])

Return the Pearson correlation coefficient of two time series.

stats.skills.spearman_rank_correlation(sim, obs)

Return the spearman rank correlation coefficient of two time series.

stats.skills.kge(sim, obs[, dim])

Return the Kling-Gupta Efficiency (KGE) of two time series.

stats.skills.kge_2012(sim, obs[, dim])

Return the Kling-Gupta Efficiency (KGE, 2012) of two time series.

stats.skills.kge_non_parametric(sim, obs[, dim])

Return the Non Parametric Kling-Gupta Efficiency (KGE, 2018).

stats.skills.kge_non_parametric_flood(sim, obs)

Return the Non Parametric Kling-Gupta Efficiency (KGE, 2018) of two time series.

stats.skills.rsquared(sim, obs[, dim])

Return the coefficient of determination of two time series.

stats.skills.mse(sim, obs[, dim])

Return the mean squared error (MSE) between two time series.

stats.skills.rmse(sim, obs[, dim])

Return the root mean squared error between two time series.

stats.skills.rsr(sim, obs[, dim])

Return the RMSE-observations standard deviation (RSR) between two time series.

Extreme Value Analysis#

stats.extremes.get_peaks(da[, ev_type, ...])

Return peaks from time series.

stats.extremes.fit_extremes(da_peaks[, ...])

Return distribution fit from extremes.

stats.extremes.get_return_value(da_params[, ...])

Return return value based on EVA.

stats.extremes.eva(da[, ev_type, min_dist, ...])

Return Extreme Value Analysis.

Design Events#

stats.design_events.get_peak_hydrographs(da, ...)

Return peak hydrographs.

Utilities#

Configuration files#

config.configread(config_fn[, defaults, ...])

Read configuration/workflow file and parse to (nested) dictionary.

config.configwrite(config_fn, cfdict, **kwargs)

Write configuration/workflow dictionary to file.

Logging#

log.setuplog([name, path, log_level, fmt, ...])

Set up the logging on sys.stdout and file if path is given.