exp <- array(rnorm(5 * 3 * 214 * 2, mean = 28, sd = 10),
                   c(member = 5, sdate = 3, time = 214, lon = 2))
obs <- array(rnorm(3 * 214 * 2, mean = 27, sd = 9),
                   c(sdate = 3, time = 214, lon = 2))
exp_percentile <- AbsToProbs(exp) 
obs_percentile <- QThreshold(obs, threshold = 35) # convert the fixed threshold to percentile with given observations
SU35_percentile <- TotalTimeExceedingThreshold(exp_percentile,
                          obs_percentile) 
SU35 <- TotalTimeExceedingThreshold(exp_percentile, obs_percentile)
all(SU35_percentile == s2dv::Reorder(SU35, c('member', 'sdate', 'lon')))


exp <- CSTools::lonlat_data$exp
exp$data <- array(rnorm(5 * 3 * 214 * 2, mean = 28, sd = 10),
                   c(member = 5, sdate = 3, ftime = 214, lon = 2))
exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", format = "%d-%m-%Y"), 
                     as.Date("30-11-2000", format = "%d-%m-%Y"), by = 'day'),
                 seq(as.Date("01-05-2001", format = "%d-%m-%Y"), 
                     as.Date("30-11-2001", format = "%d-%m-%Y"), by = 'day'),
                 seq(as.Date("01-05-2002", format = "%d-%m-%Y"), 
                     as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day'))
obs <- CSTools::lonlat_data$obs
obs$data <- array(rnorm(3 * 214 * 2, mean = 27, sd = 9),
                   c(sdate = 3, time = 214, lon = 2))
obs$Dates[[1]] <- exp$Dates[[1]]
exp_percentile <- AbsToProbs(exp$data) # convert foreasts to probability
obs_percentile <- QThreshold(obs$data, threshold = 35) # convert th
data <- exp # convert the data (exp_percentile) to a s2dv_cube object
data$data <- aperm(exp_percentile, c(2,1,3,4))
data$Dates[[1]] <- exp$Dates[[1]]
SU35_percentile <- CST_TotalTimeExceedingThreshold(data, threshold = obs_percentile) # compare percentiles between forecasts and observations

exp_percentile <- CST_AbsToProbs(exp)
SU35 <- CST_TotalTimeExceedingThreshold(exp_percentile, obs_percentile)
all(SU35_percentile$data == s2dv::Reorder(SU35$data, c('member', 'sdate', 'lon', 'time')))
