def iBootstrap(Data1,Data2,NumSims=1000):
    """
    Conduct a bootstrap test (Tauxe, 2010) for a common mean on two declination,
    inclination data sets
    
    This function modifies code from PmagPy for use calculating and plotting 
    bootstrap statistics. Three plots are generated (one for x, one for y and
    one for z). If the 95 percent confidence bounds for each component overlap
    each other, the two directions are not significantly different.

    Parameters
    ----------

    Data1 : a list of directional data [dec,inc]
    Data2 : a list of directional data [dec,inc]
    NumSims : number of bootstrap samples (default is 1000)
    """         
    counter=0
    BDI1=pmag.di_boot(Data1)
    BDI2=pmag.di_boot(Data2)
    print ""
    print "==============="
    print ""
    print "Here are the results of the bootstrap test for a common mean"
    CDF={'X':1,'Y':2,'Z':3}
    pylab.figure(CDF['X'],figsize=(3,3),dpi=160)
    pylab.figure(CDF['Y'],figsize=(3,3),dpi=160)
    pylab.figure(CDF['Z'],figsize=(3,3),dpi=160)
    pmagplotlib.plotCOM(CDF,BDI1,BDI2,["",""])
def iBootstrap(Data1, Data2, NumSims=1000):
    """
    Conduct a bootstrap test (Tauxe, 2010) for a common mean on two declination,
    inclination data sets
    
    This function modifies code from PmagPy for use calculating and plotting 
    bootstrap statistics. Three plots are generated (one for x, one for y and
    one for z). If the 95 percent confidence bounds for each component overlap
    each other, the two directions are not significantly different.

    Parameters
    ----------

    Data1 : a list of directional data [dec,inc]
    Data2 : a list of directional data [dec,inc]
    NumSims : number of bootstrap samples (default is 1000)
    """
    counter = 0
    BDI1 = pmag.di_boot(Data1)
    BDI2 = pmag.di_boot(Data2)
    print ""
    print "==============="
    print ""
    print "Here are the results of the bootstrap test for a common mean"
    CDF = {'X': 1, 'Y': 2, 'Z': 3}
    pylab.figure(CDF['X'], figsize=(3, 3), dpi=160)
    pylab.figure(CDF['Y'], figsize=(3, 3), dpi=160)
    pylab.figure(CDF['Z'], figsize=(3, 3), dpi=160)
    pmagplotlib.plotCOM(CDF, BDI1, BDI2, ["", ""])
Esempio n. 3
0
def common_dir_boot(dir1,dir2,bootsteps=1000,plot='no'):
    #test for a common direction using bootstrap method
    #directions given as pandas Series listing mean direction/pole parameters
    #this is assuming published means without input directions, so bootstrap is a little different from the one
    #described in Tauxe: not a pseudoselection from specified points but drawing from fisher distribution directly.
    #adds a level of abstraction which hopefully does not invalidate procedure
    BDI1,BDI2=[],[]
    for s in range(bootsteps):
        fpars1=pmag.fisher_mean(get_fish(dir1))
        fpars2=pmag.fisher_mean(get_fish(dir2))
        BDI1.append([fpars1['dec'],fpars1['inc']])
        BDI2.append([fpars2['dec'],fpars2['inc']])
    bounds1=get_bounds(BDI1)
    bounds2=get_bounds(BDI2)
    #now want to check if is a pass or a fail - only pass if error bounds overlap in x,y,and z
    bresult=[]
    for b1,b2 in zip(bounds1,bounds2):
        if (b1[0]>b2[1] or b1[1]<b2[0]):
            bresult.append(0)
        else: bresult.append(1)
    if sum(bresult)==3: outcome='Pass'
    else: outcome='Fail'
    angle=pmag.angle((dir1['dec'],dir1['inc']),(dir2['dec'],dir2['inc']))
    
    # set up plots - can run this if want to visually check what's going on.
    if plot=='yes':
        CDF={'X':1,'Y':2,'Z':3}
        pmagplotlib.plot_init(CDF['X'],4,4)
        pmagplotlib.plot_init(CDF['Y'],4,4)
        pmagplotlib.plot_init(CDF['Z'],4,4)
        # draw the cdfs
        pmagplotlib.plotCOM(CDF,BDI1,BDI2,["",""])
        pmagplotlib.drawFIGS(CDF)
    
    return pd.Series([outcome,angle[0]],index=['Outcome','angle'])
