Example #1
0
def plot_AMS(sdata,pointsize=50,errors='None',bedding=[],incolor='N',):
    """
    adapted from pmagplotlib.plotANIS
    set errors to 'h' for hext ellipses, 'b' for bootstrap, 'p' for parametric bootstrap
    bootstrap trials currently hard-coded as 1000
    for bedding, give as [strike,dip] ;
    """
    subplot_net() #set up stereonet
    if incolor=='N': colours=['0.4','0.6','0.5'] #specify greyscale colours
    else: colours=['lightcoral','lightskyblue','lightgreen']
    #if bedding plot bedding plane
    if bedding !=[]:
        # hard-coded version of pmag.plotC
        D_c,I_c=pmag.circ(bedding[0]-90.,90.-bedding[1],90.)
        X_c_d,Y_c_d=[],[]
        for k in range(len(D_c)):
            XY=pmag.dimap(D_c[k],I_c[k])
            if I_c[k]>0:
                X_c_d.append(XY[0])
                Y_c_d.append(XY[1])
        plt.plot(X_c_d,Y_c_d,color='grey',dashes=[10,2],linewidth=3,zorder=1)
    Vs=[]
    #plot individual sample data
    for s in sdata:
        tau,V=pmag.doseigs(s)
        Vs.append(V)
    plotEVEC(Vs,pointsize,colours)
    #plot mean eigenvectors
    nf,sigma,avs=pmag.sbar(sdata)
    Vs=[]
    mtau,mV=pmag.doseigs(avs)
    Vs.append(mV)
    plotEVEC(Vs,pointsize*4,['w','w','w'], 'black',7)
    #plot confidence limits
    hpars=pmag.dohext(nf,sigma,avs)
    if errors=='h':
        ellpars=[hpars["v1_dec"],hpars["v1_inc"],hpars["e12"],hpars["v2_dec"],hpars["v2_inc"],hpars["e13"],hpars["v3_dec"],hpars["v3_inc"]]
        plotELL(ellpars,'black',1,1)
        ellpars=[hpars["v2_dec"],hpars["v2_inc"],hpars["e23"],hpars["v3_dec"],hpars["v3_inc"],hpars["e12"],hpars["v1_dec"],hpars["v1_inc"]]
        plotELL(ellpars,'black',1,1)
        ellpars=[hpars["v3_dec"],hpars["v3_inc"],hpars["e13"],hpars["v1_dec"],hpars["v1_inc"],hpars["e23"],hpars["v2_dec"],hpars["v2_inc"]]
        plotELL(ellpars,'black',1,1)
    elif errors=='b' or errors=='p':
        if errors=='p': ipar=1
        else: ipar=0
        Tmean,Vmean,Taus,BVs=pmag.s_boot(sdata,ipar,1000) # get eigenvectors of mean tensor
        # the problem with the bootstrap is that for fabrics where one or more eigenvectors is close to the horizontal,
        # you end up with dipolar data        
                        
        bpars=pmag.sbootpars(Taus,BVs,Vmean)
        bpars['t1']=hpars['t1']
        bpars['t2']=hpars['t2']
        bpars['t3']=hpars['t3']
        #have to pair zeta value with eta dec/inc, and vice-versa, to align error ellipses correctly.
        ellpars=[bpars["v1_dec"],bpars["v1_inc"],bpars["v1_eta"],bpars["v1_eta_dec"],bpars["v1_eta_inc"],bpars["v1_zeta"],bpars["v1_zeta_dec"],bpars["v1_zeta_inc"]]
        plotELL(ellpars,'black',1,1)
        ellpars=[bpars["v2_dec"],bpars["v2_inc"],bpars["v2_eta"],bpars["v2_eta_dec"],bpars["v2_eta_inc"],bpars["v2_zeta"],bpars["v2_zeta_dec"],bpars["v2_zeta_inc"]]
        plotELL(ellpars,'black',1,1)
        ellpars=[bpars["v3_dec"],bpars["v3_inc"],bpars["v3_eta"],bpars["v3_eta_dec"],bpars["v3_eta_inc"],bpars["v3_zeta"],bpars["v3_zeta_dec"],bpars["v3_zeta_inc"]]
        plotELL(ellpars,'black',1,1) 
Example #2
0
def main():
    """
    NAME
        s_eigs.py

    DESCRIPTION 
        converts .s format data to eigenparameters.
 
    SYNTAX
        s_eigs.py [-h][options]

    OPTIONS
        -h prints help message and quits
        -i allows interactive entry of file name
        -f FILE specifies filename on command line
        -F FILE specifies output file
        < filename, reads from standard input (Unix like operating systems only) 

    INPUT
        x11,x22,x33,x12,x23,x13
  
    OUTPUT
        tau_i, dec_i inc_i of eigenvectors 
    """
    if '-h' in sys.argv:
        print main.__doc__
        sys.exit()
    elif '-i' in sys.argv:
        file=raw_input("Enter filename for processing: ")
        f=open(file,'rU')
        data=f.readlines()
        f.close()
    elif '-f' in sys.argv:
        ind=sys.argv.index('-f')
        file=sys.argv[ind+1] 
        f=open(file,'rU')
        data=f.readlines()
        f.close()
    else: 
        data=sys.stdin.readlines()
    ofile = ""
    if '-F' in sys.argv:
        ind=sys.argv.index('-F')
        ofile=sys.argv[ind+1]
        out=open(ofile, "w + a")
    for line in data:
        s=[]
        rec=line.split()
        for i in range(6):
            s.append(float(rec[i]))
        tau,Vdirs=pmag.doseigs(s)
        outstring='%10.8f %6.2f %6.2f %10.8f %6.2f %6.2f %10.8f %6.2f %6.2f'%(tau[2],Vdirs[2][0],Vdirs[2][1],tau[1],Vdirs[1][0],Vdirs[1][1],tau[0],Vdirs[0][0],Vdirs[0][1])
        if ofile == "":
            print outstring
        else:
            out.write(outstring+'\n')
