Skip to contents

This function interpolates a 4D atmospheric variable [lon, lat, lev, time] to a new set of pressure levels using either logarithmic or linear interpolation.

Usage

interpolate_profile(
  var4d,
  input_pressure,
  output_pressure,
  log_interp = FALSE,
  nthreads = 1
)

Arguments

var4d

A 4D array [lon, lat, lev, time] representing the atmospheric variable to interpolate.

input_pressure

A 1D numeric vector representing the original pressure levels in hPa.

output_pressure

A 1D numeric vector representing the desired output pressure levels in hPa.

log_interp

Logical. If `TRUE`, performs interpolation in log-pressure space; otherwise, uses linear interpolation.

nthreads

an integer specifying the number of threads to use for computation (OpenMP). Default is 1.

Value

A 4D array [lon, lat, new_lev, time].

Details

This function is designed to increase the vertical resolution of atmospheric profiles for calculating CAPE_sfc or CAPE_ml.

Examples

data("ERA5_pl")
hus_pl <- ERA5_pl$hus
pa_pl1 <- ERA5_pl$plev / 100
pa_pl2 <- seq(1, 1000, 5)
res <- interpolate_profile(hus_pl,
  pa_pl1,
  pa_pl2,
  log_interp = TRUE,
  nthreads = 6
)