st_downsample: downsample stars or stars_proxy objects

View source: R/sample.R

st_downsampleR Documentation

downsample stars or stars_proxy objects

Description

downsample a stars or stars_proxy object either by skipping rows, columns and bands, or by computing a single value (e.g. the mean) from the sub-tiles involved

Usage

st_downsample(x, n, ...)

## S3 method for class 'stars'
st_downsample(x, n, ..., offset = 0, FUN)

## S3 method for class 'stars_proxy'
st_downsample(x, n, ...)

Arguments

x

object of class stars or stars_proxy

n

integer; for each dimension the number of pixels/lines/bands etc that will be skipped; see Details.

...

arguments passed on to FUN (e.g., na.rm = TRUE to ignore missing values if FUN is mean)

offset

integer; offset(s) for downsampling, in pixels, starting at the offset of each dimension; should be smaller or equal to n

FUN

function; if given, downsampling will apply FUN to each of the the subtiles

Details

If all n == 0, no downsampling takes place; if it is 1, every second row/column/band is skipped, if it is 2, every second+third row/column/band are skipped, etc.

Downsampling a stars_proxy object returns a stars object, is equivalent to calling st_as_stars(x, downsample = 2), and only downsamples the first two (x and y) dimensions.

Downsampled regular rasters keep their dimension offsets, have a cell size (delta) that is n[i]+1 times larger, and may result in a (slightly) different extent.

Note that terra's aggregate with fact=2 corresponds to st_downsample(x, n = 1, FUN = mean): fact is one larger than n.

Examples

(m = matrix(1:121, 11, 11))
(s = st_as_stars(m))
st_downsample(s, 1)
st_downsample(s, 1)[[1]]
st_downsample(s, 1, offset = 1)
st_downsample(s, 1, offset = 1)[[1]]
st_downsample(s, 1, offset = c(0,1))
st_downsample(s, 1, offset = c(0,1))[[1]]
st_downsample(s, 1, FUN = mean)
st_downsample(s, 1, FUN = mean)[[1]]
st_downsample(s, 1, offset = 1, FUN = mean)
st_downsample(s, 1, offset = c(0,1), FUN = mean)[[1]]

stars documentation built on May 29, 2024, 8:59 a.m.