context("Start() metadata reshaping") # When data is reshaping (e.g., time_across = 'sdate'), the corresponding attribute should be reshaped too. test_that("1. time across fyear, fyear depends on sdate", { suppressWarnings( data <- Start(dat = '/esarchive/exp/ecearth/a3w5/original_files/cmorfiles/DCPP/EC-Earth-Consortium/EC-Earth3/dcppA-hindcast/$member$/day/$var$/gr/v20210910/$var$_day_EC-Earth3_dcppA-hindcast_s$sdate$-$member$_gr_$fyear$.nc', var = 'tasmin', lat = indices(1), lon = indices(1), sdate = paste0(1960:1961), time = 62:426, ## Jan to Dec (initialised in Nov) time_across = 'fyear', merge_across_dims = TRUE, fyear = 'all', fyear_depends = 'sdate', member = 'r1i4p1f1', synonims = list(lat = c('lat','latitude'), lon = c('lon','longitude')), return_vars = list(lat = NULL, lon = NULL, time = c('sdate', 'fyear')), retrieve = TRUE) ) dates <- attr(data,'Variables')$common[['time']] expect_equal( dim(dates), c(sdate = 2, time = 365) ) expect_equal( dim(drop(data)), dim(dates) ) expect_equal( names(attributes(dates)), c('variables', 'dim', 'class', 'tzone') ) expect_equal( class(dates), c("POSIXct", "POSIXt") ) expect_equal( as.vector(dates[1, c(1:2, 365)]), as.vector(as.POSIXct(c("1961-01-01 12:00:00", "1961-01-02 12:00:00", "1961-12-31 12:00:00"), tz = 'UTC')) ) expect_equal( as.vector(dates[2, c(1:2, 365)]), as.vector(as.POSIXct(c("1962-01-01 12:00:00", "1962-01-02 12:00:00", "1962-12-31 12:00:00"), tz = 'UTC')) ) }) test_that("2. time across fyear, only one sdate", { suppressWarnings( data <- Start(dat = '/esarchive/exp/ecearth/a3w5/original_files/cmorfiles/DCPP/EC-Earth-Consortium/EC-Earth3/dcppA-hindcast/$member$/day/$var$/gr/v20210910/$var$_day_EC-Earth3_dcppA-hindcast_s$sdate$-$member$_gr_$fyear$.nc', var = 'tasmin', lat = indices(1), lon = indices(1), sdate = paste0(1960), time = 62:426, ## Jan to Dec (initialised in Nov) time_across = 'fyear', merge_across_dims = TRUE, fyear = 'all', # fyear_depends = 'sdate', member = 'r1i4p1f1', synonims = list(lat = c('lat','latitude'), lon = c('lon','longitude')), return_vars = list(lat = NULL, lon = NULL, time = c('fyear')), retrieve = TRUE) ) dates <- attr(data,'Variables')$common[['time']] expect_equal( dim(dates), c(time = 365) ) expect_equal( length(data), length(dates) ) expect_equal( as.vector(dates[c(1:2, 365)]), as.vector(as.POSIXct(c("1961-01-01 12:00:00", "1961-01-02 12:00:00", "1961-12-31 12:00:00"), tz = 'UTC')) ) })