From 02ab56525b693dbcdf8ba025d1617c700219c477 Mon Sep 17 00:00:00 2001 From: THEERTHA KARIYATHAN Date: Thu, 27 Mar 2025 12:27:47 +0100 Subject: [PATCH 1/5] description and news update --- DESCRIPTION | 5 +++-- NEWS.md | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2fc850e..7fdadd0 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/NEWS.md b/NEWS.md index 613ff3d..f83b34c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,21 @@ +# CSIndicators 1.1.2 (Release date: 2025-03-27) + +### Fixes +- 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 -- GitLab From 7cc0a9600dcae1b186703e1d0442491707021758 Mon Sep 17 00:00:00 2001 From: THEERTHA KARIYATHAN Date: Thu, 27 Mar 2025 16:30:53 +0100 Subject: [PATCH 2/5] namespace, setNames --- .Rbuildignore | 1 + NAMESPACE | 1 + R/AccumulationExceedingThreshold.R | 3 ++- R/PeriodAccumulation.R | 1 + R/PeriodMax.R | 1 + R/PeriodMean.R | 1 + R/PeriodMin.R | 1 + R/PeriodVariance.R | 1 + R/TotalSpellTimeExceedingThreshold.R | 3 ++- R/TotalTimeExceedingThreshold.R | 3 ++- 10 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index da90668..89478ae 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -14,3 +14,4 @@ ^inst/doc/paper-figure-PlotForecastPDF\.R$ ^.*\.Rproj$ ^\.Rproj\.user$ +^CONTRIBUTING.md diff --git a/NAMESPACE b/NAMESPACE index 15c3c9a..466e3c6 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/R/AccumulationExceedingThreshold.R b/R/AccumulationExceedingThreshold.R index 054a8b7..5235bac 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/PeriodAccumulation.R b/R/PeriodAccumulation.R index 8b0129f..424a1c8 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, diff --git a/R/PeriodMax.R b/R/PeriodMax.R index f038aff..b028d10 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) { diff --git a/R/PeriodMean.R b/R/PeriodMean.R index bebbedd..16752e4 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 91f1cd2..a9be2d5 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) { diff --git a/R/PeriodVariance.R b/R/PeriodVariance.R index 5c52466..cc1883b 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/TotalSpellTimeExceedingThreshold.R b/R/TotalSpellTimeExceedingThreshold.R index 2f420b8..72a51e0 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 70fc188..31cbc58 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 +} -- GitLab From 9a25e63497823faec536a858c29cd7970238118b Mon Sep 17 00:00:00 2001 From: vagudets Date: Fri, 28 Mar 2025 09:31:29 +0100 Subject: [PATCH 3/5] Modify calls to Apply() to avoid using 'builtin' type functions, issue #54 --- R/MergeRefToExp.R | 9 ++++++--- R/PeriodAccumulation.R | 6 ++++-- R/PeriodMax.R | 3 +-- R/PeriodMin.R | 3 ++- R/SelectPeriodOnData.R | 2 +- R/SelectPeriodOnDates.R | 2 +- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/R/MergeRefToExp.R b/R/MergeRefToExp.R index 6d9fd6e..69f722b 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 8b0129f..a94d6f7 100644 --- a/R/PeriodAccumulation.R +++ b/R/PeriodAccumulation.R @@ -273,7 +273,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 +337,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 f038aff..ecb3376 100644 --- a/R/PeriodMax.R +++ b/R/PeriodMax.R @@ -205,11 +205,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/PeriodMin.R b/R/PeriodMin.R index 91f1cd2..e4d0c64 100644 --- a/R/PeriodMin.R +++ b/R/PeriodMin.R @@ -205,7 +205,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/SelectPeriodOnData.R b/R/SelectPeriodOnData.R index 1cc2792..731abb5 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 550aad9..b95c509 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))) { -- GitLab From 840fe0f479f0440d71173ee6e87cdf74a2fd95fd Mon Sep 17 00:00:00 2001 From: vagudets Date: Fri, 28 Mar 2025 09:58:06 +0100 Subject: [PATCH 4/5] Update NEWS.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index f83b34c..025519f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # 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 -- GitLab From 7f3fdeb97f4e6a08bdef298752707b50b6664676 Mon Sep 17 00:00:00 2001 From: THEERTHA KARIYATHAN Date: Tue, 1 Apr 2025 09:43:13 +0200 Subject: [PATCH 5/5] update citation --- inst/CITATION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/CITATION b/inst/CITATION index af27d37..5e2c82a 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" -- GitLab