hydromt.model.components.MeshComponent.add_2d_data_from_raster_reclass#
- MeshComponent.add_2d_data_from_raster_reclass(raster_filename: str | Path | DataArray, reclass_table_filename: str | Path | DataFrame, reclass_variables: List[str], grid_name: str = 'mesh2d', variable: str | None = None, fill_method: str | None = None, resampling_method: str | List[str] | None = 'centroid', rename: Dict[str, str] | None = None, **kwargs) List[str] [source]#
HYDROMT CORE METHOD: Add data variable(s) to 2D
grid_name
in mesh object by reclassifying the data inraster_filename
based onreclass_table_filename
.The reclassified raster data are subsequently interpolated to the mesh using resampling_method.
Adds model layers:
- reclass_variables mesh: reclassified raster data interpolated to the
model mesh
- Parameters:
raster_filename (
str
,Path
,xr.DataArray
) – Data catalog key, path to the raster file, or raster xarray data object. Should be a DataArray. If not, use the variable argument for selection.reclass_table_filename (
str
,Path
,pd.DataFrame
) – Data catalog key, path to the tabular data file, or tabular pandas dataframe object for the reclassification table of raster_filename.reclass_variables (
list
) – List of reclass_variables from the reclass_table_filename table to add to the mesh. The index column should match values in raster_filename.grid_name (
str
, optional) – Name of the mesh grid to add the data to. By default ‘mesh2d’.variable (
str
, optional) – Name of the raster dataset variable to use. This is only required when reading datasets with multiple variables. By default, None.fill_method (
str
, optional) – If specified, fills nodata values in raster_filename using the fill_method method before reclassifying. Available methods are {‘linear’, ‘nearest’, ‘cubic’, ‘rio_idw’}.resampling_method (
str
orlist
, optional) – Method to sample from raster data to mesh. By default mean. Options include {“centroid”, “barycentric”, “mean”, “harmonic_mean”, “geometric_mean”, “sum”, “minimum”, “maximum”, “mode”, “median”, “max_overlap”}. If centroid, will usexugrid.CentroidLocatorRegridder()
method. If barycentric, will usexugrid.BarycentricInterpolator()
method. If any other, will usexugrid.OverlapRegridder()
method. Can provide a list corresponding toreclass_variables
.rename (
dict
, optional) – Dictionary to rename variable names in reclass_variables before adding them to the mesh. The dictionary should have the form {‘name_in_reclass_table’: ‘name_in_mesh’}. By default, an empty dictionary.**kwargs (
dict
) – Additional keyword arguments to be passed to the raster dataset retrieval method.
- Returns:
variable_names – List of added variable names in the mesh.
- Return type:
List[str]
- Raises:
ValueError – If raster_filename is not a single variable raster.