Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • CSTools CSTools
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 28
    • Issues 28
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 2
    • Merge requests 2
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • External
  • CSToolsCSTools
  • Issues
  • #137
Closed
Open
Issue created Oct 05, 2023 by Eva Rifà@erifarovMaintainer

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

Assignee
Assign to
Time tracking