Hello,
I am trying to plot a set of focal mechanisms over a map; however, I get an error that I have not been able to solve.
I have tried loading a dictionary or a file in the “spec” option and it does not work. Even I have tried with the same example on the pygmt gallery.
This is a test example that generates an error:
focal_mechanism = dict(strike=330, dip=30, rake=90, magnitude=3)
fig.meca(focal_mechanism, scale=“1c”, longitude=-124.3, latitude=48.1, depth=12.0)
This is the error message I am getting:
"
Traceback (most recent call last):
File “/home/camilo/PhD/Simulations/codes/venv/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 3378, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File “”, line 1, in
fig.meca(‘test_meca.txt’, convention = ‘aki’, scale=“1.0c”)
File “/home/camilo/PhD/Simulations/codes/venv/lib/python3.10/site-packages/pygmt/helpers/decorators.py”, line 598, in new_module
return module_func(*args, **kwargs)
File “/home/camilo/PhD/Simulations/codes/venv/lib/python3.10/site-packages/pygmt/helpers/decorators.py”, line 738, in new_module
return module_func(*args, **kwargs)
File “/home/camilo/PhD/Simulations/codes/venv/lib/python3.10/site-packages/pygmt/src/meca.py”, line 339, in meca
lib.call_module(module=“meca”, args=build_arg_string(kwargs, infile=fname))
File “/home/camilo/PhD/Simulations/codes/venv/lib/python3.10/site-packages/pygmt/clib/session.py”, line 530, in call_module
raise GMTCLibError(
pygmt.exceptions.GMTCLibError: Module ‘meca’ failed with status code 45:
"
Thank you very much for your help.
Best wishes,
Camilo
Hello @cpinilla,
Welcome to the GMT forum
!
As your code example is incomplete, it is a bit difficult to say what is going wrong in detail.
Maybe you can also provide your input file “test_meca.txt”?
In your code example, arguments for the region, projection, and frame parameters are missing.
Beside specifying those within pygmt.Figure.meca you can also use pygmt.Figure.basemap (pygmt.Figure.basemap — PyGMT) or pygmt.Figure.coast (pygmt.Figure.coast — PyGMT, see also gallery example Focal mechanisms — PyGMT).
Code example:
import pygmt
focal_mechanism = dict(strike=330, dip=30, rake=90, magnitude=3)
# Create figure object
fig = pygmt.Figure()
# Plot beachball
fig.meca(
region=[-128, -122, 46, 50], # lon_min_E, lon_max_E, lat_min_N, lat_max_N
projection="M10c", # Mercator projection with width of 10 centimeters
frame=True, # Use default frame settings
spec=focal_mechanism,
scale="1c",
longitude=-124.3,
latitude=48.1,
depth=12.0,
)
# Show and save figure
fig.show()
# fig.savefig(fname="plot_meca_dict.png")
Output figure:
Hi Yvone,
Thank you for replying. I have already set up the map, with all the features I want. I just want to add the focal mechanism.
By running your code, I have the same error as before. I do not know if I should include some library or flag during the cmake compilation of GMT, considering some modifications to my virtual environment … I do not know. Here is the error message.
Traceback (most recent call last):
File “/home/camilo/PhD/Simulations/codes/venv/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 3378, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File “”, line 13, in
fig.meca(
File “/home/camilo/PhD/Simulations/codes/venv/lib/python3.10/site-packages/pygmt/helpers/decorators.py”, line 598, in new_module
return module_func(*args, **kwargs)
File “/home/camilo/PhD/Simulations/codes/venv/lib/python3.10/site-packages/pygmt/helpers/decorators.py”, line 738, in new_module
return module_func(*args, **kwargs)
File “/home/camilo/PhD/Simulations/codes/venv/lib/python3.10/site-packages/pygmt/src/meca.py”, line 339, in meca
lib.call_module(module=“meca”, args=build_arg_string(kwargs, infile=fname))
File “/home/camilo/PhD/Simulations/codes/venv/lib/python3.10/site-packages/pygmt/clib/session.py”, line 530, in call_module
raise GMTCLibError(
pygmt.exceptions.GMTCLibError: Module ‘meca’ failed with status code 45:
Hi,
I had the same issue with the version 6.5.0 of GMT and pygmt version 0.16.0
Finally the problem was caused by the library path of the GMT because the meca module is provided in the supplements library (lib/gmt/plugin/supplements.so).
So make sure that the path of the GMT library (lib/libgmt.so) and its supplements (lib/gmt/plugin/supplements.so) are available in your LD_LIBRARY_PATH
I hope it can help