Skip to content

Error when using depends and array of values in DCPP case

Hi @aho

As we have already commented, the code below fails with the message: If providing selectors for the depending dimension 'chunk', a vector of selectors must be provided for each selector of the dimension it depends on, 'sdate'. while it works with indices() (see tests in !135 (merged)).

library(startR)
DatesSequence <- function(sdate, inimonth, finalmonth, lag, nyears) {
  if (!is.numeric(sdate)) {
     sdate <- as.numeric(sdate)
  }
  sequence <- unlist(lapply(sdate, function(x) {
                a <- paste0((sdate + lag): (sdate + nyears),
                           sprintf('%02d', inimonth))
                b <- paste0((sdate + lag): (sdate + nyears),
                          sprintf('%02d', finalmonth))
                return(paste0(a, '-', b))}))
  sequence <- array(sequence,
                    c(sdate = length(sdate),
                      chunk = length(sequence)/length(sdate)))
  return(sequence)
}

path <- '/esarchive/exp/CMIP6/dcppA-hindcast/hadgem3-gc31-mm/cmip6-dcppA-hindcast_i1p1/DCPP/MOHC/HadGEM3-GC31-MM/dcppA-hindcast/r1i1p1f2/Omon/tos/gn/v20200417/$var$_Omon_HadGEM3-GC31-MM_dcppA-hindcast_s$sdate$-r1i1p1f2_gn_$chunk$.nc'

sdates <- c('2017', '2018')
chunks <- DatesSequence(sdates,
              inimonth = 1, finalmonth = 12, lag = 1, nyears = 3)

dat <- Start(dat = path,
             var = 'tos',
             sdate = sdates,
             chunk = values(chunks),
             chunk_depends = 'sdate',
             time = 'all',
             i = indices(1),
             j = 'all',
             time_across = 'chunk',
             merge_across_dims = TRUE,
             retrieve = TRUE,
             return_vars = list(time = 'sdate'))

It is not urgent since we know that we can use indices() to avoid the problem.

Cheers,

Núria