Skip to content

Commit 86137ce

Browse files
authored
Fix missing gcmt convention keys in pygmt.meca (#1611)
Adds the 'rake1' and 'strike2' keys to the global CMT (gcmt) convention, and add a unit test adapted from https://docs.generic-mapping-tools.org/6.2/supplements/seis/meca.html#examples. * Remove an unneeded if-statement and pylint disable argument
1 parent 2ebe165 commit 86137ce

File tree

3 files changed

+61
-23
lines changed

3 files changed

+61
-23
lines changed

pygmt/src/meca.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def data_format_code(convention, component="full"):
110110
)
111111
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
112112
def meca(
113-
self, # pylint: disable=unused-argument
113+
self,
114114
spec,
115115
scale,
116116
longitude=None,
@@ -249,7 +249,16 @@ def update_pointers(data_pointers):
249249

250250
param_conventions = {
251251
"AKI": ["strike", "dip", "rake", "magnitude"],
252-
"GCMT": ["strike1", "dip1", "dip2", "rake2", "mantissa", "exponent"],
252+
"GCMT": [
253+
"strike1",
254+
"dip1",
255+
"rake1",
256+
"strike2",
257+
"dip2",
258+
"rake2",
259+
"mantissa",
260+
"exponent",
261+
],
253262
"MT": ["mrr", "mtt", "mff", "mrt", "mrf", "mtf", "exponent"],
254263
"PARTIAL": ["strike1", "dip1", "strike2", "fault_type", "magnitude"],
255264
"PRINCIPAL_AXIS": [
@@ -275,23 +284,21 @@ def update_pointers(data_pointers):
275284
"plot_latitude": plot_latitude,
276285
}
277286

278-
# make a DataFrame copy to check convention if it contains
279-
# other parameters
280-
if isinstance(spec, (dict, pd.DataFrame)):
281-
# check if a copy is necessary
282-
copy = False
283-
drop_list = []
284-
for pointer in data_pointers:
285-
if pointer in spec:
286-
copy = True
287-
drop_list.append(pointer)
288-
if copy:
289-
spec_conv = spec.copy()
290-
# delete optional parameters from copy for convention check
291-
for item in drop_list:
292-
del spec_conv[item]
293-
else:
294-
spec_conv = spec
287+
# make a DataFrame copy to check convention if it contains other params
288+
# check if a copy is necessary
289+
copy = False
290+
drop_list = []
291+
for pointer in data_pointers:
292+
if pointer in spec:
293+
copy = True
294+
drop_list.append(pointer)
295+
if copy:
296+
spec_conv = spec.copy()
297+
# delete optional parameters from copy for convention check
298+
for item in drop_list:
299+
del spec_conv[item]
300+
else:
301+
spec_conv = spec
295302

296303
# set convention and focal parameters based on spec convention
297304
for conv in list(param_conventions):
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
outs:
2+
- md5: a44dc0f1af50958aeff2d359ea8b03a7
3+
size: 8732
4+
path: test_meca_gcmt_convention.png

pygmt/tests/test_meca.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
"""
22
Tests for meca.
33
"""
4-
import os
5-
64
import numpy as np
75
import pandas as pd
86
import pytest
97
from pygmt import Figure
108
from pygmt.helpers import GMTTempFile
119

12-
TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
13-
1410

1511
@pytest.mark.mpl_image_compare
1612
def test_meca_spec_dictionary():
@@ -210,3 +206,34 @@ def test_meca_loc_array():
210206
projection="M14c",
211207
)
212208
return fig
209+
210+
211+
@pytest.mark.mpl_image_compare
212+
def test_meca_gcmt_convention():
213+
"""
214+
Test plotting beachballs using the global CMT convention.
215+
"""
216+
fig = Figure()
217+
# specify focal mechanisms
218+
focal_mechanisms = dict(
219+
strike1=180,
220+
dip1=18,
221+
rake1=-88,
222+
strike2=0,
223+
dip2=72,
224+
rake2=-90,
225+
mantissa=5.5,
226+
exponent=0,
227+
)
228+
fig.meca(
229+
spec=focal_mechanisms,
230+
scale="1c",
231+
longitude=239.384,
232+
latitude=34.556,
233+
depth=12,
234+
convention="gcmt",
235+
region=[239, 240, 34, 35.2],
236+
projection="m2.5c",
237+
frame=True,
238+
)
239+
return fig

0 commit comments

Comments
 (0)