Skip to contents

This function regrids climate model outputs from their native grids to a common regular latitude-longitude grid using CDO (Climate Data Operators). This is essential for comparing and combining data from different climate models that use different spatial grids.

Usage

htr_regrid_esm(hpc = NA, file = NA, indir, outdir, cell_res = 0.25, layer)

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 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.

cell_res

Numeric. Spatial resolution in degrees for the target grid (e.g., 0.25 for quarter-degree resolution, 1.0 for one-degree resolution). Default is 0.25 degrees.

layer

Character string. Description of the data layer being regridded (e.g., "annual", "monthly", "anomalies"). This is used for filename generation and progress reporting.

Value

No return value. The function creates regridded files in the specified output directory with "Regridded" added to the layer name in the filename (e.g., "annual" becomes "RegriddedAnnual").

Details

Different climate models use various spatial grids (regular lat-lon, curvilinear, unstructured, etc.), making direct comparison difficult. This function standardizes all data to a regular latitude-longitude grid using CDO interpolation methods.

The function uses different CDO remapping operators based on the variable type:

  • Precipitation (pr): Uses conservative remapping (remapcon) to preserve total precipitation amounts

  • Other variables: Uses bilinear interpolation (remapbil) for smooth interpolation

The process:

  1. Creates a blank raster template at the specified resolution

  2. For each input file, determines the appropriate remapping method

  3. Applies CDO remapping: cdo -s -L -remapXXX,template input output

  4. Updates filenames to include "Regridded" prefix

  5. Cleans up the temporary template file

The -s flag suppresses CDO messages, and -L enables netCDF4 compression.

Note

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

  • Creates a temporary grid template file that is automatically cleaned up

  • Uses conservative remapping for precipitation to preserve mass conservation

  • Uses bilinear interpolation for other variables (consider remapdis for some applications)

  • Progress messages show the model and scenario being processed

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

References

CDO User Guide: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf CDO remapbil operator: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf#page=115 CDO remapcon operator: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf#page=116 Grid remapping methods: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf#section.1.3.2

Author

David Schoeman and Tin Buenafe

Examples

if (FALSE) { # \dontrun{
htr_regrid_esm(
  hpc = NA,
  file = NA,
  indir = file.path(base_dir, "data", "proc", "yearly", "tos"),
  outdir = file.path(base_dir, "data", "proc", "regridded", "yearly", "tos"),
  cell_res = 0.25,
  layer = "annual"
)
} # }