Calculates temporal averages for a multi-layer SpatRaster. This function serves as a smart wrapper, automatically selecting between an in-memory (`terra`) or out-of-core (`tiled`) workflow based on data size.
calculate_average(
x,
index,
output_names = NULL,
output_dir = tempdir(),
user_region = NULL,
method = c("auto", "tiled", "terra"),
tile_degrees = 5,
gdal_opt = c("COMPRESS=DEFLATE", "PREDICTOR=3", "NUM_THREADS=ALL_CPUS"),
overwrite = FALSE,
verbose = TRUE
)A `terra::SpatRaster` object pointing to the newly created files.
A `terra::SpatRaster` object with multiple layers representing a time series.
A numeric or integer vector defining the grouping for aggregation. Its length must equal the number of layers in `x`. For example, to average 360 monthly layers into 12 monthly means, `index` would be `rep(1:12, 30)`.
A character vector of names for the output layers. Its length must equal the number of unique groups in `index`. If `NULL`, names like "avg_unit_1" are generated.
The directory where the final averaged raster layers will be saved as GeoTIFF files.
(Optional) An `sf` or `terra::SpatVector` object for clipping.
The processing method: "auto", "tiled", or "terra".
(Tiled method only) The approximate size of processing tiles.
(Optional) GDAL creation options for the output GeoTIFFs.
Logical. If `FALSE` (default), stops if output files exist.
Logical, If `TRUE`, prints messages.