def main(): """ NAME gokent.py DESCRIPTION calculates Kent parameters from dec inc data INPUT FORMAT takes dec/inc as first two columns in space delimited file SYNTAX gokent.py [-h][-i][command line options] [< filename] OPTIONS -h prints help message and quits -i for interactive filename entry -f FILE, specify filename < filename for reading from standard input OUTPUT mean dec, mean inc, Eta, Deta, Ieta, Zeta, Zdec, Zinc, N """ if len(sys.argv) > 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] f=open(file,'rU') data=f.readlines() elif '-i' in sys.argv: # ask for filename file=raw_input("Enter file name with dec, inc data: ") f=open(file,'rU') data=f.readlines() else: # data=sys.stdin.readlines() # read in data from standard input DIs= [] # set up list for dec inc data for line in data: # read in the data from standard input 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 DIs.append((float(rec[0]),float(rec[1]))) # kpars=pmag.dokent(DIs,len(DIs)) print '%7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %i' % (kpars["dec"],kpars["inc"],kpars["Eta"],kpars["Edec"],kpars["Einc"],kpars["Zeta"],kpars["Zdec"],kpars["Zinc"],kpars["n"])
def main(): """ NAME eqarea_magic.py DESCRIPTION makes equal area projections from declination/inclination data SYNTAX eqarea_magic.py [command line options] INPUT takes magic formatted pmag_results, pmag_sites, pmag_samples or pmag_specimens OPTIONS -h prints help message and quits -f FILE: specify input magic format file from magic,default='pmag_results.txt' supported types=[magic_measurements,pmag_specimens, pmag_samples, pmag_sites, pmag_results, magic_web] -obj OBJ: specify level of plot [all, sit, sam, spc], default is all -crd [s,g,t]: specify coordinate system, [s]pecimen, [g]eographic, [t]ilt adjusted default is geographic, unspecified assumed geographic -fmt [svg,png,jpg] format for output plots -ell [F,K,B,Be,Bv] plot Fisher, Kent, Bingham, Bootstrap ellipses or Boostrap eigenvectors -c plot as colour contour -sav save plot and quit quietly NOTE all: entire file; sit: site; sam: sample; spc: specimen """ FIG = {} # plot dictionary FIG['eqarea'] = 1 # eqarea is figure 1 in_file, plot_key, coord, crd = 'pmag_results.txt', 'all', "0", 'g' plotE, contour = 0, 0 dir_path = '.' fmt = 'svg' verbose = pmagplotlib.verbose if '-h' in sys.argv: print main.__doc__ sys.exit() if '-WD' in sys.argv: ind = sys.argv.index('-WD') dir_path = sys.argv[ind + 1] pmagplotlib.plot_init(FIG['eqarea'], 5, 5) if '-f' in sys.argv: ind = sys.argv.index("-f") in_file = dir_path + "/" + sys.argv[ind + 1] if '-obj' in sys.argv: ind = sys.argv.index('-obj') plot_by = sys.argv[ind + 1] if plot_by == 'all': plot_key = 'all' if plot_by == 'sit': plot_key = 'er_site_name' if plot_by == 'sam': plot_key = 'er_sample_name' if plot_by == 'spc': plot_key = 'er_specimen_name' if '-c' in sys.argv: contour = 1 plots = 0 if '-sav' in sys.argv: plots = 1 verbose = 0 if '-ell' in sys.argv: plotE = 1 ind = sys.argv.index('-ell') ell_type = sys.argv[ind + 1] if ell_type == 'F': dist = 'F' if ell_type == 'K': dist = 'K' if ell_type == 'B': dist = 'B' if ell_type == 'Be': dist = 'BE' if ell_type == 'Bv': dist = 'BV' FIG['bdirs'] = 2 pmagplotlib.plot_init(FIG['bdirs'], 5, 5) if '-crd' in sys.argv: ind = sys.argv.index("-crd") crd = sys.argv[ind + 1] if crd == 's': coord = "-1" if crd == 'g': coord = "0" if crd == 't': coord = "100" if '-fmt' in sys.argv: ind = sys.argv.index("-fmt") fmt = sys.argv[ind + 1] Dec_keys = ['site_dec', 'sample_dec', 'specimen_dec', 'measurement_dec', 'average_dec', 'none'] Inc_keys = ['site_inc', 'sample_inc', 'specimen_inc', 'measurement_inc', 'average_inc', 'none'] Tilt_keys = ['tilt_correction', 'site_tilt_correction', 'sample_tilt_correction', 'specimen_tilt_correction', 'none'] Dir_type_keys = ['', 'site_direction_type', 'sample_direction_type', 'specimen_direction_type'] Name_keys = ['er_specimen_name', 'er_sample_name', 'er_site_name', 'pmag_result_name'] data, file_type = pmag.magic_read(in_file) if file_type == 'pmag_results' and plot_key != "all": plot_key = plot_key + 's' # need plural for results table if verbose: print len(data), ' records read from ', in_file # # # find desired dec,inc data: # dir_type_key = '' # # get plotlist if not plotting all records # plotlist = [] if plot_key != "all": plots = pmag.get_dictitem(data, plot_key, '', 'F') for rec in plots: if rec[plot_key] not in plotlist: plotlist.append(rec[plot_key]) plotlist.sort() else: plotlist.append('All') for plot in plotlist: if verbose: print plot DIblock = [] GCblock = [] SLblock, SPblock = [], [] title = plot mode = 1 dec_key, inc_key, tilt_key, name_key, k = "", "", "", "", 0 if plot != "All": odata = pmag.get_dictitem(data, plot_key, plot, 'T') else: odata = data # data for this obj for dec_key in Dec_keys: Decs = pmag.get_dictitem(odata, dec_key, '', 'F') # get all records with this dec_key not blank if len(Decs) > 0: break for inc_key in Inc_keys: Incs = pmag.get_dictitem(Decs, inc_key, '', 'F') # get all records with this inc_key not blank if len(Incs) > 0: break for tilt_key in Tilt_keys: if tilt_key in Incs[0].keys(): break # find the tilt_key for these records if tilt_key == 'none': # no tilt key in data, need to fix this with fake data which will be unknown tilt tilt_key = 'tilt_correction' for rec in Incs: rec[tilt_key] = '' cdata = pmag.get_dictitem(Incs, tilt_key, coord, 'T') # get all records matching specified coordinate system if coord == '0': # geographic udata = pmag.get_dictitem(Incs, tilt_key, '', 'T') # get all the blank records - assume geographic if len(cdata) == 0: crd = '' if len(udata) > 0: for d in udata: cdata.append(d) crd = crd + 'u' for name_key in Name_keys: Names = pmag.get_dictitem(cdata, name_key, '', 'F') # get all records with this name_key not blank if len(Names) > 0: break for dir_type_key in Dir_type_keys: Dirs = pmag.get_dictitem(cdata, dir_type_key, '', 'F') # get all records with this direction type if len(Dirs) > 0: break if dir_type_key == "": dir_type_key = 'direction_type' locations, site, sample, specimen = "", "", "", "" for rec in cdata: # pick out the data if 'er_location_name' in rec.keys() and rec['er_location_name'] != "" and rec[ 'er_location_name'] not in locations: locations = locations + rec['er_location_name'].replace("/", "") + "_" if 'er_location_names' in rec.keys() and rec['er_location_names'] != "": locs = rec['er_location_names'].split(':') for loc in locs: if loc not in locations: locations = locations + loc.replace("/", "") + '_' if plot_key == 'er_site_name' or plot_key == 'er_sample_name' or plot_key == 'er_specimen_name': site = rec['er_site_name'] if plot_key == 'er_sample_name' or plot_key == 'er_specimen_name': sample = rec['er_sample_name'] if plot_key == 'er_specimen_name': specimen = rec['er_specimen_name'] if plot_key == 'er_site_names' or plot_key == 'er_sample_names' or plot_key == 'er_specimen_names': site = rec['er_site_names'] if plot_key == 'er_sample_names' or plot_key == 'er_specimen_names': sample = rec['er_sample_names'] if plot_key == 'er_specimen_names': specimen = rec['er_specimen_names'] if dir_type_key not in rec.keys() or rec[dir_type_key] == "": rec[dir_type_key] = 'l' if 'magic_method_codes' not in rec.keys(): rec['magic_method_codes'] = "" DIblock.append([float(rec[dec_key]), float(rec[inc_key])]) SLblock.append([rec[name_key], rec['magic_method_codes']]) if rec[tilt_key] == coord and rec[dir_type_key] != 'l' and rec[dec_key] != "" and rec[inc_key] != "": GCblock.append([float(rec[dec_key]), float(rec[inc_key])]) SPblock.append([rec[name_key], rec['magic_method_codes']]) if len(DIblock) == 0 and len(GCblock) == 0: if verbose: print "no records for plotting" sys.exit() if verbose: for k in range(len(SLblock)): print '%s %s %7.1f %7.1f' % (SLblock[k][0], SLblock[k][1], DIblock[k][0], DIblock[k][1]) for k in range(len(SPblock)): print '%s %s %7.1f %7.1f' % (SPblock[k][0], SPblock[k][1], GCblock[k][0], GCblock[k][1]) if len(DIblock) > 0: if contour == 0: pmagplotlib.plotEQ(FIG['eqarea'], DIblock, title) else: pmagplotlib.plotEQcont(FIG['eqarea'], DIblock) else: pmagplotlib.plotNET(FIG['eqarea']) if len(GCblock) > 0: for rec in GCblock: pmagplotlib.plotC(FIG['eqarea'], rec, 90., 'g') if plotE == 1: ppars = pmag.doprinc(DIblock) # get principal directions nDIs, rDIs, npars, rpars = [], [], [], [] for rec in DIblock: angle = pmag.angle([rec[0], rec[1]], [ppars['dec'], ppars['inc']]) if angle > 90.: rDIs.append(rec) else: nDIs.append(rec) if dist == 'B': # do on whole dataset etitle = "Bingham confidence ellipse" bpars = pmag.dobingham(DIblock) for key in bpars.keys(): if key != 'n' and verbose: print " ", key, '%7.1f' % (bpars[key]) if key == 'n' and verbose: print " ", key, ' %i' % (bpars[key]) npars.append(bpars['dec']) npars.append(bpars['inc']) npars.append(bpars['Zeta']) npars.append(bpars['Zdec']) npars.append(bpars['Zinc']) npars.append(bpars['Eta']) npars.append(bpars['Edec']) npars.append(bpars['Einc']) if dist == 'F': etitle = "Fisher confidence cone" if len(nDIs) > 2: fpars = pmag.fisher_mean(nDIs) for key in fpars.keys(): if key != 'n' and verbose: print " ", key, '%7.1f' % (fpars[key]) if key == 'n' and verbose: print " ", key, ' %i' % (fpars[key]) mode += 1 npars.append(fpars['dec']) npars.append(fpars['inc']) npars.append(fpars['alpha95']) # Beta npars.append(fpars['dec']) isign = abs(fpars['inc']) / fpars['inc'] npars.append(fpars['inc'] - isign * 90.) #Beta inc npars.append(fpars['alpha95']) # gamma npars.append(fpars['dec'] + 90.) # Beta dec npars.append(0.) #Beta inc if len(rDIs) > 2: fpars = pmag.fisher_mean(rDIs) if verbose: print "mode ", mode for key in fpars.keys(): if key != 'n' and verbose: print " ", key, '%7.1f' % (fpars[key]) if key == 'n' and verbose: print " ", key, ' %i' % (fpars[key]) mode += 1 rpars.append(fpars['dec']) rpars.append(fpars['inc']) rpars.append(fpars['alpha95']) # Beta rpars.append(fpars['dec']) isign = abs(fpars['inc']) / fpars['inc'] rpars.append(fpars['inc'] - isign * 90.) #Beta inc rpars.append(fpars['alpha95']) # gamma rpars.append(fpars['dec'] + 90.) # Beta dec rpars.append(0.) #Beta inc if dist == 'K': etitle = "Kent confidence ellipse" if len(nDIs) > 3: kpars = pmag.dokent(nDIs, len(nDIs)) if verbose: print "mode ", mode for key in kpars.keys(): if key != 'n' and verbose: print " ", key, '%7.1f' % (kpars[key]) if key == 'n' and verbose: print " ", key, ' %i' % (kpars[key]) mode += 1 npars.append(kpars['dec']) npars.append(kpars['inc']) npars.append(kpars['Zeta']) npars.append(kpars['Zdec']) npars.append(kpars['Zinc']) npars.append(kpars['Eta']) npars.append(kpars['Edec']) npars.append(kpars['Einc']) if len(rDIs) > 3: kpars = pmag.dokent(rDIs, len(rDIs)) if verbose: print "mode ", mode for key in kpars.keys(): if key != 'n' and verbose: print " ", key, '%7.1f' % (kpars[key]) if key == 'n' and verbose: print " ", key, ' %i' % (kpars[key]) mode += 1 rpars.append(kpars['dec']) rpars.append(kpars['inc']) rpars.append(kpars['Zeta']) rpars.append(kpars['Zdec']) rpars.append(kpars['Zinc']) rpars.append(kpars['Eta']) rpars.append(kpars['Edec']) rpars.append(kpars['Einc']) else: # assume bootstrap if dist == 'BE': if len(nDIs) > 5: BnDIs = pmag.di_boot(nDIs) Bkpars = pmag.dokent(BnDIs, 1.) if verbose: print "mode ", mode for key in Bkpars.keys(): if key != 'n' and verbose: print " ", key, '%7.1f' % (Bkpars[key]) if key == 'n' and verbose: print " ", key, ' %i' % (Bkpars[key]) mode += 1 npars.append(Bkpars['dec']) npars.append(Bkpars['inc']) npars.append(Bkpars['Zeta']) npars.append(Bkpars['Zdec']) npars.append(Bkpars['Zinc']) npars.append(Bkpars['Eta']) npars.append(Bkpars['Edec']) npars.append(Bkpars['Einc']) if len(rDIs) > 5: BrDIs = pmag.di_boot(rDIs) Bkpars = pmag.dokent(BrDIs, 1.) if verbose: print "mode ", mode for key in Bkpars.keys(): if key != 'n' and verbose: print " ", key, '%7.1f' % (Bkpars[key]) if key == 'n' and verbose: print " ", key, ' %i' % (Bkpars[key]) mode += 1 rpars.append(Bkpars['dec']) rpars.append(Bkpars['inc']) rpars.append(Bkpars['Zeta']) rpars.append(Bkpars['Zdec']) rpars.append(Bkpars['Zinc']) rpars.append(Bkpars['Eta']) rpars.append(Bkpars['Edec']) rpars.append(Bkpars['Einc']) etitle = "Bootstrapped confidence ellipse" elif dist == 'BV': sym = {'lower': ['o', 'c'], 'upper': ['o', 'g'], 'size': 3, 'edgecolor': 'face'} if len(nDIs) > 5: BnDIs = pmag.di_boot(nDIs) pmagplotlib.plotEQsym(FIG['bdirs'], BnDIs, 'Bootstrapped Eigenvectors', sym) if len(rDIs) > 5: BrDIs = pmag.di_boot(rDIs) if len(nDIs) > 5: # plot on existing plots pmagplotlib.plotDIsym(FIG['bdirs'], BrDIs, sym) else: pmagplotlib.plotEQ(FIG['bdirs'], BrDIs, 'Bootstrapped Eigenvectors') if dist == 'B': if len(nDIs) > 3 or len(rDIs) > 3: pmagplotlib.plotCONF(FIG['eqarea'], etitle, [], npars, 0) elif len(nDIs) > 3 and dist != 'BV': pmagplotlib.plotCONF(FIG['eqarea'], etitle, [], npars, 0) if len(rDIs) > 3: pmagplotlib.plotCONF(FIG['eqarea'], etitle, [], rpars, 0) elif len(rDIs) > 3 and dist != 'BV': pmagplotlib.plotCONF(FIG['eqarea'], etitle, [], rpars, 0) if verbose: pmagplotlib.drawFIGS(FIG) # files = {} locations = locations[:-1] for key in FIG.keys(): filename = 'LO:_' + locations + '_SI:_' + site + '_SA:_' + sample + '_SP:_' + specimen + '_CO:_' + crd + '_TY:_' + key + '_.' + fmt files[key] = filename if pmagplotlib.isServer: black = '#000000' purple = '#800080' titles = {} titles['eq'] = 'Equal Area Plot' FIG = pmagplotlib.addBorders(FIG, titles, black, purple) pmagplotlib.saveP(FIG, files) elif verbose: ans = raw_input(" S[a]ve to save plot, [q]uit, Return to continue: ") if ans == "q": sys.exit() if ans == "a": pmagplotlib.saveP(FIG, files) if plots: pmagplotlib.saveP(FIG, files)
def main(): """ NAME plotdi_e.py DESCRIPTION plots equal area projection from dec inc data and cones of confidence (Fisher, kent or Bingham or bootstrap). INPUT FORMAT takes dec/inc as first two columns in space delimited file SYNTAX plotdi_e.py [command line options] OPTIONS -h prints help message and quits -i for interactive parameter entry -f FILE, sets input filename on command line -Fish plots unit vector mean direction, alpha95 -Bing plots Principal direction, Bingham confidence ellipse -Kent plots unit vector mean direction, confidence ellipse -Boot E plots unit vector mean direction, bootstrapped confidence ellipse -Boot V plots unit vector mean direction, distribution of bootstrapped means """ dist='F' # default distribution is Fisherian mode=1 EQ={'eq':1} if len(sys.argv) > 0: 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: ") dist=raw_input("Enter desired distrubution: [Fish]er, [Bing]ham, [Kent] [Boot] [default is Fisher]: ") if dist=="":dist="F" if dist=="Boot": type=raw_input(" Ellipses or distribution of vectors? [E]/V ") if type=="" or type=="E": dist="BE" else: dist="BE" else: # if '-f' in sys.argv: ind=sys.argv.index('-f') file=sys.argv[ind+1] else: print 'you must specify a file name' print main.__doc__ sys.exit() if '-Bing' in sys.argv:dist='B' if '-Kent' in sys.argv:dist='K' if '-Boot' in sys.argv: ind=sys.argv.index('-Boot') type=sys.argv[ind+1] if type=='E': dist='BE' elif type=='V': dist='BV' EQ['bdirs']=2 pmagplotlib.plot_init(EQ['bdirs'],5,5) else: print main.__doc__ sys.exit() pmagplotlib.plot_init(EQ['eq'],5,5) # # get to work f=open(file,'r') data=f.readlines() # DIs= [] # set up list for dec inc data DiRecs=[] pars=[] nDIs,rDIs,npars,rpars=[],[],[],[] mode =1 for line in data: # read in the data from standard input DiRec={} rec=line.split() # split each line on space to get records DIs.append((float(rec[0]),float(rec[1]),1.)) DiRec['dec']=rec[0] DiRec['inc']=rec[1] DiRec['direction_type']='l' DiRecs.append(DiRec) # split into two modes ppars=pmag.doprinc(DIs) # get principal directions for rec in DIs: angle=pmag.angle([rec[0],rec[1]],[ppars['dec'],ppars['inc']]) if angle>90.: rDIs.append(rec) else: nDIs.append(rec) if dist=='B': # do on whole dataset title="Bingham confidence ellipse" bpars=pmag.dobingham(DIs) for key in bpars.keys(): if key!='n':print " ",key, '%7.1f'%(bpars[key]) if key=='n':print " ",key, ' %i'%(bpars[key]) npars.append(bpars['dec']) npars.append(bpars['inc']) npars.append(bpars['Zeta']) npars.append(bpars['Zdec']) npars.append(bpars['Zinc']) npars.append(bpars['Eta']) npars.append(bpars['Edec']) npars.append(bpars['Einc']) if dist=='F': title="Fisher confidence cone" if len(nDIs)>3: fpars=pmag.fisher_mean(nDIs) print "mode ",mode for key in fpars.keys(): if key!='n':print " ",key, '%7.1f'%(fpars[key]) if key=='n':print " ",key, ' %i'%(fpars[key]) mode+=1 npars.append(fpars['dec']) npars.append(fpars['inc']) npars.append(fpars['alpha95']) # Beta npars.append(fpars['dec']) isign=abs(fpars['inc'])/fpars['inc'] npars.append(fpars['inc']-isign*90.) #Beta inc npars.append(fpars['alpha95']) # gamma npars.append(fpars['dec']+90.) # Beta dec npars.append(0.) #Beta inc if len(rDIs)>3: fpars=pmag.fisher_mean(rDIs) print "mode ",mode for key in fpars.keys(): if key!='n':print " ",key, '%7.1f'%(fpars[key]) if key=='n':print " ",key, ' %i'%(fpars[key]) mode+=1 rpars.append(fpars['dec']) rpars.append(fpars['inc']) rpars.append(fpars['alpha95']) # Beta rpars.append(fpars['dec']) isign=abs(fpars['inc'])/fpars['inc'] rpars.append(fpars['inc']-isign*90.) #Beta inc rpars.append(fpars['alpha95']) # gamma rpars.append(fpars['dec']+90.) # Beta dec rpars.append(0.) #Beta inc if dist=='K': title="Kent confidence ellipse" if len(nDIs)>3: kpars=pmag.dokent(nDIs,len(nDIs)) print "mode ",mode for key in kpars.keys(): if key!='n':print " ",key, '%7.1f'%(kpars[key]) if key=='n':print " ",key, ' %i'%(kpars[key]) mode+=1 npars.append(kpars['dec']) npars.append(kpars['inc']) npars.append(kpars['Zeta']) npars.append(kpars['Zdec']) npars.append(kpars['Zinc']) npars.append(kpars['Eta']) npars.append(kpars['Edec']) npars.append(kpars['Einc']) if len(rDIs)>3: kpars=pmag.dokent(rDIs,len(rDIs)) print "mode ",mode for key in kpars.keys(): if key!='n':print " ",key, '%7.1f'%(kpars[key]) if key=='n':print " ",key, ' %i'%(kpars[key]) mode+=1 rpars.append(kpars['dec']) rpars.append(kpars['inc']) rpars.append(kpars['Zeta']) rpars.append(kpars['Zdec']) rpars.append(kpars['Zinc']) rpars.append(kpars['Eta']) rpars.append(kpars['Edec']) rpars.append(kpars['Einc']) else: # assume bootstrap if dist=='BE': if len(nDIs)>5: BnDIs=pmag.di_boot(nDIs) Bkpars=pmag.dokent(BnDIs,1.) print "mode ",mode for key in Bkpars.keys(): if key!='n':print " ",key, '%7.1f'%(Bkpars[key]) if key=='n':print " ",key, ' %i'%(Bkpars[key]) mode+=1 npars.append(Bkpars['dec']) npars.append(Bkpars['inc']) npars.append(Bkpars['Zeta']) npars.append(Bkpars['Zdec']) npars.append(Bkpars['Zinc']) npars.append(Bkpars['Eta']) npars.append(Bkpars['Edec']) npars.append(Bkpars['Einc']) if len(rDIs)>5: BrDIs=pmag.di_boot(rDIs) Bkpars=pmag.dokent(BrDIs,1.) print "mode ",mode for key in Bkpars.keys(): if key!='n':print " ",key, '%7.1f'%(Bkpars[key]) if key=='n':print " ",key, ' %i'%(Bkpars[key]) mode+=1 rpars.append(Bkpars['dec']) rpars.append(Bkpars['inc']) rpars.append(Bkpars['Zeta']) rpars.append(Bkpars['Zdec']) rpars.append(Bkpars['Zinc']) rpars.append(Bkpars['Eta']) rpars.append(Bkpars['Edec']) rpars.append(Bkpars['Einc']) title="Bootstrapped confidence ellipse" elif dist=='BV': if len(nDIs)>5: pmagplotlib.plotEQ(EQ['eq'],nDIs,'Data') BnDIs=pmag.di_boot(nDIs) pmagplotlib.plotEQ(EQ['bdirs'],BnDIs,'Bootstrapped Eigenvectors') if len(rDIs)>5: BrDIs=pmag.di_boot(rDIs) if len(nDIs)>5: # plot on existing plots pmagplotlib.plotDI(EQ['eq'],rDIs) pmagplotlib.plotDI(EQ['bdirs'],BrDIs) else: pmagplotlib.plotEQ(EQ['eq'],rDIs,'Data') pmagplotlib.plotEQ(EQ['bdirs'],BrDIs,'Bootstrapped Eigenvectors') pmagplotlib.drawFIGS(EQ) ans=raw_input('s[a]ve, [q]uit ') if ans=='q':sys.exit() if ans=='a': files={} for key in EQ.keys(): files[key]='BE_'+key+'.svg' pmagplotlib.saveP(EQ,files) sys.exit() if len(nDIs)>5: pmagplotlib.plotCONF(EQ['eq'],title,DiRecs,npars,1) if len(rDIs)>5 and dist!='B': pmagplotlib.plotCONF(EQ['eq'],title,[],rpars,0) elif len(rDIs)>5 and dist!='B': pmagplotlib.plotCONF(EQ['eq'],title,DiRecs,rpars,1) pmagplotlib.drawFIGS(EQ) ans=raw_input('s[a]ve, [q]uit ') if ans=='q':sys.exit() if ans=='a': files={} for key in EQ.keys(): files[key]=key+'.svg' pmagplotlib.saveP(EQ,files)
def main(): """ NAME eqarea_ell.py DESCRIPTION makes equal area projections from declination/inclination data and plot ellipses SYNTAX eqarea_ell.py -h [command line options] INPUT takes space delimited Dec/Inc data OPTIONS -h prints help message and quits -f FILE -fmt [svg,png,jpg] format for output plots -ell [F,K,B,Be,Bv] plot Fisher, Kent, Bingham, Bootstrap ellipses or Boostrap eigenvectors """ FIG = {} # plot dictionary FIG["eq"] = 1 # eqarea is figure 1 fmt, dist, mode = "svg", "F", 1 plotE = 0 if "-h" in sys.argv: print main.__doc__ sys.exit() pmagplotlib.plot_init(FIG["eq"], 5, 5) if "-f" in sys.argv: ind = sys.argv.index("-f") title = sys.argv[ind + 1] f = open(title, "rU") data = f.readlines() if "-ell" in sys.argv: plotE = 1 ind = sys.argv.index("-ell") ell_type = sys.argv[ind + 1] if ell_type == "F": dist = "F" if ell_type == "K": dist = "K" if ell_type == "B": dist = "B" if ell_type == "Be": dist = "BE" if ell_type == "Bv": dist = "BV" FIG["bdirs"] = 2 pmagplotlib.plot_init(FIG["bdirs"], 5, 5) if "-fmt" in sys.argv: ind = sys.argv.index("-fmt") fmt = sys.argv[ind + 1] DIblock = [] 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 DIblock.append([float(rec[0]), float(rec[1])]) if len(DIblock) > 0: pmagplotlib.plotEQ(FIG["eq"], DIblock, title) else: print "no data to plot" sys.exit() if plotE == 1: ppars = pmag.doprinc(DIblock) # get principal directions nDIs, rDIs, npars, rpars = [], [], [], [] for rec in DIblock: angle = pmag.angle([rec[0], rec[1]], [ppars["dec"], ppars["inc"]]) if angle > 90.0: rDIs.append(rec) else: nDIs.append(rec) if dist == "B": # do on whole dataset etitle = "Bingham confidence ellipse" bpars = pmag.dobingham(DIblock) for key in bpars.keys(): if key != "n" and pmagplotlib.verbose: print " ", key, "%7.1f" % (bpars[key]) if key == "n" and pmagplotlib.verbose: print " ", key, " %i" % (bpars[key]) npars.append(bpars["dec"]) npars.append(bpars["inc"]) npars.append(bpars["Zeta"]) npars.append(bpars["Zdec"]) npars.append(bpars["Zinc"]) npars.append(bpars["Eta"]) npars.append(bpars["Edec"]) npars.append(bpars["Einc"]) if dist == "F": etitle = "Fisher confidence cone" if len(nDIs) > 3: fpars = pmag.fisher_mean(nDIs) for key in fpars.keys(): if key != "n" and pmagplotlib.verbose: print " ", key, "%7.1f" % (fpars[key]) if key == "n" and pmagplotlib.verbose: print " ", key, " %i" % (fpars[key]) mode += 1 npars.append(fpars["dec"]) npars.append(fpars["inc"]) npars.append(fpars["alpha95"]) # Beta npars.append(fpars["dec"]) isign = abs(fpars["inc"]) / fpars["inc"] npars.append(fpars["inc"] - isign * 90.0) # Beta inc npars.append(fpars["alpha95"]) # gamma npars.append(fpars["dec"] + 90.0) # Beta dec npars.append(0.0) # Beta inc if len(rDIs) > 3: fpars = pmag.fisher_mean(rDIs) if pmagplotlib.verbose: print "mode ", mode for key in fpars.keys(): if key != "n" and pmagplotlib.verbose: print " ", key, "%7.1f" % (fpars[key]) if key == "n" and pmagplotlib.verbose: print " ", key, " %i" % (fpars[key]) mode += 1 rpars.append(fpars["dec"]) rpars.append(fpars["inc"]) rpars.append(fpars["alpha95"]) # Beta rpars.append(fpars["dec"]) isign = abs(fpars["inc"]) / fpars["inc"] rpars.append(fpars["inc"] - isign * 90.0) # Beta inc rpars.append(fpars["alpha95"]) # gamma rpars.append(fpars["dec"] + 90.0) # Beta dec rpars.append(0.0) # Beta inc if dist == "K": etitle = "Kent confidence ellipse" if len(nDIs) > 3: kpars = pmag.dokent(nDIs, len(nDIs)) if pmagplotlib.verbose: print "mode ", mode for key in kpars.keys(): if key != "n" and pmagplotlib.verbose: print " ", key, "%7.1f" % (kpars[key]) if key == "n" and pmagplotlib.verbose: print " ", key, " %i" % (kpars[key]) mode += 1 npars.append(kpars["dec"]) npars.append(kpars["inc"]) npars.append(kpars["Zeta"]) npars.append(kpars["Zdec"]) npars.append(kpars["Zinc"]) npars.append(kpars["Eta"]) npars.append(kpars["Edec"]) npars.append(kpars["Einc"]) if len(rDIs) > 3: kpars = pmag.dokent(rDIs, len(rDIs)) if pmagplotlib.verbose: print "mode ", mode for key in kpars.keys(): if key != "n" and pmagplotlib.verbose: print " ", key, "%7.1f" % (kpars[key]) if key == "n" and pmagplotlib.verbose: print " ", key, " %i" % (kpars[key]) mode += 1 rpars.append(kpars["dec"]) rpars.append(kpars["inc"]) rpars.append(kpars["Zeta"]) rpars.append(kpars["Zdec"]) rpars.append(kpars["Zinc"]) rpars.append(kpars["Eta"]) rpars.append(kpars["Edec"]) rpars.append(kpars["Einc"]) else: # assume bootstrap if len(nDIs) < 10 and len(rDIs) < 10: print "too few data points for bootstrap" sys.exit() if dist == "BE": if len(nDIs) >= 10: BnDIs = pmag.di_boot(nDIs) Bkpars = pmag.dokent(BnDIs, 1.0) if pmagplotlib.verbose: print "mode ", mode for key in Bkpars.keys(): if key != "n" and pmagplotlib.verbose: print " ", key, "%7.1f" % (Bkpars[key]) if key == "n" and pmagplotlib.verbose: print " ", key, " %i" % (Bkpars[key]) mode += 1 npars.append(Bkpars["dec"]) npars.append(Bkpars["inc"]) npars.append(Bkpars["Zeta"]) npars.append(Bkpars["Zdec"]) npars.append(Bkpars["Zinc"]) npars.append(Bkpars["Eta"]) npars.append(Bkpars["Edec"]) npars.append(Bkpars["Einc"]) if len(rDIs) >= 10: BrDIs = pmag.di_boot(rDIs) Bkpars = pmag.dokent(BrDIs, 1.0) if pmagplotlib.verbose: print "mode ", mode for key in Bkpars.keys(): if key != "n" and pmagplotlib.verbose: print " ", key, "%7.1f" % (Bkpars[key]) if key == "n" and pmagplotlib.verbose: print " ", key, " %i" % (Bkpars[key]) mode += 1 rpars.append(Bkpars["dec"]) rpars.append(Bkpars["inc"]) rpars.append(Bkpars["Zeta"]) rpars.append(Bkpars["Zdec"]) rpars.append(Bkpars["Zinc"]) rpars.append(Bkpars["Eta"]) rpars.append(Bkpars["Edec"]) rpars.append(Bkpars["Einc"]) etitle = "Bootstrapped confidence ellipse" elif dist == "BV": vsym = {"lower": ["+", "k"], "upper": ["x", "k"], "size": 5} if len(nDIs) > 5: BnDIs = pmag.di_boot(nDIs) pmagplotlib.plotEQsym(FIG["bdirs"], BnDIs, "Bootstrapped Eigenvectors", vsym) if len(rDIs) > 5: BrDIs = pmag.di_boot(rDIs) if len(nDIs) > 5: # plot on existing plots pmagplotlib.plotDIsym(FIG["bdirs"], BrDIs, vsym) else: pmagplotlib.plotEQ(FIG["bdirs"], BrDIs, "Bootstrapped Eigenvectors", vsym) if dist == "B": if len(nDIs) > 3 or len(rDIs) > 3: pmagplotlib.plotCONF(FIG["eq"], etitle, [], npars, 0) elif len(nDIs) > 3 and dist != "BV": pmagplotlib.plotCONF(FIG["eq"], etitle, [], npars, 0) if len(rDIs) > 3: pmagplotlib.plotCONF(FIG["eq"], etitle, [], rpars, 0) elif len(rDIs) > 3 and dist != "BV": pmagplotlib.plotCONF(FIG["eq"], etitle, [], rpars, 0) pmagplotlib.drawFIGS(FIG) # files = {} for key in FIG.keys(): files[key] = title + "_" + key + "." + fmt if pmagplotlib.isServer: black = "#000000" purple = "#800080" titles = {} titles["eq"] = "Equal Area Plot" FIG = pmagplotlib.addBorders(FIG, titles, black, purple) pmagplotlib.saveP(FIG, files) else: ans = raw_input(" S[a]ve to save plot, [q]uit, Return to continue: ") if ans == "q": sys.exit() if ans == "a": pmagplotlib.saveP(FIG, files)
def main(): """ NAME eqarea_ell.py DESCRIPTION makes equal area projections from declination/inclination data and plot ellipses SYNTAX eqarea_ell.py -h [command line options] INPUT takes space delimited Dec/Inc data OPTIONS -h prints help message and quits -f FILE -fmt [svg,png,jpg] format for output plots -sav saves figures and quits -ell [F,K,B,Be,Bv] plot Fisher, Kent, Bingham, Bootstrap ellipses or Boostrap eigenvectors """ FIG={} # plot dictionary FIG['eq']=1 # eqarea is figure 1 fmt,dist,mode,plot='svg','F',1,0 sym={'lower':['o','r'],'upper':['o','w'],'size':10} plotE=0 if '-h' in sys.argv: print main.__doc__ sys.exit() pmagplotlib.plot_init(FIG['eq'],5,5) if '-sav' in sys.argv:plot=1 if '-f' in sys.argv: ind=sys.argv.index("-f") title=sys.argv[ind+1] data=numpy.loadtxt(title).transpose() if '-ell' in sys.argv: plotE=1 ind=sys.argv.index('-ell') ell_type=sys.argv[ind+1] if ell_type=='F':dist='F' if ell_type=='K':dist='K' if ell_type=='B':dist='B' if ell_type=='Be':dist='BE' if ell_type=='Bv': dist='BV' FIG['bdirs']=2 pmagplotlib.plot_init(FIG['bdirs'],5,5) if '-fmt' in sys.argv: ind=sys.argv.index("-fmt") fmt=sys.argv[ind+1] DIblock=numpy.array([data[0],data[1]]).transpose() if len(DIblock)>0: pmagplotlib.plotEQsym(FIG['eq'],DIblock,title,sym) if plot==0:pmagplotlib.drawFIGS(FIG) else: print "no data to plot" sys.exit() if plotE==1: ppars=pmag.doprinc(DIblock) # get principal directions nDIs,rDIs,npars,rpars=[],[],[],[] for rec in DIblock: angle=pmag.angle([rec[0],rec[1]],[ppars['dec'],ppars['inc']]) if angle>90.: rDIs.append(rec) else: nDIs.append(rec) if dist=='B': # do on whole dataset etitle="Bingham confidence ellipse" bpars=pmag.dobingham(DIblock) for key in bpars.keys(): if key!='n' and pmagplotlib.verbose:print " ",key, '%7.1f'%(bpars[key]) if key=='n' and pmagplotlib.verbose:print " ",key, ' %i'%(bpars[key]) npars.append(bpars['dec']) npars.append(bpars['inc']) npars.append(bpars['Zeta']) npars.append(bpars['Zdec']) npars.append(bpars['Zinc']) npars.append(bpars['Eta']) npars.append(bpars['Edec']) npars.append(bpars['Einc']) if dist=='F': etitle="Fisher confidence cone" if len(nDIs)>3: fpars=pmag.fisher_mean(nDIs) for key in fpars.keys(): if key!='n' and pmagplotlib.verbose:print " ",key, '%7.1f'%(fpars[key]) if key=='n' and pmagplotlib.verbose:print " ",key, ' %i'%(fpars[key]) mode+=1 npars.append(fpars['dec']) npars.append(fpars['inc']) npars.append(fpars['alpha95']) # Beta npars.append(fpars['dec']) isign=abs(fpars['inc'])/fpars['inc'] npars.append(fpars['inc']-isign*90.) #Beta inc npars.append(fpars['alpha95']) # gamma npars.append(fpars['dec']+90.) # Beta dec npars.append(0.) #Beta inc if len(rDIs)>3: fpars=pmag.fisher_mean(rDIs) if pmagplotlib.verbose:print "mode ",mode for key in fpars.keys(): if key!='n' and pmagplotlib.verbose:print " ",key, '%7.1f'%(fpars[key]) if key=='n' and pmagplotlib.verbose:print " ",key, ' %i'%(fpars[key]) mode+=1 rpars.append(fpars['dec']) rpars.append(fpars['inc']) rpars.append(fpars['alpha95']) # Beta rpars.append(fpars['dec']) isign=abs(fpars['inc'])/fpars['inc'] rpars.append(fpars['inc']-isign*90.) #Beta inc rpars.append(fpars['alpha95']) # gamma rpars.append(fpars['dec']+90.) # Beta dec rpars.append(0.) #Beta inc if dist=='K': etitle="Kent confidence ellipse" if len(nDIs)>3: kpars=pmag.dokent(nDIs,len(nDIs)) if pmagplotlib.verbose:print "mode ",mode for key in kpars.keys(): if key!='n' and pmagplotlib.verbose:print " ",key, '%7.1f'%(kpars[key]) if key=='n' and pmagplotlib.verbose:print " ",key, ' %i'%(kpars[key]) mode+=1 npars.append(kpars['dec']) npars.append(kpars['inc']) npars.append(kpars['Zeta']) npars.append(kpars['Zdec']) npars.append(kpars['Zinc']) npars.append(kpars['Eta']) npars.append(kpars['Edec']) npars.append(kpars['Einc']) if len(rDIs)>3: kpars=pmag.dokent(rDIs,len(rDIs)) if pmagplotlib.verbose:print "mode ",mode for key in kpars.keys(): if key!='n' and pmagplotlib.verbose:print " ",key, '%7.1f'%(kpars[key]) if key=='n' and pmagplotlib.verbose:print " ",key, ' %i'%(kpars[key]) mode+=1 rpars.append(kpars['dec']) rpars.append(kpars['inc']) rpars.append(kpars['Zeta']) rpars.append(kpars['Zdec']) rpars.append(kpars['Zinc']) rpars.append(kpars['Eta']) rpars.append(kpars['Edec']) rpars.append(kpars['Einc']) else: # assume bootstrap if len(nDIs)<10 and len(rDIs)<10: print 'too few data points for bootstrap' sys.exit() if dist=='BE': print 'Be patient for bootstrap...' if len(nDIs)>=10: BnDIs=pmag.di_boot(nDIs) Bkpars=pmag.dokent(BnDIs,1.) if pmagplotlib.verbose:print "mode ",mode for key in Bkpars.keys(): if key!='n' and pmagplotlib.verbose:print " ",key, '%7.1f'%(Bkpars[key]) if key=='n' and pmagplotlib.verbose:print " ",key, ' %i'%(Bkpars[key]) mode+=1 npars.append(Bkpars['dec']) npars.append(Bkpars['inc']) npars.append(Bkpars['Zeta']) npars.append(Bkpars['Zdec']) npars.append(Bkpars['Zinc']) npars.append(Bkpars['Eta']) npars.append(Bkpars['Edec']) npars.append(Bkpars['Einc']) if len(rDIs)>=10: BrDIs=pmag.di_boot(rDIs) Bkpars=pmag.dokent(BrDIs,1.) if pmagplotlib.verbose:print "mode ",mode for key in Bkpars.keys(): if key!='n' and pmagplotlib.verbose:print " ",key, '%7.1f'%(Bkpars[key]) if key=='n' and pmagplotlib.verbose:print " ",key, ' %i'%(Bkpars[key]) mode+=1 rpars.append(Bkpars['dec']) rpars.append(Bkpars['inc']) rpars.append(Bkpars['Zeta']) rpars.append(Bkpars['Zdec']) rpars.append(Bkpars['Zinc']) rpars.append(Bkpars['Eta']) rpars.append(Bkpars['Edec']) rpars.append(Bkpars['Einc']) etitle="Bootstrapped confidence ellipse" elif dist=='BV': print 'Be patient for bootstrap...' vsym={'lower':['+','k'],'upper':['x','k'],'size':5} if len(nDIs)>5: BnDIs=pmag.di_boot(nDIs) pmagplotlib.plotEQsym(FIG['bdirs'],BnDIs,'Bootstrapped Eigenvectors',vsym) if len(rDIs)>5: BrDIs=pmag.di_boot(rDIs) if len(nDIs)>5: # plot on existing plots pmagplotlib.plotDIsym(FIG['bdirs'],BrDIs,vsym) else: pmagplotlib.plotEQ(FIG['bdirs'],BrDIs,'Bootstrapped Eigenvectors',vsym) if dist=='B': if len(nDIs)> 3 or len(rDIs)>3: pmagplotlib.plotCONF(FIG['eq'],etitle,[],npars,0) elif len(nDIs)>3 and dist!='BV': pmagplotlib.plotCONF(FIG['eq'],etitle,[],npars,0) if len(rDIs)>3: pmagplotlib.plotCONF(FIG['eq'],etitle,[],rpars,0) elif len(rDIs)>3 and dist!='BV': pmagplotlib.plotCONF(FIG['eq'],etitle,[],rpars,0) if plot==0:pmagplotlib.drawFIGS(FIG) if plot==0:pmagplotlib.drawFIGS(FIG) # files={} for key in FIG.keys(): files[key]=title+'_'+key+'.'+fmt if pmagplotlib.isServer: black = '#000000' purple = '#800080' titles={} titles['eq']='Equal Area Plot' FIG = pmagplotlib.addBorders(FIG,titles,black,purple) pmagplotlib.saveP(FIG,files) elif plot==0: ans=raw_input(" S[a]ve to save plot, [q]uit, Return to continue: ") if ans=="q": sys.exit() if ans=="a": pmagplotlib.saveP(FIG,files) else: pmagplotlib.saveP(FIG,files)
def main(): """ NAME eqarea_magic.py DESCRIPTION makes equal area projections from declination/inclination data SYNTAX eqarea_magic.py [command line options] INPUT takes magic formatted pmag_results, pmag_sites, pmag_samples or pmag_specimens OPTIONS -h prints help message and quits -f FILE: specify input magic format file from magic,default='pmag_results.txt' supported types=[magic_measurements,pmag_specimens, pmag_samples, pmag_sites, pmag_results, magic_web] -obj OBJ: specify level of plot [all, sit, sam, spc], default is all -crd [s,g,t]: specify coordinate system, [s]pecimen, [g]eographic, [t]ilt adjusted default is geographic -fmt [svg,png,jpg] format for output plots -ell [F,K,B,Be,Bv] plot Fisher, Kent, Bingham, Bootstrap ellipses or Boostrap eigenvectors -c plot as colour contour NOTE all: entire file; sit: site; sam: sample; spc: specimen """ FIG={} # plot dictionary FIG['eq']=1 # eqarea is figure 1 in_file,plot_key,coord,crd='pmag_results.txt','all',"-1",'g' fmt,dist,mode='svg','F',1 plotE,contour=0,0 dir_path='.' if '-h' in sys.argv: print main.__doc__ sys.exit() if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] pmagplotlib.plot_init(FIG['eq'],5,5) if '-f' in sys.argv: ind=sys.argv.index("-f") in_file=dir_path+"/"+sys.argv[ind+1] if '-obj' in sys.argv: ind=sys.argv.index('-obj') plot_by=sys.argv[ind+1] if plot_by=='all':plot_key='all' if plot_by=='sit':plot_key='er_site_name' if plot_by=='sam':plot_key='er_sample_name' if plot_by=='spc':plot_key='er_specimen_name' if '-c' in sys.argv: contour=1 if '-ell' in sys.argv: plotE=1 ind=sys.argv.index('-ell') ell_type=sys.argv[ind+1] if ell_type=='F':dist='F' if ell_type=='K':dist='K' if ell_type=='B':dist='B' if ell_type=='Be':dist='BE' if ell_type=='Bv': dist='BV' FIG['bdirs']=2 pmagplotlib.plot_init(FIG['bdirs'],5,5) if '-crd' in sys.argv: ind=sys.argv.index("-crd") coord=sys.argv[ind+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] Dec_keys=['site_dec','sample_dec','specimen_dec','measurement_dec','average_dec'] Inc_keys=['site_inc','sample_inc','specimen_inc','measurement_inc','average_inc'] Tilt_keys=['tilt_correction','site_tilt_correction','sample_tilt_correction','specimen_tilt_correction'] Dir_type_keys=['','site_direction_type','sample_direction_type','specimen_direction_type'] Name_keys=['er_specimen_name','er_sample_name','er_site_name','pmag_result_name'] data,file_type=pmag.magic_read(in_file) if file_type=='pmag_results' and plot_key!="all":plot_key=plot_key+'s' # need plural for results table if pmagplotlib.verbose: print len(data),' records read from ',in_file # # # find desired dec,inc data: # dir_type_key='' # # get plotlist if not plotting all records # plotlist=[] if plot_key!="all": for rec in data: if rec[plot_key] not in plotlist: plotlist.append(rec[plot_key]) plotlist.sort() else: plotlist.append('Whole file') for plot in plotlist: DIblock=[] GCblock=[] SLblock,SPblock=[],[] tilt_key="" mode=1 for rec in data: # find what data are available if plot_key=='all' or rec[plot_key]==plot: if plot_key!="all": title=rec[plot_key] else: title=plot if coord=='-1':title=title+' Specimen Coordinates' if coord=='0':title=title+' Geographic Coordinates' if coord=='100':title=title+' Tilt corrected Coordinates' dec_key,inc_key,tilt_key,name_key,k="","","","",0 while dec_key=="" and k<len(Dec_keys): if Dec_keys[k] in rec.keys() and rec[Dec_keys[k]]!="" and Inc_keys[k] in rec.keys() and rec[Inc_keys[k]]!="": dec_key,inc_key =Dec_keys[k],Inc_keys[k] k+=1 k=0 while tilt_key=="" and k<len(Tilt_keys): if Tilt_keys[k] in rec.keys():tilt_key=Tilt_keys[k] k+=1 k=0 while name_key=="" and k<len(Name_keys): if Name_keys[k] in rec.keys():name_key=Name_keys[k] k+=1 k=1 while dir_type_key=="" and k<len(Dir_type_keys): if Dir_type_keys[k] in rec.keys():dir_type_key=Dir_type_keys[k] k+=1 if dec_key!="":break if tilt_key=="":tilt_key='-1' if dir_type_key=="":dir_type_key='direction_type' for rec in data: # pick out the data if (plot_key=='all' or rec[plot_key]==plot) and rec[dec_key].strip()!="" and rec[inc_key].strip()!="": if dir_type_key not in rec.keys() or rec[dir_type_key]=="":rec[dir_type_key]='l' if tilt_key not in rec.keys():rec[tilt_key]='-1' # assume specimen coordinates unless otherwise specified if coord=='-1': DIblock.append([float(rec[dec_key]),float(rec[inc_key])]) SLblock.append([rec[name_key],rec['magic_method_codes']]) elif rec[tilt_key]==coord and rec[dir_type_key]=='l' and rec[dec_key]!="" and rec[inc_key]!="": if rec[tilt_key]==coord and rec[dir_type_key]=='l' and rec[dec_key]!="" and rec[inc_key]!="": DIblock.append([float(rec[dec_key]),float(rec[inc_key])]) SLblock.append([rec[name_key],rec['magic_method_codes']]) elif rec[tilt_key]==coord and rec[dir_type_key]!='l' and rec[dec_key]!="" and rec[inc_key]!="": GCblock.append([float(rec[dec_key]),float(rec[inc_key])]) SPblock.append([rec[name_key],rec['magic_method_codes']]) if len(DIblock)==0 and len(GCblock)==0: if pmagplotlib.verbose: print "no records for plotting" sys.exit() if pmagplotlib.verbose: for k in range(len(SLblock)): print '%s %s %7.1f %7.1f'%(SLblock[k][0],SLblock[k][1],DIblock[k][0],DIblock[k][1]) for k in range(len(SPblock)): print '%s %s %7.1f %7.1f'%(SPblock[k][0],SPblock[k][1],GCblock[k][0],GCblock[k][1]) if len(DIblock)>0: if contour==0: pmagplotlib.plotEQ(FIG['eq'],DIblock,title) else: pmagplotlib.plotEQcont(FIG['eq'],DIblock) else: pmagplotlib.plotNET(FIG['eq']) if len(GCblock)>0: for rec in GCblock: pmagplotlib.plotC(FIG['eq'],rec,90.,'g') if plotE==1: ppars=pmag.doprinc(DIblock) # get principal directions nDIs,rDIs,npars,rpars=[],[],[],[] for rec in DIblock: angle=pmag.angle([rec[0],rec[1]],[ppars['dec'],ppars['inc']]) if angle>90.: rDIs.append(rec) else: nDIs.append(rec) if dist=='B': # do on whole dataset etitle="Bingham confidence ellipse" bpars=pmag.dobingham(DIblock) for key in bpars.keys(): if key!='n' and pmagplotlib.verbose:print " ",key, '%7.1f'%(bpars[key]) if key=='n' and pmagplotlib.verbose:print " ",key, ' %i'%(bpars[key]) npars.append(bpars['dec']) npars.append(bpars['inc']) npars.append(bpars['Zeta']) npars.append(bpars['Zdec']) npars.append(bpars['Zinc']) npars.append(bpars['Eta']) npars.append(bpars['Edec']) npars.append(bpars['Einc']) if dist=='F': etitle="Fisher confidence cone" if len(nDIs)>2: fpars=pmag.fisher_mean(nDIs) for key in fpars.keys(): if key!='n' and pmagplotlib.verbose:print " ",key, '%7.1f'%(fpars[key]) if key=='n' and pmagplotlib.verbose:print " ",key, ' %i'%(fpars[key]) mode+=1 npars.append(fpars['dec']) npars.append(fpars['inc']) npars.append(fpars['alpha95']) # Beta npars.append(fpars['dec']) isign=abs(fpars['inc'])/fpars['inc'] npars.append(fpars['inc']-isign*90.) #Beta inc npars.append(fpars['alpha95']) # gamma npars.append(fpars['dec']+90.) # Beta dec npars.append(0.) #Beta inc if len(rDIs)>2: fpars=pmag.fisher_mean(rDIs) if pmagplotlib.verbose:print "mode ",mode for key in fpars.keys(): if key!='n' and pmagplotlib.verbose:print " ",key, '%7.1f'%(fpars[key]) if key=='n' and pmagplotlib.verbose:print " ",key, ' %i'%(fpars[key]) mode+=1 rpars.append(fpars['dec']) rpars.append(fpars['inc']) rpars.append(fpars['alpha95']) # Beta rpars.append(fpars['dec']) isign=abs(fpars['inc'])/fpars['inc'] rpars.append(fpars['inc']-isign*90.) #Beta inc rpars.append(fpars['alpha95']) # gamma rpars.append(fpars['dec']+90.) # Beta dec rpars.append(0.) #Beta inc if dist=='K': etitle="Kent confidence ellipse" if len(nDIs)>3: kpars=pmag.dokent(nDIs,len(nDIs)) if pmagplotlib.verbose:print "mode ",mode for key in kpars.keys(): if key!='n' and pmagplotlib.verbose:print " ",key, '%7.1f'%(kpars[key]) if key=='n' and pmagplotlib.verbose:print " ",key, ' %i'%(kpars[key]) mode+=1 npars.append(kpars['dec']) npars.append(kpars['inc']) npars.append(kpars['Zeta']) npars.append(kpars['Zdec']) npars.append(kpars['Zinc']) npars.append(kpars['Eta']) npars.append(kpars['Edec']) npars.append(kpars['Einc']) if len(rDIs)>3: kpars=pmag.dokent(rDIs,len(rDIs)) if pmagplotlib.verbose:print "mode ",mode for key in kpars.keys(): if key!='n' and pmagplotlib.verbose:print " ",key, '%7.1f'%(kpars[key]) if key=='n' and pmagplotlib.verbose:print " ",key, ' %i'%(kpars[key]) mode+=1 rpars.append(kpars['dec']) rpars.append(kpars['inc']) rpars.append(kpars['Zeta']) rpars.append(kpars['Zdec']) rpars.append(kpars['Zinc']) rpars.append(kpars['Eta']) rpars.append(kpars['Edec']) rpars.append(kpars['Einc']) else: # assume bootstrap if dist=='BE': if len(nDIs)>5: BnDIs=pmag.di_boot(nDIs) Bkpars=pmag.dokent(BnDIs,1.) if pmagplotlib.verbose:print "mode ",mode for key in Bkpars.keys(): if key!='n' and pmagplotlib.verbose:print " ",key, '%7.1f'%(Bkpars[key]) if key=='n' and pmagplotlib.verbose:print " ",key, ' %i'%(Bkpars[key]) mode+=1 npars.append(Bkpars['dec']) npars.append(Bkpars['inc']) npars.append(Bkpars['Zeta']) npars.append(Bkpars['Zdec']) npars.append(Bkpars['Zinc']) npars.append(Bkpars['Eta']) npars.append(Bkpars['Edec']) npars.append(Bkpars['Einc']) if len(rDIs)>5: BrDIs=pmag.di_boot(rDIs) Bkpars=pmag.dokent(BrDIs,1.) if pmagplotlib.verbose:print "mode ",mode for key in Bkpars.keys(): if key!='n' and pmagplotlib.verbose:print " ",key, '%7.1f'%(Bkpars[key]) if key=='n' and pmagplotlib.verbose:print " ",key, ' %i'%(Bkpars[key]) mode+=1 rpars.append(Bkpars['dec']) rpars.append(Bkpars['inc']) rpars.append(Bkpars['Zeta']) rpars.append(Bkpars['Zdec']) rpars.append(Bkpars['Zinc']) rpars.append(Bkpars['Eta']) rpars.append(Bkpars['Edec']) rpars.append(Bkpars['Einc']) etitle="Bootstrapped confidence ellipse" elif dist=='BV': if len(nDIs)>5: BnDIs=pmag.di_boot(nDIs) pmagplotlib.plotEQ(FIG['bdirs'],BnDIs,'Bootstrapped Eigenvectors') if len(rDIs)>5: BrDIs=pmag.di_boot(rDIs) if len(nDIs)>5: # plot on existing plots pmagplotlib.plotDI(FIG['bdirs'],BrDIs) else: pmagplotlib.plotEQ(FIG['bdirs'],BrDIs,'Bootstrapped Eigenvectors') if dist=='B': if len(nDIs)> 3 or len(rDIs)>3: pmagplotlib.plotCONF(FIG['eq'],etitle,[],npars,0) elif len(nDIs)>3 and dist!='BV': pmagplotlib.plotCONF(FIG['eq'],etitle,[],npars,0) if len(rDIs)>3: pmagplotlib.plotCONF(FIG['eq'],etitle,[],rpars,0) elif len(rDIs)>3 and dist!='BV': pmagplotlib.plotCONF(FIG['eq'],etitle,[],rpars,0) pmagplotlib.drawFIGS(FIG) # files={} for key in FIG.keys(): files[key]=title.replace(" ","_")+'_'+'eqarea'+'.'+fmt if pmagplotlib.isServer: black = '#000000' purple = '#800080' titles={} titles['eq']='Equal Area Plot' FIG = pmagplotlib.addBorders(FIG,titles,black,purple) pmagplotlib.saveP(FIG,files) else: ans=raw_input(" S[a]ve to save plot, [q]uit, Return to continue: ") if ans=="q": sys.exit() if ans=="a": pmagplotlib.saveP(FIG,files)
def main(): """ NAME pyscu_calc.py DESCRIPTION perform the routine explained in Calvín et al. (2017) https://doi.org/10.1016/j.cageo.2017.07.002 calculates the Small Circle Intersection from a dataset calculates the paleodip of the beds INPUT spaced separated text file with header, with the next columns site dec inc kappa dipDir dip kappa interactive data entry using Easygui (http://easygui.sourceforge.net/) """ if '-h' in sys.argv: print(main.__doc__) sys.exit() infile = eg.fileopenbox(msg="Abrir archivo", title="Control: fileopenbox", default='') ans_sci = eg.boolbox(msg='Do you want to calculate te SCI solution?', title='Control: boolbox', choices=('Yes', 'No')) if ans_sci == False: campos = ['Declination', 'Inclination'] ref = [] ref = eg.multenterbox(msg='Write the remagnetization direction', title='Interactive entry of the remag. dir.', fields=campos, values=()) ref[0] = float(ref[0]) ref[1] = float(ref[1]) ans_A = eg.boolbox(msg='Do you want to calculate te A matrix?', title='Control: boolbox', choices=('Yes', 'No')) if ans_A == True: pregunta_matriz = 'y' else: pregunta_matriz = 'n' ans_inc = eg.buttonbox( msg='Are you looking a positive or a negative inclination', title='Control: boolbox', choices=('Positive', 'Negative')) if ans_inc == 'Positive': pregunta_inc = 'pos' else: pregunta_inc = 'neg' if ans_sci == True: nb = eg.integerbox( msg='Number of bootstraps (default=500):', title='Control: integerbox', default=500, lowerbound=0, upperbound=1000, ) data, site, geo, bed_d, bed_s, bed_pole, N_sites = scu.saveInputFile( infile) #Saving in diferent list the data tilt = scu.tilt_rot(geo, bed_s) #Calculating TILT directions out_file = eg.filesavebox(msg="Save plots", title="Control: filesavebox", default='') time_ini = time() #Calculating BFD and A/N for a manual input remagnetization direction. if ans_sci == False: pregunta_remag = 'n' BFD, A_min = scu.calAQQ2(geo, bed_s, ref) Qmean_min = scu.fisher_mean(BFD) N = len(BFD) An = A_min / N Dir_remag = [N, ref[0], ref[1], round(A_min, 3), round(An, 3)] print('Used direction: ', 'Dec / Inc ', '(', "%.1f" % Dir_remag[1], '/', "%.1f" % Dir_remag[2], ')', 'A/n ', "%.3f" % An) else: #Calculating SCI_solutions, their mean (the remagnetization direction) and the rest of parameters pregunta_remag = 'y' SCIs = [] pgeo = scu.para_dir(geo) pbed_pole = scu.para_dir(bed_pole) w, f, cont = 0, 0, nb / 10 print('\nplease, be patient... calculating', nb, 'SCI_solutions') for l in range(nb): w += 1 dec = np.random.randint(0, 359, 1) inc = np.random.randint(1, 89, 1) if pregunta_inc == 'neg': inc = inc * (-1) point = [dec[0], inc[0]] pgeo_u = scu.selec_para_geo(pgeo) pbed_u = scu.selec_para_pole(pbed_pole) pQ = scu.p_calAQQ2(pgeo_u, pbed_u, point) Qmean_min = scu.p_minA(pgeo_u, pbed_u, pQ) SCIs.append(Qmean_min) if w == cont: f += 1 if f != 8: print("%.0f" % cont) cont += nb / 10. else: print('almost finished...') cont += nb / 10. Qend = pmag.dokent(SCIs, 1.) ref = [Qend['dec'], Qend['inc']] BFD, A_min = [], [] BFD, A_min = scu.calAQQ2(geo, bed_s, ref) An = A_min / N_sites distance = [ ] #This is the angle between the BFD and the remagnetization direction, for each site for dato in BFD: distance_site = scu.ang2point(dato, ref) distance.append(distance_site) paleobed = scu.paleo_dip(tilt, bed_s, BFD) api = scu.cal_api(geo, bed_s) api2 = scu.cal_api2(geo, bed_s) out_inter = scu.inter(api2, site) mr = len(out_inter) mp = N_sites * (N_sites - 1.) / 2. mr_mp = round(mr / mp, 2) #joining the data in a unique list out_main = [] if pregunta_remag == 'y': Dir_remag = [ N_sites, round(Qend['dec'], 1), round(Qend['inc'], 1), round(Qend['Eta'], 1), round(Qend['Zeta'], 1), round(Qend['Edec'], 1), round(Qend['Einc'], 1), round(Qend['Zdec'], 1), round(Qend['Zinc'], 1), round(An, 3), round(A_min, 3), mr_mp, nb ] print( '\nKent mean remagnetization direction (Kent, 1982; Tauxe et al., 1991)', '\nDec / Inc: ', "%.1f" % Dir_remag[1], "/", "%.1f" % Dir_remag[2]) print('A/n: ', "%.3f" % An, 'mr/mp: ', "%.2f" % mr_mp) print('Eta_95, dec, inc:', "%.1f" % Dir_remag[3], "%.1f" % Dir_remag[5], "%.1f" % Dir_remag[6]) print('Zeta_95, dec, inc', "%.1f" % Dir_remag[4], "%.1f" % Dir_remag[7], "%.1f" % Dir_remag[8]) for i in range(len(site)): site_main = [ site[i][0], data[i][1], data[i][2], data[i][3], data[i][4], data[i][5], data[i][6], data[i][7], "%.1f" % tilt[i][0], "%.1f" % tilt[i][1], "%.1f" % BFD[i][0], "%.1f" % BFD[i][1], "%.0f" % bed_s[i][0], "%.2f" % api[i], "%.0f" % ((paleobed[i][0] + 90) % 360), "%.0f" % paleobed[i][1], "%.1f" % distance[i] ] out_main.append(site_main) #saving the files header_main = [ 'Site', 'Dec_BBC', 'Inc_BBC', 'a95', 'k', 'DipDir', 'Dip', 'k_bed', 'Dec_ATBC', 'Inc_ATBC', 'Dec_BFD', 'Inc_BFD', 'SC_Strike', 'SC_Api_angle', 'Paleo_DipDir', 'Paleo_dip', 'Ref_BFD_angle' ] name_main = out_file + '_main' scu.save_out_file(header_main, out_main, name_main) header_inter = ['Dec', 'Inc', 'Site_i', 'Site_j'] name_inter = out_file + '_inter' scu.save_out_file(header_inter, out_inter, name_inter) if pregunta_remag == 'y': header_Ref = [ 'N', 'Dec', 'Inc', 'Eta', 'Zeta', 'Dec_E', 'Inc_E', 'Dec_Z', 'Inc_Z', 'A/n', 'Asum', 'mr_mp', 'number of SCI_solutions' ] name_Ref = out_file + '_Ref' scu.save_out_file(header_Ref, [Dir_remag], name_Ref) header_SCIs = ['Dec', 'Inc'] name_SCIs = out_file + '_SCIs' scu.save_out_file(header_SCIs, SCIs, name_SCIs) if pregunta_matriz == 'y': print('\n\nTo be patient! To calculate the matrix spend some min') mat = scu.cal_matriz(geo, bed_s) header_matriz = [ 'Dec', 'Inc', 'x_eqarea', 'y_eqarea', 'x_eq_normalized', 'y_eq_normalized', 'A', 'A/n' ] name_matriz = out_file + '_mat' scu.save_out_file(header_matriz, mat, name_matriz) time_fin = time() time_tot = time_fin - time_ini print('\nExecution time: ', round(time_tot, 1), 'seg') print( '\nYou can use pyscu_draw.py and pyscu_draw_labels.py to print your results' ) print('Good bye')
def main(): """ NAME eqarea_ell.py DESCRIPTION makes equal area projections from declination/inclination data and plot ellipses SYNTAX eqarea_ell.py -h [command line options] INPUT takes space delimited Dec/Inc data OPTIONS -h prints help message and quits -f FILE -fmt [svg,png,jpg] format for output plots -sav saves figures and quits -ell [F,K,B,Be,Bv] plot Fisher, Kent, Bingham, Bootstrap ellipses or Boostrap eigenvectors """ FIG = {} # plot dictionary FIG['eq'] = 1 # eqarea is figure 1 fmt, dist, mode, plot = 'svg', 'F', 1, 0 sym = {'lower': ['o', 'r'], 'upper': ['o', 'w'], 'size': 10} plotE = 0 if '-h' in sys.argv: print main.__doc__ sys.exit() pmagplotlib.plot_init(FIG['eq'], 5, 5) if '-sav' in sys.argv: plot = 1 if '-f' in sys.argv: ind = sys.argv.index("-f") title = sys.argv[ind + 1] data = numpy.loadtxt(title).transpose() if '-ell' in sys.argv: plotE = 1 ind = sys.argv.index('-ell') ell_type = sys.argv[ind + 1] if ell_type == 'F': dist = 'F' if ell_type == 'K': dist = 'K' if ell_type == 'B': dist = 'B' if ell_type == 'Be': dist = 'BE' if ell_type == 'Bv': dist = 'BV' FIG['bdirs'] = 2 pmagplotlib.plot_init(FIG['bdirs'], 5, 5) if '-fmt' in sys.argv: ind = sys.argv.index("-fmt") fmt = sys.argv[ind + 1] DIblock = numpy.array([data[0], data[1]]).transpose() if len(DIblock) > 0: pmagplotlib.plotEQsym(FIG['eq'], DIblock, title, sym) if plot == 0: pmagplotlib.drawFIGS(FIG) else: print "no data to plot" sys.exit() if plotE == 1: ppars = pmag.doprinc(DIblock) # get principal directions nDIs, rDIs, npars, rpars = [], [], [], [] for rec in DIblock: angle = pmag.angle([rec[0], rec[1]], [ppars['dec'], ppars['inc']]) if angle > 90.: rDIs.append(rec) else: nDIs.append(rec) if dist == 'B': # do on whole dataset etitle = "Bingham confidence ellipse" bpars = pmag.dobingham(DIblock) for key in bpars.keys(): if key != 'n' and pmagplotlib.verbose: print " ", key, '%7.1f' % (bpars[key]) if key == 'n' and pmagplotlib.verbose: print " ", key, ' %i' % (bpars[key]) npars.append(bpars['dec']) npars.append(bpars['inc']) npars.append(bpars['Zeta']) npars.append(bpars['Zdec']) npars.append(bpars['Zinc']) npars.append(bpars['Eta']) npars.append(bpars['Edec']) npars.append(bpars['Einc']) if dist == 'F': etitle = "Fisher confidence cone" if len(nDIs) > 3: fpars = pmag.fisher_mean(nDIs) for key in fpars.keys(): if key != 'n' and pmagplotlib.verbose: print " ", key, '%7.1f' % (fpars[key]) if key == 'n' and pmagplotlib.verbose: print " ", key, ' %i' % (fpars[key]) mode += 1 npars.append(fpars['dec']) npars.append(fpars['inc']) npars.append(fpars['alpha95']) # Beta npars.append(fpars['dec']) isign = abs(fpars['inc']) / fpars['inc'] npars.append(fpars['inc'] - isign * 90.) #Beta inc npars.append(fpars['alpha95']) # gamma npars.append(fpars['dec'] + 90.) # Beta dec npars.append(0.) #Beta inc if len(rDIs) > 3: fpars = pmag.fisher_mean(rDIs) if pmagplotlib.verbose: print "mode ", mode for key in fpars.keys(): if key != 'n' and pmagplotlib.verbose: print " ", key, '%7.1f' % (fpars[key]) if key == 'n' and pmagplotlib.verbose: print " ", key, ' %i' % (fpars[key]) mode += 1 rpars.append(fpars['dec']) rpars.append(fpars['inc']) rpars.append(fpars['alpha95']) # Beta rpars.append(fpars['dec']) isign = abs(fpars['inc']) / fpars['inc'] rpars.append(fpars['inc'] - isign * 90.) #Beta inc rpars.append(fpars['alpha95']) # gamma rpars.append(fpars['dec'] + 90.) # Beta dec rpars.append(0.) #Beta inc if dist == 'K': etitle = "Kent confidence ellipse" if len(nDIs) > 3: kpars = pmag.dokent(nDIs, len(nDIs)) if pmagplotlib.verbose: print "mode ", mode for key in kpars.keys(): if key != 'n' and pmagplotlib.verbose: print " ", key, '%7.1f' % (kpars[key]) if key == 'n' and pmagplotlib.verbose: print " ", key, ' %i' % (kpars[key]) mode += 1 npars.append(kpars['dec']) npars.append(kpars['inc']) npars.append(kpars['Zeta']) npars.append(kpars['Zdec']) npars.append(kpars['Zinc']) npars.append(kpars['Eta']) npars.append(kpars['Edec']) npars.append(kpars['Einc']) if len(rDIs) > 3: kpars = pmag.dokent(rDIs, len(rDIs)) if pmagplotlib.verbose: print "mode ", mode for key in kpars.keys(): if key != 'n' and pmagplotlib.verbose: print " ", key, '%7.1f' % (kpars[key]) if key == 'n' and pmagplotlib.verbose: print " ", key, ' %i' % (kpars[key]) mode += 1 rpars.append(kpars['dec']) rpars.append(kpars['inc']) rpars.append(kpars['Zeta']) rpars.append(kpars['Zdec']) rpars.append(kpars['Zinc']) rpars.append(kpars['Eta']) rpars.append(kpars['Edec']) rpars.append(kpars['Einc']) else: # assume bootstrap if len(nDIs) < 10 and len(rDIs) < 10: print 'too few data points for bootstrap' sys.exit() if dist == 'BE': print 'Be patient for bootstrap...' if len(nDIs) >= 10: BnDIs = pmag.di_boot(nDIs) Bkpars = pmag.dokent(BnDIs, 1.) if pmagplotlib.verbose: print "mode ", mode for key in Bkpars.keys(): if key != 'n' and pmagplotlib.verbose: print " ", key, '%7.1f' % (Bkpars[key]) if key == 'n' and pmagplotlib.verbose: print " ", key, ' %i' % (Bkpars[key]) mode += 1 npars.append(Bkpars['dec']) npars.append(Bkpars['inc']) npars.append(Bkpars['Zeta']) npars.append(Bkpars['Zdec']) npars.append(Bkpars['Zinc']) npars.append(Bkpars['Eta']) npars.append(Bkpars['Edec']) npars.append(Bkpars['Einc']) if len(rDIs) >= 10: BrDIs = pmag.di_boot(rDIs) Bkpars = pmag.dokent(BrDIs, 1.) if pmagplotlib.verbose: print "mode ", mode for key in Bkpars.keys(): if key != 'n' and pmagplotlib.verbose: print " ", key, '%7.1f' % (Bkpars[key]) if key == 'n' and pmagplotlib.verbose: print " ", key, ' %i' % (Bkpars[key]) mode += 1 rpars.append(Bkpars['dec']) rpars.append(Bkpars['inc']) rpars.append(Bkpars['Zeta']) rpars.append(Bkpars['Zdec']) rpars.append(Bkpars['Zinc']) rpars.append(Bkpars['Eta']) rpars.append(Bkpars['Edec']) rpars.append(Bkpars['Einc']) etitle = "Bootstrapped confidence ellipse" elif dist == 'BV': print 'Be patient for bootstrap...' vsym = {'lower': ['+', 'k'], 'upper': ['x', 'k'], 'size': 5} if len(nDIs) > 5: BnDIs = pmag.di_boot(nDIs) pmagplotlib.plotEQsym(FIG['bdirs'], BnDIs, 'Bootstrapped Eigenvectors', vsym) if len(rDIs) > 5: BrDIs = pmag.di_boot(rDIs) if len(nDIs) > 5: # plot on existing plots pmagplotlib.plotDIsym(FIG['bdirs'], BrDIs, vsym) else: pmagplotlib.plotEQ(FIG['bdirs'], BrDIs, 'Bootstrapped Eigenvectors', vsym) if dist == 'B': if len(nDIs) > 3 or len(rDIs) > 3: pmagplotlib.plotCONF(FIG['eq'], etitle, [], npars, 0) elif len(nDIs) > 3 and dist != 'BV': pmagplotlib.plotCONF(FIG['eq'], etitle, [], npars, 0) if len(rDIs) > 3: pmagplotlib.plotCONF(FIG['eq'], etitle, [], rpars, 0) elif len(rDIs) > 3 and dist != 'BV': pmagplotlib.plotCONF(FIG['eq'], etitle, [], rpars, 0) if plot == 0: pmagplotlib.drawFIGS(FIG) if plot == 0: pmagplotlib.drawFIGS(FIG) # files = {} for key in FIG.keys(): files[key] = title + '_' + key + '.' + fmt if pmagplotlib.isServer: black = '#000000' purple = '#800080' titles = {} titles['eq'] = 'Equal Area Plot' FIG = pmagplotlib.addBorders(FIG, titles, black, purple) pmagplotlib.saveP(FIG, files) elif plot == 0: ans = raw_input(" S[a]ve to save plot, [q]uit, Return to continue: ") if ans == "q": sys.exit() if ans == "a": pmagplotlib.saveP(FIG, files) else: pmagplotlib.saveP(FIG, files)
def main(): """ NAME gokent.py DESCRIPTION calculates Kent parameters from dec inc data INPUT FORMAT takes dec/inc as first two columns in space delimited file SYNTAX gokent.py [options] OPTIONS -h prints help message and quits -i for interactive filename entry -f FILE, specify filename -F FILE, specifies output file name < filename for reading from standard input OUTPUT mean dec, mean inc, Eta, Deta, Ieta, Zeta, Zdec, Zinc, N """ if len(sys.argv) > 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] f = open(file, "rU") data = f.readlines() elif "-i" in sys.argv: # ask for filename file = raw_input("Enter file name with dec, inc data: ") f = open(file, "rU") data = f.readlines() else: # data = sys.stdin.readlines() # read in data from standard input ofile = "" if "-F" in sys.argv: ind = sys.argv.index("-F") ofile = sys.argv[ind + 1] out = open(ofile, "w + a") DIs = [] # set up list for dec inc data for line in data: # read in the data from standard input 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 DIs.append((float(rec[0]), float(rec[1]))) # kpars = pmag.dokent(DIs, len(DIs)) output = "%7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %i" % ( kpars["dec"], kpars["inc"], kpars["Eta"], kpars["Edec"], kpars["Einc"], kpars["Zeta"], kpars["Zdec"], kpars["Zinc"], kpars["n"], ) if ofile == "": print output else: out.write(output + "\n")