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.
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 compressiontimmean
calculates the temporal meanselyear
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