GHRtools
  • data4health
    • Overview
    • Reference
    • Changelog

    • Vignettes
    • Getting started
    • Access health data
  • clim4health
    • Overview
    • Reference
    • Changelog

    • Vignettes
    • Getting started
    • Glossary
    • s2dv_cube objects
    • Get function
    • Downscaling function
    • Verification function
  • GHRexplore
    • Overview
    • Reference
    • Changelog

    • Vignettes
    • Getting started
  • GHRmodel
    • Overview
    • Reference
    • Changelog

    • Vignettes
    • Getting started
    • Covariate structures
    • DLNMs in GHRmodel
  • GHRpredict
    • Overview
  • About GHR

On this page

  • Performs a spatial aggregation of gridded climate data into areas.
    • Description
    • Arguments
    • Returns
    • Examples

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 when fun = "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). See terra::extract for details.
  • areas_id: String. Name of the area identifier in the areas object.

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)

Copyright 2026, GHR

 

BSC IDExtremes HARMONIZE Wellcome