-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_plotters_vectorplotter_icon.py
More file actions
executable file
·140 lines (120 loc) · 4.33 KB
/
Copy pathtest_plotters_vectorplotter_icon.py
File metadata and controls
executable file
·140 lines (120 loc) · 4.33 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
"""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_vectorplotter as tpv
from psy_maps.plotters import InteractiveList
class IconVectorPlotterTest(tpv.VectorPlotterTest):
"""Test :class:`psyplot.plotter.maps.VectorPlotter` class for icon grid"""
grid_type = "icon"
ncfile = os.path.join(bt.test_dir, "icon_test.nc")
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[0].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")))
@unittest.skip(
"Density for quiver plots of unstructered data is not " "supported!"
)
def ref_density(self):
pass
@unittest.skip(
"Density for quiver plots of unstructered data is not " "supported!"
)
def test_density(self):
pass
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.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_bounds(self):
"""Test bounds formatoption"""
self.update(color="absolute")
self.assertEqual(
np.round(self.plotter.bounds.norm.boundaries, 2).tolist(),
np.linspace(0.5, 9.5, 11, endpoint=True).tolist(),
)
self.update(bounds="minmax")
bounds = [
0.66,
1.51,
2.36,
3.21,
4.05,
4.9,
5.75,
6.59,
7.44,
8.29,
9.14,
]
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.round(np.linspace(1.0, 8.0, 5, endpoint=True), 2).tolist(),
)
class IconVectorPlotterTest2D(bt.TestBase2D, IconVectorPlotterTest):
"""Test :class:`psyplot.plotter.maps.VectorPlotter` class for icon grid
without time and vertical dimension"""
var = ["u_2d", "v_2d"]
if __name__ == "__main__":
unittest.main()