Skip to content

Commit

Permalink
Figure.meca: Add a test for passing event names via pandas.DataFrame (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman authored Jun 24, 2023
1 parent 857472e commit dde23f1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
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

0 comments on commit dde23f1

Please sign in to comment.