#!/usr/bin/env python import gmt st2file = "data/oat_cedc_crude.oat2" psfile = "figs/oat_cedc_crude.ps" st2file = "data/oat_isc_crude.oat2" psfile = "figs/oat_isc_crude_station.ps" # plot the epicenter gmt5 = gmt.Gmt() Jh = "L105/36/17/55/10c" Rh = "70/140/17/55" gmt5.set("MAP_FRAME_WIDTH", "0.3p") gmt5.comment("etopo") gmt5.shell("grdgradient etopo_cn.grd -Gjunk.grd -A0/270 -Nt1.0 -V") gmt5.cmd("makecpt", "-Cglobe -T-10000/10000/100 -Z > colors.cpt") gmt5.cmd("grdimage", "etopo_cn.grd -Ijunk.grd -J%s -R%s -K -Ccolors.cpt > %s" % (Jh, Rh, psfile)) gmt5.comment("coast and tectonic lines") gmt5.cmd("pscoast", "-J%s -R%s -W1/0.5p -N1/0.5p -N2 -K -O -BWSNE -Bxa10 -Bya10 >> %s" % (Jh, Rh, psfile) ) gmt5.cmd("psxy", "China_tectonic.dat -J%s -R%s -K -O -W0.5p,blue,- >> %s" % (Jh, Rh, psfile)) # plot permanent stations gmt5.shell("cat %s | awk '{print $11,$10}' > temp.xy" % st2file)
def rayp_station(oatfile, gmtproj="B120/36/17/55/10c", gmtrange="100/140/17/60", tempdir="./temp", phase="P", threshold=10): Jh = gmtproj Rh = gmtrange try: shutil.rmtree(tempdir) except: pass if not os.path.exists(tempdir): os.makedirs(tempdir) try: shutil.rmtree("./fig") except: pass if not os.path.exists("./fig"): os.makedirs("./fig") with open(oatfile, "r") as fp: oatlst = fp.readlines() oat = Oat() for line in oatlst: oat.read(line) filen = tempdir+"/"+oat.knetwk+oat.kstnm+".oat" fp = open(filen, "a") fp.write(line) fp.close() for file in glob.glob(tempdir+"/*.oat"): psfile = "./fig/"+os.path.basename(file).split(".")[0]+".ps" print psfile with open(file, 'r') as fp: lst = fp.readlines() if len(lst)<threshold: continue gmt = gmt5.Gmt() gmt.comment("basemap") gmt.cmd("psbasemap", "-J%s -R%s -BWSNE -Bxa10+l'Latitude [\\260]' -Bya10+l'Depth [km]' -K > %s" % (Jh, Rh, psfile)) gmt.comment("coast") gmt.cmd("pscoast", "-J%s -R%s -W1/0.25p -N1 -N2 -K -O >> %s" % (Jh, Rh, psfile) ) fp_ray = open("junk.raypath", "w") for line in lst: oat.read(line) os.system("gmt project -C%f/%f -E%f/%f -G10 -Q > great_circle.xyp" % (oat.evlo, oat.evla, oat.stlo, oat.stla)) with open("great_circle.xyp", "r") as fp: raylst = fp.readlines() for rayline in raylst: row = rayline.split() fp_ray.write("%s\t%s\t%f\n" % (row[0], row[1], oat.tobs-oat.tak135)); fp_ray.close() gmt.comment("plot raypath") gmt.cmd("makecpt", "-Ccpt-city/cb/div/RdYlGn_10 -T-10/10/0.05 -I > colors.cpt") gmt.cmd("psxy", "junk.raypath -J%s -R%s -K -O -Sc0.5p -Ccolors.cpt -W+0.5p >> %s" % (Jh, Rh, psfile)) gmt.cmd("psscale", "-Ccolors.cpt -D5c/-0.7c/7.5c/0.5ch -K -O -Ba2+l'%s residuals [s]' >> %s" %(phase, psfile)) gmt.comment("end") gmt.cmd("psxy", "-J -R -O -T >> %s" % psfile) gmt.cmd("ps2raster", "-A -P %s" % psfile) gmt.execute()
#!/usr/bin/env python import gmt as gmt5 psfile = "moho_thick.ps" R = "100/140/17/55" # J = "B120/36/17/55/10c" J = "B120/36/17/55/8c" gmt = gmt5.Gmt() gmt.set("MAP_FRAME_TYPE", "plain") gmt.set("MAP_DEGREE_SYMBOL", "none") # gmt.shell("cat thickness_cmt.xyz | awk '{print $1,$2,$3}' > moho.xyz") gmt.shell("cat thickness_cmt.xyz | awk '{print $1,$2,$6}' > cmt.xyz") gmt.cmd("surface", "cmt.xyz -Gmoho.grd -I0.5/0.5 -R%s" % (R)) gmt.cmd("makecpt", "-Ctest -T0/40 > color.cpt") # gmt.cmd("pscoast", "-J%s -R%s -Bx10f5 -By10f5 -W1/0.5p -N1 -A500 -K -Slightblue > %s" % (J, R, psfile)) # gmt.cmd("surface", "data/tablea2.txt -Gmoho.grd -I0.5/0.5 -R-180/180/-90/90") # gmt.cmd("makecpt", "-Cmoho3.cpt -T20/70 > color.cpt") gmt.cmd("pscoast", "-J%s -R%s -K -Gc > %s" % (J, R, psfile)) gmt.cmd("grdimage", "moho.grd -J%s -R%s -Ccolor.cpt -K -O >> %s" % (J, R, psfile)) # gmt.cmd("pscontour", "cmt.xyz -R -J -K -O -C2 -W1p,blue >> %s" % (psfile)) gmt.cmd("pscoast", "-J%s -R%s -K -O -Q >> %s" % (J, R, psfile)) gmt.cmd(
def plot_ac(fileid, datapath, datapath2, figpath): acfile = datapath + "/" + fileid + ".sac.d" acmfile = datapath + "/" + fileid + ".norm.d" agcfile = datapath + "/" + fileid + ".agc.d" ifnfile = datapath + "/" + fileid + ".ifn.d" iffile = datapath + "/" + fileid + ".if.d" tr = read(acfile)[0] fileid = tr.id vpfile = datapath2 + "/" + fileid + ".vpn" vsfile = datapath2 + "/" + fileid + ".vsv" anfile = datapath2 + "/" + fileid + ".rani" qsfile = datapath2 + "/" + fileid + ".qsi" difile = datapath2 + "/" + fileid + ".txt" refile = datapath2 + "/" + fileid + ".res" psfile = figpath + "/" + fileid + ".ps" print psfile stnm = fileid.split(".")[1] # moho depth and lab depth with open(difile, "r") as fp: line = fp.readline() row = line.split() mdep = float(row[3]) ldep = float(row[4]) try: mdep = tr.stats.sac.t2 except: mdep = float(row[3]) # print tr.stats.sac.t5, tr.stats.sac.t4 try: os.makedirs(figpath) except: pass gmt = gmt5.Gmt() # gmt.set("PS_LINE_CAP", "round") gmt.comment("base") gmt.cmd( "psbasemap", "-JX5c/-8c -R-1/4/0/300 -Bya50f10+l'Depth [km]' -BWsNe+t'%s' -K -Bxcintfile+l'P Reflectivity' > %s" % (stnm, psfile)) # gmt.cmd("pssac", "-J -R %s %s %s -K -O -En -Q -M0.1 >> %s" % (acfile, acmfile, ifnfile, psfile)) proc_sac(file=acfile, xyfile="ac.xy", idn=0.0, scale=1.0) gmt.cmd("psxy", "ac.xy -J -R -K -O -W1p >> %s" % (psfile)) # proc_sac(file=acmfile, xyfile="acm.xy", idn=1.5, scale=0.5) # gmt.cmd("psxy", "acm.xy -J -R -K -O >> %s" % (psfile)) proc_sac(file=agcfile, xyfile="agc.xy", idn=1.5, scale=0.5) gmt.cmd("psxy", "agc.xy -J -R -K -O -W1p >> %s" % (psfile)) proc_sac(file=ifnfile, xyfile="ifn.xy", idn=3, scale=1.0) gmt.cmd("psxy", "ifn.xy -J -R -K -O -W1p >> %s" % (psfile)) # proc_sac(file=iffile, xyfile="if.xy", idn=4, scale=1.0) # gmt.cmd("psxy", "if.xy -J -R -K -O -W0.5p >> %s" % (psfile)) # plot label # gmt.shell("echo 0.0 10.0 REF | gmt pstext -J -R -K -O -Ya0.5c >> %s" % (psfile)) # gmt.shell("echo 1.5 10.0 AGC | gmt pstext -J -R -K -O -Ya0.5c >> %s" % (psfile)) # gmt.shell("echo 3.0 10.0 IF | gmt pstext -J -R -K -O -Ya0.5c >> %s" % (psfile)) # plot moho and depth gmt.shell( "echo 5.0 %f | gmt psxy -J -R -K -O -SB3p -Gsandybrown -t50 >> %s" % (mdep, psfile)) gmt.shell("echo 5.0 %f | gmt psxy -J -R -K -O -SB3p -Gblue -t50 >> %s" % (ldep, psfile)) try: gmt.shell( "echo 5.0 %f | gmt psxy -J -R -K -O -SB3p -Gcyan -t50 >> %s" % (tr.stats.sac.t5, psfile)) except: pass # gmt.shell("echo 3.0 %f | gmt psxy -J -R -K -O -S-10c -Ggreen -t50 -Wfat,green,. >> %s" % (100, psfile)) # print mdep # plot velocity gmt.cmd( "psbasemap", "-JX4c/-8c -R3/9/0/300 -Bxa1+l'Velocity [km/s]' -Bya50f10+l'Depth [km]' -BwsNe+t'%s' -K -O -X5c >> %s" % (stnm, psfile)) read_vel(file=vpfile, xyfile="vp.xy") gmt.cmd("psxy", "vp.xy -J -R -K -O -W1p >> %s" % (psfile)) read_vel(file=vsfile, xyfile="vs.xy") gmt.cmd("psxy", "vs.xy -J -R -K -O -W1p >> %s" % (psfile)) gmt.shell("echo 4.5 20 Vs | gmt pstext -J -R -K -O >> %s" % (psfile)) gmt.shell("echo 8.0 20 Vp | gmt pstext -J -R -K -O >> %s" % (psfile)) # plot moho and depth gmt.shell( "echo 10.0 %f | gmt psxy -J -R -K -O -SB3p -Gsandybrown -t50 >> %s" % (mdep, psfile)) gmt.shell("echo 10.0 %f | gmt psxy -J -R -K -O -SB3p -Gblue -t50 >> %s" % (ldep, psfile)) try: gmt.shell( "echo 10.0 %f | gmt psxy -J -R -K -O -SB3p -Gcyan -t50 >> %s" % (tr.stats.sac.t5, psfile)) except: pass # plot radial anisotropy gmt.cmd( "psbasemap", "-JX2c/-8c -R0.9/1.1/0/300 -Bxa0.1+l'Radial Ani' -Bya50f10+l'Depth [km]' -BwsNe+t'%s' -K -O -X4.5c >> %s" % (stnm, psfile)) read_vel(file=anfile, xyfile="an.xy") gmt.cmd("psxy", "an.xy -J -R -K -O -W1p >> %s" % (psfile)) gmt.cmd("psxy", "gridline.xy -J -R -K -O -W0.5p,- >> %s" % (psfile)) gmt.shell("echo 10.0 %f | gmt psxy -J -R -K -O -SB3p -Gblue -t50 >> %s" % (ldep, psfile)) try: gmt.shell( "echo 5.0 %f | gmt psxy -J -R -K -O -SB3p -Gcyan -t50 >> %s" % (tr.stats.sac.t5, psfile)) except: pass # plot Attenuation gmt.cmd( "psbasemap", "-JX2c/-8c -R0/8/0/300 -Bxa2+l'Attenuation' -Bya50f10+l'Depth [km]' -BwsNe+t'%s' -K -O -X2.6c >> %s" % (stnm, psfile)) read_vel(file=qsfile, xyfile="qs.xy") gmt.cmd("psxy", "qs.xy -J -R -K -O -W1p >> %s" % (psfile)) gmt.shell("echo 10.0 %f | gmt psxy -J -R -K -O -SB3p -Gblue -t50 >> %s" % (ldep, psfile)) try: gmt.shell( "echo 10.0 %f | gmt psxy -J -R -K -O -SB3p -Gcyan -t50 >> %s" % (tr.stats.sac.t5, psfile)) except: pass # plot Attenuation gmt.cmd( "psbasemap", "-JX2c/-8c -R2/5/0/300 -Bxa1+l'Resistivity' -Bya50f10+l'Depth [km]' -BwsNe+t'%s' -K -O -X2.6c >> %s" % (stnm, psfile)) read_vel(file=refile, xyfile="res.xy") gmt.cmd("psxy", "res.xy -J -R -K -O -W1p >> %s" % (psfile)) gmt.shell( "echo 10.0 %f | gmt psxy -J -R -K -O -SB3p -Gsandybrown -t50 >> %s" % (mdep, psfile)) gmt.shell("echo 10.0 %f | gmt psxy -J -R -K -O -SB3p -Gblue -t50 >> %s" % (ldep, psfile)) try: gmt.shell( "echo 5.0 %f | gmt psxy -J -R -K -O -SB3p -Gcyan -t50 >> %s" % (tr.stats.sac.t5, psfile)) except: pass gmt.comment("end") gmt.cmd("psxy", "-J -R -O -T >> %s" % psfile) gmt.cmd("psconvert", "-A -P -Tj %s" % psfile) gmt.cmd("psconvert", "-A -P -Tf %s" % psfile) gmt.execute() pass