def main(mdlname,dispdic,title): os.system('gpdcreport '+mdlname+' >tmp.mdl') models, data, nd, ne, nrow = get_models('tmp.mdl') gmt = GMT(config={'BASEMAP_TYPE':'plain','ANOT_FONT_SIZE':8, 'LABEL_FONT_SIZE':10,'COLOR_BACKGROUND':'255/255/255', 'COLOR_FOREGROUND':'0/0/0','COLOR_NAN':'255/255/255', 'PAGE_ORIENTATION':'landscape', 'HEADER_FONT_SIZE':15} ) xyz=gmt.tempfilename('testxyz.txt') xyz2=gmt.tempfilename('testxyz2.txt') grd=gmt.tempfilename('tmp.grd') grdcpt=gmt.tempfilename('tmp.cpt') fileout='dens_test.ps' rng='1/5/0/40' scl='X4.2/-6' dreso = 0.2 sreso = 0.05 misfit = 0.1 #grid1, grid2, x, y, smean, dmean = dplot.dplot(models,data,nd,ne,dreso=dreso, sreso=sreso,mf=misfit) grid1, grid2, x, y, smean, dmean = dplot.dplot(models,data,nd,ne,dreso=dreso, sreso=sreso,mf=misfit) #grid1, grid2, x, y = dplot.dplotpy(models,data,nd,ne,dreso=dreso, sreso=sreso,mf=misfit) # matshow(grid1) # show() f = open(xyz,'w') for ii in range(len(y)): for jj in range(len(x)): if grid1[ii,jj]>0.0: print >>f, x[jj],y[ii], grid1[ii,jj] f.close() f = open(xyz2,'w') for ii in range(len(y)): for jj in range(len(x)): if grid2[ii,jj] > 0: print >>f, x[jj], y[ii], '0.5' f.close() anot = int(grid1.max()/1000.)*1000/2. tick = anot/2 gmt.xyz2grd(xyz,G=grd,R=rng,I='%f/%f'%(sreso,dreso),out_discard=True) gmt.grd2cpt(grd,C="wysiwyg",Z=True,out_filename=grdcpt) gmt.psmask(xyz2,R=rng,T=True,J=scl,I='%f/%f'%(sreso,dreso),G='lightgray') gmt.grdimage(grd,J=scl,R=rng,Q=True,C=grdcpt) gmt.psbasemap(R=rng,J=scl,B='a1f.5:S-velocity [km/s]:/a10f5:Depth [km]::.%s:WnSe'%title) gmt.psxy(R=True,J=True,B=True,W='3,black',in_columns=[smean,dmean]) f = open('/home/behrya/dev/data/mt_fixed_layers_ray_c_u_mean.txt','w') for _p,_v in zip(dmean,smean): print >>f,_p,_v f.close() gmt.psscale(C=grdcpt,D='1.0/1./4c/.4ch',B='a%df%d:No. of models:/::'%(anot,tick)) ### plot dispersion curves gmt.psbasemap(R='5/30/2.0/5.0',J='X4.2/2.5',X='5',B='a1f.5:Period [s]:/a1f.5:Velocity [km/s]:WnSe') for _d in dispdic.keys(): vo = load(dispdic[_d][0]) p,v = gpdccurve(mdlname,wtype=dispdic[_d][1],ptype=dispdic[_d][2]) gmt.psxy(R=True,J=True,B=True,W='3,black',in_columns=[p,v]) gmt.psxy(R=True,J=True,B=True,W='3,red',in_columns=[vo[:,0],vo[:,1]]) gmt.save(fileout) os.system('gv '+fileout+'&')
def plotnad(fnad,fout): gmt = GMT(config={'BASEMAP_TYPE':'plain','ANOT_FONT_SIZE':8, 'LABEL_FONT_SIZE':10,'COLOR_BACKGROUND':'255/255/255', 'COLOR_FOREGROUND':'0/0/0','COLOR_NAN':'255/255/255'} ) grd=gmt.tempfilename('tmp.grd') grdcpt=gmt.tempfilename('tmp.cpt') xyz=gmt.tempfilename('xyz.txt') xyz2=gmt.tempfilename('xyz2.txt') rng='1/5/0/40' scl='X4.2/-6' kosu1,kosu2,x,y,dbest,sbest,dmean,smean = nadplot(fnad,smin=1.5) f = open(xyz,'w') for ii in range(len(y)): for jj in range(len(x)): if kosu1[ii,jj] > 0: print >>f, x[jj], y[ii], kosu1[ii,jj] f.close() f = open(xyz2,'w') for ii in range(len(y)): for jj in range(len(x)): if kosu2[ii,jj] > 0: print >>f, x[jj], y[ii], '0.5' f.close() gmt.xyz2grd(xyz,G=grd,R=rng,I='.02/.5',out_discard=True) gmt.grd2cpt(grd,C="wysiwyg",Q='o',Z=True,out_filename=grdcpt) gmt.psmask(xyz2,R=rng,T=True,J=scl,I='.02/.5',G='lightgray') gmt.grdimage(grd,J=scl,R=rng,Q=True,P=True,C=grdcpt) gmt.psbasemap(R=rng,J=scl,B='a1f.5:Velocity [km/s]:/a10f5:Depth [km]:WNse') gmt.psxy(R=True,J=True,B=True,W='3,red',in_columns=[sbest,dbest]) gmt.psxy(R=True,J=True,B=True,W='3,white',in_columns=[smean,dmean]) gmt.psscale(C=grdcpt,D='1.0/1./4c/.4ch',B='a40f10:No. of models:/::') gmt.save(fout) os.system('gv '+fout+'&') return 1
def plot_rep(repfile, paramfile, wtype, pixfile, show=True, misfit=0.1, minmax=True): """ Plot 1D velocity profile. """ # ## read in models from dinver-output os.system('gpdcreport ' + repfile + ' >tmp.mdl') models, data, nd, ne, nrow, nlayer = get_models('tmp.mdl') os.remove('tmp.mdl') if misfit == 'all': misfit = data.max() elif misfit <= data.min(): misfit = median(data) # ## calculate density sreso = 0.05 # horizontal resolution dreso = .5 # vertical resolution grid1, grid2, x, y, smean, dmean = dplot(models, data, nd, ne, dreso=dreso, sreso=sreso, mf=misfit, nlayer=nlayer, dmax=120) # ## write output into temporary files that can be plotted by gmt xyz = tempfile.mktemp() xyz2 = tempfile.mktemp() grd = tempfile.mktemp() grdcpt = tempfile.mktemp() fout = pixfile f = open(xyz, 'w') for ii in range(len(y)): for jj in range(len(x)): if grid1[ii, jj] > 0.0: print >> f, x[jj], -y[ii], grid1[ii, jj] f.close() f = open(xyz2, 'w') for ii in range(len(y)): for jj in range(len(x)): if grid2[ii, jj] > 0: print >> f, x[jj], -y[ii], '0.5' f.close() lat, lon = dissect_fname(repfile) if wtype == 'love': wt = 'L' if wtype == 'rayleigh': wt = 'R' # print repfile, lat, lon # ## gmt plot rng = '1/5/-120/0' step = '%f/%f' % (sreso, dreso) anot = int(grid1.max() / 1000.) * 1000 / 2. tick = anot / 2 gmt = GMT(config={'ANOT_FONT_SIZE':8, 'LABEL_FONT_SIZE':10, 'ANNOT_OFFSET_SECONDARY':'0.1c', 'ANNOT_OFFSET_PRIMARY':'0.1c', 'LABEL_OFFSET':'0.1c', 'FRAME_PEN':'.5p'}) widgets, layout = make_widget() if 1: widget = widgets[2] gmt.xyz2grd(xyz, G=grd, R=rng, I='%f/%f' % (sreso, dreso), out_discard=True) gmt.grd2cpt(grd, L='0/%d' % 3000, C="wysiwyg", D=True, Z=True, out_filename=grdcpt) gmt.psbasemap(R=True, B='a1f.5:S-velocity [km/s]:/a10f5:Depth [km]:WnSe', *widget.XYJ()) # gmt.psmask(xyz2, R=True, T=True, I='%f/%f' % (sreso, dreso), G='lightgray', *widget.XYJ()) gmt.grdimage(grd, R=True, Q=True, C=grdcpt, *widget.XYJ()) gmt.psxy(R=True, B=True, W='3,black', in_columns=[smean, -dmean], *widget.XYJ()) bmdl = get_best_model(repfile, dreso, dmax=120., dmin=0.) gmt.psxy(R=True, B=True, W='3,black,-', in_rows=bmdl, *widget.XYJ()) gmt.psscale(widget.XYJ()[0], widget.XYJ()[1], C=grdcpt, D='1.7c/1.5c/2.5c/.4ch', B='a%df%d10:No. of models:/::' % (1000, 500)) txtstr = "1.2 -7. 8 0 1 LT lat = %3.2f" % lat gmt.pstext(R=rng, G='0/0/0', N=True, in_string=txtstr, *widget.XYJ()) txtstr = "1.2 -12. 8 0 1 LT lon = %3.2f" % lon gmt.pstext(R=True, G='0/0/0', N=True, in_string=txtstr, *widget.XYJ()) # plot the minimum and maximum model that is allowed # by the parameterisation if minmax: mdl_min, mdl_max = minmax_mdl(paramfile) gmt.psxy(R=True, B=True, W='3,red,-', in_rows=mdl_min, *widget.XYJ()) gmt.psxy(R=True, B=True, W='3,red,-', in_rows=mdl_max, *widget.XYJ()) if 1: p, v, e = get_disp(repfile, wtype='phase') plot_disp(gmt, repfile, widgets[1], p, v, e, 'phase', ptype='p', wtype=wt, mode=0, misfit=misfit) p, v, e = get_disp(repfile, wtype='group') plot_disp(gmt, repfile, widgets[0], p, v, e, 'group', ptype='g', wtype=wt, mode=0, misfit=misfit) if 0: p, v, e = get_disp(repfile, wtype='grouponly') plot_disp(gmt, repfile, widgets[0], p, v, e, 'group', ptype='g', wtype=wt, mode=0, misfit=misfit) if 0: plot_hist(gmt, widgets, models, nd, ne) gmt.save(fout) meanfout = fout.replace('.eps', '_mean.txt') savetxt(meanfout, vstack((-dmean, smean)).T) if show: os.system('gv %(fout)s&' % vars())
for lat in runlat: for lon in runlon: print >>f, lon, lat f.close() ### Plot original na04_moho = loadtxt('./LITH5.0/NA04_moho.xyf') gmt = GMT(config={'PAGE_ORIENTATION':'landscape'}) rng = '-145/-50/35/80' scl = 'L-100/60/45/65/12c' anot = 'a20f10/a25f5WSne' fout = 'na04_moho.eps' tmpgrd = gmt.tempfilename('moho_temp.grd') mohogrd = gmt.tempfilename('moho.grd') mohocpt = gmt.tempfilename('moho.cpt') gmt.xyz2grd(G=mohogrd,I='%f/%f'%(0.25,0.25),R=rng,out_discard=True,in_rows=na04_moho) gmt.grd2cpt(mohogrd,E=50,L='10/60',C="seis",out_filename=mohocpt) gmt.grdtrack(xyfile,G=mohogrd,R=True,out_filename=xyzfile) gmt.grdimage(mohogrd,R=True,J=scl,C=mohocpt) gmt.pscoast(R=True,J=scl,B=anot,D='i',W='thinnest' ) ### Plot resampled na04_moho = loadtxt(xyzfile) gmt.xyz2grd(G=mohogrd,I='%f/%f'%(1.,1.),R=rng,out_discard=True,in_rows=na04_moho) gmt.grdimage(mohogrd,R=True,J=scl,C=mohocpt,X='13c') gmt.pscoast(R=True,J=scl,B=anot,D='i',W='thinnest' ) gmt.psscale(C=mohocpt,V=True,D='0c/-.7c/6c/.2ch',B='10::/:km:') gmt.save(fout) os.system('gv %s&'%fout)