-
Notifications
You must be signed in to change notification settings - Fork 224
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
Figure.meca: Refactor tests for plotting a single focal mechanism #2533
Changes from 9 commits
19b39f2
0e6d51d
fe63bc4
d91f514
f789117
1a7eb66
44f346b
632b928
0c6bc53
abe334e
47e61d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
outs: | ||
- md5: fc7c271049fc8583914b508c4bee08fe | ||
size: 9830 | ||
path: test_meca_spec_single_focalmecha.png |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,24 +8,73 @@ | |
from pygmt.helpers import GMTTempFile | ||
|
||
|
||
@pytest.mark.mpl_image_compare | ||
def test_meca_spec_dictionary(): | ||
@pytest.mark.mpl_image_compare(filename="test_meca_spec_single_focalmecha.png") | ||
@pytest.mark.parametrize("inputtype", ["dict_mecha", "dict_full", "array1d", "pandas"]) | ||
def test_meca_spec_single_focalmecha(inputtype): | ||
""" | ||
Test passing a single focal mechanism to the spec parameter. | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Different |
||
if inputtype == "dict_mecha": | ||
args = { | ||
"spec": {"strike": 0, "dip": 90, "rake": 0, "magnitude": 5}, | ||
"longitude": 0, | ||
"latitude": 5, | ||
"depth": 0, | ||
} | ||
elif inputtype == "dict_full": | ||
args = { | ||
"spec": { | ||
"longitude": 0, | ||
"latitude": 5, | ||
"depth": 0, | ||
"strike": 0, | ||
"dip": 90, | ||
"rake": 0, | ||
"magnitude": 5, | ||
} | ||
} | ||
elif inputtype == "array1d": | ||
args = { | ||
"spec": np.array([0, 5, 0, 0, 90, 0, 5]), | ||
"convention": "a", | ||
} | ||
elif inputtype == "pandas": | ||
args = { | ||
"spec": pd.DataFrame( | ||
{ | ||
"longitude": 0, | ||
"latitude": 5, | ||
"depth": 0, | ||
"strike": 0, | ||
"dip": 90, | ||
"rake": 0, | ||
"magnitude": 5, | ||
}, | ||
index=[0], | ||
) | ||
} | ||
fig = Figure() | ||
fig.basemap(region=[-1, 1, 4, 6], projection="M8c", frame=2) | ||
fig.meca(scale="2.5c", **args) | ||
return fig | ||
|
||
|
||
@pytest.mark.mpl_image_compare(filename="test_meca_spec_single_focalmecha.png") | ||
def test_meca_spec_single_focalmecha_file(): | ||
""" | ||
Test supplying a dictionary containing a single focal mechanism to the spec | ||
Test supplying a file containing focal mechanisms and locations to the spec | ||
parameter. | ||
""" | ||
fig = Figure() | ||
# Right lateral strike slip focal mechanism | ||
fig.meca( | ||
spec={"strike": 0, "dip": 90, "rake": 0, "magnitude": 5}, | ||
longitude=0, | ||
latitude=5, | ||
depth=0, | ||
scale="2.5c", | ||
region=[-1, 1, 4, 6], | ||
projection="M14c", | ||
frame=2, | ||
) | ||
fig.basemap(region=[-1, 1, 4, 6], projection="M8c", frame=2) | ||
with GMTTempFile() as temp: | ||
with open(temp.name, mode="w", encoding="utf8") as temp_file: | ||
temp_file.write("0 5 0 0 90 0 5") | ||
fig.meca( | ||
spec=temp.name, | ||
convention="aki", | ||
scale="2.5c", | ||
) | ||
return fig | ||
|
||
|
||
|
@@ -83,44 +132,6 @@ def test_meca_spec_dataframe(): | |
return fig | ||
|
||
|
||
@pytest.mark.mpl_image_compare | ||
def test_meca_spec_1d_array(): | ||
""" | ||
Test supplying a 1-D numpy array containing focal mechanisms and locations | ||
to the spec parameter. | ||
""" | ||
fig = Figure() | ||
# supply focal mechanisms to meca as a 1-D numpy array, here we are using | ||
# the Harvard CMT zero trace convention but the focal mechanism | ||
# parameters may be specified any of the available conventions. Since we | ||
# are not using a dict or dataframe the convention and component should | ||
# be specified. | ||
focal_mechanism = [ | ||
-127.40, # longitude | ||
40.87, # latitude | ||
12, # depth | ||
-3.19, # mrr | ||
0.16, # mtt | ||
3.03, # mff | ||
-1.02, # mrt | ||
-3.93, # mrf | ||
-0.02, # mtf | ||
23, # exponent | ||
0, # plot_lon, 0 to plot at event location | ||
0, # plot_lat, 0 to plot at event location | ||
] | ||
focal_mech_array = np.asarray(focal_mechanism) | ||
fig.meca( | ||
spec=focal_mech_array, | ||
convention="mt", | ||
component="full", | ||
region=[-128, -127, 40, 41], | ||
scale="2c", | ||
projection="M14c", | ||
) | ||
return fig | ||
|
||
|
||
@pytest.mark.mpl_image_compare | ||
def test_meca_spec_2d_array(): | ||
""" | ||
|
@@ -151,30 +162,6 @@ def test_meca_spec_2d_array(): | |
return fig | ||
|
||
|
||
@pytest.mark.mpl_image_compare | ||
def test_meca_spec_file(): | ||
""" | ||
Test supplying a file containing focal mechanisms and locations to the spec | ||
parameter. | ||
""" | ||
fig = Figure() | ||
focal_mechanism = [-127.43, 40.81, 12, -3.19, 1.16, 3.93, -1.02, -3.93, -1.02, 23] | ||
# writes temp file to pass to gmt | ||
with GMTTempFile() as temp: | ||
with open(temp.name, mode="w", encoding="utf8") as temp_file: | ||
temp_file.write(" ".join([str(x) for x in focal_mechanism])) | ||
# supply focal mechanisms to meca as a file | ||
fig.meca( | ||
spec=temp.name, | ||
convention="mt", | ||
component="full", | ||
region=[-128, -127, 40, 41], | ||
scale="2c", | ||
projection="M14c", | ||
) | ||
return fig | ||
|
||
|
||
@pytest.mark.mpl_image_compare | ||
def test_meca_loc_array(): | ||
""" | ||
|
@@ -207,37 +194,6 @@ def test_meca_loc_array(): | |
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 = { | ||
"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 | ||
|
||
|
||
@pytest.mark.mpl_image_compare | ||
def test_meca_dict_offset(): | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generated markdown for this is
![](pygmt/tests/baseline-new/test_meca_spec_single_focalmecha.png)
which doesn't show up since it points to a local path. Need to update this somehow?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's this deprecation warning on https://github.com/GenericMappingTools/pygmt/actions/runs/5107768299/jobs/9180964772#step:6:55:
Looks like we should be using
cml comment --publish=true
instead now, xref https://cml.dev/doc/ref/comment?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah wait, just noticed you did try to use
cml comment
in 0c6bc53. Nevermind then.