CST_AreaWeighted: Calculate the spatial area-weighted average of...

View source: R/AreaWeighted.R

CST_AreaWeightedR Documentation

Calculate the spatial area-weighted average of multidimensional arrays.

Description

This function computes a spatial area-weighted average of n-dimensional arrays given a spatial mask containing the area (e.g. in m^2) for each grid box.

Usage

CST_AreaWeighted(
  data,
  area,
  lon_dim = "lon",
  lat_dim = "lat",
  ncores = NULL,
  extra_info = NULL
)

Arguments

data

An object of class s2dv_cube with at least lon_dim and lat_dim containing climate data.

area

A multidimensional array with named dimensions (at least lon_dim and lat_dim) containing area of each grid box. The resolution, length and order of the lon_dim and lat_dim dimensions should be identical as for data. Missing values are allowed and treated as 0s.

lon_dim

A character string indicating the name of the longitudinal dimension. The default value is 'lon'.

lat_dim

A character string indicating the name of the latitudinal dimension. The default value is 'lat'.

ncores

An integer indicating the number of cores to use for parallel computation. The default value is NULL.

extra_info

A named list with additional metadata to add to the s2dv_cube. There can be one entry for each dimension in 'area' that is not also present in 'data'.

Value

An object of class s2dv_cube with same dimensions as in object data, except with lon_dim and lat_dim removed. Any extra dimensions in area not present in data are preserved in the output (e.g., region dimension).

Examples

data <- array(data = 1:10, dim = c(year = 10, lon = 5, lat = 3))
coords <- list(lat = 1:3, lon = 1:5)
data <- list(data = data, coords = coords)
attr(data, 'class') <- 's2dv_cube'
area <- array(data = 1:10, dim = c(lon = 5, lat = 3))
CST_AreaWeighted(data, area)
# With extra region dimension
area <- array(data = 1:10, dim = c(lon = 5, lat = 3, region = 4))
CST_AreaWeighted(data, area)


CSTools documentation built on Nov. 14, 2025, 5:07 p.m.