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
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, ]),
as.vector(seq(as.POSIXct('1961-01-01 12:00:00', tz = 'UTC'), as.POSIXct('1961-12-31 12:00:00', tz = 'UTC'), by = 'day'))
as.vector(dates[2, ]),
as.vector(seq(as.POSIXct('1962-01-01 12:00:00', tz = 'UTC'), as.POSIXct('1962-12-31 12:00:00', tz = 'UTC'), by = 'day'))
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
)
})
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(
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
as.vector(dates),
as.vector(seq(as.POSIXct('1961-01-01 12:00:00', tz = 'UTC'), as.POSIXct('1961-12-31 12:00:00', tz = 'UTC'), by = 'day'))
)
})
test_that("3. time across fyear, fyear depends on sdate, 1st fyear is empty, 3rd fyear has more indices than 2nd one, 1964 is leap year", {
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 = 700:860, ## 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 = 161)
)
expect_equal(
names(attributes(dates)),
c('variables', 'dim', 'class', 'tzone')
)
expect_equal(
class(dates),
c("POSIXct", "POSIXt")
)
expect_equal(
as.vector(dates[1, ]),
as.vector(seq(as.POSIXct('1962-10-01 12:00:00', tz = 'UTC'), as.POSIXct('1963-03-10 12:00:00', tz = 'UTC'), by = 'day'))
)
expect_equal(
as.vector(dates[2, ]),
as.vector(seq(as.POSIXct('1963-10-01 12:00:00', tz = 'UTC'), as.POSIXct('1964-03-09 12:00:00', tz = 'UTC'), by = 'day'))