4
4
import numpy as np
5
5
import pandas as pd
6
6
import pytest
7
- from pygmt import Figure
7
+ from packaging .version import Version
8
+ from pygmt import Figure , __gmt_version__
8
9
from pygmt .helpers import GMTTempFile
9
10
10
11
@@ -179,22 +180,55 @@ def test_meca_offset(inputtype):
179
180
return fig
180
181
181
182
182
- @pytest .mark .mpl_image_compare
183
- def test_meca_dict_eventname ():
183
+ # Passing event names via pandas doesn't work for GMT<=6.4, thus marked as
184
+ # xfail. See https://github.com/GenericMappingTools/pygmt/issues/2524.
185
+ @pytest .mark .mpl_image_compare (filename = "test_meca_eventname.png" )
186
+ @pytest .mark .parametrize (
187
+ "inputtype" ,
188
+ [
189
+ "args" ,
190
+ pytest .param (
191
+ "dataframe" ,
192
+ marks = pytest .mark .skipif (
193
+ condition = Version (__gmt_version__ ) < Version ("6.5.0" ),
194
+ reason = "Upstream bug fixed in https://github.com/GenericMappingTools/gmt/pull/7557" ,
195
+ ),
196
+ ),
197
+ ],
198
+ )
199
+ def test_meca_eventname (inputtype ):
184
200
"""
185
- Test offsetting beachballs for a dict input .
201
+ Test passing event names .
186
202
"""
203
+ if inputtype == "args" :
204
+ args = {
205
+ "spec" : {"strike" : 330 , "dip" : 30 , "rake" : 90 , "magnitude" : 3 },
206
+ "longitude" : - 124 ,
207
+ "latitude" : 48 ,
208
+ "depth" : 12.0 ,
209
+ "event_name" : "Event20220311" ,
210
+ }
211
+ elif inputtype == "dataframe" :
212
+ # Test pandas.DataFrame input. Requires GMT>=6.5.
213
+ # See https://github.com/GenericMappingTools/pygmt/issues/2524.
214
+ # The numeric columns must be in float type to trigger the bug.
215
+ args = {
216
+ "spec" : pd .DataFrame (
217
+ {
218
+ "longitude" : [- 124.0 ],
219
+ "latitude" : [48.0 ],
220
+ "depth" : [12.0 ],
221
+ "strike" : [330.0 ],
222
+ "dip" : [30.0 ],
223
+ "rake" : [90.0 ],
224
+ "magnitude" : [3.0 ],
225
+ "event_name" : ["Event20220311" ],
226
+ }
227
+ )
228
+ }
187
229
fig = Figure ()
188
- focal_mechanism = {"strike" : 330 , "dip" : 30 , "rake" : 90 , "magnitude" : 3 }
189
230
fig .basemap (region = [- 125 , - 122 , 47 , 49 ], projection = "M6c" , frame = True )
190
- fig .meca (
191
- spec = focal_mechanism ,
192
- scale = "1c" ,
193
- longitude = - 124 ,
194
- latitude = 48 ,
195
- depth = 12.0 ,
196
- event_name = "Event20220311" ,
197
- )
231
+ fig .meca (scale = "1c" , ** args )
198
232
return fig
199
233
200
234
@@ -219,7 +253,7 @@ def test_meca_dict_offset_eventname():
219
253
return fig
220
254
221
255
222
- @pytest .mark .mpl_image_compare (filename = "test_meca_dict_eventname .png" )
256
+ @pytest .mark .mpl_image_compare (filename = "test_meca_eventname .png" )
223
257
def test_meca_spec_dict_all_scalars ():
224
258
"""
225
259
Test supplying a dict with scalar values for all focal parameters.
0 commit comments