
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
st_downsample(x, n, ...)# S3 method for stars
st_downsample(x, n, ..., offset = 0, FUN)
# S3 method for stars_proxy
st_downsample(x, n, ...)
object of class stars or stars_proxy
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
)
integer; offset(s) for downsampling, in pixels, starting at the offset of
each dimension; should be smaller or equal to n
function; if given, downsampling will apply FUN to each of the the subtiles
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
.
(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]]
Run the code above in your browser using DataLab