imod.prepare.zonal_aggregate_raster#

imod.prepare.zonal_aggregate_raster(path: Union[Path, str], column: str, raster: DataArray, resolution: float, method: Union[str, Callable], chunksize: int = 10000.0) DataFrame[source]#

Compute a zonal aggregate of raster data for polygon geometries, e.g. a mean, mode, or percentile.

Parameters:
  • path (str or pathlib.Path) – path to OGR supported vector file (e.g. a shapefile). Defines zones of aggregation.

  • column (str) – column name of path, integer IDs defining zones.

  • resolution (float) – cellsize at which the rasterization of polygons and sampling occurs

  • raster (xarray.DataArray) – Raster data from which to sample and aggregate data

  • method (Union[str, Callable]) – Aggregation method. Anything that is acceptable by a pandas groupby aggregate: https://pandas.pydata.org/docs/reference/api/pandas.core.groupby.DataFrameGroupBy.aggregate.html

  • chunksize (int, optional) – The size of the chunksize. Used for both x and y dimension.

Returns:

zonal_aggregates

Return type:

pandas.DataFrame

Examples

To compute the mean surface level at polygons of water bodies:

>>> import imod
>>> surface_level = imod.rasterio.open("surface_level.tif")
>>> df = imod.prepare.spatial.overlay_raster_intersection(
>>>    "water-bodies.shp", "id", 1.0, surface_level, "mean"
>>> )

For some functions, like the mode, a function should be passed instead:

>>> import pandas as pd
>>> df = imod.prepare.spatial.overlay_raster_intersection(
>>>    "water-bodies.shp", "id", 1.0, surface_level, pd.Series.mode
>>> )