CST_SaveExp doesn't save well time_bounds
Now, CST_SaveExp can't save time_bounds attribute created from some CSIndicators functions. (1) It should save time_bounds attribute as a variable in NetCDF. (2) Also, there is an error in the function when the $attrs$Dates
don't have ftime_dim. This also needs to be corrected.
Example
# Step (0): Load the functions:
filepath <- "/esarchive/scratch/erifarov/git/csindicators/R/"
f <- list.files(filepath)
ff <- lapply(f, function(x) paste0(filepath, x))
invisible(lapply(ff, source))
# Example 1: Error when ftime_dim = NULL
exp <- NULL
exp$data <- array(rnorm(45), dim = c(member = 7, sdate = 4, time = 3))
Dates <- c(seq(as.Date("2000-11-01", "%Y-%m-%d", tz = "UTC"),
as.Date("2001-01-01", "%Y-%m-%d", tz = "UTC"), by = "month"),
seq(as.Date("2001-11-01", "%Y-%m-%d", tz = "UTC"),
as.Date("2002-01-01", "%Y-%m-%d", tz = "UTC"), by = "month"),
seq(as.Date("2002-11-01", "%Y-%m-%d", tz = "UTC"),
as.Date("2003-01-01", "%Y-%m-%d", tz = "UTC"), by = "month"),
seq(as.Date("2003-11-01", "%Y-%m-%d", tz = "UTC"),
as.Date("2004-01-01", "%Y-%m-%d", tz = "UTC"), by = "month"))
dim(Dates) <- c(sdate = 4, time = 3)
exp$attrs$Dates <- Dates
class(exp) <- 's2dv_cube'
SA <- CST_PeriodMax(exp, start = list(01, 12), end = list(01, 01))
# Call CST_SaveExp
destination = "/esarchive/scratch/erifarov/rpackages/CSIndicators/dev-bioclimatic_indicators/"
CST_SaveExp(data = SA, destination = destination, ftime_dim = NULL,
var_dim = NULL, dat_dim = NULL)
# Error in Subset(Dates, along = ftime_dim, 1, drop = "selected") :
# All provided dimension indices in 'along' must be integers or character strings.
# Example with creating ftime_dim of length 1:
SA <- CST_InsertDim(SA, posdim = 1, lendim = 1, name = 'time')
Dates <- SA$attrs$Dates
dim(SA$attrs$Dates) <- c(dim(SA$attrs$Dates), time = 1)
CST_SaveExp(data = SA, destination = destination, ftime_dim = 'time',
var_dim = NULL, dat_dim = NULL)
# By default sdates are created in different files.
For the case there has been time aggregation as in CSIndicators functions the output will be the following: One NetCDF for each start date and each file will have time and time_bounds variable of length 1. @vagudets, @aho do you agree with this?
Eva