Skip to contents

This function calculates climate anomalies by subtracting baseline mean values from projection data using CDO (Climate Data Operators). It processes multiple climate model files in parallel, matching variables, frequencies, and models between the projection data and baseline means.

Usage

htr_calc_anomalies(indir, mndir, outdir)

Arguments

indir

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

mndir

Character string. The directory where the baseline mean files are stored. Files should follow CMIP6 naming conventions with variable, frequency, and model information in the filename.

outdir

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

Value

No return value. The function creates anomaly files in the specified output directory with "anomalies" replacing "merged" in the original filenames.

Details

The function uses the CDO sub operator to subtract baseline means from projection files. It automatically matches files based on variable, frequency, and model metadata extracted from CMIP6-formatted filenames. The process runs in parallel using multiple CPU cores for efficient processing of large datasets.

The workflow involves:

  1. Extracting metadata from baseline mean files

  2. Finding corresponding projection files for each variable-frequency-model combination

  3. Subtracting the appropriate baseline mean from each projection file using CDO

  4. Saving results with "anomalies" in the filename

Note

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

  • Input files must follow CMIP6 naming conventions for proper metadata extraction

  • Baseline mean files and projection files must have matching variable, frequency, and model names

  • Uses parallel processing with (number of CPU cores - 2) workers

References

CDO User Guide: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf CDO sub operator: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf#page=297

Examples

if (FALSE) { # \dontrun{
htr_calc_anomalies(
  indir = file.path(base_dir, "data", "tos", "raw"),
  indir = file.path(base_dir, "data", "tos", "mean"),
  outdir = file.path(base_dir, "data", "tos", "anomalies")
)
} # }