-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_plot2d_icon.py
More file actions
141 lines (119 loc) · 4.21 KB
/
Copy pathtest_plot2d_icon.py
File metadata and controls
141 lines (119 loc) · 4.21 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
"""Test module for the 2D plot of icon files."""
# SPDX-FileCopyrightText: 2021-2024 Helmholtz-Zentrum Hereon
# SPDX-FileCopyrightText: 2020-2021 Helmholtz-Zentrum Geesthacht
# SPDX-FileCopyrightText: 2016-2024 University of Lausanne
#
# SPDX-License-Identifier: LGPL-3.0-only
import os
import _base_testing as bt
import matplotlib.pyplot as plt
import numpy as np
import test_base as tb
import test_plot2d as t2d
from psyplot import InteractiveList
bold = tb.bold
class IconTestMixin(object):
"""A mixin class for changed test methods for icon"""
def ref_datagrid(self, close=True):
"""Create reference file for datagrid formatoption
Create reference file for
:attr:`~psy_simple.plotters.Simple2DPlotter.datagrid`
formatoption"""
sp = self.plot()
sp.update(datagrid="k-")
sp.export(os.path.join(bt.ref_dir, self.get_ref_file("datagrid")))
if close:
sp.close(True, True)
def test_datagrid(self, *args):
"""Test datagrid formatoption"""
self.update(datagrid="k-")
self.compare_figures(next(iter(args), self.get_ref_file("datagrid")))
def test_xlabel(self):
"""Test xlabel formatoption"""
self.update(xlabel="{desc}")
label = self.plotter.ax.xaxis.get_label()
self.assertIn("longitude [radian]", label.get_text())
self.update(
labelsize=22, labelweight="bold", labelprops={"ha": "left"}
)
self.assertEqual(label.get_size(), 22)
self.assertEqual(label.get_weight(), bold)
self.assertEqual(label.get_ha(), "left")
def test_ylabel(self):
"""Test ylabel formatoption"""
self.update(ylabel="{desc}")
label = self.plotter.ax.yaxis.get_label()
self.assertIn("latitude [radian]", label.get_text())
self.update(
labelsize=22, labelweight="bold", labelprops={"ha": "left"}
)
self.assertEqual(label.get_size(), 22)
self.assertEqual(label.get_weight(), bold)
self.assertEqual(label.get_ha(), "left")
def _test_DataTicksCalculator(self):
# testing of psy_simple.plotters.DataTicksCalculator
ax = plt.gca()
if isinstance(self.data, InteractiveList):
data = self.data[0]
else:
data = self.data
try:
lon = data.clon.values
except AttributeError:
lon = data.elon.values
self.update(xticks="rounded")
self.assertEqual(
list(ax.get_xticks()),
np.linspace(-3, 3.5, 11, endpoint=True).tolist(),
)
self.update(xticks="roundedsym")
self.assertEqual(
list(ax.get_xticks()),
np.linspace(-3.5, 3.5, 10, endpoint=True).tolist(),
)
self.update(xticks="minmax")
self.assertEqual(
list(ax.get_xticks()),
np.linspace(lon.min(), lon.max(), 11, endpoint=True).tolist(),
)
self.update(xticks="sym")
vmax = np.abs(lon).max()
self.assertEqual(
list(ax.get_xticks()),
np.linspace(-vmax, vmax, 10, endpoint=True).tolist(),
)
class IconSimplePlotterTest(IconTestMixin, t2d.Simple2DPlotterTest):
"""Test :class:`psy_simple.plotters.Simple2DPlotter` class for icon grid"""
grid_type = "icon"
masking_val = 280
ncfile = os.path.join(bt.test_dir, "icon_test.nc")
def test_bounds(self):
"""Test bounds formatoption"""
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries,
np.linspace(240, 310, 11, endpoint=True),
atol=1e-2,
)
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.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries, bounds, atol=1e-2
)
self.update(bounds=["rounded", 5, 5, 95])
self.assertAlmostArrayEqual(
self.plotter.bounds.norm.boundaries,
np.linspace(255, 305, 5, endpoint=True).tolist(),
atol=1e-2,
)