Learn R Programming

CSIndicators (version 1.2.0)

CST_MultiVarExceedingThreshold: Binary probabilities based on climate thresholds

Description

This function computes an array based on the thresholds imposed to one or multiple climate variables by the user (e.g. thresholds for temperature, relative humidity...). Values of 1 imply that the conditions are met, while values of 0 imply that the conditions are not met.

Usage

CST_MultiVarExceedingThreshold(
  data,
  thresholds,
  operators,
  start = NULL,
  end = NULL,
  time_dim = "time",
  fun = max,
  ncores = NULL,
  na.rm = FALSE,
  ...
)

Value

An s2dv_cube mask for whether all objects pass the required thresholds.

Arguments

data

A list of s2dv_cube objects containing the climate variable(s)

thresholds

A list of list of scalar/vectors/arrays for each s2dv_cube object in data. If the threshold is an array and some dimensions are the same as in data, the dimension must be equal.

operators

A list of scalar/vectors containing the operators to be applied to each climate variable in data.

start

An optional parameter to define the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in data.

end

An optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in data.

time_dim

A character string indicating the name of the dimension to compute the indicator. By default, it is set to 'time'.

fun

A function to be applied along the time dimension. By default, the max is computed over time_dim. To keep the original temporal resolution (i.e., return values for each time step), set `fun = NULL`, in which case no aggregation is applied.

ncores

An integer indicating the number of cores to use in parallel computation.

na.rm

A logical value indicating whether to ignore NA values (TRUE) or not (FALSE). Default value is FALSE.

...

Additional arguments for parameter 'fun'.

Author

Javier Corvillo & Alberto Bojaly, javier.corvillo@bsc.es

Examples

Run this code
tas_data <- array(rnorm(1000, mean = 25, sd = 5),
  dim = c(
    dat = 1, var = 1, sday = 1, sweek = 1,
    syear = 5, time = 2, latitude = 10, longitude = 10, ensemble = 1
  )
)
tas_cube <- list(
  data = tas_data,
  dims = dim(tas_data),
  coords = list(
    dat = 1, var = 1, sday = 1, sweek = 1,
    syear = 1:5, time = 1:2,
    latitude = seq(40, 49, length.out = 10),
    longitude = seq(-10, -1, length.out = 10),
    ensemble = 1
  ),
  attrs = list(Variable = list(varName = "tas"))
)
class(tas_cube) <- "s2dv_cube"

prlr_data <- array(abs(rnorm(1000, mean = 50, sd = 20)),
  dim = c(
    dat = 1, var = 1, sday = 1, sweek = 1,
    syear = 5, time = 2, latitude = 10, longitude = 10, ensemble = 1
  )
)
prlr_cube <- list(
  data = prlr_data,
  dims = dim(prlr_data),
  coords = tas_cube$coords,
  attrs = list(Variable = list(varName = "prlr"))
)
class(prlr_cube) <- "s2dv_cube"

result <- CST_MultiVarExceedingThreshold(
  data = list(tas_cube, prlr_cube),
  operators = list(c(">", "<="), ">"),
  thresholds = list(c(20, 30), 40)
)

Run the code above in your browser using DataLab