def main(): """ NAME watsons_v.py DESCRIPTION calculates Watson's V statistic from input files INPUT FORMAT takes dec/inc as first two columns in two space delimited files SYNTAX watsons_v.py [command line options] OPTIONS -h prints help message and quits -f FILE (with optional second) -f2 FILE (second file) -ant, flip antipodal directions to opposite direction in first file if only one file or flip all in second, if two files -P (don't save or show plot) -sav save figure and quit silently -fmt [png,svg,eps,pdf,jpg] format for saved figure OUTPUT Watson's V and the Monte Carlo Critical Value Vc. in plot, V is solid and Vc is dashed. """ Flip = 0 show, plot = 1, 0 fmt = 'svg' file2 = "" if '-h' in sys.argv: # check if help is needed print main.__doc__ sys.exit() # graceful quit if '-ant' in sys.argv: Flip = 1 if '-sav' in sys.argv: show, plot = 0, 1 # don't display, but do save plot if '-fmt' in sys.argv: ind = sys.argv.index('-fmt') fmt = sys.argv[ind + 1] if '-P' in sys.argv: show = 0 # don't display or save plot if '-f' in sys.argv: ind = sys.argv.index('-f') file1 = sys.argv[ind + 1] data = numpy.loadtxt(file1).transpose() D1 = numpy.array([data[0], data[1]]).transpose() else: print "-f is required" print main.__doc__ sys.exit() if '-f2' in sys.argv: ind = sys.argv.index('-f2') file2 = sys.argv[ind + 1] data2 = numpy.loadtxt(file2).transpose() D2 = numpy.array([data2[0], data2[1]]).transpose() if Flip == 1: D2, D = pmag.flip(D2) # D2 are now flipped if len(D2) != 0: if len(D) != 0: D2 = numpy.concatenate(D, D2) # put all in D2 elif len(D) != 0: D2 = D else: print 'length of second file is zero' sys.exit() elif Flip == 1: D2, D1 = pmag.flip(D1) # peel out antipodal directions, put in D2 # counter, NumSims = 0, 5000 # # first calculate the fisher means and cartesian coordinates of each set of Directions # pars_1 = pmag.fisher_mean(D1) pars_2 = pmag.fisher_mean(D2) # # get V statistic for these # V = pmag.vfunc(pars_1, pars_2) # # do monte carlo simulation of datasets with same kappas, but common mean # Vp = [] # set of Vs from simulations if show == 1: print "Doing ", NumSims, " simulations" for k in range(NumSims): counter += 1 if counter == 50: if show == 1: print k + 1 counter = 0 Dirp = [] # get a set of N1 fisher distributed vectors with k1, calculate fisher stats for i in range(pars_1["n"]): Dirp.append(pmag.fshdev(pars_1["k"])) pars_p1 = pmag.fisher_mean(Dirp) # get a set of N2 fisher distributed vectors with k2, calculate fisher stats Dirp = [] for i in range(pars_2["n"]): Dirp.append(pmag.fshdev(pars_2["k"])) pars_p2 = pmag.fisher_mean(Dirp) # get the V for these Vk = pmag.vfunc(pars_p1, pars_p2) Vp.append(Vk) # # sort the Vs, get Vcrit (95th one) # Vp.sort() k = int(.95 * NumSims) if show == 1: print "Watson's V, Vcrit: " print ' %10.1f %10.1f' % (V, Vp[k]) if show == 1 or plot == 1: print "Watson's V, Vcrit: " print ' %10.1f %10.1f' % (V, Vp[k]) CDF = {'cdf': 1} pmagplotlib.plot_init(CDF['cdf'], 5, 5) pmagplotlib.plotCDF(CDF['cdf'], Vp, "Watson's V", 'r', "") pmagplotlib.plotVs(CDF['cdf'], [V], 'g', '-') pmagplotlib.plotVs(CDF['cdf'], [Vp[k]], 'b', '--') if plot == 0: pmagplotlib.drawFIGS(CDF) files = {} if file2 != "": files['cdf'] = 'watsons_v_' + file1 + '_' + file2 + '.' + fmt else: files['cdf'] = 'watsons_v_' + file1 + '.' + fmt if pmagplotlib.isServer: black = '#000000' purple = '#800080' titles = {} titles['cdf'] = 'Cumulative Distribution' CDF = pmagplotlib.addBorders(CDF, titles, black, purple) pmagplotlib.saveP(CDF, files) elif plot == 0: ans = raw_input(" S[a]ve to save plot, [q]uit without saving: ") if ans == "a": pmagplotlib.saveP(CDF, files) if plot == 1: # save and quit silently pmagplotlib.saveP(CDF, files)
def main(): """ NAME revtest_magic.py DESCRIPTION calculates bootstrap statistics to test for antipodality INPUT FORMAT takes dec/inc data from 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 criteria file to set acceptance criteria (only available for data model 3) -fmt [svg,png,jpg], sets format for image output -sav saves plot and quits -DM [2, 3] MagIC data model num, default is 3 """ if '-h' in sys.argv: # check if help is needed print(main.__doc__) sys.exit() # graceful quit dir_path = pmag.get_named_arg("-WD", ".") coord = pmag.get_named_arg("-crd", "0") # default to geographic coordinates if coord == 's': coord = '-1' elif coord == 'g': coord = '0' elif coord == 't': coord = '100' fmt = pmag.get_named_arg("-fmt", "svg") if '-sav' in sys.argv: plot = 1 data_model = int(float(pmag.get_named_arg("-DM"))) if data_model == 2: infile = pmag.get_named_arg("-f", "pmag_sites.txt") critfile = "pmag_criteria.txt" tilt_corr_col = 'site_tilt_correction' dec_col = "site_dec" inc_col = "site_inc" crit_code_col = "pmag_criteria_code" else: infile = pmag.get_named_arg("-f", "sites.txt") critfile = "criteria.txt" tilt_corr_col = "dir_tilt_correction" dec_col = "dir_dec" inc_col = "dir_inc" crit_code_col = "criterion" D = [] # infile = pmag.resolve_file_name(infile, dir_path) dir_path = os.path.split(infile)[0] critfile = pmag.resolve_file_name(critfile, dir_path) # if data_model == 2: Accept = ['site_k', 'site_alpha95', 'site_n', 'site_n_lines'] else: Accept = [ 'dir_k', 'dir_alpha95', 'dir_n_samples', 'dir_n_specimens_line' ] data, file_type = pmag.magic_read(infile) if 'sites' not in file_type: print("Error opening file", file_type) sys.exit() # ordata,file_type=pmag.magic_read(orfile) SiteCrits = [] if '-exc' in sys.argv and data_model != 2: crits, file_type = pmag.magic_read(critfile) for crit in crits: if crit[crit_code_col] == "DE-SITE": SiteCrit = crit SiteCrits.append(SiteCrit) elif '-exc' in sys.argv and data_model == 2: print( '-W- You have selected the -exc option, which is not available with MagIC data model 2.' ) for rec in data: if rec[tilt_corr_col] == coord: Dec = float(rec[dec_col]) Inc = float(rec[inc_col]) if '-exc' in sys.argv and data_model != 2: fail = False for SiteCrit in SiteCrits: for key in Accept: if key not in SiteCrit['table_column']: continue if key not in rec: continue if SiteCrit['criterion_value'] != "": op = OPS[SiteCrit['criterion_operation']] if not op(float(rec[key]), float(SiteCrit['criterion_value'])): fail = True if not fail: D.append([Dec, Inc, 1.]) else: D.append([Dec, Inc, 1.]) # set up plots 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.plot_com(CDF, BDI1, BDI2, [""]) files = {} for key in list(CDF.keys()): files[key] = 'REV' + '_' + key + '.' + fmt if plot == 0: pmagplotlib.draw_figs(CDF) ans = input("s[a]ve plots, [q]uit: ") if ans == 'a': pmagplotlib.save_plots(CDF, files) else: pmagplotlib.save_plots(CDF, files) sys.exit()
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 list(CDF.keys()): files[key]='REV'+'_'+key+'.'+fmt if plot==0: pmagplotlib.drawFIGS(CDF) ans= input("s[a]ve plots, [q]uit: ") if ans=='a': pmagplotlib.saveP(CDF,files) print('good bye') sys.exit() else: pmagplotlib.saveP(CDF,files)
def main(): """ NAME watsons_v.py DESCRIPTION calculates Watson's V statistic from input files INPUT FORMAT takes dec/inc as first two columns in two space delimited files SYNTAX watsons_v.py [command line options] OPTIONS -h prints help message and quits -f FILE (with optional second) -f2 FILE (second file) -ant, flip antipodal directions to opposite direction in first file if only one file or flip all in second, if two files -P (don't save or show plot) -sav save figure and quit silently -fmt [png,svg,eps,pdf,jpg] format for saved figure OUTPUT Watson's V and the Monte Carlo Critical Value Vc. in plot, V is solid and Vc is dashed. """ Flip=0 show,plot=1,0 fmt='svg' file2="" if '-h' in sys.argv: # check if help is needed print main.__doc__ sys.exit() # graceful quit if '-ant' in sys.argv: Flip=1 if '-sav' in sys.argv: show,plot=0,1 # don't display, but do save plot if '-fmt' in sys.argv: ind=sys.argv.index('-fmt') fmt=sys.argv[ind+1] if '-P' in sys.argv: show=0 # don't display or save plot if '-f' in sys.argv: ind=sys.argv.index('-f') file1=sys.argv[ind+1] data=numpy.loadtxt(file1).transpose() D1=numpy.array([data[0],data[1]]).transpose() else: print "-f is required" print main.__doc__ sys.exit() if '-f2' in sys.argv: ind=sys.argv.index('-f2') file2=sys.argv[ind+1] data2=numpy.loadtxt(file2).transpose() D2=numpy.array([data2[0],data2[1]]).transpose() if Flip==1: D2,D=pmag.flip(D2) # D2 are now flipped if len(D2)!=0: if len(D)!=0: D2=numpy.concatenate(D,D2) # put all in D2 elif len(D)!=0: D2=D else: print 'length of second file is zero' sys.exit() elif Flip==1:D2,D1=pmag.flip(D1) # peel out antipodal directions, put in D2 # counter,NumSims=0,5000 # # first calculate the fisher means and cartesian coordinates of each set of Directions # pars_1=pmag.fisher_mean(D1) pars_2=pmag.fisher_mean(D2) # # get V statistic for these # V=pmag.vfunc(pars_1,pars_2) # # do monte carlo simulation of datasets with same kappas, but common mean # Vp=[] # set of Vs from simulations if show==1:print "Doing ",NumSims," simulations" for k in range(NumSims): counter+=1 if counter==50: if show==1:print k+1 counter=0 Dirp=[] # get a set of N1 fisher distributed vectors with k1, calculate fisher stats for i in range(pars_1["n"]): Dirp.append(pmag.fshdev(pars_1["k"])) pars_p1=pmag.fisher_mean(Dirp) # get a set of N2 fisher distributed vectors with k2, calculate fisher stats Dirp=[] for i in range(pars_2["n"]): Dirp.append(pmag.fshdev(pars_2["k"])) pars_p2=pmag.fisher_mean(Dirp) # get the V for these Vk=pmag.vfunc(pars_p1,pars_p2) Vp.append(Vk) # # sort the Vs, get Vcrit (95th one) # Vp.sort() k=int(.95*NumSims) if show==1: print "Watson's V, Vcrit: " print ' %10.1f %10.1f'%(V,Vp[k]) if show==1 or plot==1: print "Watson's V, Vcrit: " print ' %10.1f %10.1f'%(V,Vp[k]) CDF={'cdf':1} pmagplotlib.plot_init(CDF['cdf'],5,5) pmagplotlib.plotCDF(CDF['cdf'],Vp,"Watson's V",'r',"") pmagplotlib.plotVs(CDF['cdf'],[V],'g','-') pmagplotlib.plotVs(CDF['cdf'],[Vp[k]],'b','--') if plot==0:pmagplotlib.drawFIGS(CDF) files={} if file2!="": files['cdf']='watsons_v_'+file1+'_'+file2+'.'+fmt else: files['cdf']='watsons_v_'+file1+'.'+fmt if pmagplotlib.isServer: black = '#000000' purple = '#800080' titles={} titles['cdf']='Cumulative Distribution' CDF = pmagplotlib.addBorders(CDF,titles,black,purple) pmagplotlib.saveP(CDF,files) elif plot==0: ans=raw_input(" S[a]ve to save plot, [q]uit without saving: ") if ans=="a": pmagplotlib.saveP(CDF,files) if plot==1: # save and quit silently pmagplotlib.saveP(CDF,files)
def main(): """ NAME watsons_f.py DESCRIPTION calculates Watson's F statistic from input files INPUT FORMAT takes dec/inc as first two columns in two space delimited files SYNTAX watsons_f.py [command line options] OPTIONS -h prints help message and quits -f FILE (with optional second) -f2 FILE (second file) -ant, flip antipodal directions in FILE to opposite direction OUTPUT Watson's F, critical value from F-tables for 2, 2(N-2) degrees of freedom """ D, D1, D2 = [], [], [] Flip = 0 if '-h' in sys.argv: # check if help is needed print main.__doc__ sys.exit() # graceful quit if '-ant' in sys.argv: Flip = 1 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] f = open(file1, 'rU') for line in f.readlines(): 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]) D1.append([Dec, Inc, 1.]) D.append([Dec, Inc, 1.]) f.close() if Flip == 0: f = open(file2, 'rU') for line in f.readlines(): rec = line.split() Dec, Inc = float(rec[0]), float(rec[1]) D2.append([Dec, Inc, 1.]) D.append([Dec, Inc, 1.]) f.close() else: D1, D2 = pmag.flip(D1) for d in D2: D.append(d) # # first calculate the fisher means and cartesian coordinates of each set of Directions # pars_0 = pmag.fisher_mean(D) pars_1 = pmag.fisher_mean(D1) pars_2 = pmag.fisher_mean(D2) # # get F statistic for these # N = len(D) R = pars_0['r'] R1 = pars_1['r'] R2 = pars_2['r'] F = (N - 2) * ((R1 + R2 - R) / (N - R1 - R2)) Fcrit = pmag.fcalc(2, 2 * (N - 2)) print '%7.2f %7.2f' % (F, Fcrit)
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 -sav saves plot and quits """ D, fmt, plot = [], 'svg', 0 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 '-sav' in sys.argv: plot = 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, [""]) 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) else: pmagplotlib.saveP(CDF, files) sys.exit()
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)
def main(): """ NAME watsons_f.py DESCRIPTION calculates Watson's F statistic from input files INPUT FORMAT takes dec/inc as first two columns in two space delimited files SYNTAX watsons_f.py [command line options] OPTIONS -h prints help message and quits -f FILE (with optional second) -f2 FILE (second file) -ant, flip antipodal directions in FILE to opposite direction OUTPUT Watson's F, critical value from F-tables for 2, 2(N-2) degrees of freedom """ D,D1,D2=[],[],[] Flip=0 if '-h' in sys.argv: # check if help is needed print main.__doc__ sys.exit() # graceful quit if '-ant' in sys.argv: Flip=1 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] f=open(file1,'rU') for line in f.readlines(): 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]) D1.append([Dec,Inc,1.]) D.append([Dec,Inc,1.]) f.close() if Flip==0: f=open(file2,'rU') for line in f.readlines(): rec=line.split() Dec,Inc=float(rec[0]),float(rec[1]) D2.append([Dec,Inc,1.]) D.append([Dec,Inc,1.]) f.close() else: D1,D2=pmag.flip(D1) for d in D2: D.append(d) # # first calculate the fisher means and cartesian coordinates of each set of Directions # pars_0=pmag.fisher_mean(D) pars_1=pmag.fisher_mean(D1) pars_2=pmag.fisher_mean(D2) # # get F statistic for these # N= len(D) R=pars_0['r'] R1=pars_1['r'] R2=pars_2['r'] F=(N-2)*((R1+R2-R)/(N-R1-R2)) Fcrit=pmag.fcalc(2,2*(N-2)) print '%7.2f %7.2f'%(F,Fcrit)
def main(): """ NAME revtest_magic.py DESCRIPTION calculates bootstrap statistics to test for antipodality INPUT FORMAT takes dec/inc data from 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 criteria file to set acceptance criteria (only available for data model 3) -fmt [svg,png,jpg], sets format for image output -sav saves plot and quits -DM [2, 3] MagIC data model num, default is 3 """ if '-h' in sys.argv: # check if help is needed print(main.__doc__) sys.exit() # graceful quit dir_path = pmag.get_named_arg("-WD", ".") coord = pmag.get_named_arg("-crd", "0") # default to geographic coordinates if coord == 's': coord = '-1' elif coord == 'g': coord = '0' elif coord == 't': coord = '100' fmt = pmag.get_named_arg("-fmt", "svg") if '-sav' in sys.argv: plot = 1 data_model = int(float(pmag.get_named_arg("-DM"))) if data_model == 2: infile = pmag.get_named_arg("-f", "pmag_sites.txt") critfile = "pmag_criteria.txt" tilt_corr_col = 'site_tilt_correction' dec_col = "site_dec" inc_col = "site_inc" crit_code_col = "pmag_criteria_code" else: infile = pmag.get_named_arg("-f", "sites.txt") critfile = "criteria.txt" tilt_corr_col = "dir_tilt_correction" dec_col = "dir_dec" inc_col = "dir_inc" crit_code_col = "criterion" D = [] # infile = pmag.resolve_file_name(infile, dir_path) dir_path = os.path.split(infile)[0] critfile = pmag.resolve_file_name(critfile, dir_path) # if data_model == 2: Accept = ['site_k', 'site_alpha95', 'site_n', 'site_n_lines'] else: Accept = ['dir_k', 'dir_alpha95', 'dir_n_samples', 'dir_n_specimens_line'] data, file_type = pmag.magic_read(infile) if 'sites' not in file_type: print("Error opening file", file_type) sys.exit() # ordata,file_type=pmag.magic_read(orfile) SiteCrits = [] if '-exc' in sys.argv and data_model != 2: crits, file_type = pmag.magic_read(critfile) for crit in crits: if crit[crit_code_col] == "DE-SITE": SiteCrit = crit SiteCrits.append(SiteCrit) elif '-exc' in sys.argv and data_model == 2: print('-W- You have selected the -exc option, which is not available with MagIC data model 2.') for rec in data: if rec[tilt_corr_col] == coord: Dec = float(rec[dec_col]) Inc = float(rec[inc_col]) if '-exc' in sys.argv and data_model != 2: fail = False for SiteCrit in SiteCrits: for key in Accept: if key not in SiteCrit['table_column']: continue if key not in rec: continue if SiteCrit['criterion_value'] != "": op = OPS[SiteCrit['criterion_operation']] if not op(float(rec[key]), float(SiteCrit['criterion_value'])): fail = True if not fail: D.append([Dec, Inc, 1.]) else: D.append([Dec, Inc, 1.]) # set up plots 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.plot_com(CDF, BDI1, BDI2, [""]) files = {} for key in list(CDF.keys()): files[key] = 'REV'+'_'+key+'.'+fmt if plot == 0: pmagplotlib.draw_figs(CDF) ans = input("s[a]ve plots, [q]uit: ") if ans == 'a': pmagplotlib.save_plots(CDF, files) else: pmagplotlib.save_plots(CDF, files) sys.exit()
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 -sav saves plot and quits """ D,fmt,plot=[],'svg',0 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 '-sav' in sys.argv:plot=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,[""]) 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) else: pmagplotlib.saveP(CDF,files) sys.exit()