gdalcubes (version 0.2.5)

reduce_space.array: Apply a function over space and bands in a four-dimensional (band, time, y, x) array

Description

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

Usage

# S3 method for array
reduce_space(x, FUN, ...)

Arguments

x

four-dimensional input array with dimensions band, time, y, x (in this order)

FUN

function which receives one spatial slice in a three-dimensional array with dimensions bands, y, x 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.

Examples

Run this code
# NOT RUN {
d <- c(4,16,32,32)
x <- array(rnorm(prod(d)), d)
# reduce individual bands over spatial slices 
y <- reduce_space(x, function(v) {
  apply(v, 1, mean)
})
dim(y)
# }

Run the code above in your browser using DataCamp Workspace