-
Notifications
You must be signed in to change notification settings - Fork 214
/
test_makecpt.py
170 lines (137 loc) · 4.31 KB
/
test_makecpt.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
"""
Test pygmt.makecpt.
"""
from pathlib import Path
import numpy as np
import pytest
from pygmt import Figure, makecpt
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import GMTTempFile
POINTS_DATA = Path(__file__).parent / "data" / "points.txt"
@pytest.fixture(scope="module", name="points")
def fixture_points():
"""
Load the points data from the test file.
"""
return np.loadtxt(POINTS_DATA)
@pytest.fixture(scope="module", name="position")
def fixture_position():
"""
Return a standard position argument for the colorbar.
"""
return "x0c/0c+w10c+h"
@pytest.mark.mpl_image_compare
def test_makecpt_plot_points(points):
"""
Use static color palette table to change color of points.
"""
fig = Figure()
makecpt(cmap="rainbow")
fig.plot(
x=points[:, 0],
y=points[:, 1],
fill=points[:, 2],
region=[10, 70, -5, 10],
style="c1c",
cmap=True,
)
return fig
@pytest.mark.mpl_image_compare
def test_makecpt_plot_colorbar(position):
"""
Use static color palette table to plot a colorbar.
"""
fig = Figure()
makecpt(cmap="relief")
fig.colorbar(cmap=True, frame=True, position=position)
return fig
@pytest.mark.mpl_image_compare
def test_makecpt_plot_colorbar_scaled_with_series(position):
"""
Use static color palette table scaled to a min/max series and plot it on a colorbar.
"""
fig = Figure()
makecpt(cmap="oleron", series=[0, 1000])
fig.colorbar(cmap=True, frame=True, position=position)
return fig
@pytest.mark.benchmark
def test_makecpt_output_cpt_file():
"""
Save the generated static color palette table to a .cpt file.
"""
with GMTTempFile(suffix=".cpt") as cptfile:
makecpt(output=cptfile.name)
assert Path(cptfile.name).stat().st_size > 0
def test_makecpt_blank_output():
"""
Use incorrect setting by passing in blank file name to output parameter.
"""
with pytest.raises(GMTInvalidInput):
makecpt(output="")
def test_makecpt_invalid_output():
"""
Use incorrect setting by passing in invalid type to output parameter.
"""
with pytest.raises(GMTInvalidInput):
makecpt(output=["some.cpt"])
@pytest.mark.mpl_image_compare
def test_makecpt_truncated_zlow_zhigh(position):
"""
Use static color palette table that is truncated to z-low and z-high.
"""
fig = Figure()
makecpt(cmap="rainbow", truncate=[0.15, 0.85], series=[0, 1000])
fig.colorbar(cmap=True, frame=True, position=position)
return fig
@pytest.mark.mpl_image_compare
def test_makecpt_reverse_color_only(position):
"""
Use static color palette table with its colors reversed.
"""
fig = Figure()
makecpt(cmap="earth", reverse=True, series=[0, 1000])
fig.colorbar(cmap=True, frame=True, position=position)
return fig
@pytest.mark.mpl_image_compare
def test_makecpt_reverse_color_and_zsign(position):
"""
Use static color palette table with both its colors and z-value sign reversed.
"""
fig = Figure()
makecpt(cmap="earth", reverse="cz", series=[0, 1000])
fig.colorbar(cmap=True, frame=True, position=position)
return fig
@pytest.mark.mpl_image_compare
def test_makecpt_continuous(position):
"""
Use static color palette table that is continuous from blue to white and scaled from
0 to 1000 m.
"""
fig = Figure()
makecpt(cmap="blue,white", continuous=True, series=[0, 1000])
fig.colorbar(cmap=True, frame=True, position=position)
return fig
@pytest.mark.mpl_image_compare
def test_makecpt_categorical(position):
"""
Use static color palette table that is categorical.
"""
fig = Figure()
makecpt(cmap="categorical", categorical=True, series=[0, 6, 1])
fig.colorbar(cmap=True, frame=True, position=position)
return fig
@pytest.mark.mpl_image_compare
def test_makecpt_cyclic(position):
"""
Use static color palette table that is cyclic.
"""
fig = Figure()
makecpt(cmap="cork", cyclic=True)
fig.colorbar(cmap=True, frame=True, position=position)
return fig
def test_makecpt_categorical_and_cyclic():
"""
Use incorrect setting by setting both categorical and cyclic to True.
"""
with pytest.raises(GMTInvalidInput):
makecpt(cmap="batlow", categorical=True, cyclic=True)