-
Notifications
You must be signed in to change notification settings - Fork 283
/
test_grib_load.py
230 lines (190 loc) · 7.99 KB
/
test_grib_load.py
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
220
221
222
223
224
225
226
227
228
229
230
# Copyright Iris contributors
#
# This file is part of Iris and is released under the LGPL license.
# See COPYING and COPYING.LESSER in the root of the repository for full
# licensing details.
"""
Integration tests for grib2 file loading.
This code used to be part of 'tests/test_grib_load.py', but these integration-
style tests have been split out of there.
The remainder of the old 'tests/test_grib_load.py' is now renamed as
'tests/test_grib_load_translations.py'. Those tests are implementation-
specific, and target the module 'iris_grib'.
"""
# Import iris tests first so that some things can be initialised before
# importing anything else
import iris.tests as tests
import iris
import iris.exceptions
import iris.tests.stock
import iris.util
from unittest import skipIf
# Skip out some tests that fail now that grib edition 2 files no longer use
# the GribWrapper.
# TODO: either fix these problems, or remove the tests.
skip_irisgrib_fails = skipIf(
True, "Test(s) are not currently usable with the new " "grib 2 loader."
)
@tests.skip_data
@tests.skip_grib
class TestBasicLoad(tests.GraphicsTest):
def test_load_rotated(self):
cubes = iris.load(
tests.get_data_path(("GRIB", "rotated_uk", "uk_wrongparam.grib1"))
)
self.assertCML(cubes, ("grib_load", "rotated.cml"))
def test_load_time_bound(self):
cubes = iris.load(
tests.get_data_path(("GRIB", "time_processed", "time_bound.grib1"))
)
self.assertCML(cubes, ("grib_load", "time_bound_grib1.cml"))
def test_load_time_processed(self):
cubes = iris.load(
tests.get_data_path(("GRIB", "time_processed", "time_bound.grib2"))
)
self.assertCML(cubes, ("grib_load", "time_bound_grib2.cml"))
def test_load_3_layer(self):
cubes = iris.load(
tests.get_data_path(("GRIB", "3_layer_viz", "3_layer.grib2"))
)
cubes = iris.cube.CubeList([cubes[1], cubes[0], cubes[2]])
self.assertCML(cubes, ("grib_load", "3_layer.cml"))
def test_load_masked(self):
gribfile = tests.get_data_path(
("GRIB", "missing_values", "missing_values.grib2")
)
cubes = iris.load(gribfile)
self.assertCML(cubes, ("grib_load", "missing_values_grib2.cml"))
@skip_irisgrib_fails
def test_y_fastest(self):
cubes = iris.load(
tests.get_data_path(("GRIB", "y_fastest", "y_fast.grib2"))
)
self.assertCML(cubes, ("grib_load", "y_fastest.cml"))
def test_polar_stereo_grib1(self):
cube = iris.load_cube(
tests.get_data_path(("GRIB", "polar_stereo", "ST4.2013052210.01h"))
)
self.assertCML(cube, ("grib_load", "polar_stereo_grib1.cml"))
def test_polar_stereo_grib2_grid_definition(self):
cube = iris.load_cube(
tests.get_data_path(
(
"GRIB",
"polar_stereo",
"CMC_glb_TMP_ISBL_1015_ps30km_2013052000_P006.grib2",
)
)
)
self.assertEqual(cube.shape, (200, 247))
pxc = cube.coord("projection_x_coordinate")
self.assertAlmostEqual(pxc.points.max(), 4769905.5125, places=4)
self.assertAlmostEqual(pxc.points.min(), -2610094.4875, places=4)
pyc = cube.coord("projection_y_coordinate")
self.assertAlmostEqual(pyc.points.max(), -216.1459, places=4)
self.assertAlmostEqual(pyc.points.min(), -5970216.1459, places=4)
self.assertEqual(pyc.coord_system, pxc.coord_system)
self.assertEqual(pyc.coord_system.grid_mapping_name, "stereographic")
self.assertEqual(pyc.coord_system.central_lat, 90.0)
self.assertEqual(pyc.coord_system.central_lon, 249.0)
self.assertEqual(pyc.coord_system.false_easting, 0.0)
self.assertEqual(pyc.coord_system.false_northing, 0.0)
self.assertEqual(pyc.coord_system.true_scale_lat, 60.0)
def test_lambert_grib1(self):
cube = iris.load_cube(
tests.get_data_path(("GRIB", "lambert", "lambert.grib1"))
)
self.assertCML(cube, ("grib_load", "lambert_grib1.cml"))
def test_lambert_grib2(self):
cube = iris.load_cube(
tests.get_data_path(("GRIB", "lambert", "lambert.grib2"))
)
self.assertCML(cube, ("grib_load", "lambert_grib2.cml"))
def test_regular_gg_grib1(self):
cube = iris.load_cube(
tests.get_data_path(("GRIB", "gaussian", "regular_gg.grib1"))
)
self.assertCML(cube, ("grib_load", "regular_gg_grib1.cml"))
def test_regular_gg_grib2(self):
cube = iris.load_cube(
tests.get_data_path(("GRIB", "gaussian", "regular_gg.grib2"))
)
self.assertCML(cube, ("grib_load", "regular_gg_grib2.cml"))
def test_reduced_ll(self):
cube = iris.load_cube(
tests.get_data_path(("GRIB", "reduced", "reduced_ll.grib1"))
)
self.assertCML(cube, ("grib_load", "reduced_ll_grib1.cml"))
def test_reduced_gg(self):
cube = iris.load_cube(
tests.get_data_path(("GRIB", "reduced", "reduced_gg.grib2"))
)
self.assertCML(cube, ("grib_load", "reduced_gg_grib2.cml"))
@tests.skip_data
@tests.skip_grib
class TestIjDirections(tests.GraphicsTest):
@staticmethod
def _old_compat_load(name):
cube = iris.load(tests.get_data_path(("GRIB", "ij_directions", name)))[
0
]
return [cube]
def test_ij_directions_ipos_jpos(self):
cubes = self._old_compat_load("ipos_jpos.grib2")
self.assertCML(cubes, ("grib_load", "ipos_jpos.cml"))
def test_ij_directions_ipos_jneg(self):
cubes = self._old_compat_load("ipos_jneg.grib2")
self.assertCML(cubes, ("grib_load", "ipos_jneg.cml"))
def test_ij_directions_ineg_jneg(self):
cubes = self._old_compat_load("ineg_jneg.grib2")
self.assertCML(cubes, ("grib_load", "ineg_jneg.cml"))
def test_ij_directions_ineg_jpos(self):
cubes = self._old_compat_load("ineg_jpos.grib2")
self.assertCML(cubes, ("grib_load", "ineg_jpos.cml"))
@tests.skip_data
@tests.skip_grib
class TestShapeOfEarth(tests.GraphicsTest):
@staticmethod
def _old_compat_load(name):
cube = iris.load(
tests.get_data_path(("GRIB", "shape_of_earth", name))
)[0]
return cube
def test_shape_of_earth_basic(self):
# pre-defined sphere
cube = self._old_compat_load("0.grib2")
self.assertCML(cube, ("grib_load", "earth_shape_0.cml"))
def test_shape_of_earth_custom_1(self):
# custom sphere
cube = self._old_compat_load("1.grib2")
self.assertCML(cube, ("grib_load", "earth_shape_1.cml"))
def test_shape_of_earth_IAU65(self):
# IAU65 oblate sphere
cube = self._old_compat_load("2.grib2")
self.assertCML(cube, ("grib_load", "earth_shape_2.cml"))
def test_shape_of_earth_custom_3(self):
# custom oblate spheroid (km)
cube = self._old_compat_load("3.grib2")
self.assertCML(cube, ("grib_load", "earth_shape_3.cml"))
def test_shape_of_earth_IAG_GRS80(self):
# IAG-GRS80 oblate spheroid
cube = self._old_compat_load("4.grib2")
self.assertCML(cube, ("grib_load", "earth_shape_4.cml"))
def test_shape_of_earth_WGS84(self):
# WGS84
cube = self._old_compat_load("5.grib2")
self.assertCML(cube, ("grib_load", "earth_shape_5.cml"))
def test_shape_of_earth_pre_6(self):
# pre-defined sphere
cube = self._old_compat_load("6.grib2")
self.assertCML(cube, ("grib_load", "earth_shape_6.cml"))
def test_shape_of_earth_custom_7(self):
# custom oblate spheroid (m)
cube = self._old_compat_load("7.grib2")
self.assertCML(cube, ("grib_load", "earth_shape_7.cml"))
def test_shape_of_earth_grib1(self):
# grib1 - same as grib2 shape 6, above
cube = self._old_compat_load("global.grib1")
self.assertCML(cube, ("grib_load", "earth_shape_grib1.cml"))
if __name__ == "__main__":
tests.main()