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
# This unit test tests the consistence between list of indices and vector of indices.
# 1. transform
# 2. no transform
# 3. transform, indices reversed
# 4. no transform, indices reversed
context("List of indices and vector of indices")
test_that("1. transform", {
# lat and lon are lists of indices
suppressWarnings(
exp1 <- Start(dat = '/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc',
var = 'tas',
sdate = '20000101',
ensemble = indices(1),
time = indices(1),
latitude = indices(list(1, 30)),
latitude_reorder = Sort(),
longitude = indices(list(1, 40)),
longitude_reorder = CircularSort(0, 360),
transform = CDORemapper,
transform_params = list(grid = 'r100x50',
method = 'con',
crop = c(0, 11, -90, -81)),
transform_vars = c('latitude', 'longitude'),
transform_extra_cells = 8,
synonims = list(latitude = c('lat', 'latitude'),
longitude = c('longitude', 'lon')),
return_vars = list(latitude = NULL,
longitude = NULL,
time = 'sdate'),
retrieve= T)
)
# lat and lon are vectors of indices
suppressWarnings(
exp2 <- Start(dat = '/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc',
var = 'tas',
sdate = '20000101',
ensemble = indices(1),
time = indices(1),
latitude = 1:30,
latitude_reorder = Sort(),
longitude = 1:40,
longitude_reorder = CircularSort(0, 360),
transform = CDORemapper,
transform_params = list(grid = 'r100x50',
method = 'con',
crop = c(0, 11, -90, -81)),
transform_vars = c('latitude', 'longitude'),
transform_extra_cells = 8,
synonims = list(latitude = c('lat', 'latitude'),
longitude = c('longitude', 'lon')),
return_vars = list(latitude = NULL,
longitude = NULL,
time = 'sdate'),
retrieve= T)
)
expect_equal(
as.vector(exp1),
as.vector(exp2)
)
})
#############################################################
#############################################################
#############################################################
test_that("2. no transform", {
# lat and lon are lists of indices
suppressWarnings(
exp1 <- Start(dat = '/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc',
var = 'tas',
sdate = '20000101',
ensemble = indices(1),
time = indices(1),
latitude = indices(list(1, 30)),
latitude_reorder = Sort(),
longitude = indices(list(1, 40)),
longitude_reorder = CircularSort(0, 360),
synonims = list(latitude = c('lat', 'latitude'),
longitude = c('longitude', 'lon')),
return_vars = list(latitude = NULL,
longitude = NULL,
time = 'sdate'),
retrieve= T)
)
# lat and lon are vectors of indices
suppressWarnings(
exp2 <- Start(dat = '/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc',
var = 'tas',
sdate = '20000101',
ensemble = indices(1),
time = indices(1),
latitude = 1:30,
latitude_reorder = Sort(),
longitude = 1:40,
longitude_reorder = CircularSort(0, 360),
synonims = list(latitude = c('lat', 'latitude'),
longitude = c('longitude', 'lon')),
return_vars = list(latitude = NULL,
longitude = NULL,
time = 'sdate'),
retrieve= T)
)
expect_equal(
as.vector(exp1),
as.vector(exp2)
)
})
#############################################################
#############################################################
#############################################################
# PROBLEM:
# latitude is -81 to -88.2 now, but it should be 81 to 88.2 because the indices is retrieved first then do the transform (aiat = F); and it should be ascending.
# .. ..$ latitude : num [1:3(1d)] -81 -84.6 -88.2
#test_that("3. transform, indices reverse", {
#
## lat and lon are lists of indices
#exp1 <- Start(dat = '/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc',
# var = 'tas',
# sdate = '20000101',
# ensemble = indices(1),
# time = indices(1),
# latitude = indices(list(30, 1)),
# longitude = indices(list(1, 40)), # can't reverse. Different meaning
# longitude_reorder = CircularSort(0, 360),
# transform = CDORemapper,
# transform_params = list(grid = 'r100x50',
# method = 'con',
# crop = c(0, 11, -90, -81)),
# transform_vars = c('latitude', 'longitude'),
# transform_extra_cells = 8,
# synonims = list(latitude = c('lat', 'latitude'),
# longitude = c('longitude', 'lon')),
# return_vars = list(latitude = NULL,
# longitude = NULL,
# time = 'sdate'),
# retrieve= T)
#)
#
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
## This test is not valid because it doesn't make sense to use longitude = 40:1. With the automatic "crop" values, the result is not correct.
### lat and lon are vectors of indices
##suppressWarnings(
##exp2 <- Start(dat = '/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc',
## var = 'tas',
## sdate = '20000101',
## ensemble = indices(1),
## time = indices(1),
## latitude = 30:1,
## latitude_reorder = Sort(),
## longitude = 40:1,
## longitude_reorder = CircularSort(0, 360),
## transform = CDORemapper,
## transform_params = list(grid = 'r100x50',
## method = 'con',
## crop = c(0, 11, -90, -81)),
## transform_vars = c('latitude', 'longitude'),
## transform_extra_cells = 8,
## synonims = list(latitude = c('lat', 'latitude'),
## longitude = c('longitude', 'lon')),
## return_vars = list(latitude = NULL,
## longitude = NULL,
## time = 'sdate'),
## retrieve= T)
##)
##
##expect_equal(
##as.vector(drop(exp1)[, 4:1]),
##as.vector(exp2)
##)
#
#})
################################################################
################################################################
################################################################
test_that("4. no transform, indices reverse", {
# lat and lon are lists of indices
suppressWarnings(
exp1 <- Start(dat = '/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc',
var = 'tas',
sdate = '20000101',
ensemble = indices(1),
time = indices(1),
latitude = indices(list(30, 1)),
latitude_reorder = Sort(),
longitude = indices(list(1, 40)), # can't reverse. different meaning
longitude_var = 'longitude',
longitude_reorder = CircularSort(0, 360),
synonims = list(latitude = c('lat', 'latitude'),
longitude = c('longitude', 'lon')),
return_vars = list(latitude = NULL,
longitude = NULL,
time = 'sdate'),
retrieve= T)
)
# lat and lon are vectors of indices
suppressWarnings(
exp2 <- Start(dat = '/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc',
var = 'tas',
sdate = '20000101',
ensemble = indices(1),
time = indices(1),
latitude = 30:1,
latitude_reorder = Sort(),
longitude = 40:1,
longitude_reorder = CircularSort(0, 360),
synonims = list(latitude = c('lat', 'latitude'),
longitude = c('longitude', 'lon')),
return_vars = list(latitude = NULL,
longitude = NULL,
time = 'sdate'),
retrieve= T)
)
expect_equal(