Skip to content

Wrap coupe #2019

Open
Open

Description

@konalindsey

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

Activity

  1. welcome commented on Jul 21, 2022

    @welcome

    👋 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.

  2. yvonnefroehlich commented on Jul 21, 2022

    @yvonnefroehlich
    Member

    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!

  3. konalindsey commented on Jul 21, 2022

    @konalindsey
    Author

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

  4. yvonnefroehlich commented on Jul 22, 2022

    @yvonnefroehlich
    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.

  5. yvonnefroehlich commented on Jul 23, 2022

    @yvonnefroehlich
    Member

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

  6. seisman commented on Jul 24, 2022

    @seisman
    Member

    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()
    
  7. added this to the 0.8.0 milestone on Jul 24, 2022
  8. yvonnefroehlich commented on Jul 24, 2022

    @yvonnefroehlich
    Member

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

  9. willschlitzer commented on Jul 25, 2022

    @willschlitzer
    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.

  10. maxrjones commented on Jul 25, 2022

    @maxrjones
    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

  11. willschlitzer commented on Jul 26, 2022

    @willschlitzer
    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!

  12. changed the title [-]pscoupe implementation[/-] [+]Wrap coupe[/+] on Jul 27, 2022
  13. weiji14 commented on Aug 17, 2022

    @weiji14
    Member

    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.

  14. added
    help wanted
    on Aug 17, 2022
  15. willschlitzer commented on Aug 17, 2022

    @willschlitzer
    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!

  16. willschlitzer commented on Sep 20, 2022

    @willschlitzer
    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.

  17. Josesx506 commented on Dec 4, 2022

    @Josesx506
    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

  18. modified the milestones: 0.8.0, 0.9.0 on Dec 11, 2022
  19. modified the milestones: 0.9.0, 0.10.0 on Mar 6, 2023
  20. removed this from the 0.10.0 milestone on Aug 24, 2023
  21. weiji14 commented on Jan 2, 2024

    @weiji14
    Member

    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.

  22. DianKusumawati commented on Jan 15, 2024

    @DianKusumawati

    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
  23. seisman commented on Jan 15, 2024

    @seisman
    Member

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

  24. DianKusumawati commented on Jan 15, 2024

    @DianKusumawati

    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

  25. seisman commented on Jan 15, 2024

    @seisman
    Member

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

  26. DianKusumawati commented on Jan 17, 2024

    @DianKusumawati

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requesthelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions