
Reduction over named dims.
reduce_over.Rdop 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. A pixel that is nodata in every input stays
nodata (NaN) for "mean", "median", "min" and "max"; "sum"
gives 0 and "count" gives 0. (The g_min() / g_max() primitives
return their identity, Inf / -Inf, instead.)
Arguments
- x
A
LazyRaster, or aLazyDataset.- op
Reduction name: one of
"sum","mean","min","max","median","count". Alternatively a custom reducer: a functionfn(x, dims)written in theg_*vocabulary that collapses the marginsdims(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
LazyDatasetonly: bands to reduce (default: all bands).
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.
Examples
f <- system.file("extdata", "garry-example.tif", package = "garry")
red <- lazy_source(f, band = 1L)
collect(reduce_over(red, "mean", c("x", "y")))
#> Error in confirm_plugin_install(platform, url): The "cpu" PJRT plugin needs to be downloaded for pjrt to work.
#> ℹ Automatic downloads are not performed in non-interactive sessions.
#> ℹ Set `PJRT_INSTALL` to "1" to allow the download, or set
#> `PJRT_PLUGIN_PATH_CPU` to a local plugin file.
stk <- lazy_stack(list(a = red, b = red * 2))
dim(collect(reduce_over(stk, "median", "t")))
#> Error in confirm_plugin_install(platform, url): The "cpu" PJRT plugin needs to be downloaded for pjrt to work.
#> ℹ Automatic downloads are not performed in non-interactive sessions.
#> ℹ Set `PJRT_INSTALL` to "1" to allow the download, or set
#> `PJRT_PLUGIN_PATH_CPU` to a local plugin file.