From 6a835bd448c38bef22d217fee86919479c1c8185 Mon Sep 17 00:00:00 2001 From: nperez Date: Fri, 30 Apr 2021 10:39:49 +0200 Subject: [PATCH 1/4] Fixes required from Win-builder --- DESCRIPTION | 3 +-- R/AccumulationExceedingThreshold.R | 20 +++++++--------- R/QThreshold.R | 3 --- R/TotalSpellTimeExceedingThreshold.R | 8 +++---- R/TotalTimeExceedingThreshold.R | 26 ++++++--------------- man/AccumulationExceedingThreshold.Rd | 2 -- man/CST_AccumulationExceedingThreshold.Rd | 4 ++-- man/CST_TotalSpellTimeExceedingThreshold.Rd | 2 -- man/CST_TotalTimeExceedingThreshold.Rd | 9 ------- man/QThreshold.Rd | 3 --- man/TotalTimeExceedingThreshold.Rd | 9 ------- 11 files changed, 22 insertions(+), 67 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index dfea00e..57b1ab7 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/AccumulationExceedingThreshold.R b/R/AccumulationExceedingThreshold.R index 4d3e50e..40a7403 100644 --- a/R/AccumulationExceedingThreshold.R +++ b/R/AccumulationExceedingThreshold.R @@ -24,8 +24,8 @@ #'exp <- CSTools::lonlat_data$exp #'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$data <- array(rnorm(2 * 3 * 214 * 2, mean = 25, sd = 3), +#' c(memb = 2, 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"), @@ -99,8 +99,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)) @@ -145,14 +143,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 +176,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/QThreshold.R b/R/QThreshold.R index 366cec2..b3e3700 100644 --- a/R/QThreshold.R +++ b/R/QThreshold.R @@ -110,9 +110,6 @@ CST_QThreshold <- function(data, threshold, start = NULL, end = NULL, #'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 5997a96..fab7878 100644 --- a/R/TotalSpellTimeExceedingThreshold.R +++ b/R/TotalSpellTimeExceedingThreshold.R @@ -30,8 +30,6 @@ #' 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) @@ -148,8 +146,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 4c64dbd..7e99c71 100644 --- a/R/TotalTimeExceedingThreshold.R +++ b/R/TotalTimeExceedingThreshold.R @@ -28,15 +28,6 @@ #'@examples #'exp <- CSTools::lonlat_data$exp #'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), @@ -129,15 +120,6 @@ CST_TotalTimeExceedingThreshold <- function(data, threshold, op = '>', #'@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), @@ -212,11 +194,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/AccumulationExceedingThreshold.Rd b/man/AccumulationExceedingThreshold.Rd index 2598780..c5b3a3c 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)) diff --git a/man/CST_AccumulationExceedingThreshold.Rd b/man/CST_AccumulationExceedingThreshold.Rd index 7aa58e0..82e09b6 100644 --- a/man/CST_AccumulationExceedingThreshold.Rd +++ b/man/CST_AccumulationExceedingThreshold.Rd @@ -50,8 +50,8 @@ Providing mean daily temperature data, the following agriculture indices for hea exp <- CSTools::lonlat_data$exp 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$data <- array(rnorm(2 * 3 * 214 * 2, mean = 25, sd = 3), + c(memb = 2, 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"), diff --git a/man/CST_TotalSpellTimeExceedingThreshold.Rd b/man/CST_TotalSpellTimeExceedingThreshold.Rd index 0038d36..503f7fb 100644 --- a/man/CST_TotalSpellTimeExceedingThreshold.Rd +++ b/man/CST_TotalSpellTimeExceedingThreshold.Rd @@ -53,8 +53,6 @@ exp$Dates[[1]] <- 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')) -# 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) diff --git a/man/CST_TotalTimeExceedingThreshold.Rd b/man/CST_TotalTimeExceedingThreshold.Rd index 1f4ae84..2ee7573 100644 --- a/man/CST_TotalTimeExceedingThreshold.Rd +++ b/man/CST_TotalTimeExceedingThreshold.Rd @@ -52,15 +52,6 @@ Providing maximum temperature daily data, the following agriculture indices for \examples{ exp <- CSTools::lonlat_data$exp 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), diff --git a/man/QThreshold.Rd b/man/QThreshold.Rd index 257f21e..e779dc3 100644 --- a/man/QThreshold.Rd +++ b/man/QThreshold.Rd @@ -58,7 +58,4 @@ 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/TotalTimeExceedingThreshold.Rd b/man/TotalTimeExceedingThreshold.Rd index 213db45..998c771 100644 --- a/man/TotalTimeExceedingThreshold.Rd +++ b/man/TotalTimeExceedingThreshold.Rd @@ -55,15 +55,6 @@ 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), -- GitLab From dbd8927dbf9a021f43ab8797c0110f4914522dd3 Mon Sep 17 00:00:00 2001 From: nperez Date: Fri, 30 Apr 2021 11:54:20 +0200 Subject: [PATCH 2/4] donttest added --- R/AccumulationExceedingThreshold.R | 3 ++- R/QThreshold.R | 2 ++ R/TotalSpellTimeExceedingThreshold.R | 2 ++ R/TotalTimeExceedingThreshold.R | 7 ++++--- man/CST_AccumulationExceedingThreshold.Rd | 3 ++- man/CST_TotalSpellTimeExceedingThreshold.Rd | 2 ++ man/CST_TotalTimeExceedingThreshold.Rd | 4 ++-- man/QThreshold.Rd | 2 ++ man/TotalTimeExceedingThreshold.Rd | 3 ++- 9 files changed, 20 insertions(+), 8 deletions(-) diff --git a/R/AccumulationExceedingThreshold.R b/R/AccumulationExceedingThreshold.R index 40a7403..48dea83 100644 --- a/R/AccumulationExceedingThreshold.R +++ b/R/AccumulationExceedingThreshold.R @@ -23,6 +23,7 @@ #'@examples #'exp <- CSTools::lonlat_data$exp #'DOT <- CST_AccumulationExceedingThreshold(exp, threshold = 280) +#'\donttest{ #'# Assuming exp$data is already (tasmax + tasmin)/2 - 10 #'exp$data <- array(rnorm(2 * 3 * 214 * 2, mean = 25, sd = 3), #' c(memb = 2, sdate = 3, ftime = 214, lon = 2)) @@ -34,7 +35,7 @@ #' 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, diff --git a/R/QThreshold.R b/R/QThreshold.R index b3e3700..6c84e3e 100644 --- a/R/QThreshold.R +++ b/R/QThreshold.R @@ -103,6 +103,7 @@ CST_QThreshold <- function(data, threshold, start = NULL, end = NULL, #'@import multiApply #'@importFrom ClimProjDiags Subset #'@examples +#'\donttest{ #'threshold = 25 #'data <- array(rnorm(25 * 3 * 214 * 2, mean = 26), #' c(member = 25, sdate = 3, time = 214, lon = 2)) @@ -110,6 +111,7 @@ CST_QThreshold <- function(data, threshold, start = NULL, end = NULL, #'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) +#'} #'@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 fab7878..f4ec8bf 100644 --- a/R/TotalSpellTimeExceedingThreshold.R +++ b/R/TotalSpellTimeExceedingThreshold.R @@ -22,6 +22,7 @@ #'@examples #'exp <- CSTools::lonlat_data$exp #'TTSET <- CST_TotalSpellTimeExceedingThreshold(exp, threshold = 283, spell = 3) +#'\donttest{ #'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"), @@ -33,6 +34,7 @@ #'# compare with percentile #'thresholdP <- CST_Threshold(exp, threshold = 0.9) #'WSDI_P <- CST_TotalSpellTimeExceedingThreshold(exp, threshold = thresholdP, spell = 6) +#'} #'@export CST_TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '>', start = NULL, end = NULL, diff --git a/R/TotalTimeExceedingThreshold.R b/R/TotalTimeExceedingThreshold.R index 7e99c71..760247a 100644 --- a/R/TotalTimeExceedingThreshold.R +++ b/R/TotalTimeExceedingThreshold.R @@ -28,7 +28,7 @@ #'@examples #'exp <- CSTools::lonlat_data$exp #'DOT <- CST_TotalTimeExceedingThreshold(exp, threshold = 280) -#' +#'\donttest{ #'# 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)) @@ -49,7 +49,7 @@ #' # 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, @@ -121,6 +121,7 @@ CST_TotalTimeExceedingThreshold <- function(data, threshold, op = '>', #'exp <- CSTools::lonlat_data$exp$data #'DOT <- TotalTimeExceedingThreshold(exp, threshold = 280, time_dim = 'ftime') #' +#'\donttest{ #'# 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)) @@ -132,7 +133,7 @@ CST_TotalTimeExceedingThreshold <- function(data, threshold, op = '>', #'# compare percentiles between forecasts and observations: #'SU35_percentile <- TotalTimeExceedingThreshold(aperm(exp_percentile, c(2,1,3,4)), #' obs_percentile) -#' +#'} #'@export TotalTimeExceedingThreshold <- function(data, threshold, op = '>', dates = NULL, start = NULL, end = NULL, diff --git a/man/CST_AccumulationExceedingThreshold.Rd b/man/CST_AccumulationExceedingThreshold.Rd index 82e09b6..5944f06 100644 --- a/man/CST_AccumulationExceedingThreshold.Rd +++ b/man/CST_AccumulationExceedingThreshold.Rd @@ -49,6 +49,7 @@ Providing mean daily temperature data, the following agriculture indices for hea \examples{ exp <- CSTools::lonlat_data$exp DOT <- CST_AccumulationExceedingThreshold(exp, threshold = 280) +\donttest{ # Assuming exp$data is already (tasmax + tasmin)/2 - 10 exp$data <- array(rnorm(2 * 3 * 214 * 2, mean = 25, sd = 3), c(memb = 2, sdate = 3, ftime = 214, lon = 2)) @@ -60,5 +61,5 @@ exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", 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_TotalSpellTimeExceedingThreshold.Rd b/man/CST_TotalSpellTimeExceedingThreshold.Rd index 503f7fb..9c9f8a2 100644 --- a/man/CST_TotalSpellTimeExceedingThreshold.Rd +++ b/man/CST_TotalSpellTimeExceedingThreshold.Rd @@ -45,6 +45,7 @@ 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) +\donttest{ 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"), @@ -57,6 +58,7 @@ exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), thresholdP <- CST_Threshold(exp, threshold = 0.9) WSDI_P <- CST_TotalSpellTimeExceedingThreshold(exp, threshold = thresholdP, spell = 6) } +} \seealso{ [Threshold()] and [AbsToProbs()]. } diff --git a/man/CST_TotalTimeExceedingThreshold.Rd b/man/CST_TotalTimeExceedingThreshold.Rd index 2ee7573..b6e2999 100644 --- a/man/CST_TotalTimeExceedingThreshold.Rd +++ b/man/CST_TotalTimeExceedingThreshold.Rd @@ -52,7 +52,7 @@ Providing maximum temperature daily data, the following agriculture indices for \examples{ exp <- CSTools::lonlat_data$exp DOT <- CST_TotalTimeExceedingThreshold(exp, threshold = 280) - +\donttest{ # 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)) @@ -73,5 +73,5 @@ 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/QThreshold.Rd b/man/QThreshold.Rd index e779dc3..de6c666 100644 --- a/man/QThreshold.Rd +++ b/man/QThreshold.Rd @@ -51,6 +51,7 @@ The sample used will depend on the dimensions of the data provided and the dimen \item{Wheter a reference (observations) doesn't have start date dimension, the sample used must be especified in sdate_dim parameter.}} } \examples{ +\donttest{ threshold = 25 data <- array(rnorm(25 * 3 * 214 * 2, mean = 26), c(member = 25, sdate = 3, time = 214, lon = 2)) @@ -59,3 +60,4 @@ data <- array(rnorm(1 * 3 * 214 * 2), c(member = 1, sdate = 3, time = 214, lon = threshold <- array(1:428, c(time = 214, lon = 2)) res <- QThreshold(data, threshold) } +} diff --git a/man/TotalTimeExceedingThreshold.Rd b/man/TotalTimeExceedingThreshold.Rd index 998c771..5abf814 100644 --- a/man/TotalTimeExceedingThreshold.Rd +++ b/man/TotalTimeExceedingThreshold.Rd @@ -56,6 +56,7 @@ Providing maximum temperature daily data, the following agriculture indices for exp <- CSTools::lonlat_data$exp$data DOT <- TotalTimeExceedingThreshold(exp, threshold = 280, time_dim = 'ftime') +\donttest{ # 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)) @@ -67,5 +68,5 @@ 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) - +} } -- GitLab From 2e146b29705828456fcee124e44fe10b2bac0a20 Mon Sep 17 00:00:00 2001 From: nperez Date: Fri, 30 Apr 2021 17:13:04 +0200 Subject: [PATCH 3/4] Fix seed in vignette and dontrun examples --- R/AbsToProbs.R | 2 ++ R/AccumulationExceedingThreshold.R | 2 +- R/PeriodMean.R | 3 ++- R/QThreshold.R | 2 +- R/TotalSpellTimeExceedingThreshold.R | 2 +- R/TotalTimeExceedingThreshold.R | 4 ++-- man/AbsToProbs.Rd | 2 ++ man/CST_AccumulationExceedingThreshold.Rd | 2 +- man/CST_TotalSpellTimeExceedingThreshold.Rd | 2 +- man/CST_TotalTimeExceedingThreshold.Rd | 2 +- man/PeriodMean.Rd | 3 ++- man/TotalTimeExceedingThreshold.Rd | 2 +- vignettes/EnergyIndicators.Rmd | 1 + 13 files changed, 18 insertions(+), 11 deletions(-) diff --git a/R/AbsToProbs.R b/R/AbsToProbs.R index d2bcfbd..ab31e9e 100644 --- a/R/AbsToProbs.R +++ b/R/AbsToProbs.R @@ -82,6 +82,7 @@ CST_AbsToProbs <- function(data, start = NULL, end = NULL, #'@examples #'exp <- CSTools::lonlat_prec$data #'exp_probs <- AbsToProbs(exp) +#'\dontrun{ #'data <- array(rnorm(5 * 3 * 214 * 2), #' c(member = 5, sdate = 3, ftime = 214, lon = 2)) #'Dates <- c(seq(as.Date("01-05-2000", format = "%d-%m-%Y"), @@ -91,6 +92,7 @@ CST_AbsToProbs <- function(data, start = NULL, end = NULL, #' seq(as.Date("01-05-2002", format = "%d-%m-%Y"), #' as.Date("30-11-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 48dea83..812adee 100644 --- a/R/AccumulationExceedingThreshold.R +++ b/R/AccumulationExceedingThreshold.R @@ -23,7 +23,7 @@ #'@examples #'exp <- CSTools::lonlat_data$exp #'DOT <- CST_AccumulationExceedingThreshold(exp, threshold = 280) -#'\donttest{ +#'\dontrun{ #'# Assuming exp$data is already (tasmax + tasmin)/2 - 10 #'exp$data <- array(rnorm(2 * 3 * 214 * 2, mean = 25, sd = 3), #' c(memb = 2, sdate = 3, ftime = 214, lon = 2)) diff --git a/R/PeriodMean.R b/R/PeriodMean.R index fa1b478..7043846 100644 --- a/R/PeriodMean.R +++ b/R/PeriodMean.R @@ -89,7 +89,7 @@ CST_PeriodMean <- function(data, start = NULL, end = NULL, #'@examples #'exp <- CSTools::lonlat_prec$data #'SA <- PeriodMean(exp, time_dim = 'ftime') -#' +#'\dontrun{ #'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"), @@ -100,6 +100,7 @@ CST_PeriodMean <- function(data, start = NULL, end = NULL, #' 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 6c84e3e..a55ebfe 100644 --- a/R/QThreshold.R +++ b/R/QThreshold.R @@ -103,11 +103,11 @@ CST_QThreshold <- function(data, threshold, start = NULL, end = NULL, #'@import multiApply #'@importFrom ClimProjDiags Subset #'@examples -#'\donttest{ #'threshold = 25 #'data <- array(rnorm(25 * 3 * 214 * 2, mean = 26), #' c(member = 25, sdate = 3, time = 214, lon = 2)) #'thres_q <- QThreshold(data, threshold) +#'\dontrun{ #'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) diff --git a/R/TotalSpellTimeExceedingThreshold.R b/R/TotalSpellTimeExceedingThreshold.R index f4ec8bf..f5a8941 100644 --- a/R/TotalSpellTimeExceedingThreshold.R +++ b/R/TotalSpellTimeExceedingThreshold.R @@ -22,7 +22,7 @@ #'@examples #'exp <- CSTools::lonlat_data$exp #'TTSET <- CST_TotalSpellTimeExceedingThreshold(exp, threshold = 283, spell = 3) -#'\donttest{ +#'\dontrun{ #'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"), diff --git a/R/TotalTimeExceedingThreshold.R b/R/TotalTimeExceedingThreshold.R index 760247a..25116db 100644 --- a/R/TotalTimeExceedingThreshold.R +++ b/R/TotalTimeExceedingThreshold.R @@ -28,7 +28,7 @@ #'@examples #'exp <- CSTools::lonlat_data$exp #'DOT <- CST_TotalTimeExceedingThreshold(exp, threshold = 280) -#'\donttest{ +#'\dontrun{ #'# 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)) @@ -121,7 +121,7 @@ CST_TotalTimeExceedingThreshold <- function(data, threshold, op = '>', #'exp <- CSTools::lonlat_data$exp$data #'DOT <- TotalTimeExceedingThreshold(exp, threshold = 280, time_dim = 'ftime') #' -#'\donttest{ +#'\dontrun{ #'# 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)) diff --git a/man/AbsToProbs.Rd b/man/AbsToProbs.Rd index 7b56a78..39e14f0 100644 --- a/man/AbsToProbs.Rd +++ b/man/AbsToProbs.Rd @@ -41,6 +41,7 @@ The Cumulative Distribution Function of a forecast is used to obtain the probabi \examples{ exp <- CSTools::lonlat_prec$data exp_probs <- AbsToProbs(exp) +\dontrun{ data <- array(rnorm(5 * 3 * 214 * 2), c(member = 5, sdate = 3, ftime = 214, lon = 2)) Dates <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), @@ -51,3 +52,4 @@ Dates <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), as.Date("30-11-2002", format = "\%d-\%m-\%Y"), by = 'day')) exp_probs <- AbsToProbs(exp, start = list(21, 4), end = list(21, 6)) } +} diff --git a/man/CST_AccumulationExceedingThreshold.Rd b/man/CST_AccumulationExceedingThreshold.Rd index 5944f06..e608a3c 100644 --- a/man/CST_AccumulationExceedingThreshold.Rd +++ b/man/CST_AccumulationExceedingThreshold.Rd @@ -49,7 +49,7 @@ Providing mean daily temperature data, the following agriculture indices for hea \examples{ exp <- CSTools::lonlat_data$exp DOT <- CST_AccumulationExceedingThreshold(exp, threshold = 280) -\donttest{ +\dontrun{ # Assuming exp$data is already (tasmax + tasmin)/2 - 10 exp$data <- array(rnorm(2 * 3 * 214 * 2, mean = 25, sd = 3), c(memb = 2, sdate = 3, ftime = 214, lon = 2)) diff --git a/man/CST_TotalSpellTimeExceedingThreshold.Rd b/man/CST_TotalSpellTimeExceedingThreshold.Rd index 9c9f8a2..74cea56 100644 --- a/man/CST_TotalSpellTimeExceedingThreshold.Rd +++ b/man/CST_TotalSpellTimeExceedingThreshold.Rd @@ -45,7 +45,7 @@ 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) -\donttest{ +\dontrun{ 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"), diff --git a/man/CST_TotalTimeExceedingThreshold.Rd b/man/CST_TotalTimeExceedingThreshold.Rd index b6e2999..a0ea0d9 100644 --- a/man/CST_TotalTimeExceedingThreshold.Rd +++ b/man/CST_TotalTimeExceedingThreshold.Rd @@ -52,7 +52,7 @@ Providing maximum temperature daily data, the following agriculture indices for \examples{ exp <- CSTools::lonlat_data$exp DOT <- CST_TotalTimeExceedingThreshold(exp, threshold = 280) -\donttest{ +\dontrun{ # 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)) diff --git a/man/PeriodMean.Rd b/man/PeriodMean.Rd index b0fd0c3..53597b6 100644 --- a/man/PeriodMean.Rd +++ b/man/PeriodMean.Rd @@ -42,7 +42,7 @@ Providing temperature data, two agriculture indices can be obtain by using this \examples{ exp <- CSTools::lonlat_prec$data SA <- PeriodMean(exp, time_dim = 'ftime') - +\dontrun{ 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"), @@ -54,3 +54,4 @@ Dates <- c(seq(as.Date("01-04-2000", format = "\%d-\%m-\%Y"), dim(Dates) <- c(time = 214, sdate = 3) SprTX <- PeriodMean(data, Dates, start = list(1, 4), end = list(31, 5)) } +} diff --git a/man/TotalTimeExceedingThreshold.Rd b/man/TotalTimeExceedingThreshold.Rd index 5abf814..82fb55a 100644 --- a/man/TotalTimeExceedingThreshold.Rd +++ b/man/TotalTimeExceedingThreshold.Rd @@ -56,7 +56,7 @@ Providing maximum temperature daily data, the following agriculture indices for exp <- CSTools::lonlat_data$exp$data DOT <- TotalTimeExceedingThreshold(exp, threshold = 280, time_dim = 'ftime') -\donttest{ +\dontrun{ # 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)) diff --git a/vignettes/EnergyIndicators.Rmd b/vignettes/EnergyIndicators.Rmd index 3b3d90c..1399044 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) -- GitLab From 3d35552fabacee6351e3207b0a89d8899cac2c55 Mon Sep 17 00:00:00 2001 From: nperez Date: Mon, 3 May 2021 18:17:32 +0200 Subject: [PATCH 4/4] Reduce examples size --- .Rbuildignore | 1 + .gitignore | 2 +- R/AbsToProbs.R | 8 ++--- R/AccumulationExceedingThreshold.R | 17 ++------- R/PeriodMean.R | 23 ------------ R/QThreshold.R | 9 ++--- R/TotalSpellTimeExceedingThreshold.R | 20 ++--------- R/TotalTimeExceedingThreshold.R | 40 ++------------------- man/AbsToProbs.Rd | 8 ++--- man/AccumulationExceedingThreshold.Rd | 3 +- man/CST_AccumulationExceedingThreshold.Rd | 14 +------- man/CST_PeriodMean.Rd | 11 ------ man/CST_TotalSpellTimeExceedingThreshold.Rd | 17 ++------- man/CST_TotalTimeExceedingThreshold.Rd | 23 +----------- man/PeriodMean.Rd | 12 ------- man/QThreshold.Rd | 9 ++--- man/TotalSpellTimeExceedingThreshold.Rd | 3 -- man/TotalTimeExceedingThreshold.Rd | 17 ++------- 18 files changed, 32 insertions(+), 205 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index b2d8e5f..5e7002c 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,3 +6,4 @@ .*^(?!data)\.RData$ .*\.gitlab-ci.yml$ #^tests$ +./.nfs* diff --git a/.gitignore b/.gitignore index 35a0917..23a5603 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,4 @@ Rplots.pdf .nfs* *.RData !data/*.RData - +.\.nfs* diff --git a/R/AbsToProbs.R b/R/AbsToProbs.R index ab31e9e..c36640d 100644 --- a/R/AbsToProbs.R +++ b/R/AbsToProbs.R @@ -83,14 +83,14 @@ CST_AbsToProbs <- function(data, start = NULL, end = NULL, #'exp <- CSTools::lonlat_prec$data #'exp_probs <- AbsToProbs(exp) #'\dontrun{ -#'data <- array(rnorm(5 * 3 * 214 * 2), +#'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 diff --git a/R/AccumulationExceedingThreshold.R b/R/AccumulationExceedingThreshold.R index 812adee..e953d32 100644 --- a/R/AccumulationExceedingThreshold.R +++ b/R/AccumulationExceedingThreshold.R @@ -22,20 +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) -#'\dontrun{ -#'# Assuming exp$data is already (tasmax + tasmin)/2 - 10 -#'exp$data <- array(rnorm(2 * 3 * 214 * 2, mean = 25, sd = 3), -#' c(memb = 2, 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, @@ -109,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, diff --git a/R/PeriodMean.R b/R/PeriodMean.R index 7043846..c63c5f0 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,18 +78,6 @@ CST_PeriodMean <- function(data, start = NULL, end = NULL, #'@examples #'exp <- CSTools::lonlat_prec$data #'SA <- PeriodMean(exp, time_dim = 'ftime') -#'\dontrun{ -#'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 a55ebfe..9549b93 100644 --- a/R/QThreshold.R +++ b/R/QThreshold.R @@ -104,14 +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) -#'\dontrun{ -#'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) -#'} #'@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 f5a8941..0ecbe9e 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) -#'\dontrun{ -#'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 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', diff --git a/R/TotalTimeExceedingThreshold.R b/R/TotalTimeExceedingThreshold.R index 25116db..84d829c 100644 --- a/R/TotalTimeExceedingThreshold.R +++ b/R/TotalTimeExceedingThreshold.R @@ -27,29 +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) -#'\dontrun{ -#'# 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, @@ -118,22 +97,9 @@ CST_TotalTimeExceedingThreshold <- function(data, threshold, op = '>', #' #'@import multiApply #'@examples -#'exp <- CSTools::lonlat_data$exp$data -#'DOT <- TotalTimeExceedingThreshold(exp, threshold = 280, time_dim = 'ftime') +#'exp <- CSTools::lonlat_data$exp$data[1, 5, 3, 3, 1, 1] +#'DOT <- TotalTimeExceedingThreshold(exp, threshold = 300, time_dim = 'ftime') #' -#'\dontrun{ -#'# 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) -#'} #'@export TotalTimeExceedingThreshold <- function(data, threshold, op = '>', dates = NULL, start = NULL, end = NULL, diff --git a/man/AbsToProbs.Rd b/man/AbsToProbs.Rd index 39e14f0..bb4dc50 100644 --- a/man/AbsToProbs.Rd +++ b/man/AbsToProbs.Rd @@ -42,14 +42,14 @@ The Cumulative Distribution Function of a forecast is used to obtain the probabi exp <- CSTools::lonlat_prec$data exp_probs <- AbsToProbs(exp) \dontrun{ -data <- array(rnorm(5 * 3 * 214 * 2), +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 c5b3a3c..0dd414f 100644 --- a/man/AccumulationExceedingThreshold.Rd +++ b/man/AccumulationExceedingThreshold.Rd @@ -59,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 e608a3c..4fbcebc 100644 --- a/man/CST_AccumulationExceedingThreshold.Rd +++ b/man/CST_AccumulationExceedingThreshold.Rd @@ -48,18 +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) -\dontrun{ -# Assuming exp$data is already (tasmax + tasmin)/2 - 10 -exp$data <- array(rnorm(2 * 3 * 214 * 2, mean = 25, sd = 3), - c(memb = 2, 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 bbc1fe3..95b4a36 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 74cea56..8e65e58 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) -\dontrun{ -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 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 a0ea0d9..50124fe 100644 --- a/man/CST_TotalTimeExceedingThreshold.Rd +++ b/man/CST_TotalTimeExceedingThreshold.Rd @@ -51,27 +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) -\dontrun{ -# 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 53597b6..6062daa 100644 --- a/man/PeriodMean.Rd +++ b/man/PeriodMean.Rd @@ -42,16 +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') -\dontrun{ -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 de6c666..8f55bad 100644 --- a/man/QThreshold.Rd +++ b/man/QThreshold.Rd @@ -51,13 +51,8 @@ The sample used will depend on the dimensions of the data provided and the dimen \item{Wheter a reference (observations) doesn't have start date dimension, the sample used must be especified in sdate_dim parameter.}} } \examples{ -\donttest{ 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) -} } diff --git a/man/TotalSpellTimeExceedingThreshold.Rd b/man/TotalSpellTimeExceedingThreshold.Rd index 79f3e5d..bbbfe35 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 82fb55a..855ef86 100644 --- a/man/TotalTimeExceedingThreshold.Rd +++ b/man/TotalTimeExceedingThreshold.Rd @@ -53,20 +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') +exp <- CSTools::lonlat_data$exp$data[1, 5, 3, 3, 1, 1] +DOT <- TotalTimeExceedingThreshold(exp, threshold = 300, time_dim = 'ftime') -\dontrun{ -# 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) -} } -- GitLab