Skip to contents

This function changes the temporal frequency of climate data from daily to either monthly or yearly averages using CDO (Climate Data Operators). It supports both HPC array job processing and parallel processing for efficient computation.

Usage

htr_change_freq(hpc = NA, file = NA, freq, indir, outdir)

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

file

Character string or NA. Specific file to process when hpc = "array". Not used in other modes.

freq

Character string. The target temporal frequency. Valid options are:

  • "yearly" or "annual": Calculate annual means using CDO yearmean

  • "monthly": Calculate monthly means using CDO monmean

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.

Value

No return value. The function creates frequency-converted files in the specified output directory with "annual" or "monthly" replacing "merged" in the original filenames.

Details

The function uses CDO temporal aggregation operators to change frequency:

  • For yearly frequency: Uses cdo -yearmean to calculate annual means

  • For monthly frequency: Uses cdo -monmean to calculate monthly means

The function can operate in different modes:

  • Array mode (hpc = "array"): Processes a single specified file (useful for HPC job arrays)

  • Parallel mode (hpc = "parallel" or hpc = NA): Processes all files in the input directory using parallel workers

Output files are renamed to reflect the new temporal frequency, replacing "merged" with either "annual" or "monthly" in the filename.

Note

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

  • Input files should typically be daily frequency data for meaningful aggregation

  • For HPC environments, set hpc = "array" and specify the file parameter

  • Uses parallel processing when hpc = NA or hpc = "parallel"

  • Worker count is automatically determined based on available CPU cores

References

CDO User Guide: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf CDO yearmean operator: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf#page=191 CDO monmean operator: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf#page=186

Author

Tin Buenafe

Examples

if (FALSE) { # \dontrun{
htr_change_freq(
  hpc = NA,
  file = NA,
  freq = "monthly",
  indir = file.path(".", "data", "proc", "sliced", variable),
  outdir = file.path(".", "data", "proc", "monthly", variable)
)
} # }