From 0e8f083dc9c5ea6e3a2b94756fe35390e581b14b Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sun, 7 Nov 2021 14:23:40 +1300 Subject: [PATCH 1/4] Fix missing gcmt convention keys in pygmt.meca 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. --- pygmt/src/meca.py | 11 ++++++- .../test_meca_gcmt_convention.png.dvc | 4 +++ pygmt/tests/test_meca.py | 33 +++++++++++++++++-- 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 pygmt/tests/baseline/test_meca_gcmt_convention.png.dvc diff --git a/pygmt/src/meca.py b/pygmt/src/meca.py index 6aed8b029ca..0da115ea352 100644 --- a/pygmt/src/meca.py +++ b/pygmt/src/meca.py @@ -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": [ 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..8964839c537 100644 --- a/pygmt/tests/test_meca.py +++ b/pygmt/tests/test_meca.py @@ -9,8 +9,6 @@ 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 +208,34 @@ def test_meca_loc_array(): projection="M14c", ) return fig + + +@pytest.mark.mpl_image_compare +def test_meca_spec_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 From 45ef883a5ecf20dc66fb8a5d4e1539543eb3c228 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sun, 7 Nov 2021 14:29:00 +1300 Subject: [PATCH 2/4] Remove unused os module --- pygmt/tests/test_meca.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pygmt/tests/test_meca.py b/pygmt/tests/test_meca.py index 8964839c537..beb9f78d99a 100644 --- a/pygmt/tests/test_meca.py +++ b/pygmt/tests/test_meca.py @@ -1,8 +1,6 @@ """ Tests for meca. """ -import os - import numpy as np import pandas as pd import pytest From 0dbea69c217ea7697c8530891c2998f9b2faddc6 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sun, 7 Nov 2021 14:41:17 +1300 Subject: [PATCH 3/4] Fix incorrect test name --- pygmt/tests/test_meca.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/tests/test_meca.py b/pygmt/tests/test_meca.py index beb9f78d99a..0742c08b970 100644 --- a/pygmt/tests/test_meca.py +++ b/pygmt/tests/test_meca.py @@ -209,7 +209,7 @@ def test_meca_loc_array(): @pytest.mark.mpl_image_compare -def test_meca_spec_gcmt_convention(): +def test_meca_gcmt_convention(): """ Test plotting beachballs using the global CMT convention. """ From b59c03a1580bd0d60d9387699e828600402825a1 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sun, 7 Nov 2021 23:53:02 +1300 Subject: [PATCH 4/4] Remove an unneeded if-statement and pylint disable argument --- pygmt/src/meca.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/pygmt/src/meca.py b/pygmt/src/meca.py index 0da115ea352..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, @@ -284,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):