Skip to content

Commit a63525c

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

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,33 @@ 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+
See https://github.com/GenericMappingTools/pygmt/issues/2016.
262+
"""
263+
fig = Figure()
264+
focal_mechanism = dict(
265+
strike=330,
266+
dip=30,
267+
rake=90,
268+
magnitude=3,
269+
plot_longitude=-124.5,
270+
plot_latitude=47.5,
271+
)
272+
fig.basemap(region=[-125, -122, 47, 49], projection="M6c", frame=True)
273+
fig.meca(
274+
spec=focal_mechanism,
275+
scale="1c",
276+
longitude=-124,
277+
latitude=48,
278+
depth=12.0,
279+
)
280+
return fig
281+
282+
256283
@pytest.mark.mpl_image_compare
257284
def test_meca_dict_eventname():
258285
"""

0 commit comments

Comments
 (0)