Esempio n. 4
0
def main():
    """
    NAME
       revtest.py

    DESCRIPTION
       calculates bootstrap statistics to test for antipodality

    INPUT FORMAT
       takes dec/inc as first two columns in space delimited file
   
    SYNTAX
       revtest.py [-h] [-i] [command line options]
    
    OPTION
       -h prints help message and quits
       -i for interactive entry of file names from command line
       -f FILE, sets input filename on command line
       -fmt [svg,png,jpg], sets format for image output
               

    """
    D,fmt=[],'svg'
    if '-h' in sys.argv: # check if help is needed
        print main.__doc__
        sys.exit() # graceful quit
    if '-i' in sys.argv: # ask for filename
        file=raw_input("Enter file name with dec, inc data: ")
        f=open(file,'rU')
        data=f.readlines()
    elif '-f' in sys.argv:
        ind=sys.argv.index('-f')
        file=sys.argv[ind+1]
        f=open(file,'rU')
        data=f.readlines()
        if '-fmt' in sys.argv:
            ind=sys.argv.index('-fmt')
            fmt=sys.argv[ind+1]
    for line in data:
        if '\t' in line:
            rec=line.split('\t') # split each line on space to get records
        else:
            rec=line.split() # split each line on space to get records
        Dec,Inc=float(rec[0]),float(rec[1]) 
        D.append([Dec,Inc,1.])
# set up plots
    d=""
    CDF={'X':1,'Y':2,'Z':3}
    pmagplotlib.plot_init(CDF['X'],5,5)
    pmagplotlib.plot_init(CDF['Y'],5,5)
    pmagplotlib.plot_init(CDF['Z'],5,5)
#
# flip reverse mode
#
    D1,D2=pmag.flip(D)
    counter,NumSims=0,500
#
# get bootstrapped means for each data set
#
    print 'doing first mode, be patient'
    BDI1=pmag.di_boot(D1)
    print 'doing second mode, be patient'
    BDI2=pmag.di_boot(D2)
    pmagplotlib.plotCOM(CDF,BDI1,BDI2,[""])
    pmagplotlib.drawFIGS(CDF)
    ans=  raw_input("s[a]ve plots, [q]uit: ")
    if ans=='a':
        files={}
        for key in CDF.keys():
            files[key]='REV'+'_'+key+'.'+fmt 
        pmagplotlib.saveP(CDF,files)
    else:
        print 'good bye'
        sys.exit()
Esempio n. 5
0
def main():
    """
    NAME
       revtest_magic.py

    DESCRIPTION
       calculates bootstrap statistics to test for antipodality

    INPUT FORMAT
       takes dec/inc data from pmag_sites table 
   
    SYNTAX
       revtest_magic.py [command line options]
    
    OPTION
       -h prints help message and quits
       -f FILE, sets pmag_sites filename on command line
       -crd [s,g,t], set coordinate system, default is geographic
       -exc use pmag_criteria.txt to set acceptance criteria
       -fmt [svg,png,jpg], sets format for image output
               

    """
    D,fmt=[],'svg'
    coord='0'
    infile='pmag_sites.txt'
    critfile='pmag_criteria.txt'
    dir_path='.'
    if '-h' in sys.argv: # check if help is needed
        print main.__doc__
        sys.exit() # graceful quit
    if '-WD' in sys.argv:
        ind=sys.argv.index('-WD')
        dir_path=sys.argv[ind+1]
    if '-f' in sys.argv:
        ind=sys.argv.index('-f')
        infile=sys.argv[ind+1]
    if '-crd' in sys.argv:
        ind=sys.argv.index('-crd')
        coord=sys.argv[ind+1]
        if coord=='s':coord='-1'
        if coord=='g':coord='0'
        if coord=='t':coord='100'
    if '-fmt' in sys.argv:
        ind=sys.argv.index('-fmt')
        fmt=sys.argv[ind+1]
#
    infile=dir_path+'/'+infile
    critfile=dir_path+'/'+critfile
    Accept=['site_k','site_alpha95','site_n','site_n_lines']
    data,file_type=pmag.magic_read(infile)
    if file_type!='pmag_sites':
        print "Error opening file"
        sys.exit()
#    ordata,file_type=pmag.magic_read(orfile)
    if '-exc' in sys.argv:
        crits,file_type=pmag.magic_read(critfile)
        for crit in crits:
             if crit['pmag_criteria_code']=="DE-SITE":
                 SiteCrit=crit
    for rec in data:
        if rec['site_tilt_correction']==coord:
            Dec=float(rec['site_dec'])
            Inc=float(rec['site_inc'])
            if  '-exc' in  sys.argv:
                for key in Accept:
                    if SiteCrit[key]!="":
                        if float(rec[key])<=float(SiteCrit[key]):     
                            D.append([Dec,Inc,1.])
            else:
                            D.append([Dec,Inc,1.])
# set up plots
    
    d=""
    CDF={'X':1,'Y':2,'Z':3}
    pmagplotlib.plot_init(CDF['X'],5,5)
    pmagplotlib.plot_init(CDF['Y'],5,5)
    pmagplotlib.plot_init(CDF['Z'],5,5)
#
# flip reverse mode
#
    D1,D2=pmag.flip(D)
    counter,NumSims=0,500
#
# get bootstrapped means for each data set
#
    if len(D1) < 5 or len(D2) < 5:
        print 'not enough data in two different modes for reversals test'
        sys.exit()
    print 'doing first mode, be patient'
    BDI1=pmag.di_boot(D1)
    print 'doing second mode, be patient'
    BDI2=pmag.di_boot(D2)
    pmagplotlib.plotCOM(CDF,BDI1,BDI2,[""])
    pmagplotlib.drawFIGS(CDF)
    ans=  raw_input("s[a]ve plots, [q]uit: ")
    if ans=='a':
        files={}
        for key in CDF.keys():
            files[key]='REV'+'_'+key+'.'+fmt 
        pmagplotlib.saveP(CDF,files)
    else:
        print 'good bye'
        sys.exit()
