コード例 #1
0
ファイル: find_EI.py プロジェクト: headmetal/PmagPy
def main():
    """
    NAME
        find_EI.py
 
    DESCRIPTION
        Applies series of assumed flattening factor and "unsquishes" inclinations assuming tangent function.
        Finds flattening factor that gives elongation/inclination pair consistent with TK03.  
        Finds bootstrap confidence bounds

    SYNTAX
        find_EI.py [command line options]

    OPTIONS
        -h prints help message and quits
        -i allows interactive input of file name
        -f FILE specify input file name
        -nb N specify number of bootstraps - the more the better, but slower!, default is 1000
        -fmt [svg,png,eps,pdf..] change plot format, default is svg

    INPUT
        dec/inc pairs, delimited with space or tabs

    OUTPUT
        four plots:  1) equal area plot of original directions
                      2) Elongation/inclination pairs as a function of f,  data plus 25 bootstrap samples
                      3) Cumulative distribution of bootstrapped optimal inclinations plus uncertainties.
                         Estimate from original data set plotted as solid line
                      4) Orientation of principle direction through unflattening
    NOTE: If distribution does not have a solution, plot labeled: Pathological.  Some bootstrap samples may have
       valid solutions and those are plotted in the CDFs and E/I plot.

    """
    fmt,nb='svg',1000
    if '-i' in sys.argv:
        file=raw_input("Enter file name for processing: ")
    elif '-f' in sys.argv:
        ind=sys.argv.index('-f')
        file=sys.argv[ind+1]
    else:
        print main.__doc__
        sys.exit()
    if '-nb' in sys.argv:
        ind=sys.argv.index('-nb')
        nb=int(sys.argv[ind+1])
    if '-fmt' in sys.argv:
        ind=sys.argv.index('-fmt')
        fmt=sys.argv[ind+1]
    data=numpy.loadtxt(file)
    upper,lower=int(round(.975*nb)),int(round(.025*nb))
    E,I=[],[]
    PLTS={'eq':1,'ei':2,'cdf':3,'v2':4}
    pmagplotlib.plot_init(PLTS['eq'],6,6) 
    pmagplotlib.plot_init(PLTS['ei'],5,5) 
    pmagplotlib.plot_init(PLTS['cdf'],5,5) 
    pmagplotlib.plot_init(PLTS['v2'],5,5) 
    pmagplotlib.plotEQ(PLTS['eq'],data,'Data')
    pmagplotlib.drawFIGS(PLTS)
    ppars=pmag.doprinc(data)
    Io=ppars['inc']
    n=ppars["N"]
    Es,Is,Fs,V2s=find_f(data)
    Inc,Elong=Is[-1],Es[-1]
    pmagplotlib.plotEI(PLTS['ei'],Es,Is,Fs[-1])
    pmagplotlib.plotV2s(PLTS['v2'],V2s,Is,Fs[-1])
    b=0
    print "Bootstrapping.... be patient"
    while b<nb:
        bdata=pmag.pseudo(data)
        Es,Is,Fs,V2s=find_f(bdata)
        if b<25:
            pmagplotlib.plotEI(PLTS['ei'],Es,Is,Fs[-1])
        if Es[-1]!=0:
            ppars=pmag.doprinc(bdata)
            I.append(abs(Is[-1]))
            E.append(Es[-1])
            b+=1
            if b%25==0:print b,' out of ',nb
    I.sort()
    E.sort()
    Eexp=[]
    for i in I:
       Eexp.append(EI(i)) 
    if Inc==0:
        title= 'Pathological Distribution: '+'[%7.1f, %7.1f]' %(I[lower],I[upper])
    else:
        title= '%7.1f [%7.1f, %7.1f]' %( Inc, I[lower],I[upper])
    pmagplotlib.plotEI(PLTS['ei'],Eexp,I,1)
    pmagplotlib.plotCDF(PLTS['cdf'],I,'Inclinations','r',title)
    pmagplotlib.plotVs(PLTS['cdf'],[I[lower],I[upper]],'b','--')
    pmagplotlib.plotVs(PLTS['cdf'],[Inc],'g','-')
    pmagplotlib.plotVs(PLTS['cdf'],[Io],'k','-')
    pmagplotlib.drawFIGS(PLTS)
    print "Io Inc  I_lower, I_upper, Elon, E_lower, E_upper"
    print '%7.1f %s %7.1f _ %7.1f ^ %7.1f:  %6.4f _ %6.4f ^ %6.4f' %(Io, " => ", Inc, I[lower],I[upper], Elong, E[lower],E[upper])
    ans= raw_input("S[a]ve plots - <return> to quit:  ")
    if ans!='a':
       print "\n Good bye\n"
       sys.exit()
    files={}
    files['eq']='findEI_eq.'+fmt
    files['ei']='findEI_ei.'+fmt
    files['cdf']='findEI_cdf.'+fmt
    files['v2']='findEI_v2.'+fmt
    pmagplotlib.saveP(PLTS,files)
