Newer
Older
1
2
3
4
5
6
7
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# This unit test tests the chunking over depended and depending dimension.
# ex1_14
# 1. depending dim is values()
# 2. depending dim is indices()
# a. depended dim is indices()
# b. depended dim is list of values
# Note that 2.b. doesn't work.
context("Chunk over dimensions that have dependency relationship")
path <- paste0('/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('2016', '2017', '2018')
# retrieve = T for verification
suppressWarnings(
data_T <- Start(dat = path,
var = 'tos',
sdate = sdates,
chunk = indices(2:4),
chunk_depends = 'sdate',
time = 'all',
i = indices(450:452),
j = indices(650:651),
time_across = 'chunk',
return_vars = list(time = 'sdate'),
retrieve = T, silent = T)
)
test_that("1.a. depending dim is values(); depended dim is indices()", {
suppressWarnings(
data <- Start(dat = path,
var = 'tos',
sdate = sdates,
chunk = indices(2:4),
chunk_depends = 'sdate',
time = 'all',
i = indices(450:452),
j = indices(650:651),
time_across = 'chunk',
return_vars = list(time = 'sdate'),
retrieve = F)
)
fun <- function(x) {
return(x)
}
step <- Step(fun = fun,
target_dims = 'dat', output_dims = 'dat')
wf <- AddStep(inputs = data, step_fun = step)
suppressWarnings(
res1 <- Compute(workflow = wf, chunks = list(chunk = 2))$output1
)
suppressWarnings(
res2 <- Compute(workflow = wf, chunks = list(sdate = 2))$output1
)
suppressWarnings(
res3 <- Compute(workflow = wf, chunks = list(chunk = 2, sdate = 2))$output1
)
expect_equal(
as.vector(data_T),
as.vector(res1)
)
expect_equal(
res1,
res2
)
expect_equal(
res1,
res3
)
expect_equal(
as.vector(drop(res1)[, , 1, 1, 1]),
c(29.26021, 29.37948, 30.43721, 30.66117, 30.09621, 30.14460, 30.19445, 30.93453, 30.50104),
tolerance = 0.0001
)
expect_equal(
as.vector(drop(res1)[, , 2, 1, 1]),
c(29.73614, 29.38624, 30.58396, 30.66175, 30.09205, 30.11643, 29.82516, 30.57528, 30.12949),
tolerance = 0.0001
)
})
#################################################################
#################################################################
#################################################################
test_that("1.b. depending dim is values(); depended dim is list of values", {
chunks <- list('2016' = c("201701-201712","201801-201812","201901-201912"),
'2017' = c("201801-201812","201901-201912","202001-202012"),
'2018' = c("201901-201912","202001-202012","202101-202112"))
suppressWarnings(
data <- Start(dat = path,
var = 'tos',
sdate = sdates,
chunk = chunks,
chunk_depends = 'sdate',
time = 'all',
i = indices(450:452),
j = indices(650:651),
time_across = 'chunk',
return_vars = list(time = 'sdate'),
retrieve = F)
)
fun <- function(x) {
return(x)
}
step <- Step(fun = fun,
target_dims = 'dat', output_dims = 'dat')
wf <- AddStep(inputs = data, step_fun = step)
suppressWarnings(
res1 <- Compute(workflow = wf, chunks = list(chunk = 2))$output1
)
suppressWarnings(
res2 <- Compute(workflow = wf, chunks = list(sdate = 2))$output1
)
suppressWarnings(
res3 <- Compute(workflow = wf, chunks = list(chunk = 2, sdate = 2))$output1
)
expect_equal(
as.vector(data_T),
as.vector(res1)
)
expect_equal(
res1,
res2
)
expect_equal(
res1,
res3
)
})
#################################################################
#################################################################
#################################################################
test_that("2.a. depending dim is indices(); depended dim is indices()", {
suppressWarnings(
data <- Start(dat = path,
var = 'tos',
sdate = indices(57:59), # 2016, 2017, 2018
chunk = indices(2:4),
chunk_depends = 'sdate',
time = 'all',
i = indices(450:452),
j = indices(650:651),
time_across = 'chunk',
return_vars = list(time = 'sdate'),
retrieve = F)
)
fun <- function(x) {
return(x)
}
step <- Step(fun = fun,
target_dims = 'dat', output_dims = 'dat')
wf <- AddStep(inputs = data, step_fun = step)
suppressWarnings(
res1 <- Compute(workflow = wf, chunks = list(chunk = 2))$output1
)
suppressWarnings(
res2 <- Compute(workflow = wf, chunks = list(sdate = 2))$output1
)
suppressWarnings(
res3 <- Compute(workflow = wf, chunks = list(chunk = 2, sdate = 2))$output1
)
expect_equal(
as.vector(data_T),
as.vector(res1)
)
expect_equal(
res1,
res2
)
expect_equal(
res1,
res3
)
})
#################################################################
#################################################################
#################################################################
test_that("2.b. depending dim is indices(); depended dim is list of values", {
chunks <- list('2016' = c("201701-201712","201801-201812","201901-201912"),
'2017' = c("201801-201812","201901-201912","202001-202012"),
'2018' = c("201901-201912","202001-202012","202101-202112"))
expect_error(
suppressWarnings(
Start(dat = path,
var = 'tos',
sdate = indices(57:59), # 2016, 2017, 2018
chunk = chunks,
chunk_depends = 'sdate',
time = 'all',
i = indices(450:452),
j = indices(650:651),
time_across = 'chunk',
return_vars = list(time = 'sdate'),
retrieve = F)),
"The depended dimension, chunk, is explictly defined by a list of values, while the depending dimension, sdate, is not explictly defined. Specify sdate by characters."
)
})