# --- s2dv cube creation for Temperature (K) ---
temp <- NULL
temp$data <- array(rnorm(100, mean = 300, sd = 5),
c(member = 5, sdate = 3, time = 214, lon = 2, lat = 5))
temp$coords <- list(lat = 1:5, lon = 1:2)
variableT <- list(varName = 'tas',
metadata = list(tas = list(units = 'K', long_name = '2m Temperature')))
temp$attrs <- list(Variable = variableT,
Datasets = 'synthetic',
when = Sys.time())
Dates <- c(seq(as.Date("2000-05-01"), as.Date("2000-11-30"), by = 'day'),
seq(as.Date("2001-05-01"), as.Date("2001-11-30"), by = 'day'),
seq(as.Date("2002-05-01"), as.Date("2002-11-30"), by = 'day'))
dim(Dates) <- c(sdate = 3, time = 214)
temp$attrs$Dates <- Dates
class(temp) <- "s2dv_cube"
# s2dv cube creation for Relative Humidity (%)
rh <- NULL
rh$data <- array(runif(100, min = 10, max = 100),
c(member = 5, sdate = 3, time = 214, lon = 2, lat = 5))
rh$coords <- temp$coords
variableRH <- list(varName = 'hurs',
metadata = list(hurs = list(units = '%', long_name = 'Relative Humidity')))
rh$attrs <- list(Variable = variableRH,
Datasets = 'synthetic',
when = Sys.time(),
Dates = temp$attrs$Dates)
class(rh) <- "s2dv_cube"
# Example 1 : mean Heat Index (fun = mean by default)
HI_mean <- CST_HeatIndex(temp = temp, rh = rh)
#Example 2 : Input temporal resolution (no aggregation)
HI_full <- CST_HeatIndex(temp = temp, rh = rh, fun = NULL)
# Example 3 : 90% percentile calulation
HI_p90 <- CST_HeatIndex(
temp = temp, rh = rh,
fun = function(x, na.rm = TRUE) quantile(x, 0.90, na.rm = na.rm))
# Example 4 : Summer values (1 June to 31 August)
HI_summer <- CST_HeatIndex(
temp = temp, rh = rh, fun = NULL,
start = list(1, 6), end = list(31, 8))
Run the code above in your browser using DataLab