From cd219842e704b80240be0e0c665da2c010d45042 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Thu, 18 May 2023 19:47:23 +0200 Subject: [PATCH 1/2] Remove s2dv dependency by substituting Reorder and adding auxiliary function .insertdim --- DESCRIPTION | 1 - NAMESPACE | 2 -- NEWS.md | 3 ++- R/AccumulationExceedingThreshold.R | 1 - R/MergeRefToExp.R | 10 ++++------ R/SelectPeriodOnDates.R | 4 ++-- R/zzz.R | 17 +++++++++++++++++ 7 files changed, 25 insertions(+), 13 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9865bda..90e0e83 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,7 +27,6 @@ Depends: R (>= 3.6.0) Imports: multiApply (>= 2.1.1), - s2dv, stats Suggests: testthat, diff --git a/NAMESPACE b/NAMESPACE index 0fa3f24..d80accb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -26,8 +26,6 @@ export(TotalTimeExceedingThreshold) export(WindCapacityFactor) export(WindPowerDensity) import(multiApply) -importFrom(s2dv,InsertDim) -importFrom(s2dv,Reorder) importFrom(stats,approxfun) importFrom(stats,ecdf) importFrom(stats,quantile) diff --git a/NEWS.md b/NEWS.md index 2b86867..e988a0a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,8 @@ # CSIndicators 1.0.1 (Release date: 2023-05-18) **Fixes** - Add EnergyIndicators vignette figures -- Remove ClimProjDiags dependency +- Remove ClimProjDiags dependency +- Remove s2dv dependency # CSIndicators 1.0.0 (Release date: 2023-04-05) **Fixes** diff --git a/R/AccumulationExceedingThreshold.R b/R/AccumulationExceedingThreshold.R index 7fd78f4..e346b53 100644 --- a/R/AccumulationExceedingThreshold.R +++ b/R/AccumulationExceedingThreshold.R @@ -170,7 +170,6 @@ CST_AccumulationExceedingThreshold <- function(data, threshold, op = '>', diff = #'GDD <- AccumulationExceedingThreshold(data, threshold = 0, start = list(1, 4), #' end = list(31, 10)) #'@import multiApply -#'@importFrom s2dv Reorder #'@export AccumulationExceedingThreshold <- function(data, threshold, op = '>', diff = FALSE, dates = NULL, start = NULL, end = NULL, diff --git a/R/MergeRefToExp.R b/R/MergeRefToExp.R index 1786826..434cae3 100644 --- a/R/MergeRefToExp.R +++ b/R/MergeRefToExp.R @@ -60,7 +60,6 @@ #' start2 = list(1, 7), end2 = list(21, 9)) #' #'@import multiApply -#'@importFrom s2dv InsertDim #'@export CST_MergeRefToExp <- function(data1, data2, start1, end1, start2, end2, time_dim = 'ftime', sdate_dim = 'sdate', @@ -200,7 +199,6 @@ CST_MergeRefToExp <- function(data1, data2, start1, end1, start2, end2, #' time_dim = 'time') #' #'@import multiApply -#'@importFrom s2dv InsertDim #'@export MergeRefToExp <- function(data1, dates1, start1, end1, data2, dates2, start2, end2, time_dim = 'ftime', sdate_dim = 'sdate', @@ -250,8 +248,8 @@ MergeRefToExp <- function(data1, dates1, start1, end1, data2, dates2, start2, dif_dims <- which(names(dim(data2)) %in% names(dim(data1)) == FALSE) if (length(dif_dims) > 0) { for (i in dif_dims) { - data1 <- InsertDim(data1, posdim = i, lendim = dim(data2)[i], - name = names(dim(data2))[i]) + data1 <- .insertdim(data1, posdim = i, lendim = dim(data2)[i], + name = names(dim(data2))[i]) } } } @@ -260,8 +258,8 @@ MergeRefToExp <- function(data1, dates1, start1, end1, data2, dates2, start2, dif_dims <- which(names(dim(data1)) %in% names(dim(data2)) == FALSE) if (length(dif_dims) > 0) { for (i in dif_dims) { - data2 <- InsertDim(data2, posdim = i, lendim = dim(data1)[i], - name = names(dim(data1))[i]) + data2 <- .insertdim(data2, posdim = i, lendim = dim(data1)[i], + name = names(dim(data1))[i]) } } } diff --git a/R/SelectPeriodOnDates.R b/R/SelectPeriodOnDates.R index 09633dd..fcb1a4c 100644 --- a/R/SelectPeriodOnDates.R +++ b/R/SelectPeriodOnDates.R @@ -20,7 +20,6 @@ #'the vector dates during the period requested from \code{start} to \code{end}. #' #'@import multiApply -#'@importFrom s2dv Reorder #' #'@examples #'Dates <- c(seq(as.Date("01-05-2000", format = "%d-%m-%Y"), @@ -66,7 +65,8 @@ SelectPeriodOnDates <- function(dates, start, end, res <- as.POSIXct(res, origin = '1970-01-01', tz = 'UTC') } else { if (!all(names(dim(res)) == names(dim(dates)))) { - res <- s2dv::Reorder(res, names(dim(dates))) + pos <- match(names(dim(dates)), names(dim(res))) + res <- aperm(res, pos) } res <- dates[res] dim(res) <- dims diff --git a/R/zzz.R b/R/zzz.R index 5e20873..cf91639 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -35,6 +35,23 @@ eval(call) } +# Function to insert a dimension in an array +.insertdim <- function(data, posdim, lendim, name = NULL) { + names(lendim) <- name + data <- array(data, dim = c(dim(data), lendim)) + ## Reorder dimension + if (posdim == 1) { + order <- c(length(dim(data)), 1:(length(dim(data)) - 1)) + data <- aperm(data, order) + } else if (posdim == length(dim(data))) { # last dim + + } else { # middle dim + order <- c(1:(posdim - 1), length(dim(data)), posdim:(length(dim(data)) - 1)) + data <- aperm(data, order) + } + return(data) +} + #======================= # Read a powercurve file -- GitLab From fde621ed88f2f5f52a8fdf503af07497c5ef278d Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Thu, 18 May 2023 19:49:48 +0200 Subject: [PATCH 2/2] Correct NEWS format --- NEWS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index e988a0a..44285d2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,8 @@ # CSIndicators 1.0.1 (Release date: 2023-05-18) **Fixes** - Add EnergyIndicators vignette figures -- Remove ClimProjDiags dependency -- Remove s2dv dependency +- Remove ClimProjDiags dependency +- Remove s2dv dependency # CSIndicators 1.0.0 (Release date: 2023-04-05) **Fixes** -- GitLab