Skip to contents

This function calculates temporal means over a specified time period using CDO (Climate Data Operators). It is primarily used to calculate baseline climatological means from historical climate data, which can then be used for anomaly calculations.

Usage

htr_calc_mean(indir, outdir, scenario, year_start, year_end)

Arguments

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.

scenario

Character string. The CMIP6 scenario to process (e.g., "historical", "ssp126", "ssp245"). Use "historical" for calculating baseline climatological means.

year_start

Numeric. Starting year for calculating the temporal mean (inclusive).

year_end

Numeric. Ending year for calculating the temporal mean (inclusive).

Value

No return value. The function creates mean files in the specified output directory with "_mean_YYYYMMDD-YYYYMMDD.nc" replacing "merged" in the original filenames, where the dates represent the start and end of the averaging period.

Details

The function uses the CDO timmean operator combined with selyear to calculate temporal means over the specified year range. It processes files in parallel for efficient computation of large climate datasets. The function automatically generates output filenames with "mean" and the year range in the filename.

The CDO command executed is: cdo -L -timmean -selyear,year_start/year_end input_file output_file

Where:

  • -L enables netCDF4 compression

  • timmean calculates the temporal mean

  • selyear selects the specified year range

Note

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

  • Input files must be merged time series files (typically created by htr_merge_files())

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

  • The -L flag enables netCDF4 compression for smaller output files

References

CDO User Guide: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf CDO timmean operator: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf#page=180 CDO selyear operator: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf#page=124

Author

Dave Schoeman and Tin Buenafe

Examples

if (FALSE) { # \dontrun{
htr_calc_mean(
  indir = file.path(base_dir, "data", "tos", "raw"),
  outdir = file.path(base_dir, "data", "tos", "mean"),
  scenario = "historical",
  year_start = 1950,
  year_end = 2014
)
} # }