Performs a spatial aggregation of gridded climate data into areas.
Description
Performs a spatial aggregation of gridded climate data into areas.
c4h_space(data, areas, fun = "mean", weighting = "none", areas_id = NULL)Arguments
data: s2dv_cube object with the climate data to be aggregates, usually read using c4h_load .areas: Vector data, either a sf or terra object loaded into memory, or path to a vector file to be read. Contains the areal polygon geometries for the spatial aggregation.fun: String. Method to perform the aggregation, defaults to “mean”. Other possible options include “median”, “sum”, “min” and “max”.weighting: String that indicates whether weighted means should be used whenfun = "mean"at the cost of increased computation. Options are “none” (a simple mean is applied to cells with centroid within the polygon), “approx” (for an approximate and fast weighting) and “exact” (for an exact weighting). Seeterra::extractfor details.areas_id: String. Name of the area identifier in theareasobject.
Returns
A s2dv_cube object with the aggregated data.
Examples
library(sf)
# Region municipalities (first 5)
munip_path <- system.file("extdata", "areas", "munip_vallecauca.gpkg",
package = "clim4health")
munip <- read_sf(munip_path)[1:5,]
# Forecast
fcst_path <- system.file("extdata", "forecast", package = "clim4health")
fcst <- c4h_load(fcst_path, variable = "t2m", ext = 'nc')
# Spatial aggregation
fcst_aggr <- c4h_space(fcst, munip)