Example #1
0
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+'&')
Example #2
0
def plot_rep(repfile,pixfile,realmod):
    ### read in models from dinver-output
    os.system('/usr/local/Geopsy.org/bin/gpdcreport '+repfile+' >tmp.mdl')
    models, data, nd, ne, nrow, nlayer = get_models('tmp.mdl')
    #os.remove('tmp.mdl')
    ### calculate density
    sreso = 0.05 #horizontal resolution
    dreso = 0.5  #vertical resolution
    misfit = 1.0 #misfit threshhold
    grid1, grid2, x, y, smean, dmean = dplot(models,data,nd,ne,dreso=dreso,sreso=sreso,mf=misfit,nlayer=nlayer)
    ### write output into temporary files that can be plotted by gmt
    xyz  = tempfile.mktemp()
    xyz  = 'xyz.txt'
    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()

    ### gmt plot
    rng = '-R1/5/0/40'
    scl = '-JX10.2/-12'
    step='-I%f/%f'%(sreso,dreso)
    os.system('xyz2grd %(xyz)s -G%(grd)s %(rng)s %(step)s'%vars())
    os.system('grd2cpt %(grd)s -Cwysiwyg -Z > %(grdcpt)s'%vars())
    os.system('psmask %(xyz2)s %(rng)s %(scl)s %(step)s -Glightgray -K > %(fout)s'%vars())
    os.system('grdimage %(grd)s %(rng)s %(scl)s -Q -C%(grdcpt)s -K -O >> %(fout)s'%vars())
    os.system('psmask -C -K -O >> %(fout)s'%vars())
    os.system("psbasemap %(rng)s %(scl)s -Ba1f.5:'S-velocity [km/s]':/a10f5:'Depth [km]':WnSe -K -O >> %(fout)s"%vars())
    p = Popen('psxy -R -J -B -W3,black -O -K>> %(fout)s'%vars(),shell=True,stdin=PIPE).stdin
    ### plot weighted average for all models with misfit better than defined threshhold
    for _v,_d in zip(smean,dmean):
        print >>p,_v,_d
    p.close()
    p = Popen('psxy -R -J -B -W3,red -O -K >> %(fout)s'%vars(),shell=True,stdin=PIPE).stdin
    ### plot true model
    for _v,_d in zip(realmod[:,0],realmod[:,1]):
        print >>p,_v,_d
    p.close()
    prf = get_best_model(repfile,dreso)
    p = Popen('psxy -R -J -B -W3,white -O >> %(fout)s'%vars(),shell=True,stdin=PIPE).stdin
    ### plot best model
    for l in prf:
        print >>p,l[0],-l[1]
    p.close()
    os.system('gv %(fout)s&'%vars())
Example #3
0
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())