-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_plotters_fieldplotter_icon.py
More file actions
executable file
·150 lines (129 loc) · 4.71 KB
/
Copy pathtest_plotters_fieldplotter_icon.py
File metadata and controls
executable file
·150 lines (129 loc) · 4.71 KB
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
"""Test module of the :mod:`psyplot.plotter.maps` module"""
# SPDX-FileCopyrightText: 2016-2024 University of Lausanne
# SPDX-FileCopyrightText: 2020-2021 Helmholtz-Zentrum Geesthacht
# SPDX-FileCopyrightText: 2021-2024 Helmholtz-Zentrum hereon GmbH
#
# SPDX-License-Identifier: LGPL-3.0-only
import os
import unittest
from itertools import repeat, starmap
import _base_testing as bt
import cartopy.crs as ccrs
import numpy as np
import test_plotters_fieldplotter as tpf
from psy_maps.plotters import InteractiveList
class IconFieldPlotterTest(tpf.FieldPlotterTest):
"""Test :class:`psyplot.plotter.maps.FieldPlotter` class for icon grid"""
grid_type = "icon"
ncfile = os.path.join(bt.test_dir, "icon_test.nc")
def test_bounds(self):
"""Test bounds formatoption"""
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(),
np.linspace(240, 310, 11, endpoint=True).tolist(),
)
self.update(bounds="minmax")
bounds = [
243.76,
250.04,
256.31,
262.58,
268.85,
275.12,
281.39,
287.66,
293.94,
300.21,
306.48,
]
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(), bounds
)
self.update(bounds=["rounded", 5, 5, 95])
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(),
np.linspace(255, 305, 5, endpoint=True).tolist(),
)
def test_transpose(self):
raw = next(self.plotter.plot.iter_raw_data)
xcoord = raw.psy.get_coord("x").name
ycoord = raw.psy.get_coord("y").name
self.plotter.update(transpose=True)
for raw, arr in zip(
self.plotter.plot.iter_raw_data, self.plotter.plot.iter_data
):
self.assertEqual(self.plotter.plot.xcoord.name, ycoord)
self.assertEqual(self.plotter.plot.ycoord.name, xcoord)
def test_lonlatbox(self, *args):
"""Test lonlatbox formatoption"""
def get_unmasked(coord):
"""return the values of the coordinate that is not masked in the
data"""
return coord.values[~np.isnan(data.values)]
self.update(lonlatbox="Europe|India", map_extent="data")
ax = self.plotter.ax
list(
starmap(
self.assertAlmostEqual,
zip(
ax.get_extent(ccrs.PlateCarree()),
(-32.0, 97.0, -8.0, 81.0),
repeat(5),
repeat("Failed to set the extent to Europe and India!"),
),
)
)
# test whether latitudes and longitudes succeded
msg = "Failed to fit into lonlatbox limits for %s of %s."
if isinstance(self.plotter.plot_data, InteractiveList):
all_data = self.plotter.plot_data
else:
all_data = [self.plotter.plot_data]
for data in all_data:
self.assertGreaterEqual(
get_unmasked(data.clon).min(),
-32.0,
msg=msg % ("longitude", "minimum"),
)
self.assertLessEqual(
get_unmasked(data.clon).max(),
97.0,
msg=msg % ("longitude", "maximum"),
)
self.assertGreaterEqual(
get_unmasked(data.clat).min(),
-8.0,
msg=msg % ("latitude", "minimum"),
)
self.assertLessEqual(
get_unmasked(data.clat).max(),
81.0,
msg=msg % ("latitude", "maximum"),
)
self.compare_figures(next(iter(args), self.get_ref_file("lonlatbox")))
def ref_pole(self):
"""Test whether the grid cells are correctly displayed at the pole"""
sp = self.plot()
sp.update(
projection="northpole",
lonlatbox=[-180, 180, 80, 90],
cmap="viridis",
datagrid="r-",
)
sp.export(os.path.join(bt.ref_dir, self.get_ref_file("pole")))
sp.close(True, True, True)
def test_pole(self):
"""Test whether the grid cells are correctly displayed at the pole"""
self.update(
projection="northpole",
lonlatbox=[-180, 180, 80, 90],
cmap="viridis",
datagrid="r-",
)
self.compare_figures(self.get_ref_file("pole"))
class IconFieldPlotterTest2D(bt.TestBase2D, IconFieldPlotterTest):
"""Test :class:`psyplot.plotter.maps.FieldPlotter` class for icon grid
without time and vertical dimension"""
var = "t2m_2d"
if __name__ == "__main__":
unittest.main()