How to plot focal mechanisme cross section in PyGMT

Hello EveryOne
please help me
How to plot focal mechanisme cross section in PyGMT?

my scrip beloow:

import pygmt
import  pandas as pd

#Read Data
data = pd.read_csv('data_focmec_mba_ajeng.csv')
#Region
minlon, maxlon = 95,109 #defenisikan batas geografis longitude
minlat, maxlat = -7.0,1#defenisikan batas geografis latitude
region = [minlon,maxlon,minlat,maxlat]

#Plot garis Pantai
fig = pygmt.Figure()
fig.coast(region=region,
          projection='M10c',
          frame = 'ag',
          shorelines='0.25p,black',
          land='grey',
          water='lightblue')

# #color ramp untuk kedalaman
pygmt.makecpt(cmap="jet", reverse = True,series=[data.depth.min(),data.depth.max()])

#Plot Gempa Bumi berdasarakan Kedalaman
fig.plot(x = data.longitude,
         y = data.latitude,
         pen ='faint',
         style ='c',
         color =data.depth,
         cmap = True)

#Plot colorbar Kedalaman gempa
fig.colorbar(frame='af+l"Depth (km)"')

#Plot Data Focal Mechanisme
fig.meca(spec='focmec_mba_ajeng.txt',
         convention='aki',
         scale ='0.3c',
         C = True) #panel
         #offset = True)

# # Plot Text
fig.plot(x=[100, 105], y=[-5, 0], projection="M", pen=0.5)
fig.text(x=100, y= -5, text="A", font="15,Helvetica")
fig.text(x=105, y= 0, text="B", font="15,Helvetica")

# membuat file cross section
pygmt.project('focmec_mba_ajeng.txt',
              unit=True,
              center=[100, -5],
              endpoint=[105,0],
              convention='pz',
              width=[-600, 600],
              outfile='crossfocmec.dat')
#Plot Cross section
fig.basemap(
    projection="X10/-6",
    region=[0, 400, 0, 150],
    frame=['xafg100+l"Distance"', 'yafg50+l"Depth"', "WSen"],
    yshift=-8.5)

fig.plot(data="crossfocmec.dat", projection="X", style="c0.2", pen=1, color="red")
fig.text(x=0, y=0, text="A", font="12,Helvetica")
fig.text(x=1210, y=0, text="B", font="12,Helvetica")

#Convert file ke PNG
fig.savefig ("focmech_ajeng.png", crop=True, dpi=300, transparent=True)

1 Like

Hello @quake10,

thanks for trying out PyGMT!

You are probably searching for pscoupe of GMT, see the GMT documentation https://docs.generic-mapping-tools.org/latest/supplements/seis/pscoupe.html. Unfortunately pscoupe is not wrapped in PyGMT yet, see the related GitHub issue https://github.com/GenericMappingTools/pygmt/issues/2019.

However, you can use GMT modules in PyGMT via Session.call_module. Maybe you can modify the code example in https://github.com/GenericMappingTools/pygmt/issues/2019#issuecomment-1193255522 for your needs.

1 Like

Thanks a lot yvonnefroehlich for your response. I even understand how I modify the code and if you already done fixed it problem maybe you can share with me.

@quake10 can you please share the file containing the focal mecaniss data, and if you can explain how it is structured ! Thanks in advance !

If you read the manual(s) I am sure that the different formats in which the focal mechanisms may be passed in to GMT are explained there.

Have u slove this problem? I meet same problem, can u help me?