Skip to content
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: Add a test for passing event names via pandas.DataFrame #2582

Merged
merged 5 commits into from
Jun 24, 2023
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outs:
- md5: 81203f9e3a43ec235cf4b5068f928b56
size: 10689
path: test_meca_dict_eventname.png
path: test_meca_eventname.png
62 changes: 48 additions & 14 deletions pygmt/tests/test_meca.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import numpy as np
import pandas as pd
import pytest
from pygmt import Figure
from packaging.version import Version
from pygmt import Figure, __gmt_version__
from pygmt.helpers import GMTTempFile


Expand Down Expand Up @@ -179,22 +180,55 @@ def test_meca_offset(inputtype):
return fig


@pytest.mark.mpl_image_compare
def test_meca_dict_eventname():
# Passing event names via pandas doesn't work for GMT<=6.4, thus marked as
# xfail. See https://github.com/GenericMappingTools/pygmt/issues/2524.
@pytest.mark.mpl_image_compare(filename="test_meca_eventname.png")
@pytest.mark.parametrize(
"inputtype",
[
"args",
pytest.param(
"dataframe",
marks=pytest.mark.skipif(
condition=Version(__gmt_version__) < Version("6.5.0"),
reason="Upstream bug fixed in https://github.com/GenericMappingTools/gmt/pull/7557",
),
),
],
)
def test_meca_eventname(inputtype):
"""
Test offsetting beachballs for a dict input.
Test passing event names.
"""
if inputtype == "args":
args = {
"spec": {"strike": 330, "dip": 30, "rake": 90, "magnitude": 3},
"longitude": -124,
"latitude": 48,
"depth": 12.0,
"event_name": "Event20220311",
}
elif inputtype == "dataframe":
# Test pandas.DataFrame input. Requires GMT>=6.5.
# See https://github.com/GenericMappingTools/pygmt/issues/2524.
# The numeric columns must be in float type to trigger the bug.
args = {
"spec": pd.DataFrame(
{
"longitude": [-124.0],
"latitude": [48.0],
"depth": [12.0],
"strike": [330.0],
"dip": [30.0],
"rake": [90.0],
"magnitude": [3.0],
"event_name": ["Event20220311"],
}
)
}
fig = Figure()
focal_mechanism = {"strike": 330, "dip": 30, "rake": 90, "magnitude": 3}
fig.basemap(region=[-125, -122, 47, 49], projection="M6c", frame=True)
fig.meca(
spec=focal_mechanism,
scale="1c",
longitude=-124,
latitude=48,
depth=12.0,
event_name="Event20220311",
)
fig.meca(scale="1c", **args)
return fig


Expand All @@ -219,7 +253,7 @@ def test_meca_dict_offset_eventname():
return fig


@pytest.mark.mpl_image_compare(filename="test_meca_dict_eventname.png")
@pytest.mark.mpl_image_compare(filename="test_meca_eventname.png")
def test_meca_spec_dict_all_scalars():
"""
Test supplying a dict with scalar values for all focal parameters.
Expand Down