apply_pixel.array: Apply a function over pixels in a four-dimensional (band,...

View source: R/streaming.R

apply_pixel.arrayR Documentation

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

Description

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

Usage

## S3 method for class 'array'
apply_pixel(x, FUN, ...)

Arguments

x

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

FUN

function that receives a vector of band values in a one-dimensional array

...

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. 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)
y <- apply_pixel(x, function(v) {
  v[1] + v[2] + v[3] - v[4]
})
dim(y)

gdalcubes documentation built on May 29, 2024, 5:11 a.m.