Skip to contents

This function calculates vertical (depth) means from 3D ocean climate model data using CDO (Climate Data Operators). It can either integrate across all vertical levels or select a specific depth range before calculating the vertical mean.

Usage

htr_integrate_levels(
  hpc = NA,
  file = NA,
  indir,
  tempdir,
  outdir,
  select_levels = FALSE,
  min_level,
  max_level,
  domain_name = ""
)

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

tempdir

Character string. Directory for temporary files during processing. Used when select_levels = TRUE to store intermediate files after level selection.

outdir

Character string. Directory where time-sliced files will be saved.

select_levels

Logical. If TRUE, selects a specific depth range defined by min_level and max_level before calculating vertical means. If FALSE (default), integrates across all available vertical levels.

min_level

Numeric. Minimum depth level for integration (required when select_levels = TRUE). Units depend on the model's vertical coordinate system.

max_level

Numeric. Maximum depth level for integration (required when select_levels = TRUE). Units depend on the model's vertical coordinate system.

domain_name

Character string. Optional suffix to add to output filenames to identify the depth domain (e.g., "surface", "0-100m"). Default is empty string.

Value

No return value. The function creates vertically-integrated files in the specified output directory. If domain_name is provided, it is added as a suffix to the original filename before the file extension.

Details

The function processes depth-resolved ocean data (e.g., temperature, salinity) to create vertically-averaged fields. This is useful for analyzing ocean properties at specific depth ranges or creating depth-integrated quantities.

The CDO operations performed are:

  • With level selection: cdo select,levrange=min,max followed by cdo vertmean

  • Without level selection: cdo vertmean directly on the full depth range

The function:

  1. Optionally selects a specific depth range using CDO select with levrange

  2. Calculates the vertical mean using CDO vertmean operator

  3. Adds an optional domain name suffix to output filenames

  4. Uses a temporary directory for intermediate processing when level selection is used

Note

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

  • Input files must be 3D ocean data with vertical levels (depth or pressure coordinates)

  • Temporary files are automatically cleaned up after processing

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

  • Level selection uses CDO's levrange which works with the model's native vertical coordinates

References

CDO User Guide: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf CDO vertmean operator: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf#page=203 CDO select operator: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf#page=123

Examples

if (FALSE) { # \dontrun{
# Integrate all levels
htr_integrate_levels(
  indir = "path/to/3d/data",
  tempdir = "path/to/temp",
  outdir = "path/to/output",
  select_levels = FALSE
)

# Integrate specific depth range (e.g., upper 100m)
htr_integrate_levels(
  indir = "path/to/3d/data",
  tempdir = "path/to/temp",
  outdir = "path/to/output",
  select_levels = TRUE,
  min_level = 0,
  max_level = 100,
  domain_name = "upper100m"
)
} # }