Example #3
0
def plot_AMS(
    sdata,
    pointsize=50,
    errors='None',
    bedding=[],
    incolor='N',
):
    """
    adapted from pmagplotlib.plotANIS
    set errors to 'h' for hext ellipses, 'b' for bootstrap, 'p' for parametric bootstrap
    bootstrap trials currently hard-coded as 1000
    for bedding, give as [strike,dip] ;
    """
    subplot_net()  #set up stereonet
    if incolor == 'N':
        colours = ['0.4', '0.6', '0.5']  #specify greyscale colours
    else:
        colours = ['lightcoral', 'lightskyblue', 'lightgreen']
    #if bedding plot bedding plane
    if bedding != []:
        # hard-coded version of pmag.plotC
        D_c, I_c = pmag.circ(bedding[0] - 90., 90. - bedding[1], 90.)
        X_c_d, Y_c_d = [], []
        for k in range(len(D_c)):
            XY = pmag.dimap(D_c[k], I_c[k])
            if I_c[k] > 0:
                X_c_d.append(XY[0])
                Y_c_d.append(XY[1])
        plt.plot(X_c_d,
                 Y_c_d,
                 color='grey',
                 dashes=[10, 2],
                 linewidth=3,
                 zorder=1)
    Vs = []
    #plot individual sample data
    for s in sdata:
        tau, V = pmag.doseigs(s)
        Vs.append(V)
    plotEVEC(Vs, pointsize, colours)
    #plot mean eigenvectors
    nf, sigma, avs = pmag.sbar(sdata)
    Vs = []
    mtau, mV = pmag.doseigs(avs)
    Vs.append(mV)
    plotEVEC(Vs, pointsize * 4, ['w', 'w', 'w'], 'black', 7)
    #plot confidence limits
    hpars = pmag.dohext(nf, sigma, avs)
    if errors == 'h':
        ellpars = [
            hpars["v1_dec"], hpars["v1_inc"], hpars["e12"], hpars["v2_dec"],
            hpars["v2_inc"], hpars["e13"], hpars["v3_dec"], hpars["v3_inc"]
        ]
        plotELL(ellpars, 'black', 1, 1)
        ellpars = [
            hpars["v2_dec"], hpars["v2_inc"], hpars["e23"], hpars["v3_dec"],
            hpars["v3_inc"], hpars["e12"], hpars["v1_dec"], hpars["v1_inc"]
        ]
        plotELL(ellpars, 'black', 1, 1)
        ellpars = [
            hpars["v3_dec"], hpars["v3_inc"], hpars["e13"], hpars["v1_dec"],
            hpars["v1_inc"], hpars["e23"], hpars["v2_dec"], hpars["v2_inc"]
        ]
        plotELL(ellpars, 'black', 1, 1)
    elif errors == 'b' or errors == 'p':
        if errors == 'p': ipar = 1
        else: ipar = 0
        Tmean, Vmean, Taus, BVs = pmag.s_boot(
            sdata, ipar, 1000)  # get eigenvectors of mean tensor
        # the problem with the bootstrap is that for fabrics where one or more eigenvectors is close to the horizontal,
        # you end up with dipolar data

        bpars = pmag.sbootpars(Taus, BVs, Vmean)
        bpars['t1'] = hpars['t1']
        bpars['t2'] = hpars['t2']
        bpars['t3'] = hpars['t3']
        #have to pair zeta value with eta dec/inc, and vice-versa, to align error ellipses correctly.
        ellpars = [
            bpars["v1_dec"], bpars["v1_inc"], bpars["v1_eta"],
            bpars["v1_eta_dec"], bpars["v1_eta_inc"], bpars["v1_zeta"],
            bpars["v1_zeta_dec"], bpars["v1_zeta_inc"]
        ]
        plotELL(ellpars, 'black', 1, 1)
        ellpars = [
            bpars["v2_dec"], bpars["v2_inc"], bpars["v2_eta"],
            bpars["v2_eta_dec"], bpars["v2_eta_inc"], bpars["v2_zeta"],
            bpars["v2_zeta_dec"], bpars["v2_zeta_inc"]
        ]
        plotELL(ellpars, 'black', 1, 1)
        ellpars = [
            bpars["v3_dec"], bpars["v3_inc"], bpars["v3_eta"],
            bpars["v3_eta_dec"], bpars["v3_eta_inc"], bpars["v3_zeta"],
            bpars["v3_zeta_dec"], bpars["v3_zeta_inc"]
        ]
        plotELL(ellpars, 'black', 1, 1)