コード例 #2
0
ファイル: EI.py プロジェクト: jholmes/PmagPy
def main():
    """
    NAME
        EI.py [command line options]

    DESCRIPTION
        Finds bootstrap confidence bounds on Elongation and Inclination data

    SYNTAX
        EI.py  [command line options]

    OPTIONS
        -h prints help message and quits
        -f FILE specifies input file
        -p do parametric bootstrap

    INPUT
        dec/inc pairs

    OUTPUT
        makes a plot of the E/I pair and bootstrapped confidence bounds
        along with the E/I trend predicted by the TK03 field model
        prints out:
            Io (mean inclination), I_lower and I_upper are 95% confidence bounds on inclination
            Eo (elongation), E_lower and E_upper are 95% confidence bounds on elongation
            Edec,Einc are the elongation direction

    """
    par=0
    if '-h' in sys.argv:
        print main.__doc__
        sys.exit()
    if '-f' in sys.argv:
        ind=sys.argv.index('-f')
        file=open(sys.argv[ind+1],'rU')
    if '-p' in sys.argv: par=1
    rseed,nb,data=10,5000,[]
    upper,lower=int(round(.975*nb)),int(round(.025*nb))
    Es,Is=[],[]
    PLTS={'eq':1,'ei':2}
    pmagplotlib.plot_init(PLTS['eq'],5,5) 
    pmagplotlib.plot_init(PLTS['ei'],5,5) 
#    poly_tab= [  3.07448925e-06,  -3.49555831e-04,  -1.46990847e-02,   2.90905483e+00]
    poly_new= [  3.15976125e-06,  -3.52459817e-04,  -1.46641090e-02,   2.89538539e+00]
#    poly_cp88= [ 5.34558576e-06,  -7.70922659e-04,   5.18529685e-03,   2.90941351e+00]
#    poly_qc96= [  7.08210133e-06,  -8.79536536e-04,   1.09625547e-03,   2.92513660e+00]
#    poly_cj98=[  6.56675431e-06,  -7.91823539e-04,  -1.08211350e-03,   2.80557710e+00]
#    poly_tk03_g20= [  4.96757685e-06,  -6.02256097e-04,  -5.96103272e-03,   2.84227449e+00]
#    poly_tk03_g30= [  7.82525963e-06,  -1.39781724e-03,   4.47187092e-02,   2.54637535e+00]
#    poly_gr99_g=[  1.24362063e-07,  -1.69383384e-04,  -4.24479223e-03,   2.59257437e+00]
#    poly_gr99_e=[  1.26348154e-07,   2.01691452e-04,  -4.99142308e-02,   3.69461060e+00]
    E_EI,E_tab,E_new,E_cp88,E_cj98,E_qc96,E_tk03_g20=[],[],[],[],[],[],[]
    E_tk03_g30,E_gr99_g,E_gr99_e=[],[],[]
    I2=range(0,90,5)
    for inc in I2:
        E_new.append(EI(inc,poly_new)) # use the polynomial from Tauxe et al. (2008)
    pmagplotlib.plotEI(PLTS['ei'],E_new,I2,1)
    if '-f' in sys.argv:
        random.seed(rseed)
        for line in file.readlines():
            rec=line.split()
            dec=float(rec[0])
            inc=float(rec[1])
            if par==1:
                if  len(rec)==4:
                    N=(int(rec[2]))  # append n
                    K=float(rec[3])  # append k
                    rec=[dec,inc,N,K]
                    data.append(rec)
            else:
                rec=[dec,inc]
                data.append(rec)
        pmagplotlib.plotEQ(PLTS['eq'],data,'Data')
        ppars=pmag.doprinc(data)
        n=ppars["N"]
        Io=ppars['inc']
        Edec=ppars['Edir'][0]
        Einc=ppars['Edir'][1]
        Eo=(ppars['tau2']/ppars['tau3'])
        b=0
        print 'doing bootstrap - be patient'
        while b<nb:
            bdata=[]
            for j in range(n):
                boot=random.randint(0,n-1)
                random.jumpahead(rseed)
                if par==1:
                    DIs=[]
                    D,I,N,K=data[boot][0],data[boot][1],data[boot][2],data[boot][3]
                    for k in range(N):
                        dec,inc=pmag.fshdev(K)
                        drot,irot=pmag.dodirot(dec,inc,D,I)
                        DIs.append([drot,irot])
                    fpars=pmag.fisher_mean(DIs)
                    bdata.append([fpars['dec'],fpars['inc'],1.])  # replace data[boot] with parametric dec,inc    
                else:
                    bdata.append(data[boot])
            ppars=pmag.doprinc(bdata)
            Is.append(ppars['inc'])
            Es.append(ppars['tau2']/ppars['tau3'])
            b+=1
            if b%100==0:print b
        Is.sort()
        Es.sort()
        x,std=pmag.gausspars(Es)
        stderr=std/math.sqrt(len(data))
        pmagplotlib.plotX(PLTS['ei'],Io,Eo,Is[lower],Is[upper],Es[lower],Es[upper],'b-')
