Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap coupe #2019

Open
konalindsey opened this issue Jul 21, 2022 · 20 comments
Open

Wrap coupe #2019

konalindsey opened this issue Jul 21, 2022 · 20 comments
Labels
feature request New feature wanted help wanted Helping hands are appreciated

Comments

@konalindsey
Copy link

konalindsey commented Jul 21, 2022

Description of the desired feature

I am mapping cross sections of subduction zones, and need to plot focal mechanisms.
I tried using Session.call_module, but ran into various errors... I probably am not using it correctly, but a real pyGMT function of pscoupe would be preferable.

Are you willing to help implement and maintain this feature? Yes/No

@konalindsey konalindsey added the feature request New feature wanted label Jul 21, 2022
@welcome
Copy link

welcome bot commented Jul 21, 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.

@yvonnefroehlich
Copy link
Member

yvonnefroehlich commented Jul 21, 2022

Thanks @konalindsey for trying out PyGMT 😃 !

Maybe the method pygmt.Figure.meca is helpful for you?

There is also a gallery example for this method: https://www.pygmt.org/latest/gallery/seismology/meca.html#sphx-glr-gallery-seismology-meca-py

Please note: This method was fully rewritten after release v0.7.0 (see #2016 (comment)). Despite this, there are still some known issues and limitations with this method (e.g. #2016).


Edit
Maybe I understood you / the question wrong, and you want to plot a cross section of a focal mechanisms, as the title of this issue refers to pscoupe module of GMT (https://docs.generic-mapping-tools.org/latest/supplements/seis/pscoupe.html)? Sorry for that!

@konalindsey
Copy link
Author

konalindsey commented Jul 21, 2022

Hi @yvonnefroehlich. Yes, meca works great! But I need to make cross sections of the focal mechanisms which would correspond to pscoupe in GMT.

@yvonnefroehlich
Copy link
Member

I have no experience with pscoupe. So, probably the PyGMT maintainers can help you better and faster 😉, regarding both wrapping pscoupe and using pscoupe in PyGMT via Session.call_module.

I tried using Session.call_module, but ran into various errors... I probably am not using it correctly,

I think it could be helpful if you post your code or a minimal example showing your issues when using pscoupe via Session.call_module.

@yvonnefroehlich
Copy link
Member

Ping at @seisman, @weiji14, @maxrjones, @willschlitzer, and @michaelgrund for help on this, please.

@seisman
Copy link
Member

seisman commented Jul 24, 2022

I don't think I have time to wrap the coupe module recently, but here is a minimal script showing how to call a module that is not wrapped in PyGMT yet.

The example data is available at https://raw.githubusercontent.com/GenericMappingTools/gmt-for-geodesy/main/5_seismology/meca.dat

import pygmt

spec = "meca.dat"
fig = pygmt.Figure()
with pygmt.clib.Session() as lib:
    file_context = lib.virtualfile_from_data(check_kind="vector", data=spec)
    with file_context as fname:
        lib.call_module(module="coupe", args=f"{fname} -Sa1c -Aa110/33/120/33+r -JX15c/-5c -Baf")
fig.show()

@seisman seisman added this to the 0.8.0 milestone Jul 24, 2022
@yvonnefroehlich
Copy link
Member

Thanks @seisman for your answer and especially for the code example! 😃

@willschlitzer
Copy link
Contributor

@GenericMappingTools/pygmt-maintainers Is there a remote file that would be applicable as a table for this? The example in the GMT docs does not point to an input file.

@maxrjones
Copy link
Member

I'm not sure how easy it would be to create a simpler example from this, but @GCMT_1976-2017_meca.gmt contains focal mechanism data and is used in https://docs.generic-mapping-tools.org/latest/animations/anim14.html

@willschlitzer
Copy link
Contributor

Thanks! I'm mostly looking for a remote file so I can write a test; I'll give that a go at some point!

@seisman seisman changed the title pscoupe implementation Wrap coupe Jul 27, 2022
@weiji14
Copy link
Member

weiji14 commented Aug 17, 2022

Another request from the forum at https://forum.generic-mapping-tools.org/t/how-to-plot-focal-mechanisme-cross-section-in-pygmt/3209. Looks like coupe is very in demand! Is anyone interested in implementing this in PyGMT?

We've got some draft instructions on how to wrap a new module at #1687, specifically at https://github.com/GenericMappingTools/pygmt/blob/wrap-module-instructions/doc/contributing.md#initial-feature-implementation. Let us know if anyone is interested in helping out with this and the team will be happy to provide guidance.

@weiji14 weiji14 added the help wanted Helping hands are appreciated label Aug 17, 2022
@willschlitzer
Copy link
Contributor

I'm planning on trying to wrap it in September/October (my computer is still enroute from the U.K.); happy to help if anyone wants to give it a go!

@willschlitzer
Copy link
Contributor

I was unsuccessful in getting coupe to work. I pushed my edits so far to the branch wrap/coupe if anyone wants to take a look at it/wrap it and submit a PR. I'm giving up on it for the time being.

@Josesx506
Copy link

fig = pygmt.Figure()
# Use the session helper to import the 'clip' module from GMT
with pygmt.helpers.GMTTempFile() as temp_file:
    with open(temp_file.name, 'w') as f:
        for i in range(len(mts_array)):
            f.write(f'{mts_array[i,0]} {mts_array[i,1]} {mts_array[i,2]} {mts_array[i,3]} {mts_array[i,4]} {mts_array[i,5]} {mts_array[i,6]}\n')
    with pygmt.clib.Session() as session:
        session.call_module('coupe', f'{temp_file.name} -R0/5/-0.4/3.2 -JX8.72c/-3c -Sa1.5 -Aa-90.82/30.174/-90.76/30.174+d90+w0.7/0/0 -Gred -Baf255')
fig.show()

The format of mts_array is
longitude latitude depth strike dip rake Mw
Each row is a new event. e.g for 20 events, the array shape is (20,7)

The 2 coordinates in the -Aa argument are the start and end long-lat locations of the profile, w is the width of profile in kilometers and d90 makes sure the moment tensors are viewed vertically from the side

pscoupe

@seisman seisman modified the milestones: 0.8.0, 0.9.0 Dec 11, 2022
@weiji14 weiji14 modified the milestones: 0.9.0, 0.10.0 Mar 6, 2023
@weiji14 weiji14 removed this from the 0.10.0 milestone Aug 24, 2023
@weiji14
Copy link
Member

weiji14 commented Jan 2, 2024

Found this blog post (in Japanese) from @yasuit21 who implemented some code to wrap coupe (see also code at https://gist.github.com/yasuit21/db1d676d784769b80365a3528d1ab547). Might be a good reference for someone who wants to bring this into PyGMT.

@DianKusumawati
Copy link

Found this blog post (in Japanese) from @yasuit21 who implemented some code to wrap coupe (see also code at https://gist.github.com/yasuit21/db1d676d784769b80365a3528d1ab547). Might be a good reference for someone who wants to bring this into PyGMT.

Thank you for the guidance. I have checked on the website and tried to implement it (the coupe.py). However, I encountered a problem related to:

decorators.py
module_func.doc = docstring.format(**filler_text)
KeyError: 'projection'

I tried to trace the script. As I checked on this website (https://github.com/GenericMappingTools/pygmt/blob/wrap-module-instructions/doc/contributing.md#add-missing-aliases), I tried to guess that the issue is possibly related to missing aliases in my case (?) (please correct me if I'm wrong). However, I am still puzzled about how to solve the problem.

May I ask for help regarding this problem?

Below is the screenshot of the error.
The script that I use is:
Crosssec_tes.py and coupe.py from https://gist.github.com/yasuit21/db1d676d784769b80365a3528d1ab547
meca.py from https://github.com/GenericMappingTools/pygmt/blob/v0.10.0/pygmt/src/meca.py

Your guidance will be very valuable to me. Thank you.

error

@seisman
Copy link
Member

seisman commented Jan 15, 2024

It seems the error comes from meca_edit.py. Please attach the script so that we can see what's inside.

@DianKusumawati
Copy link

DianKusumawati commented Jan 15, 2024

It seems the error comes from meca_edit.py. Please attach the script so that we can see what's inside.

for the meca_edit.py script, I copied it entirely from the script in https://github.com/GenericMappingTools/pygmt/blob/v0.10.0/pygmt/src/meca.py

I renamed it to meca_edit.py because there is already a meca.py script in the Pygmt installation on my machine, and I noticed there is a slight difference with the meca script posted in Git Hub.

Below is the attachment of the script (meca_edit.py as well as with the other script that I use) in a zip file.

Thank you

script.zip

@seisman
Copy link
Member

seisman commented Jan 15, 2024

The script works well for me after some necessary minor changes, and I can't reproduce your issue.

@DianKusumawati
Copy link

The script works well for me after some necessary minor changes, and I can't reproduce your issue.

After I checked on the PyGMT version requirement (python=3.10.12 pygmt=0.10.0 numpy=1.25.2 pandas=2.0.3) on the website from @yasuit21, I was able to produce the figure in the example script. My previous PyGMT version was 0.5.0.

Kindly apologize for the missed version.

Thank you.
Screenshot OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature wanted help wanted Helping hands are appreciated
Projects
None yet
Development

No branches or pull requests

8 participants