Example #4
0
def main():
    """
    NAME
        aniso_magic.py

    DESCRIPTION
        plots anisotropy data with either bootstrap or hext ellipses
    
    SYNTAX
        aniso_magic.py [-h] [command line options]
    OPTIONS 
        -h plots help message and quits
        -usr USER: set the user name
        -f AFILE, specify rmag_anisotropy formatted file for input
        -F RFILE, specify rmag_results formatted file for output
        -x Hext [1963] and bootstrap
        -B DON'T do bootstrap, do Hext
        -par Tauxe [1998] parametric bootstrap
        -v plot bootstrap eigenvectors instead of ellipses
        -sit plot by site instead of entire file
        -crd [s,g,t] coordinate system, default is specimen (g=geographic, t=tilt corrected)
        -P don't make any plots - just make rmag_results table
        -sav don't make the rmag_results table - just save all the plots
        -fmt [svg, png, jpg] format for output images, pdf default
        -gtc DEC INC  dec,inc of pole to great circle 
        -d Vi DEC INC; Vi (1,2,3) to compare to direction DEC INC
        -nb N; specifies the number of bootstraps - default is 1000
    DEFAULTS  
       AFILE:  rmag_anisotropy.txt
       RFILE:  rmag_results.txt
       plot bootstrap ellipses of Constable & Tauxe [1987]
    NOTES
       minor axis: circles
       major axis: triangles
       principal axis: squares
       directions are plotted on the lower hemisphere
       for bootstrapped eigenvector components: Xs: blue, Ys: red, Zs: black
"""
#
    dir_path="."
    version_num=pmag.get_version()
    verbose=pmagplotlib.verbose
    args=sys.argv
    ipar,ihext,ivec,iboot,imeas,isite,iplot,vec=0,0,0,1,1,0,1,0
    hpars,bpars,PDir=[],[],[]
    CS,crd='-1','s'
    nb=1000
    fmt='eps'
    ResRecs=[]
    orlist=[]
    outfile,comp,Dir,gtcirc,PDir='rmag_results.txt',0,[],0,[]
    infile='rmag_anisotropy.txt'
    if "-h" in args:
        print main.__doc__
        sys.exit()
    if '-WD' in args:
        ind=args.index('-WD')
        dir_path=args[ind+1]
    if '-nb' in args:
        ind=args.index('-nb')
        nb=int(args[ind+1])
    if '-usr' in args:
        ind=args.index('-usr')
        user=args[ind+1]
    else:
        user=""
    if '-B' in args:iboot,ihext=0,1
    if '-par' in args:ipar=1
    if '-x' in args:ihext=1
    if '-v' in args:ivec=1
    if '-sit' in args:isite=1
    if '-P' in args:iplot=0
    if '-f' in args:
        ind=args.index('-f')
        infile=args[ind+1]
    if '-F' in args:
        ind=args.index('-F')
        outfile=args[ind+1]
    if '-crd' in sys.argv:
        ind=sys.argv.index('-crd')
        crd=sys.argv[ind+1]
        if crd=='g':CS='0'
        if crd=='t': CS='100'
    if '-fmt' in args:
        ind=args.index('-fmt')
        fmt=args[ind+1]
    if '-sav' in args:
        plots=1
        verbose=0
    else:
        plots=0
    if '-gtc' in args:
        ind=args.index('-gtc')
        d,i=float(args[ind+1]),float(args[ind+2])
        PDir.append(d)
        PDir.append(i)
    if '-d' in args:
        comp=1
        ind=args.index('-d')
        vec=int(args[ind+1])-1
        Dir=[float(args[ind+2]),float(args[ind+3])] 
#
# set up plots
#
    infile=dir_path+'/'+infile
    outfile=dir_path+'/'+outfile
    ANIS={}
    initcdf,inittcdf=0,0
    ANIS['data'],ANIS['conf']=1,2
    if iboot==1: 
        ANIS['tcdf']=3
        if iplot==1:
            inittcdf=1
            pmagplotlib.plot_init(ANIS['tcdf'],5,5)
        if comp==1 and iplot==1:
            initcdf=1
            ANIS['vxcdf'],ANIS['vycdf'],ANIS['vzcdf']=4,5,6
            pmagplotlib.plot_init(ANIS['vxcdf'],5,5)
            pmagplotlib.plot_init(ANIS['vycdf'],5,5)
            pmagplotlib.plot_init(ANIS['vzcdf'],5,5)
    if iplot==1:
        pmagplotlib.plot_init(ANIS['conf'],5,5)
        pmagplotlib.plot_init(ANIS['data'],5,5)
