reduce_time.array

Apply a function over time and bands in a four-dimensional (band, time, y, x) array and reduce time dimension

Description

Apply a function over time and bands in a four-dimensional (band, time, y, x) array and reduce time dimension

Usage

reduce_time.array(x, FUN, ...)

Arguments

Argument Description
x four-dimensional input array with dimensions band, time, y, x (in this order)
FUN function which receives one time series in a two-dimensional array with dimensions bands, time as input
further arguments passed to FUN

Details

FUN is expected to produce a numeric vector (or scalar) where elements are interpreted as new bands in the result.

Note

This is a helper function that uses the same dimension ordering as gdalcubes streaming. It can be used to simplify the application of R functions e.g. over time series in a data cube.

Examples

d <- c(4,16,32,32)
x <- array(rnorm(prod(d)), d)
# reduce individual bands over pixel time series
y <- reduce_time(x, function(v) {
  apply(v, 1, mean)
})
dim(y)
[1]  4  1 32 32