Skip to content

Commit 2b167a9

Browse files
committed
Figure.meca: Fix beachball offsetting with dict/pandas inputs
1 parent cc532f1 commit 2b167a9

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

pygmt/src/meca.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ def meca(
273273
if depth is not None:
274274
spec["depth"] = np.atleast_1d(depth)
275275
if plot_longitude is not None: # must be in string type
276-
spec["plot_longitude"] = np.atleast_1d(plot_longitude).astype(str)
276+
spec["plot_longitude"] = np.atleast_1d(plot_longitude)
277277
if plot_latitude is not None: # must be in string type
278-
spec["plot_latitude"] = np.atleast_1d(plot_latitude).astype(str)
278+
spec["plot_latitude"] = np.atleast_1d(plot_latitude)
279279
if event_name is not None:
280280
spec["event_name"] = np.atleast_1d(event_name).astype(str)
281281

@@ -293,9 +293,13 @@ def meca(
293293
newcols = ["longitude", "latitude", "depth"] + param_conventions[convention]
294294
if "plot_longitude" in spec.columns and "plot_latitude" in spec.columns:
295295
newcols += ["plot_longitude", "plot_latitude"]
296+
spec[["plot_longitude", "plot_latitude"]] = spec[
297+
["plot_longitude", "plot_latitude"]
298+
].astype(str)
296299
kwargs["A"] = True
297300
if "event_name" in spec.columns:
298301
newcols += ["event_name"]
302+
spec["event_name"] = spec["event_name"].astype(str)
299303
# reorder columns in DataFrame
300304
spec = spec.reindex(newcols, axis=1)
301305
elif isinstance(spec, np.ndarray) and spec.ndim == 1:

pygmt/tests/test_meca.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,34 @@ def test_meca_dict_offset():
253253
return fig
254254

255255

256+
@pytest.mark.mpl_image_compare(filename="test_meca_dict_offset.png")
257+
def test_meca_dict_offset_in_dict():
258+
"""
259+
Test offsetting beachballs for a dict input with offset parameters in the
260+
dict.
261+
262+
See https://github.com/GenericMappingTools/pygmt/issues/2016.
263+
"""
264+
fig = Figure()
265+
focal_mechanism = dict(
266+
strike=330,
267+
dip=30,
268+
rake=90,
269+
magnitude=3,
270+
plot_longitude=-124.5,
271+
plot_latitude=47.5,
272+
)
273+
fig.basemap(region=[-125, -122, 47, 49], projection="M6c", frame=True)
274+
fig.meca(
275+
spec=focal_mechanism,
276+
scale="1c",
277+
longitude=-124,
278+
latitude=48,
279+
depth=12.0,
280+
)
281+
return fig
282+
283+
256284
@pytest.mark.mpl_image_compare
257285
def test_meca_dict_eventname():
258286
"""

0 commit comments

Comments
 (0)