Newer
Older
library(s2dv)
context("Irregular regriding in the workflow")
test_that("1. ex2_13", {
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'DCPP/CMCC/CMCC-CM2-SR5/dcppA-hindcast/$member$/Omon/$var$/gn/v20210312/',
'$var$_*_s$sdate$-$member$_gn_$aux$.nc')
suppressWarnings(
data <- Start(dataset = path,
var = 'tos',
sdate = '1960',
aux = 'all',
aux_depends = 'sdate',
j = indices(2:361), # remove two indices to avoid white strips
i = indices(2:291), # remove two indices to avoid white strips
time = indices(1),
member = 'r1i1p1f1',
return_vars = list(j = NULL, i = NULL,
latitude = NULL, longitude = NULL),
retrieve = F)
)
func_regrid <- function(data) {
lons <- attr(data, 'Variables')$common$longitude
lats <- attr(data, 'Variables')$common$latitude
data <- s2dv::CDORemap(data, lons, lats, grid = 'r360x180',
method = 'bil', crop = FALSE)
lons_reg <- data[['lons']]
lats_reg <- data[['lats']]
return(list(data = data[[1]], lats = lats_reg, lons = lons_reg))
}
#NOTE: The data transposes if target_dims are only 'j' and 'i'.
# If only 'j' and 'i', output_dims will be 'lat', 'lon'.
step <- Step(fun = func_regrid,
target_dims = list(data = c('j', 'i')),
output_dims = list(data = c('lon', 'lat'),
lats = 'lat', lons = 'lon'),
use_attributes = list(data = "Variables"))
suppressWarnings(
wf <- AddStep(data, step)
)
suppressWarnings(
res <- Compute(workflow = wf$data, chunks = list(sdate = 1))
)
expect_equal(
dim(res$data),
c(lon = 360, lat = 180, dataset = 1, var = 1, sdate = 1, aux = 1, time = 1, member = 1)
)
expect_equal(
dim(res$lons),
c(lon = 360, dataset = 1, var = 1, sdate = 1, aux = 1, time = 1, member = 1)
)
expect_equal(
attr(data, 'Dimensions'),
c(dataset = 1, var = 1, sdate = 1, aux = 1, j = 360, i = 290, time = 1, member = 1)
)
expect_equal(
mean(res$data, na.rm = T),
13.20951,
tolerance = 0.0001
)
expect_equal(
drop(res$data)[120,105:110],
c(28.32521, 28.07044, 27.59033, 27.02514, 26.55184, 26.67090),
tolerance = 0.0001
)
})