hydromt.model.components.GridComponent.create_from_region#

GridComponent.create_from_region(region: Dict[str, Any], *, res: int | float | None = None, crs: int | None = None, region_crs: int = 4326, rotated: bool = False, hydrography_path: str | None = None, basin_index_path: str | None = None, add_mask: bool = True, align: bool = True, dec_origin: int = 0, dec_rotation: int = 3) DataArray[source]#

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

A 2D regular grid will be created from a geometry (geom_fn) or bbox. If an existing grid is given, then no new grid will be generated.

Adds/Updates model layers (if add_mask): * mask grid mask: add grid mask to grid object

Parameters:
  • region (dict) –

    Dictionary describing region of interest, e.g.: * {‘bbox’: [xmin, ymin, xmax, ymax]} * {‘geom’: ‘path/to/polygon_geometry’} * {‘grid’: ‘path/to/grid_file’} * {‘basin’: [x, y]}

    Region must be of kind [grid, bbox, geom, basin, subbasin, interbasin].

  • res (float or int, optional) – Resolution used to generate 2D grid [unit of the CRS], required if region is not based on ‘grid’.

  • crs (int, optional) – EPSG code of the grid to create.

  • region_crs (int, optional) – EPSG code of the region geometry, by default None. Only applies if region is of kind ‘bbox’or if geom crs is not defined in the file itself.

  • rotated (bool) – if True, a minimum rotated rectangular grid is fitted around the region, by default False. Only applies if region is of kind ‘bbox’, ‘geom’

  • hydrography_fn (str, optional) –

    Name of data source for hydrography data. Required if region is of kind

    ’basin’, ‘subbasin’ or ‘interbasin’.

    • Required variables: [‘flwdir’] and any other ‘snapping’ variable required

      to define the region.

    • Optional variables: [‘basins’] if the region is based on a

      (sub)(inter)basins without a ‘bounds’ argument.

  • basin_index_path (str, optional) – Name of data source with basin (bounding box) geometries associated with the ‘basins’ layer of hydrography_fn. Only required if the region is based on a (sub)(inter)basins without a ‘bounds’ argument.

  • add_mask (bool) – Add mask variable to grid object, by default True.

  • align (bool) – If True (default), align target transform to resolution.

  • dec_origin (int, optional) – number of decimals to round the origin coordinates, by default 0

  • dec_rotation (int, optional) – number of decimals to round the rotation angle, by default 3

Returns:

grid – Generated grid mask.

Return type:

xr.DataArray