Skip to contents

This function creates multi-model ensembles by combining outputs from multiple climate models using CDO (Climate Data Operators). It can calculate either the ensemble mean or median across the specified models, with support for seasonal and depth-resolved data filtering.

Usage

htr_create_ensemble(
  hpc = NA,
  indir,
  outdir,
  model_list,
  variable = "tos",
  freq = "Omon",
  scenario = "historical",
  season = "",
  domain = "",
  mean = TRUE
)

Arguments

hpc

Character string or NA. Indicates High Performance Computing mode:

  • NA: Standard processing mode

  • "array": HPC array job mode (requires file parameter)

  • "parallel": HPC parallel mode

indir

Character string. Directory containing merged NetCDF files to be time-sliced. Files should be continuous time series created by htr_merge_files().

outdir

Character string. Directory where time-sliced files will be saved.

model_list

Character vector. Names of climate models to include in the ensemble. Model names must match those in the input filenames (e.g., c("ACCESS-ESM1-5", "CanESM5", "GFDL-ESM4")).

variable

Character string. The climate variable to create the ensemble for (e.g., "tos" for sea surface temperature, "pr" for precipitation). Default is "tos".

freq

Character string. CMIP6 frequency identifier to filter files (e.g., "Omon" for ocean monthly, "day" for daily, "Amon" for atmosphere monthly).

scenario

Character string. CMIP6 scenario identifier to filter files (e.g., "historical", "ssp126", "ssp245", "ssp585"). Use partial strings to match multiple scenarios (e.g., "ssp" for all SSP scenarios).

season

Character string. Optional season name to filter files (e.g., "DJF", "JJA"). Only files containing this string will be included. Default is empty string (no filtering).

domain

Character string. Optional domain name for depth-resolved models (e.g., "surface", "0-100m"). Only files containing this string will be included. Default is empty string (no filtering).

mean

Logical. If TRUE (default), calculates ensemble mean using CDO ensmean. If FALSE, calculates ensemble median using CDO ensmedian.

Value

No return value. The function creates an ensemble file in the specified output directory with "ensemble" replacing the model name in the original filename.

Details

The function uses CDO ensemble operators to combine multiple model outputs:

  • Ensemble mean: Uses cdo -ensmean to calculate the arithmetic mean across models

  • Ensemble median: Uses cdo -ensmedian to calculate the median across models

The function automatically:

  1. Filters files based on variable, frequency, scenario, and optionally season/domain

  2. Selects only files from the specified models in model_list

  3. Creates ensemble statistics using the appropriate CDO operator

  4. Saves output with "ensemble" replacing the model name in the filename

Output files are compressed using zip compression (-z zip) and use netCDF4 format with the -L flag for efficient storage.

Note

  • Requires CDO (Climate Data Operators) to be installed and accessible from the system PATH

  • All input files must be on the same spatial grid (use htr_regrid_esm() first if needed)

  • All input files must have the same temporal resolution and time periods

  • Model names in model_list must exactly match those in the input filenames

  • Uses zip compression for efficient file storage

References

CDO User Guide: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf CDO ensmean operator: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf#page=78 CDO ensmedian operator: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf#page=79

Examples

if (FALSE) { # \dontrun{
htr_create_ensemble(
  hpc = NA,
  indir = file.path(base_dir, "data", "proc", "regridded", "yearly", "tos"),
  outdir = file.path(base_dir, "data", "proc", "ensemble", "mean", "tos"),
  model_list = c("ACCESS-ESM1-5", "CanESM5"),
  variable = "tos",
  freq = "Omon",
  scenario = "ssp126",
  mean = TRUE
)
} # }