Error retrieving time with values(): 1:(data_dims[[inner_dim]] * chunk_amount)
Hi @aho
As we discussed, I am opening the issue now although we have other priorities.
I am able to successfully run the code declaring time dimension using indices():
hist <- Start(dat = "/esarchive/exp/CMIP6/historical/cnrm-cm6-1/cmip6-historical_i0p1/CMIP/CNRM-CERFACS/CNRM-CM6-1/historical/$member$/day/$var$/gr/v20200101/$var$_day_CNRM-CM6-1_historical_$member$_gr_$period$.nc",
var = 'tas',
member = 'r1i1p1f2',
period = '18500101-20141231',
lat = 'all',
lon = 'all',
time = indices(1:730),
transform = CDORemapper,
transform_extra_cells = 2,
transform_params = list(grid = 'r180x90',
method = 'conservative',
crop = FALSE),
transform_vars = c('lat', 'lon'),
synonims = list(lon = c('lon', 'longitude'),
lat = c('lat', 'latitude')),
return_vars = list(time = NULL,
lat = 'dat',
lon = 'dat'),
retrieve = FALSE)
lon <- attributes(hist)$Varia$dat1$lon
lat <- attributes(hist)$Varia$dat1$lat
time <- attributes(hist)$Variable$common$time
climdex_ind <- function(dat, times) {
datefactor <- as.numeric(substr(times, 1, 4))
datefactor <- as.factor(datefactor)
fd <- climdex.pcic::number.days.op.threshold(dat, datefactor, 273.15, "<")
return(fd)
}
step <- Step(fun = climdex_ind,
target_dims = 'time',
output_dims = 'time')
wf <- AddStep(hist, step, times = time)
## locally
res <- Compute(wf,
chunks = list(lat = 2,
lon = 2))
I have successfully tested I am able to retrieve data when defining time with values:
hist <- Start(dat = "/esarchive/exp/CMIP6/historical/cnrm-cm6-1/cmip6-historical_i0p1/CMIP/CNRM-CERFACS/CNRM-CM6-1/historical/$member$/day/$var$/gr/v20200101/$var$_day_CNRM-CM6-1_historical_$member$_gr_$period$.nc",
var = 'tas',
member = 'r1i1p1f2',
period = '18500101-20141231',
lat = 'all',
lon = 'all',
time = values(list(as.POSIXct('1981-01-01 12:00:00 UTC', tz = 'UTC'),
as.POSIXct('1982-12-31 12:00:00 UTC', tz = 'UTC'))),
transform = CDORemapper,
transform_extra_cells = 2,
transform_params = list(grid = 'r180x90',
method = 'conservative',
crop = FALSE),
transform_vars = c('lat', 'lon'),
synonims = list(lon = c('lon', 'longitude'),
lat = c('lat', 'latitude')),
return_vars = list(time = NULL,
lat = 'dat',
lon = 'dat'),
retrieve = TRUE)
I fail when combining them:
hist <- Start(dat = "/esarchive/exp/CMIP6/historical/cnrm-cm6-1/cmip6-historical_i0p1/CMIP/CNRM-CERFACS/CNRM-CM6-1/historical/$member$/day/$var$/gr/v20200101/$var$_day_CNRM-CM6-1_historical_$member$_gr_$period$.nc",
var = 'tas',
member = 'r1i1p1f2',
period = '18500101-20141231',
lat = 'all',
lon = 'all',
time = values(list(as.POSIXct('1981-01-01 12:00:00 UTC', tz = 'UTC'),
as.POSIXct('1982-12-31 12:00:00 UTC', tz = 'UTC'))),
transform = CDORemapper,
transform_extra_cells = 2,
transform_params = list(grid = 'r180x90',
method = 'conservative',
crop = FALSE),
transform_vars = c('lat', 'lon'),
synonims = list(lon = c('lon', 'longitude'),
lat = c('lat', 'latitude')),
return_vars = list(time = NULL,
lat = 'dat',
lon = 'dat'),
retrieve = FALSE)
lon <- attributes(hist)$Varia$dat1$lon
lat <- attributes(hist)$Varia$dat1$lat
time <- attributes(hist)$Variable$common$time
climdex_ind <- function(dat, times) {
datefactor <- as.numeric(substr(times, 1, 4))
datefactor <- as.factor(datefactor)
fd <- climdex.pcic::number.days.op.threshold(dat, datefactor, 273.15, "<")
return(fd)
}
step <- Step(fun = climdex_ind,
target_dims = 'time',
output_dims = 'time')
wf <- AddStep(hist, step, times = time)
## locally
res <- Compute(wf,
chunks = list(lat = 2,
lon = 2))
* Processing chunks... remaining time estimate soon...
* Loading chunk 1 out of 4 ...
Error in 1:(data_dims[[inner_dim]] * chunk_amount) : argument of length 0
Well, I'll keep using indices() for now to develop this test of climdex.pcic.
We can talk about this in the coming days.
Cheers,
Núria