
Create multi-model ensemble from climate model outputs
Source:R/htr_create_ensemble.R
htr_create_ensemble.Rd
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 (requiresfile
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. IfFALSE
, 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 modelsEnsemble median: Uses
cdo -ensmedian
to calculate the median across models
The function automatically:
Filters files based on variable, frequency, scenario, and optionally season/domain
Selects only files from the specified models in
model_list
Creates ensemble statistics using the appropriate CDO operator
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 filenamesUses 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
)
} # }