Plot FocalMechanims

Dear all,
I was trying to plot focal mechanism solutions based on aki format, however I got the following error:

GMTInvalidInput: Arguments in short-form (C) and long-form (offset) can't coexist

My input file is attached gCMT_sols.dat (762 Bytes)

The code I am using to plot the focal mechanism is:

df_focal_mecha = pd.read_csv('gCMT_sols.dat', sep='\s+')

df_focal_mecha.head()

fig.meca(
    spec=df_focal_mecha,
    convention = 'aki',
    scale="1.0c",
    C=True,
    offset = True,
    )           

Dis I do a mistake over the input format?
Thanks in advance
Tonino

First of all you need to define a cpt before using C = True:

import pygmt

fig = pygmt.Figure()
pygmt.makecpt(cmap= "roma")

fig.meca(
    spec = 'gCMT_sols.dat',
    convention = 'aki',
    scale = "1.0c",
    offset = True,
    frame = True,
    C = True)  

fig.show()

which gives you the following:

However, I assume you want to color your focal mechanisms based on depth or something like that?

Dear @mgrund,
Thank you for the answer. Yes I’d like to color according to depth. Should I create a color map too rigth?
Tonino

In principle, yes. Depending on how your input data is formatted, depth should be in the third column. However, your data has 9 columns and the filename contains “gCMT”, on the other side you set convention to 'aki'. Is your data in the right format?

@mgrund, about the input file, the data comes from GCMT for that reason I named gCMT.
The input is “sorted” like the AKI format, however the last two columns are offset where I’d like to plot the beach-balls (same as GMT input), however I am not able to plot with offset the beach-balls.

@mgrund, I just updated the version of PyGMT to newest and it’s running smooth the offset for beach-balls, thank you, stay safe and best regards
Tonino

Dear @mgrund,
It worked, here I paste the code, just in case anyone need it.

pygmt.makecpt(cmap = 'hot',
                  series = [1,70,3])  

fig.meca(
    spec='Nieto_sols.dat',
    convention = 'aki',
    scale="0.7c",
    offset = True,
    frame = True,
    C = True
    )           

fig.colorbar(frame=["x+lFM-Depth", "y+lkm"], position="JMR+o0.5c/0c+w8c")

Stay safe and best regards,
Tonino

Dear @tonino13,

Thank you very much for posting your code for coloring focal mechanisms by depth. I hadn’t updated PyGMT to v0.5.0 but have now done that and this seems to have been the final step required to crack the problem. Like you, I think, I also found I had to write my data frame out as a tab-separated file and then read it in again, instead of passing it directly to meca.

Thanks again and best wishes from Wellington,
John T.

The GMT must be installed to work with pygmt

i cant still plotting offset for beachballs???
data input coulmn is lon lat depth strike dip slip mag plot_lon plot_lat with txt format
whats problem
and i installed last version pygmt 7.0

Hi @kami, your input data file must have the following format:

Lon Lat Depth Strike Dip Rake Mag OffsetLon OffsetLat

For exmaple, in a txt file you should have:

-65.700 -17.108 4.6 114.78 39.78 45.35 4.4 -65.516 -17.148

The last two columns (OffsetLon and OffsetLat) are the place where you want to plot the Focal Mechanism.

I hope this help, stay safe,
Tonino

Dear @tonino13 thanks for reply. see my input file What do you think?

I think, input file reads all the columns in just one column

my code with its error is:

​data=pd.read_csv(“focmec.txt”)
lon lat depth strike dip rake mag p_lon p_lat
0 53.48 36.07 12.2 220.7 52.3 170.4 4.6 53.1 36.2
1 55.09 36.98 16.1 316.6 64.7 -190.1 5.2 55.1 37.2
2 53.01 36.67 25.1 137.6 28.5 91.0 4.7 54.2 35.9

fig.meca(spec=data, convention=“aki”, scale=“0.7c”,plot_longitude=True, plot_latitude=True, offset=True)
raise GMTError(
pygmt.exceptions.GMTError: Parameters in spec dictionary do not match known conventions.

if the leading 0, 1, 2 is in your data file then you are off by one column - you gotta get rid of those running numbers.

Dear @pwessel your comment is true. i change input data to this

data=pd.read_csv(“focmec.csv”, header=None,delimiter=“\s+”)

data
0 1 2 3 4 5 6 7 8
0 53.48 36.07 12.2 220.7 52.3 170.4 4.6 53.1 36.2
1 55.09 36.98 16.1 316.6 64.7 -190.1 5.2 55.1 37.2
2 53.01 36.67 25.1 137.6 28.5 91.0 4.7 54.2 35.9
but it doesnt still work.
If possible you give me a csv file that you with it plotted offset and i will try with it.

Sorry, I do not use pyGMT so I do not know if the read_csv command inserts those running numbers 0 1 2 etc or if they are in your data file. Maybe @seisman can suggest something?

@kami, can you reply with the first few lines from focmec.csv so that we can see what the raw data look like?