Skip to content

Fix missing gcmt convention keys in pygmt.meca #1611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions pygmt/src/meca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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": [
Expand All @@ -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)):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that this if-statement is unnecessary, because this code block is already nested under an if isinstance(spec, (dict, pd.DataFrame)) statement at L143 above, and there doesn't seem to be any modifications made to the spec variable in between. Please double-check if this looks ok.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Looks great

# 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):
Expand Down
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_meca_gcmt_convention.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: a44dc0f1af50958aeff2d359ea8b03a7
size: 8732
path: test_meca_gcmt_convention.png
35 changes: 31 additions & 4 deletions pygmt/tests/test_meca.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down Expand Up @@ -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