#        pmagplotlib.plotX(PLTS['ei'],Io,Eo,Is[lower],Is[upper],Eo-stderr,Eo+stderr,'b-')
        print 'Io, Eo, I_lower, I_upper, E_lower, E_upper, Edec, Einc'
        print '%7.1f %4.2f %7.1f %7.1f %4.2f %4.2f %7.1f %7.1f' %(Io,Eo,Is[lower],Is[upper],Es[lower],Es[upper], Edec,Einc)
#        print '%7.1f %4.2f %7.1f %7.1f %4.2f %4.2f' %(Io,Eo,Is[lower],Is[upper],Eo-stderr,Eo+stderr)
    pmagplotlib.drawFIGS(PLTS)
    files,fmt={},'svg'
    for key in PLTS.keys():
        files[key]=key+'.'+fmt 
    ans=raw_input(" S[a]ve to save plot, [q]uit without saving:  ")
    if ans=="a": pmagplotlib.saveP(PLTS,files) 
コード例 #3
0
ファイル: find_EI.py プロジェクト: jholmes/PmagPy
def main():
    """
    NAME
        find_EI.py
 
    DESCRIPTION
        Applies assumed flattening factor and "unsquishes" inclinations assuming tangent function.
        Finds flattening factor that gives elongation/inclination pair consistent with TK03.  
        Finds bootstrap confidence bounds

    SYNTAX
        find_EI.py [-h][-i] [-f FILE] 

    INPUT
        dec/inc pairs

    OUTPUT
        three plots:  1) equal area plot of original directions
                      2) Elongation/inclination pairs as a function of f,  data plus 25 bootstrap samples
                      3) Cumulative distribution of bootstrapped optimal inclinations plus uncertainties.
                         Estimate from original data set plotted as solid line

    """
    if '-i' in sys.argv:
        file=raw_input("Enter file name for processing: ")
        f=open(file,'rU') 
    elif '-f' in sys.argv:
        ind=sys.argv.index('-f')
        file=sys.argv[ind+1]
        f=open(file,'rU') 
    else:
        print main.__doc__
        sys.exit()
    rseed,nb,data=10,5000,[]
    upper,lower=int(round(.975*nb)),int(round(.025*nb))
    E,I=[],[]
    PLTS={'eq':1,'ei':2,'cdf':3,'v2':4}
    pmagplotlib.plot_init(PLTS['eq'],6,6) 
    pmagplotlib.plot_init(PLTS['ei'],5,5) 
    pmagplotlib.plot_init(PLTS['cdf'],5,5) 
    pmagplotlib.plot_init(PLTS['v2'],5,5) 
    random.seed(rseed)
    for line in f.readlines():
        rec=line.split()
        dec=float(rec[0])
        inc=float(rec[1])
        rec=[dec,inc,1.]
        data.append(rec)
    pmagplotlib.plotEQ(PLTS['eq'],data,'Data')
    ppars=pmag.doprinc(data)
    Io=ppars['inc']
    n=ppars["N"]
    Es,Is,Fs,V2s=find_f(data)
    Inc,Elong=Is[-1],Es[-1]
    pmagplotlib.plotEI(PLTS['ei'],Es,Is,Fs[-1])
    pmagplotlib.plotV2s(PLTS['v2'],V2s,Is,Fs[-1])
    b=0
    print "Bootstrapping.... be patient"
    while b<nb:
        bdata=[]
        for j in range(n):
            boot=random.randint(0,n-1)
            random.jumpahead(rseed)
            bdata.append(data[boot])
        Es,Is,Fs,V2s=find_f(bdata)
        if b<25:
            pmagplotlib.plotEI(PLTS['ei'],Es,Is,Fs[-1])
        if Es[-1]!=0:
            ppars=pmag.doprinc(bdata)
            I.append(abs(Is[-1]))
            E.append(Es[-1])
            b+=1
            if b%25==0:print b,' out of ',nb
    I.sort()
    E.sort()
    Eexp=[]
    for i in I:
       Eexp.append(EI(i)) 
    title= '%7.1f [%7.1f, %7.1f]' %( Inc, I[lower],I[upper])
    pmagplotlib.plotEI(PLTS['ei'],Eexp,I,1)
    pmagplotlib.plotCDF(PLTS['cdf'],I,'Inclinations','r',title)
    pmagplotlib.plotVs(PLTS['cdf'],[I[lower],I[upper]],'b','--')
    pmagplotlib.plotVs(PLTS['cdf'],[Inc],'g','-')
    pmagplotlib.plotVs(PLTS['cdf'],[Io],'k','-')
    print "Io Inc  I_lower, I_upper, Elon, E_lower, E_upper"
    print '%7.1f %s %7.1f _ %7.1f ^ %7.1f:  %6.4f _ %6.4f ^ %6.4f' %(Io, " => ", Inc, I[lower],I[upper], Elong, E[lower],E[upper])
    try:
        raw_input("Return to save plots - <return> to quit:  ")
    except EOFError:
       print "\n Good bye\n"
       sys.exit()
    files={}
    files['eq']='findEI_eq.svg'
    files['ei']='findEI_ei.svg'
    files['cdf']='findEI_cdf.svg'
    files['v2']='findEI_v2.svg'
    pmagplotlib.saveP(PLTS,files)