Esempio n. 6
0
def main():
    """
    NAME
       revtest.py

    DESCRIPTION
       calculates bootstrap statistics to test for antipodality

    INPUT FORMAT
       takes dec/inc as first two columns in space delimited file
   
    SYNTAX
       revtest.py [-h] [command line options]
    
    OPTION
       -h prints help message and quits
       -f FILE, sets input filename on command line
       -fmt [svg,png,jpg], sets format for image output
       -sav saves the figures silently and quits
               

    """
    fmt,plot='svg',0
    if '-h' in sys.argv: # check if help is needed
        print main.__doc__
        sys.exit() # graceful quit
    if '-f' in sys.argv:
        ind=sys.argv.index('-f')
        file=sys.argv[ind+1]
        data=numpy.loadtxt(file).transpose()
        D=numpy.array([data[0],data[1]]).transpose()
    else: 
        print '-f is a required switch'
        print main.__doc__
        print sys.exit()
    if '-fmt' in sys.argv:
        ind=sys.argv.index('-fmt')
        fmt=sys.argv[ind+1]
    if '-sav' in sys.argv:plot=1
# set up plots
    d=""
    CDF={'X':1,'Y':2,'Z':3}
    pmagplotlib.plot_init(CDF['X'],5,5)
    pmagplotlib.plot_init(CDF['Y'],5,5)
    pmagplotlib.plot_init(CDF['Z'],5,5)
#
# flip reverse mode
#
    D1,D2=pmag.flip(D)
    counter,NumSims=0,500
#
# get bootstrapped means for each data set
#
    print 'doing first mode, be patient'
    BDI1=pmag.di_boot(D1)
    print 'doing second mode, be patient'
    BDI2=pmag.di_boot(D2)
    pmagplotlib.plotCOM(CDF,BDI1,BDI2,[""])
    files={}
    for key in CDF.keys():
        files[key]='REV'+'_'+key+'.'+fmt 
    if plot==0:
        pmagplotlib.drawFIGS(CDF)
        ans=  raw_input("s[a]ve plots, [q]uit: ")
        if ans=='a':
            pmagplotlib.saveP(CDF,files)
        print 'good bye'
        sys.exit()
    else:
        pmagplotlib.saveP(CDF,files)
Esempio n. 7
0
def main():
    """
    NAME
       common_mean.py

    DESCRIPTION
       calculates bootstrap statistics to test for common mean

    INPUT FORMAT
       takes dec/inc as first two columns in two space delimited files
   
    SYNTAX
       common_mean.py [command line options]
    
    OPTIONS
       -h prints help message and quits
       -f FILE, input file 
       -f2 FILE, optional second file to compare with first file
       -dir D I, optional direction to compare with input file
    NOTES
       must have either F2 OR dir but not both
     

    """
    d,i,file2="","",""
    if '-h' in sys.argv: # check if help is needed
        print main.__doc__
        sys.exit() # graceful quit
    if '-f' in sys.argv:
        ind=sys.argv.index('-f')
        file1=sys.argv[ind+1]
    if '-f2' in sys.argv:
        ind=sys.argv.index('-f2')
        file2=sys.argv[ind+1]
    if '-dir' in sys.argv:
        ind=sys.argv.index('-dir')
        d=float(sys.argv[ind+1])
        i=float(sys.argv[ind+2])
    D1=numpy.loadtxt(file1,dtype=numpy.float)
    if file2!="": D2=numpy.loadtxt(file2,dtype=numpy.float)
#
    counter,NumSims=0,1000
#
# get bootstrapped means for first data set
#
    print "Doing first set of directions, please be patient.."
    BDI1=pmag.di_boot(D1)
#
#   convert to cartesian coordinates X1,X2, Y1,Y2 and Z1, Z2
#
    if d=="": # repeat for second data set
        print "Doing second  set of directions, please be patient.."
        BDI2=pmag.di_boot(D2)
    else:
        BDI2=[]
# set up plots
    CDF={'X':1,'Y':2,'Z':3}
    pmagplotlib.plot_init(CDF['X'],4,4)
    pmagplotlib.plot_init(CDF['Y'],4,4)
    pmagplotlib.plot_init(CDF['Z'],4,4)
# draw the cdfs
    pmagplotlib.plotCOM(CDF,BDI1,BDI2,[d,i])
    pmagplotlib.drawFIGS(CDF)
    try:
        ans=raw_input("S[a]ve plots, <Return> to quit ")
    except:
       print "\n Good bye\n"
       sys.exit()
    if ans=="a":
        files={}
        files['X']='CD_X.svg'
        files['Y']='CD_Y.svg'
        files['Z']='CD_Z.svg'
        pmagplotlib.saveP(CDF,files)