Skip to contents

op is a reduction name, not a function: the planner needs op identity for algebraic decomposition and dtype rules. nan_rm = TRUE (the default) skips nodata, matching R's na.rm = TRUE under the NaN nodata sentinel.

Usage

reduce_over(x, op, over, nan_rm = TRUE, bands = NULL)

Arguments

x

A LazyRaster, or a LazyDataset.

op

Reduction name: one of "sum", "mean", "min", "max", "prod", "median", "quantile", "sd", "var", "count", "any", "all". Alternatively a custom reducer: a function fn(x, dims) written in the g_* vocabulary that collapses the margins dims (e.g. a per-pixel model fit over time).

over

Names of dims to reduce over (subset of names(dims)).

nan_rm

Skip NaN (nodata) values?

bands

LazyDataset only: bands to reduce (default: all bands).

Value

A LazyRaster on the reduced grid, or a LazyDataset when given one.

Details

Over a LazyDataset, each band is reduced independently (over "t": stack the band's slices and collapse time to a composite); bands restricts which bands. over = "band" collapses the band axis, returning a LazyRaster.

See also

geomedian() and medoid() for multivariate time composites; band_project() and mlp_project() for band-axis models; group_by_time() for calendar-grouped reduction; scan_over() for order-preserving passes.