hydromt icon indicating copy to clipboard operation
hydromt copied to clipboard

extend raster.zonal_stats with count of classes (mode, percentage)

Open bartvanosnabrugge opened this issue 3 years ago • 0 comments

use case For lumped models (geometries), derive the count, mode, or percentage that is covered by a certain land class.

Current behavior zonal_stats can calculate several stats, but not counts (and related stats) related to categorical grids (i.e. the count of occurrence of a land class).

simple solution wrapper around zonal_stats that runs zonal_stats('count') for each class in the grid, with all other values masked. see here.

elaborate solution add functionality to zonal_stats itself.

  • check which classes exists (globally, or provide a list)
  • use numpy.unique to gie both values and counts
  • store counts (or other stats) in additional dimension 'classes' to zonal_stats xarray output

bartvanosnabrugge avatar Aug 03 '22 10:08 bartvanosnabrugge