# read in the data
    data,ifiletype=pmag.magic_read(infile)
    for rec in data:  # find all the orientation systems
        if 'anisotropy_tilt_correction' not in rec.keys():rec['anisotropy_tilt_correction']='-1'
        if rec['anisotropy_tilt_correction'] not in orlist: 
            orlist.append(rec['anisotropy_tilt_correction'])
    if CS not in orlist:
        if len(orlist)>0:
            CS=orlist[0]
        else:
            CS='-1'   
        if CS=='-1':crd='s'
        if CS=='0':crd='g'
        if CS=='100':crd='t'
        if verbose:print "desired coordinate system not available, using available: ",crd
    if isite==1:
        sitelist=[]
        for rec in data:
            if rec['er_site_name'] not in sitelist:sitelist.append(rec['er_site_name']) 
        sitelist.sort()  
        plt=len(sitelist)
    else:plt=1
    k=0
    while k<plt:
      site=""
      sdata,Ss=[],[] # list of S format data
      Locs,Sites,Samples,Specimens,Cits=[],[],[],[],[]
      if isite==0:
          sdata=data
      else:
          site=sitelist[k]
          for rec in data:
              if rec['er_site_name']==site:sdata.append(rec) 
      anitypes=[]
      csrecs=pmag.get_dictitem(sdata,'anisotropy_tilt_correction',CS,'T')
      for rec in csrecs:
          if rec['anisotropy_type'] not in anitypes:anitypes.append(rec['anisotropy_type'])
          if rec['er_location_name'] not in Locs:Locs.append(rec['er_location_name'])
          if rec['er_site_name'] not in Sites:Sites.append(rec['er_site_name'])
          if rec['er_sample_name'] not in Samples:Samples.append(rec['er_sample_name'])
          if rec['er_specimen_name'] not in Specimens:Specimens.append(rec['er_specimen_name'])
          if rec['er_citation_names'] not in Cits:Cits.append(rec['er_citation_names'])
          s=[]
          s.append(float(rec["anisotropy_s1"]))
          s.append(float(rec["anisotropy_s2"]))
          s.append(float(rec["anisotropy_s3"]))
          s.append(float(rec["anisotropy_s4"]))
          s.append(float(rec["anisotropy_s5"]))
          s.append(float(rec["anisotropy_s6"]))
          if s[0]<=1.0:Ss.append(s) # protect against crap
          tau,Vdirs=pmag.doseigs(s)
          ResRec={}
          ResRec['er_location_names']=rec['er_location_name']
          ResRec['er_citation_names']=rec['er_citation_names']
          ResRec['er_site_names']=rec['er_site_name']
          ResRec['er_sample_names']=rec['er_sample_name']
          ResRec['er_specimen_names']=rec['er_specimen_name']
          ResRec['rmag_result_name']=rec['er_specimen_name']+":"+rec['anisotropy_type']
          ResRec["er_analyst_mail_names"]=user
          ResRec["tilt_correction"]=CS
          ResRec["anisotropy_type"]=rec['anisotropy_type']
          ResRec["anisotropy_v1_dec"]='%7.1f'%(Vdirs[0][0])
          ResRec["anisotropy_v2_dec"]='%7.1f'%(Vdirs[1][0])
          ResRec["anisotropy_v3_dec"]='%7.1f'%(Vdirs[2][0])
          ResRec["anisotropy_v1_inc"]='%7.1f'%(Vdirs[0][1])
          ResRec["anisotropy_v2_inc"]='%7.1f'%(Vdirs[1][1])
          ResRec["anisotropy_v3_inc"]='%7.1f'%(Vdirs[2][1])
          ResRec["anisotropy_t1"]='%10.8f'%(tau[0])
          ResRec["anisotropy_t2"]='%10.8f'%(tau[1])
          ResRec["anisotropy_t3"]='%10.8f'%(tau[2])
          ResRec['anisotropy_type']=pmag.makelist(anitypes)
          ResRecs.append(ResRec) 
      if len(Ss)>1:
          title="LO:_"+ResRec['er_location_names']+'_SI:_'+site+'_SA:__SP:__CO:_'+crd
          ResRec['er_location_names']=pmag.makelist(Locs)
          bpars,hpars=pmagplotlib.plotANIS(ANIS,Ss,iboot,ihext,ivec,ipar,title,iplot,comp,vec,Dir,nb)
          if len(PDir)>0:
              pmagplotlib.plotC(ANIS['data'],PDir,90.,'g')
              pmagplotlib.plotC(ANIS['conf'],PDir,90.,'g')
          if verbose:pmagplotlib.drawFIGS(ANIS)
          ResRec['er_location_names']=pmag.makelist(Locs)
          if plots==1:
              save(ANIS,fmt,title)
              sys.exit()
          ResRec={}
          ResRec['er_citation_names']=pmag.makelist(Cits)
          ResRec['er_location_names']=pmag.makelist(Locs)
          ResRec['er_site_names']=pmag.makelist(Sites)
          ResRec['er_sample_names']=pmag.makelist(Samples)
          ResRec['er_specimen_names']=pmag.makelist(Specimens)
          ResRec['rmag_result_name']=pmag.makelist(Sites)+":"+pmag.makelist(anitypes)
          ResRec['anisotropy_type']=pmag.makelist(anitypes)
          ResRec["er_analyst_mail_names"]=user
          ResRec["tilt_correction"]=CS
          if isite=="0":ResRec['result_description']="Study average using coordinate system: "+ CS
          if isite=="1":ResRec['result_description']="Site average using coordinate system: " +CS
          if hpars!=[] and ihext==1:
              HextRec={}
              for key in ResRec.keys():HextRec[key]=ResRec[key]   # copy over stuff 
              HextRec["anisotropy_v1_dec"]='%7.1f'%(hpars["v1_dec"])
              HextRec["anisotropy_v2_dec"]='%7.1f'%(hpars["v2_dec"])
              HextRec["anisotropy_v3_dec"]='%7.1f'%(hpars["v3_dec"])
              HextRec["anisotropy_v1_inc"]='%7.1f'%(hpars["v1_inc"])
              HextRec["anisotropy_v2_inc"]='%7.1f'%(hpars["v2_inc"])
              HextRec["anisotropy_v3_inc"]='%7.1f'%(hpars["v3_inc"])
              HextRec["anisotropy_t1"]='%10.8f'%(hpars["t1"])
              HextRec["anisotropy_t2"]='%10.8f'%(hpars["t2"])
              HextRec["anisotropy_t3"]='%10.8f'%(hpars["t3"])
              HextRec["anisotropy_hext_F"]='%7.1f '%(hpars["F"])
              HextRec["anisotropy_hext_F12"]='%7.1f '%(hpars["F12"])
              HextRec["anisotropy_hext_F23"]='%7.1f '%(hpars["F23"])
              HextRec["anisotropy_v1_eta_semi_angle"]='%7.1f '%(hpars["e12"])
              HextRec["anisotropy_v1_eta_dec"]='%7.1f '%(hpars["v2_dec"])
              HextRec["anisotropy_v1_eta_inc"]='%7.1f '%(hpars["v2_inc"])
              HextRec["anisotropy_v1_zeta_semi_angle"]='%7.1f '%(hpars["e13"])
              HextRec["anisotropy_v1_zeta_dec"]='%7.1f '%(hpars["v3_dec"])
              HextRec["anisotropy_v1_zeta_inc"]='%7.1f '%(hpars["v3_inc"])
              HextRec["anisotropy_v2_eta_semi_angle"]='%7.1f '%(hpars["e12"])
              HextRec["anisotropy_v2_eta_dec"]='%7.1f '%(hpars["v1_dec"])
              HextRec["anisotropy_v2_eta_inc"]='%7.1f '%(hpars["v1_inc"])
              HextRec["anisotropy_v2_zeta_semi_angle"]='%7.1f '%(hpars["e23"])
              HextRec["anisotropy_v2_zeta_dec"]='%7.1f '%(hpars["v3_dec"])
              HextRec["anisotropy_v2_zeta_inc"]='%7.1f '%(hpars["v3_inc"])
              HextRec["anisotropy_v3_eta_semi_angle"]='%7.1f '%(hpars["e12"])
              HextRec["anisotropy_v3_eta_dec"]='%7.1f '%(hpars["v1_dec"])
              HextRec["anisotropy_v3_eta_inc"]='%7.1f '%(hpars["v1_inc"])
              HextRec["anisotropy_v3_zeta_semi_angle"]='%7.1f '%(hpars["e23"])
              HextRec["anisotropy_v3_zeta_dec"]='%7.1f '%(hpars["v2_dec"])
              HextRec["anisotropy_v3_zeta_inc"]='%7.1f '%(hpars["v2_inc"])
              HextRec["magic_method_codes"]='LP-AN:AE-H'
              if verbose:
                  print "Hext Statistics: "
                  print " tau_i, V_i_D, V_i_I, V_i_zeta, V_i_zeta_D, V_i_zeta_I, V_i_eta, V_i_eta_D, V_i_eta_I"
                  print HextRec["anisotropy_t1"], HextRec["anisotropy_v1_dec"], HextRec["anisotropy_v1_inc"], HextRec["anisotropy_v1_eta_semi_angle"], HextRec["anisotropy_v1_eta_dec"], HextRec["anisotropy_v1_eta_inc"], HextRec["anisotropy_v1_zeta_semi_angle"], HextRec["anisotropy_v1_zeta_dec"], HextRec["anisotropy_v1_zeta_inc"]
                  print HextRec["anisotropy_t2"],HextRec["anisotropy_v2_dec"], HextRec["anisotropy_v2_inc"], HextRec["anisotropy_v2_eta_semi_angle"], HextRec["anisotropy_v2_eta_dec"], HextRec["anisotropy_v2_eta_inc"], HextRec["anisotropy_v2_zeta_semi_angle"], HextRec["anisotropy_v2_zeta_dec"], HextRec["anisotropy_v2_zeta_inc"]
                  print HextRec["anisotropy_t3"], HextRec["anisotropy_v3_dec"], HextRec["anisotropy_v3_inc"], HextRec["anisotropy_v3_eta_semi_angle"], HextRec["anisotropy_v3_eta_dec"], HextRec["anisotropy_v3_eta_inc"], HextRec["anisotropy_v3_zeta_semi_angle"], HextRec["anisotropy_v3_zeta_dec"], HextRec["anisotropy_v3_zeta_inc"]
              HextRec['magic_software_packages']=version_num
              ResRecs.append(HextRec)
          if bpars!=[]:
              BootRec={}
              for key in ResRec.keys():BootRec[key]=ResRec[key]   # copy over stuff 
              BootRec["anisotropy_v1_dec"]='%7.1f'%(bpars["v1_dec"])
              BootRec["anisotropy_v2_dec"]='%7.1f'%(bpars["v2_dec"])
              BootRec["anisotropy_v3_dec"]='%7.1f'%(bpars["v3_dec"])
              BootRec["anisotropy_v1_inc"]='%7.1f'%(bpars["v1_inc"])
              BootRec["anisotropy_v2_inc"]='%7.1f'%(bpars["v2_inc"])
              BootRec["anisotropy_v3_inc"]='%7.1f'%(bpars["v3_inc"])
              BootRec["anisotropy_t1"]='%10.8f'%(bpars["t1"])
              BootRec["anisotropy_t2"]='%10.8f'%(bpars["t2"])
              BootRec["anisotropy_t3"]='%10.8f'%(bpars["t3"])
              BootRec["anisotropy_v1_eta_inc"]='%7.1f '%(bpars["v1_eta_inc"])
              BootRec["anisotropy_v1_eta_dec"]='%7.1f '%(bpars["v1_eta_dec"])
              BootRec["anisotropy_v1_eta_semi_angle"]='%7.1f '%(bpars["v1_eta"])
              BootRec["anisotropy_v1_zeta_inc"]='%7.1f '%(bpars["v1_zeta_inc"])
              BootRec["anisotropy_v1_zeta_dec"]='%7.1f '%(bpars["v1_zeta_dec"])
              BootRec["anisotropy_v1_zeta_semi_angle"]='%7.1f '%(bpars["v1_zeta"])
              BootRec["anisotropy_v2_eta_inc"]='%7.1f '%(bpars["v2_eta_inc"])
              BootRec["anisotropy_v2_eta_dec"]='%7.1f '%(bpars["v2_eta_dec"])
              BootRec["anisotropy_v2_eta_semi_angle"]='%7.1f '%(bpars["v2_eta"])
              BootRec["anisotropy_v2_zeta_inc"]='%7.1f '%(bpars["v2_zeta_inc"])
              BootRec["anisotropy_v2_zeta_dec"]='%7.1f '%(bpars["v2_zeta_dec"])
              BootRec["anisotropy_v2_zeta_semi_angle"]='%7.1f '%(bpars["v2_zeta"])
              BootRec["anisotropy_v3_eta_inc"]='%7.1f '%(bpars["v3_eta_inc"])
              BootRec["anisotropy_v3_eta_dec"]='%7.1f '%(bpars["v3_eta_dec"])
              BootRec["anisotropy_v3_eta_semi_angle"]='%7.1f '%(bpars["v3_eta"])
              BootRec["anisotropy_v3_zeta_inc"]='%7.1f '%(bpars["v3_zeta_inc"])
              BootRec["anisotropy_v3_zeta_dec"]='%7.1f '%(bpars["v3_zeta_dec"])
              BootRec["anisotropy_v3_zeta_semi_angle"]='%7.1f '%(bpars["v3_zeta"])
              BootRec["anisotropy_hext_F"]=''
              BootRec["anisotropy_hext_F12"]=''
              BootRec["anisotropy_hext_F23"]=''
              BootRec["magic_method_codes"]='LP-AN:AE-H:AE-BS' # regular bootstrap
              if ipar==1:BootRec["magic_method_codes"]='LP-AN:AE-H:AE-BS-P' # parametric bootstrap
              if verbose:
                  print "Boostrap Statistics: "
                  print " tau_i, V_i_D, V_i_I, V_i_zeta, V_i_zeta_D, V_i_zeta_I, V_i_eta, V_i_eta_D, V_i_eta_I"
                  print BootRec["anisotropy_t1"], BootRec["anisotropy_v1_dec"], BootRec["anisotropy_v1_inc"], BootRec["anisotropy_v1_eta_semi_angle"], BootRec["anisotropy_v1_eta_dec"], BootRec["anisotropy_v1_eta_inc"], BootRec["anisotropy_v1_zeta_semi_angle"], BootRec["anisotropy_v1_zeta_dec"], BootRec["anisotropy_v1_zeta_inc"]
                  print BootRec["anisotropy_t2"],BootRec["anisotropy_v2_dec"], BootRec["anisotropy_v2_inc"], BootRec["anisotropy_v2_eta_semi_angle"], BootRec["anisotropy_v2_eta_dec"], BootRec["anisotropy_v2_eta_inc"], BootRec["anisotropy_v2_zeta_semi_angle"], BootRec["anisotropy_v2_zeta_dec"], BootRec["anisotropy_v2_zeta_inc"]
                  print BootRec["anisotropy_t3"], BootRec["anisotropy_v3_dec"], BootRec["anisotropy_v3_inc"], BootRec["anisotropy_v3_eta_semi_angle"], BootRec["anisotropy_v3_eta_dec"], BootRec["anisotropy_v3_eta_inc"], BootRec["anisotropy_v3_zeta_semi_angle"], BootRec["anisotropy_v3_zeta_dec"], BootRec["anisotropy_v3_zeta_inc"]
              BootRec['magic_software_packages']=version_num
              ResRecs.append(BootRec)
          k+=1
          goon=1
          while goon==1 and iplot==1 and verbose: 
              if iboot==1: print "compare with [d]irection "
              print " plot [g]reat circle,  change [c]oord. system, change [e]llipse calculation,  s[a]ve plots, [q]uit "
              if isite==1: print "  [p]revious, [s]ite, [q]uit, <return> for next "
              ans=raw_input("")
              if ans=="q":
                 sys.exit()
              if ans=="e":
                 iboot,ipar,ihext,ivec=1,0,0,0
                 e=raw_input("Do Hext Statistics  1/[0]: ")
                 if e=="1":ihext=1  
                 e=raw_input("Suppress bootstrap 1/[0]: ")
                 if e=="1":iboot=0  
                 if iboot==1:
                     e=raw_input("Parametric bootstrap 1/[0]: ")
                     if e=="1":ipar=1  
                     e=raw_input("Plot bootstrap eigenvectors:  1/[0]: ")
                     if e=="1":ivec=1
                     if iplot==1:
                         if inittcdf==0:
                             ANIS['tcdf']=3
                             pmagplotlib.plot_init(ANIS['tcdf'],5,5)
                             inittcdf=1
                 bpars,hpars=pmagplotlib.plotANIS(ANIS,Ss,iboot,ihext,ivec,ipar,title,iplot,comp,vec,Dir,nb)
                 pmagplotlib.drawFIGS(ANIS)
              if ans=="c":
                  print "Current Coordinate system is: "
                  if CS=='-1':print " Specimen"
                  if CS=='0':print " Geographic"
                  if CS=='100':print " Tilt corrected"
                  key=raw_input(" Enter desired coordinate system: [s]pecimen, [g]eographic, [t]ilt corrected ")
                  if key=='s':CS='-1'
                  if key=='g':CS='0'
                  if key=='t': CS='100'
                  if CS not in orlist:
                      if len(orlist)>0:
                          CS=orlist[0]
                      else:
                          CS='-1'   
                      if CS=='-1':crd='s'
                      if CS=='0':crd='g'
                      if CS=='100':crd='t'
                      print "desired coordinate system not available, using available: ",crd
                  k-=1
                  goon=0
              if ans=="":
                  if isite==1:
                      goon=0
                  else:
                      print "Good bye "
                      sys.exit()
              if ans=='d':
                  if initcdf==0:
                      initcdf=1
                      ANIS['vxcdf'],ANIS['vycdf'],ANIS['vzcdf']=4,5,6
                      pmagplotlib.plot_init(ANIS['vxcdf'],5,5)
                      pmagplotlib.plot_init(ANIS['vycdf'],5,5)
                      pmagplotlib.plot_init(ANIS['vzcdf'],5,5)
                  Dir,comp=[],1
                  print """ 
                      Input: Vi D I to  compare  eigenvector Vi with direction D/I
                             where Vi=1: principal
                                   Vi=2: major
                                   Vi=3: minor
                                   D= declination of comparison direction
                                   I= inclination of comparison direction"""
                  con=1
                  while con==1:
                      try:
                          vdi=raw_input("Vi D I: ").split()
                          vec=int(vdi[0])-1
                          Dir=[float(vdi[1]),float(vdi[2])]
                          con=0
                      except IndexError:
                          print " Incorrect entry, try again " 
                  bpars,hpars=pmagplotlib.plotANIS(ANIS,Ss,iboot,ihext,ivec,ipar,title,iplot,comp,vec,Dir,nb)
                  Dir,comp=[],0
              if ans=='g':
                  con,cnt=1,0
                  while con==1:
                      try:
                          print " Input:  input pole to great circle ( D I) to  plot a great circle:   "
                          di=raw_input(" D I: ").split()
                          PDir.append(float(di[0]))
                          PDir.append(float(di[1]))
                          con=0
                      except:
                          cnt+=1
                          if cnt<10:
                              print " enter the dec and inc of the pole on one line "
                          else:
                              print "ummm - you are doing something wrong - i give up"
                              sys.exit()
                  pmagplotlib.plotC(ANIS['data'],PDir,90.,'g')
                  pmagplotlib.plotC(ANIS['conf'],PDir,90.,'g')
                  if verbose:pmagplotlib.drawFIGS(ANIS)
              if ans=="p": 
                  k-=2
                  goon=0
              if ans=="q": 
                  k=plt
                  goon=0
              if ans=="s":
                  keepon=1
                  site=raw_input(" print site or part of site desired: ")
                  while keepon==1:
                      try:
                          k=sitelist.index(site)
                          keepon=0
                      except:
                          tmplist=[]
                          for qq in range(len(sitelist)):
                              if site in sitelist[qq]:tmplist.append(sitelist[qq])
                          print site," not found, but this was: "
                          print tmplist
                          site=raw_input('Select one or try again\n ')
                          k=sitelist.index(site)
                  goon,ans=0,""
              if ans=="a":
                  locs=pmag.makelist(Locs)
                  title="LO:_"+locs+'_SI:__'+'_SA:__SP:__CO:_'+crd
                  save(ANIS,fmt,title)
                  goon=0
      else:
          if verbose:print 'skipping plot - not enough data points'
          k+=1 
