test-Compute-transform_all.R 3.06 KB
Newer Older
aho's avatar
aho committed
context("Transform with 'all'")

test_that("1. Chunk along non-lat/lon dim", {
aho's avatar
aho committed
#skip_on_cran()
aho's avatar
aho committed

path <- '/esarchive/exp/ecearth/a1ua/cmorfiles/DCPP/EC-Earth-Consortium/EC-Earth3/dcppA-hindcast/$member$/Amon/$var$/gr/v20190713/$var$_Amon_*_s$sdate$-$member$_gr_$fyear$.nc'
suppressWarnings(
data <- Start(dat = path,
              var = 'tos',
              sdate = paste0(1960),
              time = indices(1:2), #'all',
              lat = 'all',
              lon = 'all',
              fyear = indices(1),
              member = indices(1:2),
              transform = CDORemapper,
              transform_extra_cells = 2,
              transform_params = list(grid = 'r100x50', method = 'conservative'),
              transform_vars = c('lat', 'lon'),
aho's avatar
aho committed
              synonims = list(lon = c('lon', 'longitude'), lat = c('lat', 'latitude')),
              return_vars = list(lat = 'dat', lon = 'dat', time = 'sdate'),
              retrieve = FALSE)
)

func <- function(x) {
  return(x)
}

step <- Step(func, target_dims = c('time'),
             output_dims = 'time')
wf <- AddStep(data, step)

#---
aho's avatar
aho committed
suppressWarnings(
resT <- eval(data)
)
suppressWarnings(
res1 <- Compute(wf, chunks = list(member = 2))
aho's avatar
aho committed
)

expect_equal(
dim(res1$output1),
c(time = 2, dat = 1, var = 1, sdate = 1, lat = 50, lon = 100, fyear = 1, member = 2)
aho's avatar
aho committed
)
expect_equal(
as.vector(resT),
as.vector(res1$output1)
aho's avatar
aho committed
})

aho's avatar
aho committed
#skip_on_cran()
aho's avatar
aho committed

#NOTE: the results are not identical when exp has extra cells = 2
aho's avatar
aho committed
suppressWarnings(
exp <- Start(dat = '/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc',
             var = 'tas',
             sdate = '20000101',
             ensemble = indices(1),
aho's avatar
aho committed
             time = indices(1),
             latitude_reorder = Sort(),
             longitude_reorder = CircularSort(0, 360),
aho's avatar
aho committed
             transform = CDORemapper,
             transform_params = list(grid = 'r100x50',
                                     method = 'con'),
#                                     crop = FALSE),
aho's avatar
aho committed
             transform_vars = c('latitude', 'longitude'),
             transform_extra_cells = 8,
aho's avatar
aho committed
             synonims = list(latitude = c('lat', 'latitude'),
                             longitude = c('longitude', 'lon')),
             return_vars = list(latitude = 'dat',#NULL,
                                longitude = 'dat',#NULL,
                                time = 'sdate'),
             retrieve = F)
)

  func <- function(x) {
    return(x)
aho's avatar
aho committed
  }
  step <- Step(func, target_dims = 'time', output_dims = 'time')
aho's avatar
aho committed
  wf <- AddStep(exp, step)
aho's avatar
aho committed
suppressWarnings(
aho's avatar
aho committed
)
suppressWarnings(
res1 <- Compute(wf, chunks = list(longitude = 2))$output1
#suppressWarnings(
#  res2 <- Compute(wf, chunks = list(ensemble = 1))
#)
suppressWarnings(
res3 <- Compute(wf, chunks = list(longitude = 2, latitude = 2))$output1
)
suppressWarnings(
res4 <- Compute(wf, chunks = list(longitude = 3))$output1
as.vector(resT),
as.vector(res1)
)
expect_equal(
res1,
res3
)
expect_equal(
res1,
res4