CST_PeriodMean() and CST_PeriodAccumulation(): Dates in s2dv_cube do not change to reflect aggregation
Hi @aho
Opening this to continue the discussion we had offline about the behavior of CST_PeriodMean() and CST_PeriodAccumulation() re: the s2dv_cube Dates attribute.
Trying to summarize, I have identified two different scenarios:
Scenario 1: parameters start and end are not defined. In this case, the mean or sum for the entire period is computed, and $Dates is returned with no modification. The time steps in $Dates do not reflect the new time steps in the array. Here's an example:
library(CSIndicators)
# Create s2dv_cube
exp <- NULL
exp$data <- array(rnorm(45), dim = c(member = 7, ftime = 8))
class(exp) <- 's2dv_cube'
# Assign Dates
exp$Dates$start <- seq(from = as.Date("01-01-1993", "%d-%m-%Y", tz = 'UTC'),
to = as.Date("01-08-1993", "%d-%m-%Y", tz = 'UTC'),
by = "month")
dim(exp$Dates$start) <- c(ftime = 8)
exp$Dates$start
# [1] "1993-01-01" "1993-02-01" "1993-03-01" "1993-04-01" "1993-05-01"
# [6] "1993-06-01" "1993-07-01" "1993-08-01"
# Compute mean for the whole period (default setting)
exp_mean <- CST_PeriodMean(exp)
dim(exp_mean$data)
# member
# 7
dim(exp_mean$Dates$start)
# ftime
# 8
exp_mean$Dates$start
# [1] "1993-01-01" "1993-02-01" "1993-03-01" "1993-04-01" "1993-05-01"
# [6] "1993-06-01" "1993-07-01" "1993-08-01"
Scenario 2: start
and end
are provided. In this case, the array in Dates$start is cropped to the period defined by start
and end
and stored in $Dates (not in Dates
start). The time steps in $Dates still do not reflect the new time steps in the array. Example:
exp$Dates$start
# [1] "1993-01-01" "1993-02-01" "1993-03-01" "1993-04-01" "1993-05-01"
# [6] "1993-06-01" "1993-07-01" "1993-08-01"
# Compute mean for the period between January 1st and March 31st
exp_mean_JFM <- CST_PeriodMean(exp, start = list(1, 1), end = list(31, 3))
dim(exp_mean_JFM$data)
# member
# 7
# The dates are now stored in a different location...
exp_mean_JFM$Dates$start
# Error in exp_mean$Dates$start : $ operator is invalid for atomic vectors
exp_mean_JFM$Dates
# [1] "1993-01-01" "1993-02-01" "1993-03-01"
Let me know if you need more details or want to discuss this further.
Thanks,
Victòria