#   put rmag_results stuff here
    if plots==0:
        if len(ResRecs)>0:
            pmag.magic_write(outfile,ResRecs,'rmag_results')
        if verbose:print "Anisotropy results saved in ",outfile
    if verbose:
        print " Good bye "
Example #5
0
def main():
    """
    NAME 
        ANI_depthplot.py

    DESCRIPTION
        plots tau, V3_inc versus core_depth

    SYNTAX
        ANI_depthplot.py [command line optins]

    OPTIONS
        -h prints help message and quits
        -f FILE: specify input rmag_anisotropy format file from magic
        -fb FILE: specify input magic_measurements format file from magic
        -fsa FILE: specify input er_samples format file from magic 
        -d min max [in m] depth range to plot
     DEFAULTS:
         Anisotropy file: rmag_anisotropy.txt
         Bulk susceptibility file: magic_measurements.txt
         Samples file: er_samples.txt
    """
    fmt='.svg'
    dir_path="./"
    pcol=2
    if '-WD' in sys.argv: 
        ind=sys.argv.index('-WD')
        dir_path=sys.argv[ind+1]
    ani_file=dir_path+'/rmag_anisotropy.txt'
    meas_file=dir_path+'/magic_measurements.txt'
    samp_file=dir_path+'/er_samples.txt'
    if '-h' in sys.argv:
        print main.__doc__
        sys.exit()
    if '-f' in sys.argv:
        ind=sys.argv.index('-f')
        ani_file=dir_path+'/'+sys.argv[ind+1]
    if '-fb' in sys.argv:
        ind=sys.argv.index('-fb')
        meas_file=dir_path+'/'+sys.argv[ind+1]
    if '-fsa' in sys.argv:
        ind=sys.argv.index('-fsa')
        samp_file=dir_path+'/'+sys.argv[ind+1]
    if '-fmt' in sys.argv:
        ind=sys.argv.index('-fmt')
        fmt='.'+sys.argv[ind+1]
    dmin,dmax=-1,-1
    if '-d' in sys.argv:
        ind=sys.argv.index('-d')
        dmin=float(sys.argv[ind+1])
        dmax=float(sys.argv[ind+2])
    #
    # get data read in
    isbulk=0
    AniData,file_type=pmag.magic_read(ani_file) 
    Samps,file_type=pmag.magic_read(samp_file) 
    Meas,file_type=pmag.magic_read(meas_file) 
    if file_type=='magic_measurements':isbulk=1
    Data=[]
    Bulks=[]
    BulkDepths=[]
    bmin,bmax=1e6,-1e6 
    for rec in AniData:
        for samp in Samps:
            if samp['er_sample_name'].upper()== rec['er_sample_name'].upper() and 'sample_core_depth' in samp.keys() and samp['sample_core_depth']!="":
                rec['core_depth'] = samp['sample_core_depth']
                if dmax==-1 or float(rec['core_depth'])<dmax and float(rec['core_depth'])>dmin: 
                    Data.append(rec) # fish out data with core_depth
                    if isbulk: 
                        thisbulk=[]
                        for meas in Meas:
                            if meas['er_specimen_name']== rec['er_specimen_name'] and 'measurement_chi_volume' in meas.keys() and meas['measurement_chi_volume'].strip()!="" :
                               Bulks.append(1e6*float(meas['measurement_chi_volume']))
                               if Bulks[-1]<bmin:bmin=Bulks[-1]
                               if Bulks[-1]>bmax:bmax=Bulks[-1]
                               BulkDepths.append(float(samp['sample_core_depth']))
    xlab="Depth (m)"
    if len(Data)>0:
        location=Data[0]['er_location_name']
    else:
        print 'no data to plot'
        sys.exit()
    # collect the data for plotting tau and V3_inc
    Depths,Tau1,Tau2,Tau3,V3Incs=[],[],[],[],[]
    tau_min,tau_max=1,0
    if len(Bulks)>0: pcol+=1
    for rec in Data:
        s=[]
        Depths.append(float(rec['core_depth']))
        s.append(float(rec['anisotropy_s1']))
        s.append(float(rec['anisotropy_s2']))
        s.append(float(rec['anisotropy_s3']))
        s.append(float(rec['anisotropy_s4']))
        s.append(float(rec['anisotropy_s5']))
        s.append(float(rec['anisotropy_s6']))
        tau,Vdirs=pmag.doseigs(s)
        Tau1.append(tau[0])
        Tau2.append(tau[1])
        Tau3.append(tau[2])
        if tau[0]>tau_max:tau_max=tau[0]
        if tau[2]<tau_min:tau_min=tau[2]
        V3Incs.append(Vdirs[2][1])
    if len(Depths)>0:
        if dmax==-1:
            dmax=max(Depths)
            dmin=min(Depths)
        #dmax=dmax+.05*dmax
        #dmin=dmin-.05*dmax
        pylab.figure(1,figsize=(10,8))
        version_num=pmag.get_version()
        pylab.figtext(.02,.01,version_num)
        pylab.subplot(1,pcol,1)
        pylab.plot(Tau1,Depths,'rs') 
        pylab.plot(Tau2,Depths,'b^') 
        pylab.plot(Tau3,Depths,'ko') 
        pylab.axis([tau_min,tau_max,dmax,dmin])
        pylab.xlabel('Eigenvalues')
        pylab.ylabel('Depth (m)')
        pylab.subplot(1,pcol,2)
        pylab.plot(V3Incs,Depths,'ko') 
        pylab.axis([0,90,dmax,dmin])
        pylab.xlabel('V3 Inclination')
        pylab.title(location)
        if pcol==3:
            pylab.subplot(1,pcol,3)
            pylab.plot(Bulks,BulkDepths,'bo') 
            pylab.axis([bmin-1,bmax+1,dmax,dmin])
            pylab.xlabel('Bulk Susc. (uSI)')
        pylab.draw()
        ans=raw_input("Press return to quit  ")
        sys.exit()
    else:
        print "No data points met your criteria - try again"