WaveDuration: Heat and cold waves duration for n-dimensional arrays

View source: R/WaveDuration.R

WaveDurationR Documentation

Heat and cold waves duration for n-dimensional arrays

Description

This function computes the duration of a heat/cold wave as the number of consecutive days for which the maximum/minimum temperature is exceeding/below a threshold over a minimum number of days in month or seasonal resolution.

Usage

WaveDuration(
  data,
  threshold,
  op = ">",
  spell.length = 6,
  by.seasons = TRUE,
  dates = NULL,
  calendar = NULL,
  ncores = NULL
)

Arguments

data

A numeric n-dimensional array containing daily maximum or minimum temperature

threshold

An array with the threshold to be/not to be reach, usually given by the 90th/10th percentiles for heat/cold waves computed with the Threshold function.

op

A character ">" (by default) or ">=" for heat waves and "<" or "<=" for cold waves indicating the operator must be used to compare data to threshold.

spell.length

A number indicating the number of consecutive days with extreme temperature to be considered heat or cold wave.

by.seasons

If TRUE (by default), the wave duration is computed for each season (DJF/MAM/JJA/SON) separately. If FALSE is specified, the monthly wave duration is computed.

dates

A vector of dates including calendar attributes. If NULL (by default), the 'time' attributes of parameter 'data' is used.

calendar

A character indicating the calendar type.

ncores

The number of cores to be used when computing the wave duration.

Value

A list of length 2:

  • $result, an array with the same dimensions as the input data, but with the time dimension reduce from daily to monthly or seasonal resolution depending on the selected resolution in by.season.

  • $years, a vector of the years and season/months corresponding to the resolution selected in by.season and temporal length of the input data.

Examples

##Example synthetic data:
data <- 1:(2 * 3 * 31 * 5)
dim(data) <- c(lon = 2, lat = 3, time = 31, model = 5)
time <- as.POSIXct(paste(paste(1900, 1, 1:31, sep = "-"), paste(12, 0, 0.0, 
                  sep = ":")), tz = "CET")
metadata <- list(time = list(standard_name = 'time', long_name = 'time', 
                calendar = 'standard', 
                units = 'days since 1970-01-01 00:00:00', prec = 'double', 
                dim = list(list(name ='time', unlim = FALSE))))
attr(time, "variables") <- metadata                 
attr(data, 'Variables')$dat1$time <- time
threshold <- rep(40, 31)

a <- WaveDuration(data, threshold, op = ">", spell.length = 6, 
                 by.seasons = TRUE, ncores = NULL)
str(a)

ClimProjDiags documentation built on May 29, 2024, 8:56 a.m.