@@ -68,20 +68,23 @@ def test_earth_mag_02m_without_region():
68
68
69
69
def test_earth_mag_incorrect_resolution_registration ():
70
70
"""
71
- Test that an error is raised when trying to load a grid registration with
72
- an unavailable resolution.
71
+ Test that an error is raised when trying to load a EMAG2 grid registration
72
+ with an unavailable resolution.
73
73
"""
74
74
with pytest .raises (GMTInvalidInput ):
75
75
load_earth_magnetic_anomaly (
76
- resolution = "02m" , region = [0 , 1 , 3 , 5 ], registration = "gridline" , mag4km = False
76
+ resolution = "02m" ,
77
+ region = [0 , 1 , 3 , 5 ],
78
+ registration = "gridline" ,
79
+ data_source = "emag2_4km" ,
77
80
)
78
81
79
82
80
83
def test_earth_mag4km_01d ():
81
84
"""
82
85
Test some properties of the magnetic anomaly 4km 01d data.
83
86
"""
84
- data = load_earth_magnetic_anomaly (resolution = "01d" , mag4km = True )
87
+ data = load_earth_magnetic_anomaly (resolution = "01d" , data_source = "emag2_4km" )
85
88
assert data .name == "magnetic_anomaly"
86
89
assert data .attrs ["long_name" ] == "Earth magnetic anomaly"
87
90
assert data .attrs ["units" ] == "nT"
@@ -102,7 +105,7 @@ def test_earth_mag4km_01d_with_region():
102
105
resolution = "01d" ,
103
106
region = [- 10 , 10 , - 5 , 5 ],
104
107
registration = "gridline" ,
105
- mag4km = True ,
108
+ data_source = "emag2_4km" ,
106
109
)
107
110
assert data .shape == (11 , 21 )
108
111
npt .assert_allclose (data .lat , np .arange (- 5 , 6 , 1 ))
@@ -125,3 +128,102 @@ def test_earth_mag_02m_default_registration():
125
128
npt .assert_allclose (data .coords ["lon" ].data .max (), - 9.01666667 )
126
129
npt .assert_allclose (data .min (), - 231 )
127
130
npt .assert_allclose (data .max (), 131.79999 )
131
+
132
+ data = load_earth_magnetic_anomaly (
133
+ resolution = "05m" ,
134
+ region = [- 115 , - 112 , 4 , 6 ],
135
+ registration = "gridline" ,
136
+ data_source = "emag2_4km" ,
137
+ )
138
+ assert data .shape == (25 , 37 )
139
+ assert data .lat .min () == 4
140
+ assert data .lat .max () == 6
141
+ assert data .lon .min () == - 115
142
+ assert data .lon .max () == - 112
143
+ npt .assert_allclose (data .min (), - 128.40015 )
144
+ npt .assert_allclose (data .max (), 76.80005 )
145
+
146
+
147
+ def test_earth_mag_01d_wdmam ():
148
+ """
149
+ Test some properties of the WDMAM 01d data.
150
+ """
151
+ data = load_earth_magnetic_anomaly (
152
+ resolution = "01d" , registration = "gridline" , data_source = "wdmam"
153
+ )
154
+ assert data .name == "wdmam"
155
+ assert data .attrs ["long_name" ] == "World Digital Magnetic Anomaly Map"
156
+ assert data .attrs ["units" ] == "nT"
157
+ assert data .attrs ["horizontal_datum" ] == "WGS84"
158
+ assert data .shape == (181 , 361 )
159
+ npt .assert_allclose (data .lat , np .arange (- 90 , 91 , 1 ))
160
+ npt .assert_allclose (data .lon , np .arange (- 180 , 181 , 1 ))
161
+ npt .assert_allclose (data .min (), - 773.5 )
162
+ npt .assert_allclose (data .max (), 1751.3 )
163
+
164
+
165
+ def test_earth_mag_01d_wdmam_with_region ():
166
+ """
167
+ Test loading low-resolution WDMAM grid with 'region'.
168
+ """
169
+ data = load_earth_magnetic_anomaly (
170
+ resolution = "01d" ,
171
+ region = [- 10 , 10 , - 5 , 5 ],
172
+ registration = "gridline" ,
173
+ data_source = "wdmam" ,
174
+ )
175
+ assert data .shape == (11 , 21 )
176
+ npt .assert_allclose (data .lat , np .arange (- 5 , 6 , 1 ))
177
+ npt .assert_allclose (data .lon , np .arange (- 10 , 11 , 1 ))
178
+ npt .assert_allclose (data .min (), - 103.900024 )
179
+ npt .assert_allclose (data .max (), 102.19995 )
180
+
181
+
182
+ def test_earth_mag_03m_wdmam_with_region ():
183
+ """
184
+ Test loading a subregion of high-resolution WDMAM data.
185
+ """
186
+ data = load_earth_magnetic_anomaly (
187
+ resolution = "03m" , region = [10 , 13 , - 60 , - 58 ], data_source = "wdmam"
188
+ )
189
+ assert data .gmt .registration == 0
190
+ assert data .shape == (41 , 61 )
191
+ assert data .lat .min () == - 60
192
+ assert data .lat .max () == - 58
193
+ assert data .lon .min () == 10
194
+ assert data .lon .max () == 13
195
+ npt .assert_allclose (data .min (), - 639.7001 )
196
+ npt .assert_allclose (data .max (), 629.6 )
197
+
198
+
199
+ def test_earth_mag_05m_wdmam_without_region ():
200
+ """
201
+ Test loading a high-resolution WDMAM grid without passing 'region'.
202
+ """
203
+ with pytest .raises (GMTInvalidInput ):
204
+ load_earth_magnetic_anomaly (
205
+ resolution = "05m" , registration = "gridline" , data_source = "wdmam"
206
+ )
207
+
208
+
209
+ def test_earth_mag_wdmam_incorrect_resolution_registration ():
210
+ """
211
+ Test that an error is raised when trying to load a WDMAM grid registration
212
+ with an unavailable resolution.
213
+ """
214
+ with pytest .raises (GMTInvalidInput ):
215
+ load_earth_magnetic_anomaly (
216
+ resolution = "03m" ,
217
+ region = [0 , 1 , 3 , 5 ],
218
+ registration = "pixel" ,
219
+ data_source = "wdmam" ,
220
+ )
221
+
222
+
223
+ def test_earth_mag_data_source_error ():
224
+ """
225
+ Test that an error is raised when an invalid argument is passed to
226
+ 'data_source'.
227
+ """
228
+ with pytest .raises (GMTInvalidInput ):
229
+ load_earth_magnetic_anomaly (resolution = "01d" , data_source = "invalid" )
0 commit comments