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

  • Collapse one dimension of a s2dv_cube object
    • Description
    • Arguments
    • Returns
    • Examples

Collapse one dimension of a s2dv_cube object

Description

Collapse one dimension of the s2dv_cube. c4h_collapse() works differently depending on the dimension being collapsed:

  • Use dim = “ensemble” to compute a summary statistic across ensemble members in forecast and hindcast datasets.
  • Use dim = “time” to compute a time aggregation with observational data (i.e. the length of the ‘sdate’ dimension must be one). In this case the first “time” of the dataset is assigned as the new s2dv time coordinate. To compute time aggregations when ‘sdate’ has length greater than one, use the function c4h_time() instead.
  • Use dim = “sdate” to compute a climatology, if each ‘sdate’ corresponds to a different year. In this case the first “sdate” of the dataset is assigned as the new s2dv sdate coordinate.
c4h_collapse(data, dim, fun = "mean", na.rm = TRUE)

Arguments

  • data: s2dv_cube object with the climate data.
  • dim: Dimension to collapse. Options include ‘ensemble’, ‘sdate’ and ‘time’.
  • fun: Function to perform the aggregation, defaults to ‘mean’. Other options include ‘median’, ‘min’ and ‘max’.
  • na.rm: Logical, indicating whether NA values should be ignored when applying the collapsing function. Defaults to TRUE.

Returns

The collapsed s2dv_cube.

Examples

# Load a forecast
fcst <- c4h_load(system.file("extdata", "forecast", package = "clim4health"),
                 var = "t2m",
                 year = 2025,
                 month = 1,
                 ext = 'nc')
fcst$dims

# Ensemble median of a forecast
fcst_coll <- c4h_collapse(fcst, dim = "ensemble", fun = "median")
fcst_coll$dims

# Load an observational time-series dataset
stations_path <- system.file("extdata", "stations", package = "clim4health")
stations <- c4h_load(stations_path, var = "temp_mean", ext = "csv")
stations$dims

# Compute time-mean (average temp conditions)
stations_coll <- c4h_collapse(stations, dim = "time")
stations_coll$dims

# Load an observational dataset aligned to a hindcast
obs_path <- system.file("extdata", "reanalysis", package = "clim4health")
obs <- c4h_load(obs_path, var = "t2m", ext = "nc",
                year = 2010:2012, month = 1, leadtime_month = 1:3)
obs$dims

# Compute climatology (average over years)
obs_coll <- c4h_collapse(obs, dim = "sdate")
obs_coll$dims

Copyright 2026, GHR

 

BSC IDExtremes HARMONIZE Wellcome