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
I am using pygmt to graph focal mechanisms with magnitude scale.
However, when I try to give it an offset so that they don't pile up the function doesn't seem to work.
👋 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.
Thanks, @rdcorona. I think you find a bug in the meca method. I can re-produce this potential bug using Focal mechanisms gallery example. The earthquake is at longitude=-124.3 and latitude=48.1 and the beachball should be plotted at plot_longitude=-124.3 and plot_latitude=47.5. However, the beachball is stilled plotted at the epicenter.
I can reproduce the issue, and now know why it fails. Unfortunately, there is no workaround now.
Still a problem on PyGMT v0.5.0 unfortunately. Could you elaborate more on why it fails? I tried debugging this while handling #1611, and couldn't see any obvious issue on the Python side, e.g. the plot_longitude and plot_latitude variables seem to be appended to spec ok here:
Ah I see, maybe we could use lib.virtualfile_from_data as with #949?
Yes, ideally we should use lib.virtualfile_from_data.
Just to be clear, do you mean that plot_longitude, plot_latitude and event_name is to be passed in as 3 columns or 1 column using GMT_Put_Strings?
We can only call GMT_Put_Strings once, so we have to combine the three parameters into one string vector and pass it to GMT_Put_Strings. Actually, we already did it in the virtualfile_from_vector function. The virtualfile_from_vector function doesn't work for meca, because plot_longitude and plot_latitude are numeric vectors but must be passed as strings.
Yeah I see the same thing, must be time going backwards 😆
Ah I see, maybe we could use lib.virtualfile_from_data as with #949?
Yes, ideally we should use lib.virtualfile_from_data.
Just to be clear, do you mean that plot_longitude, plot_latitude and event_name is to be passed in as 3 columns or 1 column using GMT_Put_Strings?
We can only call GMT_Put_Strings once, so we have to combine the three parameters into one string vector and pass it to GMT_Put_Strings. Actually, we already did it in the virtualfile_from_vector function. The virtualfile_from_vector function doesn't work for meca, because plot_longitude and plot_latitude are numeric vectors but must be passed as strings.
Ok, I think I got a clear idea on what to do now. We'll need to convert the plot_longitude and plot_latitude vectors from numerical arrays to string arrays, and then lib.virtualfile_from_vectors (via lib.virtualfile_from_data) should do the concatenation magic (joining event_name if it is present) and call GMT_Put_Strings only once on the concatenated string column.
Probably do 2 separate PRs:
Refactor from using lib.virtualfile_from_matrix to lib.virtualfile_from_data (which will enable other input data structures like xarray.Dataset arrays) and possibly allow for text labels to work on non-file inputs (fixing Wrap meca #516 (comment)).
Ok, I think I got a clear idea on what to do now. We'll need to convert the plot_longitude and plot_latitude vectors from numerical arrays to string arrays, and then lib.virtualfile_from_vectors (via lib.virtualfile_from_data) should do the concatenation magic (joining event_name if it is present) and call GMT_Put_Strings only once on the concatenated string column.
Probably do 2 separate PRs. 1) Refactor from using lib.virtualfile_from_matrix to lib.virtualfile_from_data (which will enable other input data structures like xarray.Dataset arrays) and 2) Do the actual bugfix so that offset works.
The input parameters of the meca module are a little complicated. I will take the Aki & Richard convention (-Sa) as an example. The input parameters are:
longitude latitude depth strike dip rake magnitude [plot_longitude plot_latitude] [event_name]
As you can see, plot_longitude & plot_latitude and event_name are optional. Thus users can give input parameters in many different ways:
don't give plot longitude&latitude and event_name
give plot longitude&latitude but not event_name
give event_name but not plot longitude&latitude
Due to these complications, the first few columns (7 columns for the -Sa case) are read as numeric values (S->data in the GMT source code), thus data passed as vectors (virtualfile_from_vector) or a matrix (virtualfile_from_matrix) can be read correctly. However, because GMT can't know exactly the number of trailing columns and the event_name parameter can contain whitespace, all the trailing columns are read as trailing text (S->text in the GMT source code).
Due to the above reasons, we have to pass the trailing columns (plot longitude&latitude and event_name) using GMT_Put_Strings, not GMT_Put_Matrix or GMT_Put_Vectors. Actually, we once had similar issues with the text function (related to #483, #520).
Thus, what we need to do is:
Replace lib.virtualfile_from_matrix with lib.virtualfile_from_vector
Build a string list/vector for plot_longitude plot_latitude event_name and pass it to lib.virtual_from_vector.
Ok, I think I got a clear idea on what to do now. We'll need to convert the plot_longitude and plot_latitude vectors from numerical arrays to string arrays, and then lib.virtualfile_from_vectors (via lib.virtualfile_from_data) should do the concatenation magic (joining event_name if it is present) and call GMT_Put_Strings only once on the concatenated string column.
Probably do 2 separate PRs. 1) Refactor from using lib.virtualfile_from_matrix to lib.virtualfile_from_data (which will enable other input data structures like xarray.Dataset arrays) and 2) Do the actual bugfix so that offset works.
Yes!
On third thought, maybe 3 separate PRs (because pygmt.meca is a beast to refactor...):
Apparently the beachball offset bug wasn't properly fixed in #1784 for PyGMT v0.7.0, but there's a workaround at #2016 (comment) (use str types for plot_longitude and plot_latitude inputs), and we're looking at fixing things properly in #2202 for PyGMT v0.8.0.
Activity
welcome commentedon Mar 26, 2021
👋 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.
core-man commentedon Mar 27, 2021
Thanks, @rdcorona. I think you find a bug in the
mecamethod. I can re-produce this potential bug using Focal mechanisms gallery example. The earthquake is atlongitude=-124.3andlatitude=48.1and the beachball should be plotted atplot_longitude=-124.3andplot_latitude=47.5. However, the beachball is stilled plotted at the epicenter.seisman commentedon Apr 1, 2021
I can reproduce the issue, and now know why it fails. Unfortunately, there is no workaround now.
rdcorona commentedon Apr 1, 2021
Hello seisman.
So, we'll have to wait for the 0.4.0 release.🤷🏻♂️
Thanks for the reply
seisman commentedon Apr 1, 2021
Currently, offsetting beachballs only works for files.
I'll see what I can do to fix it.
rdcorona commentedon Apr 1, 2021
Ok, meanwhile I'll try it with a dataFrame and an ASCII file
Thanks again
weiji14 commentedon Nov 7, 2021
Still a problem on PyGMT v0.5.0 unfortunately. Could you elaborate more on why it fails? I tried debugging this while handling #1611, and couldn't see any obvious issue on the Python side, e.g. the
plot_longitudeandplot_latitudevariables seem to be appended tospecok here:pygmt/pygmt/src/meca.py
Lines 330 to 337 in 9e8a7bd
Only thing I can think of is that this is a problem with the
specarray to GMT virtualfile convention atpygmt/pygmt/src/meca.py
Line 454 in 9e8a7bd
seisman commentedon Nov 7, 2021
Yes, ideally we should use
lib.virtualfile_from_data.We can only call
GMT_Put_Stringsonce, so we have to combine the three parameters into one string vector and pass it toGMT_Put_Strings. Actually, we already did it in thevirtualfile_from_vectorfunction. Thevirtualfile_from_vectorfunction doesn't work formeca, because plot_longitude and plot_latitude are numeric vectors but must be passed as strings.pygmt/pygmt/clib/session.py
Lines 1159 to 1172 in 4b80f3c
seisman commentedon Nov 7, 2021
I don't know what happened to GitHub.
My reply to your comment #1129 (comment) is displayed before your comment at here: #1129 (comment)
weiji14 commentedon Nov 7, 2021
Yeah I see the same thing, must be time going backwards 😆
Ok, I think I got a clear idea on what to do now. We'll need to convert the
plot_longitudeandplot_latitudevectors from numerical arrays to string arrays, and thenlib.virtualfile_from_vectors(vialib.virtualfile_from_data) should do the concatenation magic (joiningevent_nameif it is present) and callGMT_Put_Stringsonly once on the concatenated string column.Probably do 2 separate PRs:
lib.virtualfile_from_matrixtolib.virtualfile_from_data(which will enable other input data structures likexarray.Datasetarrays) and possibly allow for text labels to work on non-file inputs (fixing Wrap meca #516 (comment)).offsetworks.seisman commentedon Nov 7, 2021
Yes!
seisman commentedon Nov 7, 2021
The input parameters of the
mecamodule are a little complicated. I will take the Aki & Richard convention (-Sa) as an example. The input parameters are:As you can see, plot_longitude & plot_latitude and event_name are optional. Thus users can give input parameters in many different ways:
Due to these complications, the first few columns (7 columns for the -Sa case) are read as numeric values (
S->data in the GMT source code), thus data passed as vectors (virtualfile_from_vector) or a matrix (virtualfile_from_matrix) can be read correctly. However, because GMT can't know exactly the number of trailing columns and theevent_nameparameter can contain whitespace, all the trailing columns are read as trailing text (S->textin the GMT source code).See https://github.com/GenericMappingTools/gmt/blob/3e68b8de02774f2eda0068ea356586d61770f070/src/seis/psmeca.c#L775 and https://github.com/GenericMappingTools/gmt/blob/3e68b8de02774f2eda0068ea356586d61770f070/src/seis/psmeca.c#L824 if you want to read the GMT source code.
Due to the above reasons, we have to pass the trailing columns (plot longitude&latitude and event_name) using
GMT_Put_Strings, notGMT_Put_MatrixorGMT_Put_Vectors. Actually, we once had similar issues with thetextfunction (related to #483, #520).Thus, what we need to do is:
lib.virtualfile_from_matrixwithlib.virtualfile_from_vectorplot_longitude plot_latitude event_nameand pass it tolib.virtual_from_vector.weiji14 commentedon Nov 7, 2021
Ah I see, maybe we could use
lib.virtualfile_from_dataas with #949? Since it basically passes things tolib.virtualfile_from_vectorsanyways:pygmt/pygmt/clib/session.py
Lines 1427 to 1431 in 4b80f3c
though it sounds like we'll need to be careful and ensure that it doesn't get into this case:
pygmt/pygmt/clib/session.py
Lines 1454 to 1458 in 4b80f3c
so some very careful refactoring and unit test writing to do!
Just to be clear, do you mean that
plot_longitude,plot_latitudeandevent_nameis to be passed in as 3 columns or 1 column usingGMT_Put_Strings?weiji14 commentedon Nov 7, 2021
On third thought, maybe 3 separate PRs (because
pygmt.mecais a beast to refactor...):mecato usevirtualfile_from_data(doing at Refactor meca to use virtualfile_from_data #1613)offsetparameter bug (pygmt.Figure.meca offset not working #1129).weiji14 commentedon Nov 24, 2022
Apparently the beachball offset bug wasn't properly fixed in #1784 for PyGMT v0.7.0, but there's a workaround at #2016 (comment) (use
strtypes forplot_longitudeandplot_latitudeinputs), and we're looking at fixing things properly in #2202 for PyGMT v0.8.0.