diff --git a/.Rbuildignore b/.Rbuildignore index b2d8e5fcebca62bff5e5380a881580283874cd54..5e7002cde0d3d0c313e16670c354202c777521ab 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,3 +6,4 @@ .*^(?!data)\.RData$ .*\.gitlab-ci.yml$ #^tests$ +./.nfs* diff --git a/.gitignore b/.gitignore index 35a09175a4a4e587947985914ec082148bc51880..23a560302d2818630fb7428585681dd3b07a2b3a 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,4 @@ Rplots.pdf .nfs* *.RData !data/*.RData - +.\.nfs* diff --git a/DESCRIPTION b/DESCRIPTION index dfea00eacdfbaec8857e73d3a2bebc400bb21c1a..57b1ab7161f66500fe9dbd7bb4ed787b194eb98e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,7 +4,7 @@ Version: 0.0.1 Authors@R: c( person("Núria", "Pérez-Zanón", , "nuria.perez@bsc.es", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-8568-3071")), person("Llorenç", "Lledó", , "llorenc.lledo@bsc.es", role = "aut")) -Description: The package contains the definition-based computation of the sectoral indicators for the Climate Service. +Description: The definition-based computation of the sectoral indicators for the Climate Service. Depends: R (>= 3.6.0) Imports: @@ -22,6 +22,5 @@ VignetteBuilder: knitr License: Apache License 2.0 URL: https://earth.bsc.es/gitlab/es/csindicators/ BugReports: https://earth.bsc.es/gitlab/es/csindicators/-/issues -LazyData: true Encoding: UTF-8 RoxygenNote: 7.0.1 diff --git a/R/AbsToProbs.R b/R/AbsToProbs.R index d2bcfbd14bb3067378fe520755647ea87f54624e..c36640d17526a0b000958620cebe2521fdb885fc 100644 --- a/R/AbsToProbs.R +++ b/R/AbsToProbs.R @@ -82,15 +82,17 @@ CST_AbsToProbs <- function(data, start = NULL, end = NULL, #'@examples #'exp <- CSTools::lonlat_prec$data #'exp_probs <- AbsToProbs(exp) -#'data <- array(rnorm(5 * 3 * 214 * 2), +#'\dontrun{ +#'data <- array(rnorm(5 * 2 * 61 * 2), #' c(member = 5, sdate = 3, ftime = 214, lon = 2)) #'Dates <- c(seq(as.Date("01-05-2000", format = "%d-%m-%Y"), -#' as.Date("30-11-2000", format = "%d-%m-%Y"), by = 'day'), +#' as.Date("30-06-2000", format = "%d-%m-%Y"), by = 'day'), #' seq(as.Date("01-05-2001", format = "%d-%m-%Y"), -#' as.Date("30-11-2001", format = "%d-%m-%Y"), by = 'day'), +#' as.Date("30-06-2001", format = "%d-%m-%Y"), by = 'day'), #' seq(as.Date("01-05-2002", format = "%d-%m-%Y"), -#' as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day')) +#' as.Date("30-06-2002", format = "%d-%m-%Y"), by = 'day')) #'exp_probs <- AbsToProbs(exp, start = list(21, 4), end = list(21, 6)) +#'} #'@export AbsToProbs <- function(data, dates = NULL, start = NULL, end = NULL, time_dim = 'time', memb_dim = 'member', diff --git a/R/AccumulationExceedingThreshold.R b/R/AccumulationExceedingThreshold.R index 4d3e50e3f2bea78dcf17941496ef2e3dc340d430..e953d32c5f781f6eb2dbe17e717593aa25439d0e 100644 --- a/R/AccumulationExceedingThreshold.R +++ b/R/AccumulationExceedingThreshold.R @@ -22,19 +22,8 @@ #'@import multiApply #'@examples #'exp <- CSTools::lonlat_data$exp +#'exp$data <- CSTools::lonlat_data$exp$data[1, 5, 3, 3, 1, 1] #'DOT <- CST_AccumulationExceedingThreshold(exp, threshold = 280) -#'# Assuming exp$data is already (tasmax + tasmin)/2 - 10 -#'exp$data <- array(rnorm(5 * 3 * 214 * 2, mean = 25, sd = 3), -#' c(memb = 5, sdate = 3, ftime = 214, lon = 2)) -#'exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", format = "%d-%m-%Y"), -#' as.Date("30-11-2000", format = "%d-%m-%Y"), by = 'day'), -#' seq(as.Date("01-05-2001", format = "%d-%m-%Y"), -#' as.Date("30-11-2001", format = "%d-%m-%Y"), by = 'day'), -#' seq(as.Date("01-05-2002", format = "%d-%m-%Y"), -#' as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day')) -#'GDD <- CST_AccumulationExceedingThreshold(exp, threshold = 0, -#' start = list(1, 4), end = list(31, 10)) -#' #'@export CST_AccumulationExceedingThreshold <- function(data, threshold, op = '>', diff = FALSE, @@ -99,8 +88,6 @@ CST_AccumulationExceedingThreshold <- function(data, threshold, op = '>', #' #'@import multiApply #'@examples -#'exp <- CSTools::lonlat_data$exp$data -#'AET <- AccumulationExceedingThreshold(exp, threshold = 280, time_dim = 'ftime') #'# Assuming data is already (tasmax + tasmin)/2 - 10 #'data <- array(rnorm(5 * 3 * 214 * 2, mean = 25, sd = 3), #' c(memb = 5, sdate = 3, time = 214, lon = 2)) @@ -110,7 +97,8 @@ CST_AccumulationExceedingThreshold <- function(data, threshold, op = '>', #' as.Date("30-11-2001", format = "%d-%m-%Y"), by = 'day'), #' seq(as.Date("01-05-2002", format = "%d-%m-%Y"), #' as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day')) -#'GDD <- AccumulationExceedingThreshold(data, threshold = 0, start = list(1, 4), end = list(31, 10)) +#'GDD <- AccumulationExceedingThreshold(data, threshold = 0, start = list(1, 4), +#' end = list(31, 10)) #'@export AccumulationExceedingThreshold <- function(data, threshold, op = '>', diff = FALSE, @@ -145,14 +133,6 @@ AccumulationExceedingThreshold <- function(data, threshold, op = '>', if (is.null(names(dim(threshold))) && length(threshold) > 1) { stop("Parameter 'threshold' must have named dimensions.") } - # This check doen't seem necessary. It limits flexibility. - #common_dims <- which(names(dim(data)) %in% names(dim(threshold))) - #if (length(threshold) > 1) { - # if (any(dim(data)[common_dims] != - # dim(threshold)[which(names(dim(threshold)) %in% names(dim(data)))])) { - # stop("Parameter 'data' and 'threshold' must have the same length on common dimensions.") - # } - #} if (!is.null(dates)) { if (!is.null(start) && !is.null(end)) { if (!any(c(is.list(start), is.list(end)))) { @@ -186,6 +166,12 @@ AccumulationExceedingThreshold <- function(data, threshold, op = '>', target_dims = list(time_dim, time_dim), fun = .sumexceedthreshold, op = op, na.rm = na.rm, ncores = ncores)$output1 + } else if (any(time_dim %in% names(dim(threshold)))) { + total <- Apply(list(data, threshold), + target_dims = list(time_dim, + time_dim[time_dim %in% names(dim(threshold))]), + fun = .sumexceedthreshold, op = op, na.rm = na.rm, + ncores = ncores)$output1 } else { total <- Apply(list(data, threshold), target_dims = list(time_dim, NULL), diff --git a/R/PeriodMean.R b/R/PeriodMean.R index fa1b4783131560e9de5b5ba7cd5a731a3bf68f2a..c63c5f05dfc19d323c15abad431fffe192670dce 100644 --- a/R/PeriodMean.R +++ b/R/PeriodMean.R @@ -21,17 +21,6 @@ #'exp <- CSTools::lonlat_data$exp #'SA <- CST_PeriodMean(exp) #' -#'exp$data <- array(rnorm(5 * 3 * 214 * 2), -#' c(memb = 5, sdate = 3, ftime = 214, lon = 2)) -#'exp$Dates[[1]] <- c(seq(as.Date("01-04-2000", format = "%d-%m-%Y"), -#' as.Date("31-10-2000", format = "%d-%m-%Y"), by = 'day'), -#' seq(as.Date("01-04-2001", format = "%d-%m-%Y"), -#' as.Date("31-10-2001", format = "%d-%m-%Y"), by = 'day'), -#' seq(as.Date("01-04-2002", format = "%d-%m-%Y"), -#' as.Date("31-10-2002", format = "%d-%m-%Y"), by = 'day')) -#'SprTX <- CST_PeriodMean(exp, start = list(1, 4), end = list(31, 5)) -#'dim(SprTX$data) -#'head(SprTX$Dates) #'@export CST_PeriodMean <- function(data, start = NULL, end = NULL, time_dim = 'ftime', na.rm = FALSE, @@ -89,17 +78,6 @@ CST_PeriodMean <- function(data, start = NULL, end = NULL, #'@examples #'exp <- CSTools::lonlat_prec$data #'SA <- PeriodMean(exp, time_dim = 'ftime') -#' -#'data <- array(rnorm(5 * 3 * 214 * 2), -#' c(memb = 5, sdate = 3, time = 214, lon = 2)) -#'Dates <- c(seq(as.Date("01-04-2000", format = "%d-%m-%Y"), -#' as.Date("31-10-2000", format = "%d-%m-%Y"), by = 'day'), -#' seq(as.Date("01-04-2001", format = "%d-%m-%Y"), -#' as.Date("31-10-2001", format = "%d-%m-%Y"), by = 'day'), -#' seq(as.Date("01-04-2002", format = "%d-%m-%Y"), -#' as.Date("31-10-2002", format = "%d-%m-%Y"), by = 'day')) -#'dim(Dates) <- c(time = 214, sdate = 3) -#'SprTX <- PeriodMean(data, Dates, start = list(1, 4), end = list(31, 5)) #'@export PeriodMean <- function(data, dates = NULL, start = NULL, end = NULL, time_dim = 'time', na.rm = FALSE, ncores = NULL) { diff --git a/R/QThreshold.R b/R/QThreshold.R index 366cec2f305c5cea402986d246939970505708be..9549b93611f2da690d8c35a214337ad2960bb036 100644 --- a/R/QThreshold.R +++ b/R/QThreshold.R @@ -104,15 +104,9 @@ CST_QThreshold <- function(data, threshold, start = NULL, end = NULL, #'@importFrom ClimProjDiags Subset #'@examples #'threshold = 25 -#'data <- array(rnorm(25 * 3 * 214 * 2, mean = 26), -#' c(member = 25, sdate = 3, time = 214, lon = 2)) +#'data <- array(rnorm(25 * 3 * 20 * 2, mean = 26), +#' c(member = 25, sdate = 3, time = 20, lon = 2)) #'thres_q <- QThreshold(data, threshold) -#'data <- array(rnorm(1 * 3 * 214 * 2), c(member = 1, sdate = 3, time = 214, lon = 2)) -#'threshold <- array(1:428, c(time = 214, lon = 2)) -#'res <- QThreshold(data, threshold) -#'threshold <- array(1:50, c(member = 25, lon = 2)) -#'# it can work using the version for separated members. -#'threshold <- array(1:75, c(member = 25, sdate = 3)) #'@export QThreshold <- function(data, threshold, dates = NULL, start = NULL, end = NULL, time_dim = 'time', memb_dim = 'member', sdate_dim = 'sdate', diff --git a/R/TotalSpellTimeExceedingThreshold.R b/R/TotalSpellTimeExceedingThreshold.R index 5997a96bc48f7c1f4a73c22e1ed07a2a14dc2c45..0ecbe9ef97ea4fe6ed57f7c1f08f330a8f42c31a 100644 --- a/R/TotalSpellTimeExceedingThreshold.R +++ b/R/TotalSpellTimeExceedingThreshold.R @@ -21,20 +21,9 @@ #'@import multiApply #'@examples #'exp <- CSTools::lonlat_data$exp -#'TTSET <- CST_TotalSpellTimeExceedingThreshold(exp, threshold = 283, spell = 3) -#'exp$data <- array(rnorm(5 * 3 * 214 * 2, mean = 25, sd = 3), -#' c(member = 5, sdate = 3, ftime = 214, lon = 2)) -#'exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", format = "%d-%m-%Y"), -#' as.Date("30-11-2000", format = "%d-%m-%Y"), by = 'day'), -#' seq(as.Date("01-05-2001", format = "%d-%m-%Y"), -#' as.Date("30-11-2001", format = "%d-%m-%Y"), by = 'day'), -#' seq(as.Date("01-05-2002", format = "%d-%m-%Y"), -#' as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day')) -#'# compare with the scalar fixed threshold -#'WSDI <- CST_TotalSpellTimeExceedingThreshold(exp, threshold = 35, spell = 6) -#'# compare with percentile -#'thresholdP <- CST_Threshold(exp, threshold = 0.9) -#'WSDI_P <- CST_TotalSpellTimeExceedingThreshold(exp, threshold = thresholdP, spell = 6) +#'exp$data <- array(rnorm(5 * 3 * 20 * 2, mean = 25, sd = 3), +#' c(member = 5, sdate = 3, ftime = 20, lon = 2)) +#'TTSET <- CST_TotalSpellTimeExceedingThreshold(exp, threshold = 23, spell = 3) #'@export CST_TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '>', start = NULL, end = NULL, @@ -101,9 +90,6 @@ CST_TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '> #'data <- array(rnorm(120), c(member = 1, sdate = 2, time = 20, lat = 4)) #'threshold <- array(rnorm(4), c(lat = 4)) #'total <- TotalSpellTimeExceedingThreshold(data, threshold, spell = 6) -#'# compare with percentile -#'thresholdP <- Threshold(data, threshold = 0.9) -#'total_P <- TotalSpellTimeExceedingThreshold(data, threshold = thresholdP, spell = 6) #'@export TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '>', dates = NULL, start = NULL, end = NULL, time_dim = 'time', @@ -148,8 +134,10 @@ TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '>', d fun = .totalspellthres, threshold = threshold, spell = spell, op = op, ncores = ncores)$output1 - } else if (time_dim %in% names(dim(threshold))) { - total <- Apply(list(data, threshold), target_dims = list(time_dim, time_dim), + } else if (any(time_dim %in% names(dim(threshold)))) { + total <- Apply(list(data, threshold), + target_dims = list(time_dim, + time_dim[time_dim %in% names(dim(threshold))]), fun = .totalspellthres, spell = spell, op = op, ncores = ncores)$output1 diff --git a/R/TotalTimeExceedingThreshold.R b/R/TotalTimeExceedingThreshold.R index 4c64dbd559f6557d4e846b9c21f2fa5747d91f87..84d829c5e67eef14c76d6a02669e46293a1600b5 100644 --- a/R/TotalTimeExceedingThreshold.R +++ b/R/TotalTimeExceedingThreshold.R @@ -27,38 +27,8 @@ #'@import multiApply #'@examples #'exp <- CSTools::lonlat_data$exp +#'exp$data <- CSTools::lonlat_data$exp$data[1, 5, 3, 3, 1, 1] #'DOT <- CST_TotalTimeExceedingThreshold(exp, threshold = 280) -#'exp$data <- array(rnorm(5 * 3 * 214 * 2, mean = 25, sd = 3), -#' c(memb = 5, sdate = 3, ftime = 214, lon = 2)) -#'exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", format = "%d-%m-%Y"), -#' as.Date("30-11-2000", format = "%d-%m-%Y"), by = 'day'), -#' seq(as.Date("01-05-2001", format = "%d-%m-%Y"), -#' as.Date("30-11-2001", format = "%d-%m-%Y"), by = 'day'), -#' seq(as.Date("01-05-2002", format = "%d-%m-%Y"), -#' as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day')) -#'SU35 <- CST_TotalTimeExceedingThreshold(exp, threshold = 35) -#' -#'# For the case of comparing percentiles -#'exp$data <- array(rnorm(5 * 3 * 214 * 2, mean = 28, sd = 10), -#' c(member = 5, sdate = 3, ftime = 214, lon = 2)) -#'exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", format = "%d-%m-%Y"), -#' as.Date("30-11-2000", format = "%d-%m-%Y"), by = 'day'), -#' seq(as.Date("01-05-2001", format = "%d-%m-%Y"), -#' as.Date("30-11-2001", format = "%d-%m-%Y"), by = 'day'), -#' seq(as.Date("01-05-2002", format = "%d-%m-%Y"), -#' as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day')) -#'obs <- exp -#'obs$data <- array(rnorm(3 * 214 * 2, mean = 27, sd = 9), -#' c(sdate = 3, time = 214, lon = 2)) -#'# convert foreasts to probability -#'exp_percentile <- CST_AbsToProbs(exp) -#'# convert the fixed threshold to percentile with given observations -#'obs_percentile <- CST_QThreshold(obs, threshold = 35) -#' -#' # compare percentiles between forecasts and observations -#'SU35_percentile <- CST_TotalTimeExceedingThreshold(exp, -#' threshold = obs_percentile) -#' #'@export CST_TotalTimeExceedingThreshold <- function(data, threshold, op = '>', start = NULL, end = NULL, @@ -127,29 +97,8 @@ CST_TotalTimeExceedingThreshold <- function(data, threshold, op = '>', #' #'@import multiApply #'@examples -#'exp <- CSTools::lonlat_data$exp$data -#'DOT <- TotalTimeExceedingThreshold(exp, threshold = 280, time_dim = 'ftime') -#'data <- array(rnorm(5 * 3 * 214 * 2, mean = 25, sd = 3), -#' c(memb = 5, sdate = 3, time = 214, lon = 2)) -#'Dates <- c(seq(as.Date("01-05-2000", format = "%d-%m-%Y"), -#' as.Date("30-11-2000", format = "%d-%m-%Y"), by = 'day'), -#' seq(as.Date("01-05-2001", format = "%d-%m-%Y"), -#' as.Date("30-11-2001", format = "%d-%m-%Y"), by = 'day'), -#' seq(as.Date("01-05-2002", format = "%d-%m-%Y"), -#' as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day')) -#'SU35 <- TotalTimeExceedingThreshold(data, threshold = 35) -#' -#'# For the case of comparing between percentiles -#'exp <- array(rnorm(5 * 3 * 214 * 2, mean = 28, sd = 10), -#' c(member = 5, sdate = 3, time = 214, lon = 2)) -#'obs <- array(rnorm(3 * 214 * 2, mean = 27, sd = 9), -#' c(sdate = 3, time = 214, lon = 2)) -#'exp_percentile <- AbsToProbs(exp) # convert foreasts to probability -#'# convert the fixed threshold to percentile with given observations: -#'obs_percentile <- QThreshold(obs, threshold = 35) -#'# compare percentiles between forecasts and observations: -#'SU35_percentile <- TotalTimeExceedingThreshold(aperm(exp_percentile, c(2,1,3,4)), -#' obs_percentile) +#'exp <- CSTools::lonlat_data$exp$data[1, 5, 3, 3, 1, 1] +#'DOT <- TotalTimeExceedingThreshold(exp, threshold = 300, time_dim = 'ftime') #' #'@export TotalTimeExceedingThreshold <- function(data, threshold, op = '>', @@ -212,11 +161,17 @@ TotalTimeExceedingThreshold <- function(data, threshold, op = '>', fun = .exceedthreshold, y = threshold, op = op, na.rm = na.rm, ncores = ncores)$output1 - } else if (time_dim %in% names(dim(threshold))) { + } else if (all(time_dim %in% names(dim(threshold)))) { total <- Apply(list(data, threshold), target_dims = list(time_dim, time_dim), fun = .exceedthreshold, op = op, na.rm = na.rm, ncores = ncores)$output1 + } else if (any(time_dim %in% names(dim(threshold)))) { + total <- Apply(list(data, threshold), + target_dims = list(time_dim, + time_dim[time_dim %in% names(dim(threshold))]), + fun = .exceedthreshold, op = op, na.rm = na.rm, + ncores = ncores)$output1 } else { total <- Apply(list(data, threshold), target_dims = list(time_dim, NULL), diff --git a/man/AbsToProbs.Rd b/man/AbsToProbs.Rd index 7b56a7855d3488714a636acd9c749b77688f8537..bb4dc50de9240f0c7bdfb8244dd11495fad6d3e0 100644 --- a/man/AbsToProbs.Rd +++ b/man/AbsToProbs.Rd @@ -41,13 +41,15 @@ The Cumulative Distribution Function of a forecast is used to obtain the probabi \examples{ exp <- CSTools::lonlat_prec$data exp_probs <- AbsToProbs(exp) -data <- array(rnorm(5 * 3 * 214 * 2), +\dontrun{ +data <- array(rnorm(5 * 2 * 61 * 2), c(member = 5, sdate = 3, ftime = 214, lon = 2)) Dates <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), - as.Date("30-11-2000", format = "\%d-\%m-\%Y"), by = 'day'), + as.Date("30-06-2000", format = "\%d-\%m-\%Y"), by = 'day'), seq(as.Date("01-05-2001", format = "\%d-\%m-\%Y"), - as.Date("30-11-2001", format = "\%d-\%m-\%Y"), by = 'day'), + as.Date("30-06-2001", format = "\%d-\%m-\%Y"), by = 'day'), seq(as.Date("01-05-2002", format = "\%d-\%m-\%Y"), - as.Date("30-11-2002", format = "\%d-\%m-\%Y"), by = 'day')) + as.Date("30-06-2002", format = "\%d-\%m-\%Y"), by = 'day')) exp_probs <- AbsToProbs(exp, start = list(21, 4), end = list(21, 6)) } +} diff --git a/man/AccumulationExceedingThreshold.Rd b/man/AccumulationExceedingThreshold.Rd index 25987809784fee76f624a20884aec708de17eadc..0dd414f7a476a9767de2c8b76da61d1c3d5e147e 100644 --- a/man/AccumulationExceedingThreshold.Rd +++ b/man/AccumulationExceedingThreshold.Rd @@ -50,8 +50,6 @@ Providing mean daily temperature data, the following agriculture indices for hea \item\code{GDD}{Summation of daily differences between daily average temperatures and 10°C between April 1st and October 31st}} } \examples{ -exp <- CSTools::lonlat_data$exp$data -AET <- AccumulationExceedingThreshold(exp, threshold = 280, time_dim = 'ftime') # Assuming data is already (tasmax + tasmin)/2 - 10 data <- array(rnorm(5 * 3 * 214 * 2, mean = 25, sd = 3), c(memb = 5, sdate = 3, time = 214, lon = 2)) @@ -61,5 +59,6 @@ Dates <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), as.Date("30-11-2001", format = "\%d-\%m-\%Y"), by = 'day'), seq(as.Date("01-05-2002", format = "\%d-\%m-\%Y"), as.Date("30-11-2002", format = "\%d-\%m-\%Y"), by = 'day')) -GDD <- AccumulationExceedingThreshold(data, threshold = 0, start = list(1, 4), end = list(31, 10)) +GDD <- AccumulationExceedingThreshold(data, threshold = 0, start = list(1, 4), + end = list(31, 10)) } diff --git a/man/CST_AccumulationExceedingThreshold.Rd b/man/CST_AccumulationExceedingThreshold.Rd index 7aa58e060172ceab4a1f03585226c99e9694672f..4fbcebc97ef68a855a66971c331ce974b9072d45 100644 --- a/man/CST_AccumulationExceedingThreshold.Rd +++ b/man/CST_AccumulationExceedingThreshold.Rd @@ -48,17 +48,6 @@ Providing mean daily temperature data, the following agriculture indices for hea } \examples{ exp <- CSTools::lonlat_data$exp +exp$data <- CSTools::lonlat_data$exp$data[1, 5, 3, 3, 1, 1] DOT <- CST_AccumulationExceedingThreshold(exp, threshold = 280) -# Assuming exp$data is already (tasmax + tasmin)/2 - 10 -exp$data <- array(rnorm(5 * 3 * 214 * 2, mean = 25, sd = 3), - c(memb = 5, sdate = 3, ftime = 214, lon = 2)) -exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), - as.Date("30-11-2000", format = "\%d-\%m-\%Y"), by = 'day'), - seq(as.Date("01-05-2001", format = "\%d-\%m-\%Y"), - as.Date("30-11-2001", format = "\%d-\%m-\%Y"), by = 'day'), - seq(as.Date("01-05-2002", format = "\%d-\%m-\%Y"), - as.Date("30-11-2002", format = "\%d-\%m-\%Y"), by = 'day')) -GDD <- CST_AccumulationExceedingThreshold(exp, threshold = 0, - start = list(1, 4), end = list(31, 10)) - } diff --git a/man/CST_PeriodMean.Rd b/man/CST_PeriodMean.Rd index bbc1fe350f14d11ae56bc1af07431feb8dbba825..95b4a36560f33c5975460872cb09f4d55145371a 100644 --- a/man/CST_PeriodMean.Rd +++ b/man/CST_PeriodMean.Rd @@ -40,15 +40,4 @@ Providing temperature data, two agriculture indices can be obtain by using this exp <- CSTools::lonlat_data$exp SA <- CST_PeriodMean(exp) -exp$data <- array(rnorm(5 * 3 * 214 * 2), - c(memb = 5, sdate = 3, ftime = 214, lon = 2)) -exp$Dates[[1]] <- c(seq(as.Date("01-04-2000", format = "\%d-\%m-\%Y"), - as.Date("31-10-2000", format = "\%d-\%m-\%Y"), by = 'day'), - seq(as.Date("01-04-2001", format = "\%d-\%m-\%Y"), - as.Date("31-10-2001", format = "\%d-\%m-\%Y"), by = 'day'), - seq(as.Date("01-04-2002", format = "\%d-\%m-\%Y"), - as.Date("31-10-2002", format = "\%d-\%m-\%Y"), by = 'day')) -SprTX <- CST_PeriodMean(exp, start = list(1, 4), end = list(31, 5)) -dim(SprTX$data) -head(SprTX$Dates) } diff --git a/man/CST_TotalSpellTimeExceedingThreshold.Rd b/man/CST_TotalSpellTimeExceedingThreshold.Rd index 0038d367b280726c75a32adf546902de09e98ec1..8e65e5827b9e6998ddabefa54420883ffa65dea6 100644 --- a/man/CST_TotalSpellTimeExceedingThreshold.Rd +++ b/man/CST_TotalSpellTimeExceedingThreshold.Rd @@ -44,20 +44,9 @@ This function requires the data and the threshold to be in the same units. The 9 } \examples{ exp <- CSTools::lonlat_data$exp -TTSET <- CST_TotalSpellTimeExceedingThreshold(exp, threshold = 283, spell = 3) -exp$data <- array(rnorm(5 * 3 * 214 * 2, mean = 25, sd = 3), - c(member = 5, sdate = 3, ftime = 214, lon = 2)) -exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), - as.Date("30-11-2000", format = "\%d-\%m-\%Y"), by = 'day'), - seq(as.Date("01-05-2001", format = "\%d-\%m-\%Y"), - as.Date("30-11-2001", format = "\%d-\%m-\%Y"), by = 'day'), - seq(as.Date("01-05-2002", format = "\%d-\%m-\%Y"), - as.Date("30-11-2002", format = "\%d-\%m-\%Y"), by = 'day')) -# compare with the scalar fixed threshold -WSDI <- CST_TotalSpellTimeExceedingThreshold(exp, threshold = 35, spell = 6) -# compare with percentile -thresholdP <- CST_Threshold(exp, threshold = 0.9) -WSDI_P <- CST_TotalSpellTimeExceedingThreshold(exp, threshold = thresholdP, spell = 6) +exp$data <- array(rnorm(5 * 3 * 20 * 2, mean = 25, sd = 3), + c(member = 5, sdate = 3, ftime = 20, lon = 2)) +TTSET <- CST_TotalSpellTimeExceedingThreshold(exp, threshold = 23, spell = 3) } \seealso{ [Threshold()] and [AbsToProbs()]. diff --git a/man/CST_TotalTimeExceedingThreshold.Rd b/man/CST_TotalTimeExceedingThreshold.Rd index 1f4ae842512353e132cbe9f75622676e212e50ff..50124fe72818e7b3c0bf9f5abeca496e4a94ef57 100644 --- a/man/CST_TotalTimeExceedingThreshold.Rd +++ b/man/CST_TotalTimeExceedingThreshold.Rd @@ -51,36 +51,6 @@ Providing maximum temperature daily data, the following agriculture indices for } \examples{ exp <- CSTools::lonlat_data$exp +exp$data <- CSTools::lonlat_data$exp$data[1, 5, 3, 3, 1, 1] DOT <- CST_TotalTimeExceedingThreshold(exp, threshold = 280) -exp$data <- array(rnorm(5 * 3 * 214 * 2, mean = 25, sd = 3), - c(memb = 5, sdate = 3, ftime = 214, lon = 2)) -exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), - as.Date("30-11-2000", format = "\%d-\%m-\%Y"), by = 'day'), - seq(as.Date("01-05-2001", format = "\%d-\%m-\%Y"), - as.Date("30-11-2001", format = "\%d-\%m-\%Y"), by = 'day'), - seq(as.Date("01-05-2002", format = "\%d-\%m-\%Y"), - as.Date("30-11-2002", format = "\%d-\%m-\%Y"), by = 'day')) -SU35 <- CST_TotalTimeExceedingThreshold(exp, threshold = 35) - -# For the case of comparing percentiles -exp$data <- array(rnorm(5 * 3 * 214 * 2, mean = 28, sd = 10), - c(member = 5, sdate = 3, ftime = 214, lon = 2)) -exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), - as.Date("30-11-2000", format = "\%d-\%m-\%Y"), by = 'day'), - seq(as.Date("01-05-2001", format = "\%d-\%m-\%Y"), - as.Date("30-11-2001", format = "\%d-\%m-\%Y"), by = 'day'), - seq(as.Date("01-05-2002", format = "\%d-\%m-\%Y"), - as.Date("30-11-2002", format = "\%d-\%m-\%Y"), by = 'day')) -obs <- exp -obs$data <- array(rnorm(3 * 214 * 2, mean = 27, sd = 9), - c(sdate = 3, time = 214, lon = 2)) -# convert foreasts to probability -exp_percentile <- CST_AbsToProbs(exp) -# convert the fixed threshold to percentile with given observations -obs_percentile <- CST_QThreshold(obs, threshold = 35) - -# compare percentiles between forecasts and observations -SU35_percentile <- CST_TotalTimeExceedingThreshold(exp, - threshold = obs_percentile) - } diff --git a/man/PeriodMean.Rd b/man/PeriodMean.Rd index b0fd0c3bc3bd7930b3e53016761a9c2cab3f04b9..6062daa437dadd3ec1c5cfbc748bb7f53c2853ae 100644 --- a/man/PeriodMean.Rd +++ b/man/PeriodMean.Rd @@ -42,15 +42,4 @@ Providing temperature data, two agriculture indices can be obtain by using this \examples{ exp <- CSTools::lonlat_prec$data SA <- PeriodMean(exp, time_dim = 'ftime') - -data <- array(rnorm(5 * 3 * 214 * 2), - c(memb = 5, sdate = 3, time = 214, lon = 2)) -Dates <- c(seq(as.Date("01-04-2000", format = "\%d-\%m-\%Y"), - as.Date("31-10-2000", format = "\%d-\%m-\%Y"), by = 'day'), - seq(as.Date("01-04-2001", format = "\%d-\%m-\%Y"), - as.Date("31-10-2001", format = "\%d-\%m-\%Y"), by = 'day'), - seq(as.Date("01-04-2002", format = "\%d-\%m-\%Y"), - as.Date("31-10-2002", format = "\%d-\%m-\%Y"), by = 'day')) -dim(Dates) <- c(time = 214, sdate = 3) -SprTX <- PeriodMean(data, Dates, start = list(1, 4), end = list(31, 5)) } diff --git a/man/QThreshold.Rd b/man/QThreshold.Rd index 257f21eee90ed7103fc8108cc9353d384613819c..8f55badb94c1120165ccda35cb6dbbd10ce17963 100644 --- a/man/QThreshold.Rd +++ b/man/QThreshold.Rd @@ -52,13 +52,7 @@ The sample used will depend on the dimensions of the data provided and the dimen } \examples{ threshold = 25 -data <- array(rnorm(25 * 3 * 214 * 2, mean = 26), - c(member = 25, sdate = 3, time = 214, lon = 2)) +data <- array(rnorm(25 * 3 * 20 * 2, mean = 26), + c(member = 25, sdate = 3, time = 20, lon = 2)) thres_q <- QThreshold(data, threshold) -data <- array(rnorm(1 * 3 * 214 * 2), c(member = 1, sdate = 3, time = 214, lon = 2)) -threshold <- array(1:428, c(time = 214, lon = 2)) -res <- QThreshold(data, threshold) -threshold <- array(1:50, c(member = 25, lon = 2)) -# it can work using the version for separated members. -threshold <- array(1:75, c(member = 25, sdate = 3)) } diff --git a/man/TotalSpellTimeExceedingThreshold.Rd b/man/TotalSpellTimeExceedingThreshold.Rd index 79f3e5d4f16497e59f34deec6d023ad6b99fcb74..bbbfe357c65818e3eff3e50e9ed64609192a50bf 100644 --- a/man/TotalSpellTimeExceedingThreshold.Rd +++ b/man/TotalSpellTimeExceedingThreshold.Rd @@ -52,9 +52,6 @@ This function considers NA values as the end of the spell. For a different behav data <- array(rnorm(120), c(member = 1, sdate = 2, time = 20, lat = 4)) threshold <- array(rnorm(4), c(lat = 4)) total <- TotalSpellTimeExceedingThreshold(data, threshold, spell = 6) -# compare with percentile -thresholdP <- Threshold(data, threshold = 0.9) -total_P <- TotalSpellTimeExceedingThreshold(data, threshold = thresholdP, spell = 6) } \seealso{ [Threshold()] and [AbsToProbs()]. diff --git a/man/TotalTimeExceedingThreshold.Rd b/man/TotalTimeExceedingThreshold.Rd index 213db45b58e83cedbad8bf69418e7b73617bb213..855ef869f4818c6da3e31644c94c36bdc35ed69d 100644 --- a/man/TotalTimeExceedingThreshold.Rd +++ b/man/TotalTimeExceedingThreshold.Rd @@ -53,28 +53,7 @@ Providing maximum temperature daily data, the following agriculture indices for } } \examples{ -exp <- CSTools::lonlat_data$exp$data -DOT <- TotalTimeExceedingThreshold(exp, threshold = 280, time_dim = 'ftime') -data <- array(rnorm(5 * 3 * 214 * 2, mean = 25, sd = 3), - c(memb = 5, sdate = 3, time = 214, lon = 2)) -Dates <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), - as.Date("30-11-2000", format = "\%d-\%m-\%Y"), by = 'day'), - seq(as.Date("01-05-2001", format = "\%d-\%m-\%Y"), - as.Date("30-11-2001", format = "\%d-\%m-\%Y"), by = 'day'), - seq(as.Date("01-05-2002", format = "\%d-\%m-\%Y"), - as.Date("30-11-2002", format = "\%d-\%m-\%Y"), by = 'day')) -SU35 <- TotalTimeExceedingThreshold(data, threshold = 35) - -# For the case of comparing between percentiles -exp <- array(rnorm(5 * 3 * 214 * 2, mean = 28, sd = 10), - c(member = 5, sdate = 3, time = 214, lon = 2)) -obs <- array(rnorm(3 * 214 * 2, mean = 27, sd = 9), - c(sdate = 3, time = 214, lon = 2)) -exp_percentile <- AbsToProbs(exp) # convert foreasts to probability -# convert the fixed threshold to percentile with given observations: -obs_percentile <- QThreshold(obs, threshold = 35) -# compare percentiles between forecasts and observations: -SU35_percentile <- TotalTimeExceedingThreshold(aperm(exp_percentile, c(2,1,3,4)), - obs_percentile) +exp <- CSTools::lonlat_data$exp$data[1, 5, 3, 3, 1, 1] +DOT <- TotalTimeExceedingThreshold(exp, threshold = 300, time_dim = 'ftime') } diff --git a/vignettes/EnergyIndicators.Rmd b/vignettes/EnergyIndicators.Rmd index 3b3d90cfa9f7e61b6cec7e1d27e347530e8f83c6..1399044f2bde3617c56bfeaa56d874fd9a0ad487 100644 --- a/vignettes/EnergyIndicators.Rmd +++ b/vignettes/EnergyIndicators.Rmd @@ -32,6 +32,7 @@ The `mean` and `sd` of the WPD can be employed to summarize the wind resource in ```{r} library(CSIndicators) +set.seed(1) wind <- rweibull(n = 1000, shape = 2, scale = 6) WPD <- WindPowerDensity(wind) mean(WPD)