diff --git a/pygmt/src/meca.py b/pygmt/src/meca.py index 6aed8b029ca..ed93deb02b0 100644 --- a/pygmt/src/meca.py +++ b/pygmt/src/meca.py @@ -110,7 +110,7 @@ def data_format_code(convention, component="full"): ) @kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence") def meca( - self, # pylint: disable=unused-argument + self, spec, scale, longitude=None, @@ -249,7 +249,16 @@ def update_pointers(data_pointers): param_conventions = { "AKI": ["strike", "dip", "rake", "magnitude"], - "GCMT": ["strike1", "dip1", "dip2", "rake2", "mantissa", "exponent"], + "GCMT": [ + "strike1", + "dip1", + "rake1", + "strike2", + "dip2", + "rake2", + "mantissa", + "exponent", + ], "MT": ["mrr", "mtt", "mff", "mrt", "mrf", "mtf", "exponent"], "PARTIAL": ["strike1", "dip1", "strike2", "fault_type", "magnitude"], "PRINCIPAL_AXIS": [ @@ -275,23 +284,21 @@ def update_pointers(data_pointers): "plot_latitude": plot_latitude, } - # make a DataFrame copy to check convention if it contains - # other parameters - if isinstance(spec, (dict, pd.DataFrame)): - # check if a copy is necessary - copy = False - drop_list = [] - for pointer in data_pointers: - if pointer in spec: - copy = True - drop_list.append(pointer) - if copy: - spec_conv = spec.copy() - # delete optional parameters from copy for convention check - for item in drop_list: - del spec_conv[item] - else: - spec_conv = spec + # make a DataFrame copy to check convention if it contains other params + # check if a copy is necessary + copy = False + drop_list = [] + for pointer in data_pointers: + if pointer in spec: + copy = True + drop_list.append(pointer) + if copy: + spec_conv = spec.copy() + # delete optional parameters from copy for convention check + for item in drop_list: + del spec_conv[item] + else: + spec_conv = spec # set convention and focal parameters based on spec convention for conv in list(param_conventions): diff --git a/pygmt/tests/baseline/test_meca_gcmt_convention.png.dvc b/pygmt/tests/baseline/test_meca_gcmt_convention.png.dvc new file mode 100644 index 00000000000..b8a2c1c6022 --- /dev/null +++ b/pygmt/tests/baseline/test_meca_gcmt_convention.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: a44dc0f1af50958aeff2d359ea8b03a7 + size: 8732 + path: test_meca_gcmt_convention.png diff --git a/pygmt/tests/test_meca.py b/pygmt/tests/test_meca.py index 9364cf23845..0742c08b970 100644 --- a/pygmt/tests/test_meca.py +++ b/pygmt/tests/test_meca.py @@ -1,16 +1,12 @@ """ Tests for meca. """ -import os - import numpy as np import pandas as pd import pytest from pygmt import Figure from pygmt.helpers import GMTTempFile -TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data") - @pytest.mark.mpl_image_compare def test_meca_spec_dictionary(): @@ -210,3 +206,34 @@ def test_meca_loc_array(): projection="M14c", ) return fig + + +@pytest.mark.mpl_image_compare +def test_meca_gcmt_convention(): + """ + Test plotting beachballs using the global CMT convention. + """ + fig = Figure() + # specify focal mechanisms + focal_mechanisms = dict( + strike1=180, + dip1=18, + rake1=-88, + strike2=0, + dip2=72, + rake2=-90, + mantissa=5.5, + exponent=0, + ) + fig.meca( + spec=focal_mechanisms, + scale="1c", + longitude=239.384, + latitude=34.556, + depth=12, + convention="gcmt", + region=[239, 240, 34, 35.2], + projection="m2.5c", + frame=True, + ) + return fig