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

Description

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

Usage

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

Arguments

data

A n-dimensional array containing daily data.

threshold

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

op

The operator to use to compare data to threshold.

min.length

The minimum spell length to be considered.

spells.can.span.years

Whether spells can span years.

max.missing.days

Maximum number of NA values per time period.

dates

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

timedim

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.

calendar

A character indicating the calendar type.

ncores

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

Details

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.

Value

A list of length 2:

  • $output1, an 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.

  • $year, a vector indicating the corresponding years.

Examples

##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)
str(res)


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