diff --git a/.Rbuildignore b/.Rbuildignore index da906688382daf52144113e08e6a8476f4bbf46f..89478ae5ef8cfeefc4e2e2a2f9b4e842cd35beea 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -14,3 +14,4 @@ ^inst/doc/paper-figure-PlotForecastPDF\.R$ ^.*\.Rproj$ ^\.Rproj\.user$ +^CONTRIBUTING.md diff --git a/DESCRIPTION b/DESCRIPTION index 2fc850e7062e3837df08804b24d93cd9995afd59..7fdadd0c4d72f5780370a15e20025bc2284ff4f2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,9 @@ Package: CSIndicators Title: Climate Services' Indicators Based on Sub-Seasonal to Decadal Predictions -Version: 1.1.1 +Version: 1.1.2 Authors@R: c( - person("Victòria", "Agudetse", , "victoria.agudetse@bsc.es", role = c("cre")), + person("Theertha", "Kariyathan", ,"theertha.kariyathan@bsc.es", role = c("cre")), + person("Victòria", "Agudetse", , "victoria.agudetse@bsc.es", role = c("ctb")), person("Eva", "Rifà", , "eva.rifarovira@bsc.es", role = c("ctb")), person("Nuria", "Perez-Zanon", , "nuria.perez@bsc.es", role = c("aut"), comment = c(ORCID = "0000-0001-8568-3071")), person("Chou", "Chihchung", ,"chihchung.chou@bsc.es", role = "aut"), diff --git a/NAMESPACE b/NAMESPACE index 15c3c9a6e194bd8fea84dac36081c0d8033674aa..466e3c69ba7c7209d4f30841941ed1a712e890c3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -60,6 +60,7 @@ importFrom(stats,ecdf) importFrom(stats,qnorm) importFrom(stats,quantile) importFrom(stats,sd) +importFrom(stats,setNames) importFrom(stats,window) importFrom(utils,read.delim) importFrom(zoo,rollapply) diff --git a/NEWS.md b/NEWS.md index 613ff3d314ed923d54617b34aab89466e5221be6..025519f7b365a1f180655e23a7b3a438809ba0b9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,22 @@ +# CSIndicators 1.1.2 (Release date: 2025-03-27) + +### Fixes +- Avoid using 'builtin' type functions in call to multiApply::Apply() +- CST_PeriodStandardization: Set na.rm = TRUE when replacing infinite values with maximum/minimum period values +- CST_PeriodPET(): Add longname and other variable metadata +- Not drop singleton time dimensions in + PeriodAccumulation + PeriodMean + PeriodMax + PeriodMin + PeriodVariance + AccumulationExceedingThreshold + TotalSpellTimeExceedingThreshold + TotalTimeExceedingThreshold + +### Other +- add CONTRIBUTING.md + # CSIndicators 1.1.1 (Release date: 2024-01-24) ### Fixes diff --git a/R/AccumulationExceedingThreshold.R b/R/AccumulationExceedingThreshold.R index 054a8b71a7aca73b3ceb75a94eb7da924aa5673b..5235bace541754f36d7872c7daca6565261ab36a 100644 --- a/R/AccumulationExceedingThreshold.R +++ b/R/AccumulationExceedingThreshold.R @@ -203,6 +203,7 @@ CST_AccumulationExceedingThreshold <- function(data, threshold, op = '>', diff = #'GDD <- AccumulationExceedingThreshold(data, threshold = 0, start = list(1, 4), #' end = list(31, 10)) #'@import multiApply +#'@importFrom stats setNames #'@export AccumulationExceedingThreshold <- function(data, threshold, op = '>', diff = FALSE, dates = NULL, start = NULL, end = NULL, @@ -477,4 +478,4 @@ AccumulationExceedingThreshold <- function(data, threshold, op = '>', diff = FAL } return(res) -} \ No newline at end of file +} diff --git a/R/MergeRefToExp.R b/R/MergeRefToExp.R index 6d9fd6e88104d58c871254ac52171b4e4fce115d..69f722b7934de0df3185b4042304bd832946dc84 100644 --- a/R/MergeRefToExp.R +++ b/R/MergeRefToExp.R @@ -184,8 +184,10 @@ CST_MergeRefToExp <- function(data1, data2, start1 = NULL, end1 = NULL, names(dim(dates2)) <- time_dim } } - res <- Apply(list(dates1, dates2), target_dims = time_dim, - 'c', output_dims = time_dim, ncores = ncores)$output1 + res <- Apply(list(dates1, dates2), + target_dims = time_dim, + fun = function(x, ...) {c(x, ...)}, + output_dims = time_dim, ncores = ncores)$output1 if (inherits(dates1, 'Date')) { data1$attrs$Dates <- as.Date(res, origin = '1970-01-01') @@ -421,7 +423,8 @@ MergeRefToExp <- function(data1, data2, dates1 = NULL, dates2 = NULL, } } - data1 <- Apply(list(data1, data2), target_dims = time_dim, fun = 'c', + data1 <- Apply(list(data1, data2), target_dims = time_dim, + fun = function(x, ...) {c(x, ...)}, output_dims = time_dim, ncores = ncores)$output1 if (all(names(dim(data1)) %in% data1dims)) { diff --git a/R/PeriodAccumulation.R b/R/PeriodAccumulation.R index 8b0129fe9bcc07ca2f983f02a1183040edde09a9..2adf45f78da157b89aecaa4978a4f3090e2e9de4 100644 --- a/R/PeriodAccumulation.R +++ b/R/PeriodAccumulation.R @@ -222,6 +222,7 @@ CST_PeriodAccumulation <- function(data, start = NULL, end = NULL, #' #'@import multiApply #'@importFrom zoo rollapply +#'@importFrom stats setNames #'@export PeriodAccumulation <- function(data, dates = NULL, start = NULL, end = NULL, time_dim = 'time', rollwidth = NULL, @@ -273,7 +274,7 @@ PeriodAccumulation <- function(data, dates = NULL, start = NULL, end = NULL, if (is.null(rollwidth)) { # period accumulation - total <- Apply(list(data), target_dims = time_dim, fun = sum, + total <- Apply(list(data), target_dims = time_dim, fun = function(...) {sum(...)}, na.rm = na.rm, ncores = ncores)$output1 } else { # rolling accumulation @@ -337,7 +338,9 @@ PeriodAccumulation <- function(data, dates = NULL, start = NULL, end = NULL, } } - data_accum <- rollapply(data = data_vector, width = rollwidth, FUN = sum, na.rm = na.rm) + data_accum <- rollapply(data = data_vector, width = rollwidth, + FUN = function(...) {sum(...)}, + na.rm = na.rm) if (!forwardroll) { data_accum <- c(rep(NA, rollwidth-1), data_accum) } else { diff --git a/R/PeriodMax.R b/R/PeriodMax.R index f038afffe317f2db9d28a1a4d50b1b106dc11656..46f09846517677865317337b5dce9beb6415df52 100644 --- a/R/PeriodMax.R +++ b/R/PeriodMax.R @@ -163,6 +163,7 @@ CST_PeriodMax <- function(data, start = NULL, end = NULL, #'res <- PeriodMax(data, dates = Dates, start = list(01, 12), end = list(01, 01)) #' #'@import multiApply +#'@importFrom stats setNames #'@export PeriodMax <- function(data, dates = NULL, start = NULL, end = NULL, time_dim = 'time', na.rm = FALSE, ncores = NULL) { @@ -205,11 +206,10 @@ PeriodMax <- function(data, dates = NULL, start = NULL, end = NULL, } } } - total <- Apply(list(data), target_dims = time_dim, fun = max, + total <- Apply(list(data), target_dims = time_dim, fun = function(...) {max(...)}, na.rm = na.rm, ncores = ncores)$output1 dim(total) <- c(dim(total), setNames(1, time_dim)) return(total) } - diff --git a/R/PeriodMean.R b/R/PeriodMean.R index bebbedd1047328ba9f27b9ac2a72796b01fddd76..16752e4e4fdfda9adf964214afc37525fc9ec1cf 100644 --- a/R/PeriodMean.R +++ b/R/PeriodMean.R @@ -162,6 +162,7 @@ CST_PeriodMean <- function(data, start = NULL, end = NULL, #'SA <- PeriodMean(data, dates = Dates, start = list(01, 12), end = list(01, 01)) #' #'@import multiApply +#'@importFrom stats setNames #'@export PeriodMean <- function(data, dates = NULL, start = NULL, end = NULL, time_dim = 'time', na.rm = FALSE, ncores = NULL) { diff --git a/R/PeriodMin.R b/R/PeriodMin.R index 91f1cd294395621b598dc91b3a229eba577df997..52fb10a91cef7d805d3ff0ac0863e07d6e35b2f9 100644 --- a/R/PeriodMin.R +++ b/R/PeriodMin.R @@ -163,6 +163,7 @@ CST_PeriodMin <- function(data, start = NULL, end = NULL, #'res <- PeriodMin(data, dates = Dates, start = list(01, 12), end = list(01, 01)) #' #'@import multiApply +#'@importFrom stats setNames #'@export PeriodMin <- function(data, dates = NULL, start = NULL, end = NULL, time_dim = 'time', na.rm = FALSE, ncores = NULL) { @@ -205,7 +206,8 @@ PeriodMin <- function(data, dates = NULL, start = NULL, end = NULL, } } } - total <- Apply(list(data), target_dims = time_dim, fun = min, + total <- Apply(list(data), target_dims = time_dim, + fun = function(...) {min(...)}, na.rm = na.rm, ncores = ncores)$output1 dim(total) <- c(dim(total), setNames(1, time_dim)) return(total) diff --git a/R/PeriodVariance.R b/R/PeriodVariance.R index 5c52466ba07d6b4e2abde7d6f18d05d3c7256988..cc1883b2e9ec0038b6d76c26a2dbe31083fbaba4 100644 --- a/R/PeriodVariance.R +++ b/R/PeriodVariance.R @@ -171,6 +171,7 @@ CST_PeriodVariance <- function(data, start = NULL, end = NULL, #'res <- PeriodVariance(data, dates = Dates, start = list(01, 12), end = list(01, 01)) #' #'@import multiApply +#'@importFrom stats setNames #'@export PeriodVariance <- function(data, dates = NULL, start = NULL, end = NULL, time_dim = 'time', na.rm = FALSE, ncores = NULL) { diff --git a/R/SelectPeriodOnData.R b/R/SelectPeriodOnData.R index 1cc2792ed9a1bb3cdd909fd99a4a1a1db6402559..731abb5c47320617b81e9b4816acf9b776708c78 100644 --- a/R/SelectPeriodOnData.R +++ b/R/SelectPeriodOnData.R @@ -121,7 +121,7 @@ SelectPeriodOnData <- function(data, dates, start, end, ncores = ncores)$output1 # when 29Feb is included the length of the output changes: regular <- Apply(list(res), target_dims = time_dim, - fun = sum, ncores = ncores)$output1 + fun = function(...) {sum(...)}, ncores = ncores)$output1 dims <- dim(data) dims[names(dims) == time_dim] <- max(regular) if (any(regular != max(regular))) { diff --git a/R/SelectPeriodOnDates.R b/R/SelectPeriodOnDates.R index 550aad94ff28525af253b13a68b80d785f10725f..b95c50912c7f7cacb7b26051957bdb9083dec03b 100644 --- a/R/SelectPeriodOnDates.R +++ b/R/SelectPeriodOnDates.R @@ -53,7 +53,7 @@ SelectPeriodOnDates <- function(dates, start, end, } # when 29Feb is included the length of the output changes: regular <- Apply(list(res), target_dims = time_dim, - fun = sum, ncores = ncores)$output1 + fun = function(...) {sum(...)}, ncores = ncores)$output1 dims <- dim(dates) dims[names(dims) == time_dim] <- max(regular) if (any(regular != max(regular))) { diff --git a/R/TotalSpellTimeExceedingThreshold.R b/R/TotalSpellTimeExceedingThreshold.R index 2f420b83446bebc97f4f3036fbc100e99443f1c3..72a51e0a7d0cd06a85d5b86949c1517da2028768 100644 --- a/R/TotalSpellTimeExceedingThreshold.R +++ b/R/TotalSpellTimeExceedingThreshold.R @@ -219,6 +219,7 @@ CST_TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '> #' end = list(21, 6)) #' #'@import multiApply +#'@importFrom stats setNames #'@export TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '>', dates = NULL, start = NULL, end = NULL, @@ -485,4 +486,4 @@ TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '>', return(days) }))) return(total) -} \ No newline at end of file +} diff --git a/R/TotalTimeExceedingThreshold.R b/R/TotalTimeExceedingThreshold.R index 70fc188db5657fac78f11c4a41dfbb750268b79a..31cbc585ddc3594a37c1da486b396da4b5c0ebb4 100644 --- a/R/TotalTimeExceedingThreshold.R +++ b/R/TotalTimeExceedingThreshold.R @@ -221,6 +221,7 @@ CST_TotalTimeExceedingThreshold <- function(data, threshold, op = '>', #' start = list(21, 4), end = list(21, 6)) #' #'@import multiApply +#'@importFrom stats setNames #'@export TotalTimeExceedingThreshold <- function(data, threshold, op = '>', dates = NULL, start = NULL, end = NULL, @@ -468,4 +469,4 @@ TotalTimeExceedingThreshold <- function(data, threshold, op = '>', } } return(res) -} \ No newline at end of file +} diff --git a/inst/CITATION b/inst/CITATION index af27d374775d31dab7fadd43ede5747e0e67fe31..5e2c82a00dab07e2cc251caa1ba4169414b6fd2e 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -17,7 +17,7 @@ bibentry( author = c(person("Núria", "Pérez-Zanón", email = "nuria.perez@bsc.es"), person("", "et al.")), title = "CSIndicators: Get tailored climate indicators for applications in your sector", doi = "10.1016/j.cliser.2023.100393", - url = "https://www.sciencedirect.com/science/article/pii/S2405880723000547", + url = URLencode("https://doi.org/10.1016/j.cliser.2023.100393"), journal = "Climate Services", publisher = "Elsevier", year = "2023"