Extremes: Sum of spell lengths exceeding daily threshold for...

View source: R/Extremes.R

ExtremesR Documentation

Sum of spell lengths exceeding daily threshold for n-dimensional arrays


This function returns the number of spells of more than min.length days which exceed or are below the given threshold from daily data.


  op = ">",
  min.length = 6,
  spells.can.span.years = TRUE,
  max.missing.days = 5,
  dates = NULL,
  timedim = NULL,
  calendar = NULL,
  ncores = NULL



A n-dimensional array containing daily data.


A n-dimensional array with the threshold to be/not to be reach, usually given by the a percentile computed with the Threshold function.


The operator to use to compare data to threshold.


The minimum spell length to be considered.


Whether spells can span years.


Maximum number of NA values per time period.


A vector of dates with a calendar attributes. If NULL (by default), the 'time' attributes of parameter 'data' are considered.


An integer number indicating the position of the time dimension in the parameter data. If NULL (by default), the dimension called 'time' in parameter data.


A character indicating the calendar type.


The number of cores to be used when computing the extreme.


This routine compares data to the thresholds using the given operator, generating a series of TRUE or FALSE values; these values are then filtered to remove any sequences of less than min.length days of TRUE values. It then computes the lengths of the remaining sequences of TRUE values (spells) and sums their lengths. The spells.can.spa .years option controls whether spells must always terminate at the end of a period, or whether they may continue until the criteria ceases to be met or the end of the data is reached. The default for fclimdex is FALSE.


A list of length 2:

  • $output1An array with the same dimensions as the original data, except the time dimension which is reduced to annual resolution given a timeseries of maximum spell lengths for each year.

  • $yearA vector indicating the corresponding years.


##Example synthetic data:
data <- 1:(2 * 3 * 310 * 1)
dim(data) <- c(time = 310, lon = 2, lat = 3, model = 1)
time <- as.POSIXct(paste(sort(rep(1902:1911, 31)), 1, 1:31, sep = "-"), tz = "CET")
metadata <- list(time = list(standard_name = 'time', long_name = 'time', 
                            calendar = 'noleap', 
                            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 <- Threshold(data, dates = NULL, base.range = NULL, qtiles = 0.9, ncores = NULL)
res <- Extremes(data, threshold = threshold, op = ">", min.length = 6, 
               spells.can.span.years = TRUE, max.missing.days = 5, 
               ncores = NULL)

ClimProjDiags documentation built on June 7, 2023, 5:48 p.m.