vibespatial.raster.zonal¶
Zonal statistics via CCCL segmented reduce.
Computes per-zone aggregate statistics (count, sum, mean, min, max, std, median) over raster values using CCCL segmented reduce primitives.
GPU path: sort by zone_id (CCCL radix_sort), find segment boundaries, then CCCL segmented_reduce for each requested statistic. All computation stays on-device until the final DataFrame transfer.
CPU path: numpy sort + segment loop (baseline).
Functions¶
|
Compute zonal statistics of values raster over zone labels. |
|
Compute zonal statistics of a raster over vector zone boundaries. |
Module Contents¶
- vibespatial.raster.zonal.zonal_stats(zones: vibespatial.raster.buffers.OwnedRasterArray, values: vibespatial.raster.buffers.OwnedRasterArray, stats: vibespatial.raster.buffers.ZonalSpec | list[str] | None = None, *, use_gpu: bool | None = None) pandas.DataFrame¶
Compute zonal statistics of values raster over zone labels.
Parameters¶
- zonesOwnedRasterArray
Integer label raster defining zones (must be single-band). Each unique nonzero value is a zone.
- valuesOwnedRasterArray
Value raster to aggregate. Must have same height/width as zones. May be single-band or multiband. For multiband values, per-band statistics are computed and returned with
band_N_prefixed column names (e.g.band_1_mean,band_2_mean).- statsZonalSpec or list[str] or None
Statistics to compute. Default: count, sum, mean, min, max.
- use_gpubool or None
Force GPU (True), force CPU (False), or auto-dispatch (None). Auto uses GPU when CuPy is available and pixel count >= 100k.
Returns¶
- pd.DataFrame
One row per zone. For single-band values, columns are
zoneplus each requested statistic name. For multiband values, columns arezoneplusband_N_<stat>for each band and statistic.
- vibespatial.raster.zonal.zonal_stats_gdf(gdf, values: vibespatial.raster.buffers.OwnedRasterArray, stats: vibespatial.raster.buffers.ZonalSpec | list[str] | None = None, *, grid_spec: vibespatial.raster.buffers.GridSpec | None = None, use_gpu: bool | None = None) pandas.DataFrame¶
Compute zonal statistics of a raster over vector zone boundaries.
Rasterizes the GeoDataFrame zones to a label grid matching the values raster, then runs zonal_stats on the label grid.
Parameters¶
- gdfGeoDataFrame
Vector zones. Each row is a zone.
- valuesOwnedRasterArray
Value raster to aggregate.
- statsZonalSpec or list[str] or None
Statistics to compute.
- grid_specGridSpec or None
Grid to rasterize zones onto. If None, matches the values raster grid.
- use_gpubool or None
Force GPU (True), force CPU (False), or auto-dispatch (None).
Returns¶
- pd.DataFrame
One row per zone with zone index and requested statistics.