hydromt.model.components.GridComponent#

class hydromt.model.components.GridComponent(model: Model, *, filename: str = 'grid/grid.nc', region_component: str | None = None, region_filename: str = 'grid/grid_region.geojson')[source]#

ModelComponent class for grid components.

This class is used for setting, creating, writing, and reading regular grid data for a HydroMT model. The grid component data stored in the data property of this class is of the hydromt.gis.raster.RasterDataset type which is an extension of xarray.Dataset for regular grid.

Initialize a GridComponent.

Parameters:
  • model (Model) – HydroMT model instance

  • filename (str) – The path to use for reading and writing of component data by default. By default “grid/grid.nc”.

  • region_component (str, optional) – The name of the region component to use as reference for this component’s region. If None, the region will be set to the grid extent. Note that the create method only works if the region_component is None. For add_data_from_* methods, the other region_component should be a reference to another grid component for correct reprojection.

  • region_filename (str) – The path to use for reading and writing of the region data by default. By default “grid/grid_region.geojson”.

__init__(model: Model, *, filename: str = 'grid/grid.nc', region_component: str | None = None, region_filename: str = 'grid/grid_region.geojson')[source]#

Initialize a GridComponent.

Parameters:
  • model (Model) – HydroMT model instance

  • filename (str) – The path to use for reading and writing of component data by default. By default “grid/grid.nc”.

  • region_component (str, optional) – The name of the region component to use as reference for this component’s region. If None, the region will be set to the grid extent. Note that the create method only works if the region_component is None. For add_data_from_* methods, the other region_component should be a reference to another grid component for correct reprojection.

  • region_filename (str) – The path to use for reading and writing of the region data by default. By default “grid/grid_region.geojson”.

Methods

__init__(model, *[, filename, ...])

Initialize a GridComponent.

add_data_from_constant(constant, name[, ...])

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

add_data_from_geodataframe(vector_data[, ...])

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

add_data_from_raster_reclass(raster_data, ...)

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

add_data_from_rasterdataset(raster_data[, ...])

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

create_from_region(region, *[, res, crs, ...])

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

read([filename, mask_and_scale])

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

set(data[, name])

Add data to grid.

test_equal(other)

Test if two components are equal.

write([filename, gdal_compliant, ...])

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

write_region(*[, filename, to_wgs84])

Write the model region to file.

Attributes

bounds

Returns the bounding box of the model grid.

crs

Returns coordinate reference system embedded in the model grid.

data

Model static gridded data as xarray.Dataset.

data_catalog

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

model

Return the model object this component is associated with.

region

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

res

Returns the resolution of the model grid.

root

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

transform

Returns spatial transform of the model grid.