From 620c7f6c9a786309080dd0b6c632ba81bd16d69c Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Mon, 23 Oct 2023 12:21:17 +0200 Subject: [PATCH] Subset 'coords' element for CST functions --- R/AccumulationExceedingThreshold.R | 1 + R/PeriodAccumulation.R | 1 + R/PeriodMax.R | 7 ++++--- R/PeriodMean.R | 1 + R/PeriodMin.R | 1 + R/PeriodVariance.R | 1 + R/QThreshold.R | 1 + R/Threshold.R | 3 +++ R/TotalSpellTimeExceedingThreshold.R | 1 + R/TotalTimeExceedingThreshold.R | 1 + 10 files changed, 15 insertions(+), 3 deletions(-) diff --git a/R/AccumulationExceedingThreshold.R b/R/AccumulationExceedingThreshold.R index eecded6..0b312e9 100644 --- a/R/AccumulationExceedingThreshold.R +++ b/R/AccumulationExceedingThreshold.R @@ -113,6 +113,7 @@ CST_AccumulationExceedingThreshold <- function(data, threshold, op = '>', diff = na.rm = na.rm, ncores = ncores) data$data <- total data$dims <- dim(total) + data$coords[[time_dim]] <- NULL if (!is.null(Dates)) { if (!is.null(start) && !is.null(end)) { diff --git a/R/PeriodAccumulation.R b/R/PeriodAccumulation.R index b8dcf9a..41c9b67 100644 --- a/R/PeriodAccumulation.R +++ b/R/PeriodAccumulation.R @@ -87,6 +87,7 @@ CST_PeriodAccumulation <- function(data, start = NULL, end = NULL, time_dim = time_dim, na.rm = na.rm, ncores = ncores) data$data <- total data$dims <- dim(total) + data$coords[[time_dim]] <- NULL if (!is.null(Dates)) { if (!is.null(start) && !is.null(end)) { diff --git a/R/PeriodMax.R b/R/PeriodMax.R index 0806c51..d0004e0 100644 --- a/R/PeriodMax.R +++ b/R/PeriodMax.R @@ -61,8 +61,8 @@ #'@importFrom ClimProjDiags Subset #'@export CST_PeriodMax <- function(data, start = NULL, end = NULL, - time_dim = 'time', na.rm = FALSE, - ncores = NULL) { + time_dim = 'time', na.rm = FALSE, + ncores = NULL) { # Check 's2dv_cube' if (!inherits(data, 's2dv_cube')) { stop("Parameter 'data' must be of the class 's2dv_cube'.") @@ -80,10 +80,11 @@ CST_PeriodMax <- function(data, start = NULL, end = NULL, Dates <- data$attrs$Dates total <- PeriodMax(data = data$data, dates = Dates, start = start, end = end, - time_dim = time_dim, na.rm = na.rm, ncores = ncores) + time_dim = time_dim, na.rm = na.rm, ncores = ncores) data$data <- total data$dims <- dim(total) + data$coords[[time_dim]] <- NULL if (!is.null(Dates)) { if (!is.null(start) && !is.null(end)) { diff --git a/R/PeriodMean.R b/R/PeriodMean.R index 7066fdd..69ffc8c 100644 --- a/R/PeriodMean.R +++ b/R/PeriodMean.R @@ -83,6 +83,7 @@ CST_PeriodMean <- function(data, start = NULL, end = NULL, data$data <- total data$dims <- dim(total) + data$coords[[time_dim]] <- NULL if (!is.null(Dates)) { if (!is.null(start) && !is.null(end)) { diff --git a/R/PeriodMin.R b/R/PeriodMin.R index 842e2e8..afe5eb8 100644 --- a/R/PeriodMin.R +++ b/R/PeriodMin.R @@ -84,6 +84,7 @@ CST_PeriodMin <- function(data, start = NULL, end = NULL, data$data <- total data$dims <- dim(total) + data$coords[[time_dim]] <- NULL if (!is.null(Dates)) { if (!is.null(start) && !is.null(end)) { diff --git a/R/PeriodVariance.R b/R/PeriodVariance.R index b702981..77bf68d 100644 --- a/R/PeriodVariance.R +++ b/R/PeriodVariance.R @@ -88,6 +88,7 @@ CST_PeriodVariance <- function(data, start = NULL, end = NULL, data$data <- total data$dims <- dim(total) + data$coords[[time_dim]] <- NULL if (!is.null(Dates)) { if (!is.null(start) && !is.null(end)) { diff --git a/R/QThreshold.R b/R/QThreshold.R index 4686cb3..0f20858 100644 --- a/R/QThreshold.R +++ b/R/QThreshold.R @@ -97,6 +97,7 @@ CST_QThreshold <- function(data, threshold, start = NULL, end = NULL, sdate_dim = sdate_dim, ncores = ncores) data$data <- probs data$dims <- dim(probs) + if (!is.null(start) && !is.null(end)) { data$attrs$Dates <- SelectPeriodOnDates(dates = data$attrs$Dates, start = start, end = end, diff --git a/R/Threshold.R b/R/Threshold.R index 9efaebd..ee4fa38 100644 --- a/R/Threshold.R +++ b/R/Threshold.R @@ -76,6 +76,9 @@ CST_Threshold <- function(data, threshold, start = NULL, end = NULL, sdate_dim = sdate_dim, na.rm = na.rm, ncores = ncores) data$data <- thres data$dims <- dim(thres) + data$coords[[memb_dim]] <- NULL + data$coords[[sdate_dim]] <- NULL + if (!is.null(start) && !is.null(end)) { data$attrs$Dates <- SelectPeriodOnDates(dates = data$attrs$Dates, start = start, end = end, diff --git a/R/TotalSpellTimeExceedingThreshold.R b/R/TotalSpellTimeExceedingThreshold.R index b7e33cf..1bc1bb3 100644 --- a/R/TotalSpellTimeExceedingThreshold.R +++ b/R/TotalSpellTimeExceedingThreshold.R @@ -115,6 +115,7 @@ CST_TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '> ncores = ncores) data$data <- total data$dims <- dim(total) + data$coords[[time_dim]] <- NULL if (!is.null(Dates)) { if (!is.null(start) && !is.null(end)) { diff --git a/R/TotalTimeExceedingThreshold.R b/R/TotalTimeExceedingThreshold.R index 4d46260..5c6bb62 100644 --- a/R/TotalTimeExceedingThreshold.R +++ b/R/TotalTimeExceedingThreshold.R @@ -119,6 +119,7 @@ CST_TotalTimeExceedingThreshold <- function(data, threshold, op = '>', ncores = ncores) data$data <- total data$dims <- dim(total) + data$coords[[time_dim]] <- NULL if (!is.null(Dates)) { if (!is.null(start) && !is.null(end)) { -- GitLab