Skip to contents

This function standardizes climate model data to use a consistent 365-day calendar system by removing leap days (February 29th) and setting the calendar attribute. This is essential for consistent temporal analysis across different climate models that may use different calendar systems.

Usage

htr_fix_calendar(hpc = NA, file = NA, indir)

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.

indir

Character string. Directory containing NetCDF files that need calendar standardization. Files should be climate model outputs with time dimensions.

Value

No return value. The function modifies files in-place, replacing original files with calendar-standardized versions. Progress messages are printed to the console indicating which files had leap days removed.

Details

Climate models use various calendar systems (Gregorian, 365-day, 360-day, etc.), which can cause issues when comparing or combining data from different models. This function standardizes all data to a 365-day calendar using CDO operations.

The function:

  1. Checks if files contain leap days by examining if the number of time steps is divisible by 365

  2. For daily data with leap days: Uses cdo -setcalendar,365_day -delete,month=2,day=29 to remove February 29th

  3. For data without leap days: Uses cdo setcalendar,365_day to set the calendar attribute

  4. Replaces original files with the calendar-corrected versions

The process creates temporary files during processing to avoid data corruption.

Note

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

  • WARNING: This function modifies files in-place. Ensure you have backups of original data

  • Only processes daily frequency data for leap day removal (detected by "day" in frequency)

  • Uses parallel processing when hpc is not set to "array"

  • Creates temporary files during processing which are automatically cleaned up

  • Prints informative messages about which files are being processed

References

CDO User Guide: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf CDO setcalendar operator: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf#page=142 CDO delete operator: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf#page=60 CMIP6 calendar conventions: https://pcmdi.llnl.gov/CMIP6/Guide/dataUsers.html

Author

Dave Schoeman and Tin Buenafe

Examples

if (FALSE) { # \dontrun{
htr_fix_calendar(
  hpc = NA,
  file = NA,
  indir = file.path(base_dir, "data", "merged") # input directory
)
} # }