You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
beachball offsetting doesn't work for pandas/dict/ndarray input #2016
I am trying to plot focal mechanisms on a map with an offset. I’ve tried to follow the tips given here:
[ PyGMT: How to offset focal mechanism beachballs?]
but still cannot get it to work, the two beachballs in the southeast are still plotted on top of each other, although there is no error message.
My file contains the columns
longitude latitude depth strike dip rake magnitude plot_longitude plot_latitude
and columns are separated by tabs:
👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.
The meca() function is known to have issues/limitations in old PyGMT versions. We have fully rewritten the meca function after v0.7.0. Please try to install the PyGMT dev version using the following command:
I upgraded to v0.7.0 . I am not sure that I understand you correctly. I don't mind reading in the file in separately, I only mind that I cannot offset the beachballs. If that also will not work in the dev-version, I'd rather stick to the normal version, or does it? (It does not seem to work in v0.7.0, either.)
changed the title [-]Pygmt psmeca beachball - no offset despite following tips from previous post[/-][+]beachball offsetting doesn't work for pandas input[/+]on Jul 20, 2022
changed the title [-]beachball offsetting doesn't work for pandas input[/-][+]beachball offsetting doesn't work for pandas/dict input[/+]on Jul 20, 2022
As a workaround for PyGMT v0.7.0, if you can set your plot_longitude and plot_latitude values to a str type (i.e. wrapping your numbers in quotes like '53'), then the beachball offset should work. E.g. using @yvonnefroehlich's code at #2016 (comment)
Notice how the beachball is now at 53N instead of 52N. For those using pandas.DataFrame inputs, there should be a way to convert your plot_longitude and plot_latitude columns to str type too using astype. Something like df["plot_longitude"].astype(dtype=str").
This will be fixed properly in #2202 (so that numeric int/float inputs will work) and should be available in the upcoming PyGMT v0.8.0. Thanks @seisman for identifying the issue!
changed the title [-]beachball offsetting doesn't work for pandas/dict input[/-][+]beachball offsetting doesn't work for pandas/dict/ndarray input[/+]on Nov 25, 2022
As a workaround for PyGMT v0.7.0, if you can set your plot_longitude and plot_latitude values to a str type (i.e. wrapping your numbers in quotes like '53'), then the beachball offset should work. E.g. using @yvonnefroehlich's code at #2016 (comment)
For me stetting the arguments for plot_longitude and plot_latitude into quotation marks (i.e. string input) does not work with PyGMT v0.7.0 and GMT 6.4.0:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\envs\pygmt_env_070_640\lib\site-packages\spyder_kernels\py3compat.py", line 356, in compat_exec
exec(code, globals, locals)
File "c:\users\admin\c2\eigenedokumente\studium\promotion\e_gmt\00_testing\issuse_meca_offset\meca_offset_line.py", line 62, in <module>
fig.meca(
File "C:\ProgramData\Anaconda3\envs\pygmt_env_070_640\lib\site-packages\pygmt\helpers\decorators.py", line 585, in new_module
return module_func(*args, **kwargs)
File "C:\ProgramData\Anaconda3\envs\pygmt_env_070_640\lib\site-packages\pygmt\helpers\decorators.py", line 725, in new_module
return module_func(*args, **kwargs)
File "C:\ProgramData\Anaconda3\envs\pygmt_env_070_640\lib\site-packages\pygmt\src\meca.py", line 466, in meca
with file_context as fname:
File "C:\ProgramData\Anaconda3\envs\pygmt_env_070_640\lib\contextlib.py", line 119, in __enter__
return next(self.gen)
File "C:\ProgramData\Anaconda3\envs\pygmt_env_070_640\lib\site-packages\pygmt\clib\session.py", line 1259, in virtualfile_from_matrix
self.put_matrix(dataset, matrix)
File "C:\ProgramData\Anaconda3\envs\pygmt_env_070_640\lib\site-packages\pygmt\clib\session.py", line 901, in put_matrix
raise GMTCLibError(f"Failed to put matrix of type {matrix.dtype}.")
GMTCLibError: Failed to put matrix of type <U11.
An other aspect is, that the line and the small circle are not plotted or modified via the offset parameter (see https://www.pygmt.org/dev/api/generated/pygmt.Figure.meca.html#pygmt.Figure.meca) when passing a dictionary to spec (see case (II)). It works when reading the focal mechanism data from a text file (see case (I)). In both cases a PyGMT dev version (after PR #2202 was megerd) was used.
Example script
importpygmt#------------------------------------------------------------------------------# (I) read focal mechanism data from input file (aki convention)fig=pygmt.Figure()
fig.basemap(
region=[-5, 5, -5, 5],
projection="X10c",
frame="afg",
)
fig.meca(
spec="gmt_meca_doc.txt",
scale="1c",
offset="+p1p,green+s0.5c", # line thickness and color, size of circleconvention="aki",
)
fig.show()
# fig.savefig(fname="meca_offset_line_file.png")# ------------------------------------------------------------------------------# (II) use dictionary to provided focal mechanism data (aki convention)dict_meca= {
"longitude": 0,
"latitude": 0,
"depth": 12,
"strike": 330,
"dip": 30,
"rake": 90,
"magnitude": 5,
"plot_longitude": 2,
"plot_latitude": 2,
}
fig=pygmt.Figure()
fig.basemap(
region=[-5, 5, -5, 5],
projection="X10c",
frame="afg",
)
fig.meca(
spec=dict_meca,
convention="aki",
scale="1c",
offset="+p1p,green+s0.5c", # line thickness and color, size of circle
)
fig.show()
# fig.savefig(fname="meca_offset_line_dict.png")
Output figure for (I) reading a txt file (expectation)
Can we close this issue? It should be now (hopefully) fixed by #2202 and Figure.meca: Fix line and circle of offset parameter for dict/pandas input #2226.
Beachball offsetting may still fail for ndarray input. Need some time to test.
Can we close this issue? It should be now (hopefully) fixed by #2202 and Figure.meca: Fix line and circle of offset parameter for dict/pandas input #2226.
Beachball offsetting may still fail for ndarray input. Need some time to test.
Thanks! I see the updated issue title. Hm, then bump this back to v0.9.0 🙂?
Activity
welcome commentedon Jul 19, 2022
👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.
seisman commentedon Jul 19, 2022
The
meca()function is known to have issues/limitations in old PyGMT versions. We have fully rewritten themecafunction after v0.7.0. Please try to install the PyGMT dev version using the following command:After installing the PyGMT dev version, you'll see that it still doesn't work as expected, but at least setting
spec="FM_ISC_exampleplot.txt"works.MsDannie76 commentedon Jul 20, 2022
Hi,
I upgraded to v0.7.0 . I am not sure that I understand you correctly. I don't mind reading in the file in separately, I only mind that I cannot offset the beachballs. If that also will not work in the dev-version, I'd rather stick to the normal version, or does it? (It does not seem to work in v0.7.0, either.)
seisman commentedon Jul 20, 2022
The following script works for me with both PyGMT v0.7.0 and the dev version:
The output image is:
MsDannie76 commentedon Jul 20, 2022
OK, great, thanks! It now works for me in v0.7.0 as well as long as I directly read the file using meca and not go via pandas.
[-]Pygmt psmeca beachball - no offset despite following tips from previous post[/-][+]beachball offsetting doesn't work for pandas input[/+]yvonnefroehlich commentedon Jul 20, 2022
I think the same problem occurs when passing a dictionary (dict) to
spec(at least for PyGMT v0.7.0):The beachball should be offset to latitude 53, but is plotted at latitude 52, which is the event latitude:
[-]beachball offsetting doesn't work for pandas input[/-][+]beachball offsetting doesn't work for pandas/dict input[/+]weiji14 commentedon Nov 24, 2022
As a workaround for PyGMT v0.7.0, if you can set your
plot_longitudeandplot_latitudevalues to astrtype (i.e. wrapping your numbers in quotes like'53'), then the beachball offset should work. E.g. using @yvonnefroehlich's code at #2016 (comment)should give:
Notice how the beachball is now at 53N instead of 52N. For those using
pandas.DataFrameinputs, there should be a way to convert yourplot_longitudeandplot_latitudecolumns tostrtype too usingastype. Something likedf["plot_longitude"].astype(dtype=str").This will be fixed properly in #2202 (so that numeric int/float inputs will work) and should be available in the upcoming PyGMT v0.8.0. Thanks @seisman for identifying the issue!
[-]beachball offsetting doesn't work for pandas/dict input[/-][+]beachball offsetting doesn't work for pandas/dict/ndarray input[/+]yvonnefroehlich commentedon Dec 4, 2022
For me stetting the arguments for
plot_longitudeandplot_latitudeinto quotation marks (i.e. string input) does not work with PyGMT v0.7.0 and GMT 6.4.0:Example script
Error message
Output of pygmt.show_versions()
yvonnefroehlich commentedon Dec 4, 2022
An other aspect is, that the line and the small circle are not plotted or modified via the
offsetparameter (seehttps://www.pygmt.org/dev/api/generated/pygmt.Figure.meca.html#pygmt.Figure.meca) when passing a dictionary to
spec(see case (II)). It works when reading the focal mechanism data from a text file (see case (I)). In both cases a PyGMT dev version (after PR #2202 was megerd) was used.Example script
Output figure for (I) reading a txt file (expectation)

Output figure for (II) using a dictionary

Output of pygmt.show_versions()
3 remaining items
seisman commentedon Dec 20, 2022
Beachball offsetting may still fail for ndarray input. Need some time to test.
yvonnefroehlich commentedon Dec 20, 2022
Thanks! I see the updated issue title. Hm, then bump this back to v0.9.0 🙂?
seisman commentedon Dec 21, 2022
I'll see if I can finish it before v0.8.0.
seisman commentedon Dec 24, 2022
I'm bumping this issue to v0.9.0 because beachball offsetting for ndarray input is more tricky than I initially thought so I can't finish it soon.
weiji14 commentedon Mar 6, 2023
Do you have time to work on this before end of March 2023? Or should we bump this to PyGMT v0.10.0?
seisman commentedon Mar 6, 2023
I'll give it another try in the following week.