def main(): """ NAME core_depthplot.py DESCRIPTION plots various measurements versus core_depth or age. plots data flagged as 'FS-SS-C' as discrete samples. SYNTAX core_depthplot.py [command line optins] OPTIONS -h prints help message and quits -f FILE: specify input magic_measurments format file from magi -fsum FILE: specify input LIMS database (IODP) core summary csv file -fwig FILE: specify input depth,wiggle to plot, in magic format with sample_core_depth key for depth -fsa FILE: specify input er_samples format file from magic for depth -fa FILE: specify input er_ages format file from magic for age NB: must have either -fsa OR -fa (not both) -fsp FILE sym size: specify input zeq_specimen format file from magic, sym and size NB: PCAs will have specified color, while fisher means will be white with specified color as the edgecolor -fres FILE specify input pmag_results file from magic, sym and size -LP [AF,T,ARM,IRM, X] step [in mT,C,mT,mT, mass/vol] to plot -S do not plot blanket treatment data (if this is set, you don't need the -LP) -sym SYM SIZE, symbol, size for continuous points (e.g., ro 5, bs 10, g^ 10 for red dot, blue square, green triangle), default is blue dot at 5 pt -D do not plot declination -M do not plot magnetization -log plot magnetization on a log scale -L do not connect dots with a line -I do not plot inclination -d min max [in m] depth range to plot -n normalize by weight in er_specimen table -Iex: plot the expected inc at lat - only available for results with lat info in file -ts TS amin amax: plot the GPTS for the time interval between amin and amax (numbers in Ma) TS: [ck95, gts04, gts12] -ds [mbsf,mcd] specify depth scale, mbsf default -fmt [svg, eps, pdf, png] specify output format for plot (default: svg) -sav save plot silently DEFAULTS: Measurements file: magic_measurements.txt Samples file: er_samples.txt NRM step Summary file: none """ meas_file='magic_measurements.txt' intlist=['measurement_magnitude','measurement_magn_moment','measurement_magn_volume','measurement_magn_mass'] samp_file='er_samples.txt' depth_scale='sample_core_depth' wt_file='' verbose=pmagplotlib.verbose width=10 sym,size='bo',5 Ssym,Ssize='cs',5 method,fmt="LT-NO",'.svg' step=0 pcol=3 pel=3 pltD,pltI,pltM,pltL,pltS=1,1,1,1,1 logit=0 maxInt=-1000 minInt=1e10 maxSuc=-1000 minSuc=10000 plotexp,pTS=0,0 dir_path="." sum_file="" suc_file="" age_file="" spc_file="" res_file="" ngr_file="" wig_file="" title,location="","" if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] norm=0 if '-h' in sys.argv: print(main.__doc__) sys.exit() if '-L' in sys.argv: pltL=0 if '-S' in sys.argv: pltS=0 # don't plot the bulk measurements at all if '-D' in sys.argv: pltD=0 pcol-=1 pel-=1 width-=2 if '-I' in sys.argv: pltI=0 pcol-=1 pel-=1 width-=2 if '-M' in sys.argv: pltM=0 pcol-=1 pel-=1 width-=2 if '-log' in sys.argv:logit=1 if '-ds' in sys.argv and 'mcd' in sys.argv:depth_scale='sample_composite_depth' if '-sym' in sys.argv: ind=sys.argv.index('-sym') sym=sys.argv[ind+1] size=float(sys.argv[ind+2]) if '-f' in sys.argv: ind=sys.argv.index('-f') meas_file=sys.argv[ind+1] if '-fsa' in sys.argv: ind=sys.argv.index('-fsa') samp_file=sys.argv[ind+1] if '-fa' in sys.argv: print(main.__doc__) print('only -fsa OR -fa - not both') sys.exit() elif '-fa' in sys.argv: ind=sys.argv.index('-fa') age_file=sys.argv[ind+1] if '-fsp' in sys.argv: ind=sys.argv.index('-fsp') spc_file=dir_path+'/'+sys.argv[ind+1] spc_sym=sys.argv[ind+2] spc_size=float(sys.argv[ind+3]) if '-fres' in sys.argv: ind=sys.argv.index('-fres') res_file=dir_path+'/'+sys.argv[ind+1] res_sym=sys.argv[ind+2] res_size=float(sys.argv[ind+3]) if '-fwig' in sys.argv: ind=sys.argv.index('-fwig') wig_file=dir_path+'/'+sys.argv[ind+1] pcol+=1 width+=2 if '-fsum' in sys.argv: ind=sys.argv.index('-fsum') sum_file=dir_path+'/'+sys.argv[ind+1] if '-fmt' in sys.argv: ind=sys.argv.index('-fmt') fmt='.'+sys.argv[ind+1] if '-sav' in sys.argv: plots=1 verbose=0 if '-LP' in sys.argv: ind=sys.argv.index('-LP') meth=sys.argv[ind+1] if meth=="AF": step=round(float(sys.argv[ind+2])*1e-3,6) method='LT-AF-Z' elif meth== 'T': step=round(float(sys.argv[ind+2])+273,6) method='LT-T-Z' elif meth== 'ARM': method='LT-AF-I' step=round(float(sys.argv[ind+2])*1e-3,6) elif meth== 'IRM': method='LT-IRM' step=round(float(sys.argv[ind+2])*1e-3,6) elif meth== 'X': method='LP-X' pcol+=1 if sys.argv[ind+2]=='mass': suc_key='measurement_chi_mass' elif sys.argv[ind+2]=='vol': suc_key='measurement_chi_volume' else: print('error in susceptibility units') sys.exit() else: print('method not supported') sys.exit() if '-n' in sys.argv: ind=sys.argv.index('-n') wt_file=dir_path+'/'+sys.argv[ind+1] norm=1 dmin,dmax=-1,-1 if '-d' in sys.argv: ind=sys.argv.index('-d') dmin=float(sys.argv[ind+1]) dmax=float(sys.argv[ind+2]) if '-ts' in sys.argv: ind=sys.argv.index('-ts') ts=sys.argv[ind+1] amin=float(sys.argv[ind+2]) amax=float(sys.argv[ind+3]) pTS=1 pcol+=1 width+=2 # # # get data read in meas_file=dir_path+'/'+meas_file if age_file=="": samp_file=dir_path+'/'+samp_file Samps,file_type=pmag.magic_read(samp_file) else: depth_scale='age' age_file=dir_path+'/'+age_file Samps,file_type=pmag.magic_read(age_file) age_unit="" if spc_file!="":Specs,file_type=pmag.magic_read(spc_file) if res_file!="":Results,file_type=pmag.magic_read(res_file) if norm==1: ErSpecs,file_type=pmag.magic_read(wt_file) print(len(ErSpecs), ' specimens read in from ',wt_file) Cores=[] core_depth_key="Top depth cored CSF (m)" if sum_file!="": input=open(sum_file,'r').readlines() if "Core Summary" in input[0]: headline=1 else: headline=0 keys=input[headline].replace('\n','').split(',') if "Core Top (m)" in keys:core_depth_key="Core Top (m)" if "Core Label" in keys:core_label_key="Core Label" if "Core label" in keys:core_label_key="Core label" for line in input[2:]: if 'TOTALS' not in line: CoreRec={} for k in range(len(keys)):CoreRec[keys[k]]=line.split(',')[k] Cores.append(CoreRec) if len(Cores)==0: print('no Core depth information available: import core summary file') sum_file="" Data=[] if depth_scale=='sample_core_depth': ylab="Depth (mbsf)" elif depth_scale=='age': ylab="Age" else: ylab="Depth (mcd)" # collect the data for plotting declination Depths,Decs,Incs,Ints=[],[],[],[] SDepths,SDecs,SIncs,SInts=[],[],[],[] SSucs=[] samples=[] methods,steps,m2=[],[],[] if pltS: # plot the bulk measurement data Meas,file_type=pmag.magic_read(meas_file) meas_key='measurement_magn_moment' print(len(Meas), ' measurements read in from ',meas_file) for m in intlist: # find the intensity key with data meas_data=pmag.get_dictitem(Meas,m,'','F') # get all non-blank data for this specimen if len(meas_data)>0: meas_key=m break m1=pmag.get_dictitem(Meas,'magic_method_codes',method,'has') # fish out the desired method code if method=='LT-T-Z': m2=pmag.get_dictitem(m1,'treatment_temp',str(step),'eval') # fish out the desired step elif 'LT-AF' in method: m2=pmag.get_dictitem(m1,'treatment_ac_field',str(step),'eval') elif 'LT-IRM' in method: m2=pmag.get_dictitem(m1,'treatment_dc_field',str(step),'eval') elif 'LT-X' in method: m2=pmag.get_dictitem(m1,suc_key,'','F') if len(m2)>0: for rec in m2: # fish out depths and weights D=pmag.get_dictitem(Samps,'er_sample_name',rec['er_sample_name'],'T') if not D: # if using an age_file, you may need to sort by site D=pmag.get_dictitem(Samps,'er_site_name',rec['er_site_name'],'T') depth=pmag.get_dictitem(D,depth_scale,'','F') if len(depth)>0: if ylab=='Age': ylab=ylab+' ('+depth[0]['age_unit']+')' # get units of ages - assume they are all the same! rec['core_depth'] = float(depth[0][depth_scale]) rec['magic_method_codes'] = rec['magic_method_codes']+':'+depth[0]['magic_method_codes'] if norm==1: specrecs=pmag.get_dictitem(ErSpecs,'er_specimen_name',rec['er_specimen_name'],'T') specwts=pmag.get_dictitem(specrecs,'specimen_weight',"",'F') if len(specwts)>0: rec['specimen_weight'] = specwts[0]['specimen_weight'] Data.append(rec) # fish out data with core_depth and (if needed) weights else: Data.append(rec) # fish out data with core_depth and (if needed) weights if title=="": pieces=rec['er_sample_name'].split('-') location=rec['er_location_name'] title=location SData=pmag.sort_diclist(Data,'core_depth') for rec in SData: # fish out bulk measurement data from desired depths if dmax==-1 or float(rec['core_depth'])<dmax and float(rec['core_depth'])>dmin: Depths.append((rec['core_depth'])) if method=="LP-X": SSucs.append(float(rec[suc_key])) else: if pltD==1:Decs.append(float(rec['measurement_dec'])) if pltI==1:Incs.append(float(rec['measurement_inc'])) if norm==0 and pltM==1:Ints.append(float(rec[meas_key])) if norm==1 and pltM==1:Ints.append(old_div(float(rec[meas_key]),float(rec['specimen_weight']))) if len(SSucs)>0: maxSuc=max(SSucs) minSuc=min(SSucs) if len(Ints)>1: maxInt=max(Ints) minInt=min(Ints) if len(Depths)==0: print('no bulk measurement data matched your request') SpecDepths,SpecDecs,SpecIncs=[],[],[] FDepths,FDecs,FIncs=[],[],[] if spc_file!="": # add depths to spec data print('spec file found') BFLs=pmag.get_dictitem(Specs,'magic_method_codes','DE-BFL','has') # get all the discrete data with best fit lines for spec in BFLs: if location=="": location=spec['er_location_name'] samp=pmag.get_dictitem(Samps,'er_sample_name',spec['er_sample_name'],'T') if len(samp)>0 and depth_scale in list(samp[0].keys()) and samp[0][depth_scale]!="": if ylab=='Age': ylab=ylab+' ('+samp[0]['age_unit']+')' # get units of ages - assume they are all the same! if dmax==-1 or float(samp[0][depth_scale])<dmax and float(samp[0][depth_scale])>dmin: # filter for depth SpecDepths.append(float(samp[0][depth_scale])) # fish out data with core_depth SpecDecs.append(float(spec['specimen_dec'])) # fish out data with core_depth SpecIncs.append(float(spec['specimen_inc'])) # fish out data with core_depth else: print('no core_depth found for: ',spec['er_specimen_name']) FMs=pmag.get_dictitem(Specs,'magic_method_codes','DE-FM','has') # get all the discrete data with best fit lines for spec in FMs: if location=="": location=spec['er_location_name'] samp=pmag.get_dictitem(Samps,'er_sample_name',spec['er_sample_name'],'T') if len(samp)>0 and depth_scale in list(samp[0].keys()) and samp[0][depth_scale]!="": if ylab=='Age': ylab=ylab+' ('+samp[0]['age_unit']+')' # get units of ages - assume they are all the same! if dmax==-1 or float(samp[0][depth_scale])<dmax and float(samp[0][depth_scale])>dmin: # filter for depth FDepths.append(float(samp[0][depth_scale]))# fish out data with core_depth FDecs.append(float(spec['specimen_dec'])) # fish out data with core_depth FIncs.append(float(spec['specimen_inc'])) # fish out data with core_depth else: print('no core_depth found for: ',spec['er_specimen_name']) ResDepths,ResDecs,ResIncs=[],[],[] if 'age' in depth_scale: # set y-key res_scale='average_age' else: res_scale='average_height' if res_file!="": #creates lists of Result Data for res in Results: meths=res['magic_method_codes'].split(":") if 'DE-FM' in meths: if dmax==-1 or float(res[res_scale])<dmax and float(res[res_scale])>dmin: # filter for depth ResDepths.append(float(res[res_scale])) # fish out data with core_depth ResDecs.append(float(res['average_dec'])) # fish out data with core_depth ResIncs.append(float(res['average_inc'])) # fish out data with core_depth Susc,Sus_depths=[],[] if dmin==-1: if len(Depths)>0: dmin,dmax=Depths[0],Depths[-1] if len(FDepths)>0: dmin,dmax=Depths[0],Depths[-1] if pltS==1 and len(SDepths)>0: if SDepths[0]<dmin:dmin=SDepths[0] if SDepths[-1]>dmax:dmax=SDepths[-1] if len(SpecDepths)>0: if min(SpecDepths)<dmin:dmin=min(SpecDepths) if max(SpecDepths)>dmax:dmax=max(SpecDepths) if len(ResDepths)>0: if min(ResDepths)<dmin:dmin=min(ResDepths) if max(ResDepths)>dmax:dmax=max(ResDepths) if suc_file!="": sucdat=open(suc_file,'r').readlines() keys=sucdat[0].replace('\n','').split(',') # splits on underscores for line in sucdat[1:]: SucRec={} for k in range(len(keys)):SucRec[keys[k]]=line.split(',')[k] if float(SucRec['Top Depth (m)'])<dmax and float(SucRec['Top Depth (m)'])>dmin and SucRec['Magnetic Susceptibility (80 mm)']!="": Susc.append(float(SucRec['Magnetic Susceptibility (80 mm)'])) if Susc[-1]>maxSuc:maxSuc=Susc[-1] if Susc[-1]<minSuc:minSuc=Susc[-1] Sus_depths.append(float(SucRec['Top Depth (m)'])) WIG,WIG_depths=[],[] if wig_file!="": wigdat,file_type=pmag.magic_read(wig_file) swigdat=pmag.sort_diclist(wigdat,depth_scale) keys=list(wigdat[0].keys()) for key in keys: if key!=depth_scale: plt_key=key break for wig in swigdat: if float(wig[depth_scale])<dmax and float(wig[depth_scale])>dmin: WIG.append(float(wig[plt_key])) WIG_depths.append(float(wig[depth_scale])) tint=4.5 plt=1 if len(Decs)>0 and len(Depths)>0 or (len(SpecDecs)>0 and len(SpecDepths)>0) or (len(ResDecs)>0 and len(ResDepths)>0) or (len(SDecs)>0 and len(SDepths)>0) or (len(SInts)>0 and len(SDepths)>0) or (len(SIncs)>0 and len(SDepths)>0): pylab.figure(1,figsize=(width,8)) version_num=pmag.get_version() pylab.figtext(.02,.01,version_num) if pltD==1: ax=pylab.subplot(1,pcol,plt) if pltL==1: pylab.plot(Decs,Depths,'k') if len(Decs)>0: pylab.plot(Decs,Depths,sym,markersize=size) if len(Decs)==0 and pltL==1 and len(SDecs)>0: pylab.plot(SDecs,SDepths,'k') if len(SDecs)>0: pylab.plot(SDecs,SDepths,Ssym,markersize=Ssize) if spc_file!="": pylab.plot(SpecDecs,SpecDepths,spc_sym,markersize=spc_size) if spc_file!="" and len(FDepths)>0: pylab.scatter(FDecs,FDepths,marker=spc_sym[-1],edgecolor=spc_sym[0],facecolor='white',s=spc_size**2) if res_file!="": pylab.plot(ResDecs,ResDepths,res_sym,markersize=res_size) if sum_file!="": for core in Cores: depth=float(core[core_depth_key]) if depth>dmin and depth<dmax: pylab.plot([0,360.],[depth,depth],'b--') if pel==plt:pylab.text(360,depth+tint,core[core_label_key]) if pel==plt: pylab.axis([0,400,dmax,dmin]) else: pylab.axis([0,360.,dmax,dmin]) pylab.xlabel('Declination') pylab.ylabel(ylab) plt+=1 pmagplotlib.delticks(ax) # dec xticks are too crowded otherwise if pltI==1: pylab.subplot(1,pcol,plt) if pltL==1:pylab.plot(Incs,Depths,'k') if len(Incs)>0:pylab.plot(Incs,Depths,sym,markersize=size) if len(Incs)==0 and pltL==1 and len(SIncs)>0:pylab.plot(SIncs,SDepths,'k') if len(SIncs)>0:pylab.plot(SIncs,SDepths,Ssym,markersize=Ssize) if spc_file!="" and len(SpecDepths)>0:pylab.plot(SpecIncs,SpecDepths,spc_sym,markersize=spc_size) if spc_file!="" and len(FDepths)>0: pylab.scatter(FIncs,FDepths,marker=spc_sym[-1],edgecolor=spc_sym[0],facecolor='white',s=spc_size**2) if res_file!="":pylab.plot(ResIncs,ResDepths,res_sym,markersize=res_size) if sum_file!="": for core in Cores: depth=float(core[core_depth_key]) if depth>dmin and depth<dmax: if pel==plt:pylab.text(90,depth+tint,core[core_label_key]) pylab.plot([-90,90],[depth,depth],'b--') pylab.plot([0,0],[dmax,dmin],'k-') if pel==plt: pylab.axis([-90,110,dmax,dmin]) else: pylab.axis([-90,90,dmax,dmin]) pylab.xlabel('Inclination') pylab.ylabel('') plt+=1 if pltM==1 and len(Ints)>0 or len(SInts)>0: pylab.subplot(1,pcol,plt) for pow in range(-10,10): if maxInt*10**pow>1:break if logit==0: for k in range(len(Ints)): Ints[k]=Ints[k]*10**pow for k in range(len(SInts)): SInts[k]=SInts[k]*10**pow if pltL==1 and len(Ints)>0: pylab.plot(Ints,Depths,'k') if len(Ints)>0:pylab.plot(Ints,Depths,sym,markersize=size) if len(Ints)==0 and pltL==1 and len(SInts)>0:pylab.plot(SInts,SDepths,'k-') if len(SInts)>0:pylab.plot(SInts,SDepths,Ssym,markersize=Ssize) if sum_file!="": for core in Cores: depth=float(core[core_depth_key]) pylab.plot([0,maxInt*10**pow+.1],[depth,depth],'b--') if depth>dmin and depth<dmax:pylab.text(maxInt*10**pow-.2*maxInt*10**pow,depth+tint,core[core_label_key]) pylab.axis([0,maxInt*10**pow+.1,dmax,dmin]) if norm==0: pylab.xlabel('%s %i %s'%('Intensity (10^-',pow,' Am^2)')) else: pylab.xlabel('%s %i %s'%('Intensity (10^-',pow,' Am^2/kg)')) else: if pltL==1: pylab.semilogx(Ints,Depths,'k') if len(Ints)>0:pylab.semilogx(Ints,Depths,sym,markersize=size) if len(Ints)==0 and pltL==1 and len(SInts)>0:pylab.semilogx(SInts,SDepths,'k') if len(Ints)==0 and pltL==1 and len(SInts)>0:pylab.semilogx(SInts,SDepths,'k') if len(SInts)>0:pylab.semilogx(SInts,SDepths,Ssym,markersize=Ssize) if sum_file!="": for core in Cores: depth=float(core[core_depth_key]) pylab.semilogx([minInt,maxInt],[depth,depth],'b--') if depth>dmin and depth<dmax:pylab.text(maxInt-.2*maxInt,depth+tint,core[core_label_key]) pylab.axis([0,maxInt,dmax,dmin]) if norm==0: pylab.xlabel('Intensity (Am^2)') else: pylab.xlabel('Intensity (Am^2/kg)') plt+=1 if suc_file!="" or len(SSucs)>0: pylab.subplot(1,pcol,plt) if len(Susc)>0: if pltL==1:pylab.plot(Susc,Sus_depths,'k') if logit==0:pylab.plot(Susc,Sus_depths,sym,markersize=size) if logit==1:pylab.semilogx(Susc,Sus_depths,sym,markersize=size) if len(SSucs)>0: if logit==0:pylab.plot(SSucs,SDepths,sym,markersize=size) if logit==1:pylab.semilogx(SSucs,SDepths,sym,markersize=size) if sum_file!="": for core in Cores: depth=float(core[core_depth_key]) if logit==0:pylab.plot([minSuc,maxSuc],[depth,depth],'b--') if logit==1:pylab.semilogx([minSuc,maxSuc],[depth,depth],'b--') pylab.axis([minSuc,maxSuc,dmax,dmin]) pylab.xlabel('Susceptibility') plt+=1 if wig_file!="": pylab.subplot(1,pcol,plt) pylab.plot(WIG,WIG_depths,'k') if sum_file!="": for core in Cores: depth=float(core[core_depth_key]) pylab.plot([WIG[0],WIG[-1]],[depth,depth],'b--') pylab.axis([min(WIG),max(WIG),dmax,dmin]) pylab.xlabel(plt_key) plt+=1 if pTS==1: ax1=pylab.subplot(1,pcol,plt) ax1.axis([-.25,1.5,amax,amin]) plt+=1 TS,Chrons=pmag.get_ts(ts) X,Y,Y2=[0,1],[],[] cnt=0 if amin<TS[1]: # in the Brunhes Y=[amin,amin] # minimum age Y1=[TS[1],TS[1]] # age of the B/M boundary ax1.fill_between(X,Y,Y1,facecolor='black') # color in Brunhes, black for d in TS[1:]: pol=cnt%2 cnt+=1 if d<=amax and d>=amin: ind=TS.index(d) Y=[TS[ind],TS[ind]] Y1=[TS[ind+1],TS[ind+1]] if pol: ax1.fill_between(X,Y,Y1,facecolor='black') # fill in every other time ax1.plot([0,1,1,0,0],[amin,amin,amax,amax,amin],'k-') ax2=ax1.twinx() pylab.ylabel("Age (Ma): "+ts) for k in range(len(Chrons)-1): c=Chrons[k] cnext=Chrons[k+1] d=cnext[1]-old_div((cnext[1]-c[1]),3.) if d>=amin and d<amax: ax2.plot([1,1.5],[c[1],c[1]],'k-') # make the Chron boundary tick ax2.text(1.05,d,c[0]) # ax2.axis([-.25,1.5,amax,amin]) figname=location+'_m:_'+method+'_core-depthplot'+fmt pylab.title(location) if verbose: pylab.draw() ans=input("S[a]ve plot? ") if ans=='a': pylab.savefig(figname) print('Plot saved as ',figname) elif plots: pylab.savefig(figname) print('Plot saved as ',figname) sys.exit()
def main(): """ NAME make_magic_plots.py DESCRIPTION inspects magic directory for available plots. SYNTAX make_magic_plots.py [command line options] INPUT magic files OPTIONS -h prints help message and quits -f FILE specifies input file name -fmt [png,eps,svg,jpg,pdf] specify format, default is png """ dirlist=['./'] dir_path=os.getcwd() names=os.listdir(dir_path) for n in names: if 'Location' in n: dirlist.append(n) if '-fmt' in sys.argv: ind=sys.argv.index("-fmt") fmt=sys.argv[ind+1] else: fmt='png' if '-f' in sys.argv: ind=sys.argv.index("-f") filelist=[sys.argv[ind+1]] else: filelist=os.listdir(dir_path) if '-h' in sys.argv: print main.__doc__ sys.exit() for loc in dirlist: print 'working on: ',loc os.chdir(loc) # change working directories to each location crd='s' if 'er_samples.txt' in filelist: # find coordinate systems samps,file_type=pmag.magic_read('er_samples.txt') # read in data Srecs=pmag.get_dictitem(samps,'sample_azimuth','','F')# get all none blank sample orientations if len(Srecs)>0: crd='g' if 'magic_measurements.txt' in filelist: # start with measurement data print 'working on measurements data' data,file_type=pmag.magic_read('magic_measurements.txt') # read in data if loc == './': data=pmag.get_dictitem(data,'er_location_name','','T') # get all the blank location names from data file # looking for zeq_magic possibilities AFZrecs=pmag.get_dictitem(data,'magic_method_codes','LT-AF-Z','has')# get all none blank method codes TZrecs=pmag.get_dictitem(data,'magic_method_codes','LT-T-Z','has')# get all none blank method codes MZrecs=pmag.get_dictitem(data,'magic_method_codes','LT-M-Z','has')# get all none blank method codes Drecs=pmag.get_dictitem(data,'measurement_dec','','F') # get all dec measurements Irecs=pmag.get_dictitem(data,'measurement_inc','','F') # get all dec measurements Mkeys=['measurement_magnitude','measurement_magn_moment','measurement_magn_volume','measurement_magn_mass'] for key in Mkeys: Mrecs=pmag.get_dictitem(data,key,'','F') # get intensity data if len(Mrecs)>0:break if len(AFZrecs)>0 or len(TZrecs)>0 or len(MZrecs)>0 and len(Drecs)>0 and len(Irecs)>0 and len(Mrecs)>0: # potential for stepwise demag curves print 'zeq_magic.py -fsp pmag_specimens.txt -sav -fmt '+fmt+' -crd '+crd os.system('zeq_magic.py -sav -fmt '+fmt+' -crd '+crd ) #pass # looking for thellier_magic possibilities if len(pmag.get_dictitem(data,'magic_method_codes','LP-PI-TRM','has'))>0: print 'thellier_magic.py -fsp pmag_specimens.txt -sav -fmt '+fmt os.system('thellier_magic.py -sav -fmt '+fmt) #pass # looking for hysteresis possibilities if len(pmag.get_dictitem(data,'magic_method_codes','LP-HYS','has'))>0: # find hyst experiments print 'quick_hyst.py -sav -fmt '+fmt os.system('quick_hyst.py -sav -fmt '+fmt) #pass if 'pmag_results.txt' in filelist: # start with measurement data print 'working on pmag_results' data,file_type=pmag.magic_read('pmag_results.txt') # read in data if loc == './': data=pmag.get_dictitem(data,'er_location_names',':','has') # get all the concatenated location names from data file SiteDIs=pmag.get_dictitem(data,'average_dec','','F') # find decs SiteDIs=pmag.get_dictitem(SiteDIs,'average_inc','','F') # find decs and incs SiteDIs=pmag.get_dictitem(SiteDIs,'data_type','i','T') # only individual results - not poles SiteDIs_t=pmag.get_dictitem(SiteDIs,'tilt_correction','100','T')# tilt corrected coordinates if len(SiteDIs_t)>0: print 'eqarea_magic.py -sav -crd t -fmt '+fmt os.system('eqarea_magic.py -sav -crd t -fmt '+fmt) elif len(SiteDIs)>0 and 'tilt_correction' not in SiteDIs[0].keys(): print 'eqarea_magic.py -sav -fmt '+fmt os.system('eqarea_magic.py -sav -fmt '+fmt) else: SiteDIs_g=pmag.get_dictitem(SiteDIs,'tilt_correction','0','T')# geographic coordinates if len(SiteDIs_g)>0: print 'eqarea_magic.py -sav -crd g -fmt '+fmt os.system('eqarea_magic.py -sav -crd g -fmt '+fmt) else: SiteDIs_s=pmag.get_dictitem(SiteDIs,'tilt_correction','-1','T')# sample coordinates if len(SiteDIs_s)>0: print 'eqarea_magic.py -sav -crd s -fmt '+fmt os.system('eqarea_magic.py -sav -crd s -fmt '+fmt) else: SiteDIs_x=pmag.get_dictitem(SiteDIs,'tilt_correction','','T')# no coordinates if len(SiteDIs_x)>0: print 'eqarea_magic.py -sav -fmt '+fmt os.system('eqarea_magic.py -sav -fmt '+fmt) if 'rmag_hysteresis.txt' in filelist: # start with measurement data print 'working on rmag_hysteresis' data,file_type=pmag.magic_read('rmag_hysteresis.txt') # read in data if loc == './': data=pmag.get_dictitem(data,'er_location_name','','T') # get all the blank location names from data file hdata=pmag.get_dictitem(data,'hysteresis_bcr','','F') hdata=pmag.get_dictitem(hdata,'hysteresis_mr_moment','','F') hdata=pmag.get_dictitem(hdata,'hysteresis_ms_moment','','F') hdata=pmag.get_dictitem(hdata,'hysteresis_bc','','F') # there are data for a dayplot if len(hdata)>0: print 'dayplot_magic.py -sav -fmt '+fmt os.system('dayplot_magic.py -sav -fmt '+fmt) #if 'er_sites.txt' in filelist: # start with measurement data # print 'working on er_sites' #os.system('basemap_magic.py -sav -fmt '+fmt) if 'rmag_anisotropy.txt' in filelist: # do anisotropy plots if possible print 'working on rmag_anisotropy' data,file_type=pmag.magic_read('rmag_anisotropy.txt') # read in data if loc == './': data=pmag.get_dictitem(data,'er_location_name','','T') # get all the blank location names from data file sdata=pmag.get_dictitem(data,'anisotropy_tilt_correction','-1','T') # get specimen coordinates gdata=pmag.get_dictitem(data,'anisotropy_tilt_correction','0','T') # get specimen coordinates tdata=pmag.get_dictitem(data,'anisotropy_tilt_correction','100','T') # get specimen coordinates if len(sdata)>3: print 'aniso_magic.py -x -B -crd s -sav -fmt '+fmt os.system('aniso_magic.py -x -B -crd s -sav -fmt '+fmt) if len(gdata)>3: os.system('aniso_magic.py -x -B -crd g -sav -fmt '+fmt) if len(tdata)>3: os.system('aniso_magic.py -x -B -crd t -sav -fmt '+fmt) if loc!='./':os.chdir('..') # change working directories to each location
def main(): """ NAME download_magic.py DESCRIPTION unpacks a magic formatted smartbook .txt file from the MagIC database into the tab delimited MagIC format txt files for use with the MagIC-Py programs. SYNTAX download_magic.py command line options] INPUT takes either the upload.txt file created by upload_magic.py or the file exported by the MagIC v2.2 console software (downloaded from the MagIC database or output by the Console on your PC). OPTIONS -h prints help message and quits -i allows interactive entry of filename -f FILE specifies input file name """ dir_path='.' if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] if '-i' in sys.argv: file=raw_input("Magic txt file for unpacking? ") elif '-f' in sys.argv: ind=sys.argv.index("-f") file=sys.argv[ind+1] else: print main.__doc__ sys.exit() f=open(dir_path+'/'+file,'rU') File=f.readlines() LN=0 type_list=[] filenum=0 while LN<len(File)-1: line=File[LN] file_type=line.split('\t')[1] file_type=file_type.lower() if file_type=='delimited':file_type=Input[skip].split('\t')[2] if file_type[-1]=="\n":file_type=file_type[:-1] print 'working on: ',repr(file_type) if file_type not in type_list: type_list.append(file_type) else: filenum+=1 LN+=1 line=File[LN] keys=line.replace('\n','').split('\t') LN+=1 Recs=[] while LN<len(File): line=File[LN] if line[:4]==">>>>" and len(Recs)>0: if filenum==0: outfile=dir_path+"/"+file_type.strip()+'.txt' else: outfile=dir_path+"/"+file_type.strip()+'_'+str(filenum)+'.txt' NewRecs=[] for rec in Recs: if 'magic_method_codes' in rec.keys(): meths=rec['magic_method_codes'].split(":") if len(meths)>0: methods="" for meth in meths: methods=methods+meth.strip()+":" # get rid of nasty spaces!!!!!! rec['magic_method_codes']=methods[:-1] NewRecs.append(rec) pmag.magic_write(outfile,Recs,file_type) print file_type," data put in ",outfile if file_type =='pmag_specimens' and 'magic_measurements.txt' in File and 'measurement_step_min' in File and 'measurement_step_max' in File: # sort out zeq_specimens and thellier_specimens os.system('mk_redo.py') os.system('zeq_magic_redo.py') os.system('thellier_magic_redo.py') type_list.append('zeq_specimens') type_list.append('thellier_specimens') Recs=[] LN+=1 break else: rec=line.split('\t') Rec={} if len(rec)==len(keys): for k in range(len(rec)): Rec[keys[k]]=rec[k] Recs.append(Rec) else: print 'WARNING: problem in file with line: ' print line print 'skipping....' LN+=1 if len(Recs)>0: if filenum==0: outfile=dir_path+"/"+file_type.strip()+'.txt' else: outfile=dir_path+"/"+file_type.strip()+'_'+str(filenum)+'.txt' NewRecs=[] for rec in Recs: if 'magic_method_codes' in rec.keys(): meths=rec['magic_method_codes'].split(":") if len(meths)>0: methods="" for meth in meths: methods=methods+meth.strip()+":" # get rid of nasty spaces!!!!!! rec['magic_method_codes']=methods[:-1] NewRecs.append(rec) pmag.magic_write(outfile,Recs,file_type) print file_type," data put in ",outfile # look through locations table and create separate directories for each location locs,locnum=[],1 if 'er_locations' in type_list: locs,file_type=pmag.magic_read(dir_path+'/er_locations.txt') if len(locs)>0: # at least one location for loc in locs: print 'location_'+str(locnum)+": ",loc['er_location_name'] lpath=dir_path+'/Location_'+str(locnum) locnum+=1 try: os.mkdir(lpath) except: print 'directory ',lpath,' already exists - overwrite everything [y/n]?' ans=raw_input() if ans=='n':sys.exit() for f in type_list: print 'unpacking: ',dir_path+'/'+f+'.txt' recs,file_type=pmag.magic_read(dir_path+'/'+f+'.txt') print len(recs),' read in' if 'results' not in f: lrecs=pmag.get_dictitem(recs,'er_location_name',loc['er_location_name'],'T') if len(lrecs)>0: pmag.magic_write(lpath+'/'+f+'.txt',lrecs,file_type) print len(lrecs),' stored in ',lpath+'/'+f+'.txt' else: lrecs=pmag.get_dictitem(recs,'er_location_names',loc['er_location_name'],'T') if len(lrecs)>0: pmag.magic_write(lpath+'/'+f+'.txt',lrecs,file_type) print len(lrecs),' stored in ',lpath+'/'+f+'.txt'
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 aniso_magic.py DESCRIPTION plots anisotropy data with either bootstrap or hext ellipses SYNTAX aniso_magic.py [-h] [command line options] OPTIONS -h plots help message and quits -usr USER: set the user name -f AFILE, specify rmag_anisotropy formatted file for input -F RFILE, specify rmag_results formatted file for output -x Hext [1963] and bootstrap -B DON'T do bootstrap, do Hext -par Tauxe [1998] parametric bootstrap -v plot bootstrap eigenvectors instead of ellipses -sit plot by site instead of entire file -crd [s,g,t] coordinate system, default is specimen (g=geographic, t=tilt corrected) -P don't make any plots - just make rmag_results table -sav don't make the rmag_results table - just save all the plots -fmt [svg, jpg, eps] format for output images, pdf default -gtc DEC INC dec,inc of pole to great circle [down(up) in green (cyan) -d Vi DEC INC; Vi (1,2,3) to compare to direction DEC INC -nb N; specifies the number of bootstraps - default is 1000 DEFAULTS AFILE: rmag_anisotropy.txt RFILE: rmag_results.txt plot bootstrap ellipses of Constable & Tauxe [1987] NOTES minor axis: circles major axis: triangles principal axis: squares directions are plotted on the lower hemisphere for bootstrapped eigenvector components: Xs: blue, Ys: red, Zs: black """ # dir_path = "." version_num = pmag.get_version() verbose = pmagplotlib.verbose args = sys.argv ipar, ihext, ivec, iboot, imeas, isite, iplot, vec = 0, 0, 0, 1, 1, 0, 1, 0 hpars, bpars, PDir = [], [], [] CS, crd = "-1", "s" nb = 1000 fmt = "pdf" ResRecs = [] orlist = [] outfile, comp, Dir, gtcirc, PDir = "rmag_results.txt", 0, [], 0, [] infile = "rmag_anisotropy.txt" if "-h" in args: print main.__doc__ sys.exit() if "-WD" in args: ind = args.index("-WD") dir_path = args[ind + 1] if "-nb" in args: ind = args.index("-nb") nb = int(args[ind + 1]) if "-usr" in args: ind = args.index("-usr") user = args[ind + 1] else: user = "" if "-B" in args: iboot, ihext = 0, 1 if "-par" in args: ipar = 1 if "-x" in args: ihext = 1 if "-v" in args: ivec = 1 if "-sit" in args: isite = 1 if "-P" in args: iplot = 0 if "-f" in args: ind = args.index("-f") infile = args[ind + 1] if "-F" in args: ind = args.index("-F") outfile = args[ind + 1] if "-crd" in sys.argv: ind = sys.argv.index("-crd") crd = sys.argv[ind + 1] if crd == "g": CS = "0" if crd == "t": CS = "100" if "-fmt" in args: ind = args.index("-fmt") fmt = args[ind + 1] if "-sav" in args: plots = 1 verbose = 0 else: plots = 0 if "-gtc" in args: ind = args.index("-gtc") d, i = float(args[ind + 1]), float(args[ind + 2]) PDir.append(d) PDir.append(i) if "-d" in args: comp = 1 ind = args.index("-d") vec = int(args[ind + 1]) - 1 Dir = [float(args[ind + 2]), float(args[ind + 3])] # # set up plots # if infile[0] != "/": infile = dir_path + "/" + infile if outfile[0] != "/": outfile = dir_path + "/" + outfile ANIS = {} initcdf, inittcdf = 0, 0 ANIS["data"], ANIS["conf"] = 1, 2 if iboot == 1: ANIS["tcdf"] = 3 if iplot == 1: inittcdf = 1 pmagplotlib.plot_init(ANIS["tcdf"], 5, 5) if comp == 1 and iplot == 1: initcdf = 1 ANIS["vxcdf"], ANIS["vycdf"], ANIS["vzcdf"] = 4, 5, 6 pmagplotlib.plot_init(ANIS["vxcdf"], 5, 5) pmagplotlib.plot_init(ANIS["vycdf"], 5, 5) pmagplotlib.plot_init(ANIS["vzcdf"], 5, 5) if iplot == 1: pmagplotlib.plot_init(ANIS["conf"], 5, 5) pmagplotlib.plot_init(ANIS["data"], 5, 5) # read in the data data, ifiletype = pmag.magic_read(infile) for rec in data: # find all the orientation systems if "anisotropy_tilt_correction" not in rec.keys(): rec["anisotropy_tilt_correction"] = "-1" if rec["anisotropy_tilt_correction"] not in orlist: orlist.append(rec["anisotropy_tilt_correction"]) if CS not in orlist: if len(orlist) > 0: CS = orlist[0] else: CS = "-1" if CS == "-1": crd = "s" if CS == "0": crd = "g" if CS == "100": crd = "t" if verbose: print "desired coordinate system not available, using available: ", crd if isite == 1: sitelist = [] for rec in data: if rec["er_site_name"] not in sitelist: sitelist.append(rec["er_site_name"]) sitelist.sort() plt = len(sitelist) else: plt = 1 k = 0 while k < plt: site = "" sdata, Ss = [], [] # list of S format data Locs, Sites, Samples, Specimens, Cits = [], [], [], [], [] if isite == 0: sdata = data else: site = sitelist[k] for rec in data: if rec["er_site_name"] == site: sdata.append(rec) anitypes = [] csrecs = pmag.get_dictitem(sdata, "anisotropy_tilt_correction", CS, "T") for rec in csrecs: if rec["anisotropy_type"] not in anitypes: anitypes.append(rec["anisotropy_type"]) if rec["er_location_name"] not in Locs: Locs.append(rec["er_location_name"]) if rec["er_site_name"] not in Sites: Sites.append(rec["er_site_name"]) if rec["er_sample_name"] not in Samples: Samples.append(rec["er_sample_name"]) if rec["er_specimen_name"] not in Specimens: Specimens.append(rec["er_specimen_name"]) if rec["er_citation_names"] not in Cits: Cits.append(rec["er_citation_names"]) s = [] s.append(float(rec["anisotropy_s1"])) s.append(float(rec["anisotropy_s2"])) s.append(float(rec["anisotropy_s3"])) s.append(float(rec["anisotropy_s4"])) s.append(float(rec["anisotropy_s5"])) s.append(float(rec["anisotropy_s6"])) if s[0] <= 1.0: Ss.append(s) # protect against crap # tau,Vdirs=pmag.doseigs(s) fpars = pmag.dohext(int(rec["anisotropy_n"]) - 6, float(rec["anisotropy_sigma"]), s) ResRec = {} ResRec["er_location_names"] = rec["er_location_name"] ResRec["er_citation_names"] = rec["er_citation_names"] ResRec["er_site_names"] = rec["er_site_name"] ResRec["er_sample_names"] = rec["er_sample_name"] ResRec["er_specimen_names"] = rec["er_specimen_name"] ResRec["rmag_result_name"] = rec["er_specimen_name"] + ":" + rec["anisotropy_type"] ResRec["er_analyst_mail_names"] = user ResRec["tilt_correction"] = CS ResRec["anisotropy_type"] = rec["anisotropy_type"] ResRec["anisotropy_v1_dec"] = "%7.1f" % (fpars["v1_dec"]) ResRec["anisotropy_v2_dec"] = "%7.1f" % (fpars["v2_dec"]) ResRec["anisotropy_v3_dec"] = "%7.1f" % (fpars["v3_dec"]) ResRec["anisotropy_v1_inc"] = "%7.1f" % (fpars["v1_inc"]) ResRec["anisotropy_v2_inc"] = "%7.1f" % (fpars["v2_inc"]) ResRec["anisotropy_v3_inc"] = "%7.1f" % (fpars["v3_inc"]) ResRec["anisotropy_t1"] = "%10.8f" % (fpars["t1"]) ResRec["anisotropy_t2"] = "%10.8f" % (fpars["t2"]) ResRec["anisotropy_t3"] = "%10.8f" % (fpars["t3"]) ResRec["anisotropy_ftest"] = "%10.3f" % (fpars["F"]) ResRec["anisotropy_ftest12"] = "%10.3f" % (fpars["F12"]) ResRec["anisotropy_ftest23"] = "%10.3f" % (fpars["F23"]) ResRec["result_description"] = "F_crit: " + fpars["F_crit"] + "; F12,F23_crit: " + fpars["F12_crit"] ResRec["anisotropy_type"] = pmag.makelist(anitypes) ResRecs.append(ResRec) if len(Ss) > 1: title = "LO:_" + ResRec["er_location_names"] + "_SI:_" + site + "_SA:__SP:__CO:_" + crd ResRec["er_location_names"] = pmag.makelist(Locs) bpars, hpars = pmagplotlib.plotANIS(ANIS, Ss, iboot, ihext, ivec, ipar, title, iplot, comp, vec, Dir, nb) if len(PDir) > 0: pmagplotlib.plotC(ANIS["data"], PDir, 90.0, "g") pmagplotlib.plotC(ANIS["conf"], PDir, 90.0, "g") if verbose and plots == 0: pmagplotlib.drawFIGS(ANIS) ResRec["er_location_names"] = pmag.makelist(Locs) if plots == 1: save(ANIS, fmt, title) ResRec = {} ResRec["er_citation_names"] = pmag.makelist(Cits) ResRec["er_location_names"] = pmag.makelist(Locs) ResRec["er_site_names"] = pmag.makelist(Sites) ResRec["er_sample_names"] = pmag.makelist(Samples) ResRec["er_specimen_names"] = pmag.makelist(Specimens) ResRec["rmag_result_name"] = pmag.makelist(Sites) + ":" + pmag.makelist(anitypes) ResRec["anisotropy_type"] = pmag.makelist(anitypes) ResRec["er_analyst_mail_names"] = user ResRec["tilt_correction"] = CS if isite == "0": ResRec["result_description"] = "Study average using coordinate system: " + CS if isite == "1": ResRec["result_description"] = "Site average using coordinate system: " + CS if hpars != [] and ihext == 1: HextRec = {} for key in ResRec.keys(): HextRec[key] = ResRec[key] # copy over stuff HextRec["anisotropy_v1_dec"] = "%7.1f" % (hpars["v1_dec"]) HextRec["anisotropy_v2_dec"] = "%7.1f" % (hpars["v2_dec"]) HextRec["anisotropy_v3_dec"] = "%7.1f" % (hpars["v3_dec"]) HextRec["anisotropy_v1_inc"] = "%7.1f" % (hpars["v1_inc"]) HextRec["anisotropy_v2_inc"] = "%7.1f" % (hpars["v2_inc"]) HextRec["anisotropy_v3_inc"] = "%7.1f" % (hpars["v3_inc"]) HextRec["anisotropy_t1"] = "%10.8f" % (hpars["t1"]) HextRec["anisotropy_t2"] = "%10.8f" % (hpars["t2"]) HextRec["anisotropy_t3"] = "%10.8f" % (hpars["t3"]) HextRec["anisotropy_hext_F"] = "%7.1f " % (hpars["F"]) HextRec["anisotropy_hext_F12"] = "%7.1f " % (hpars["F12"]) HextRec["anisotropy_hext_F23"] = "%7.1f " % (hpars["F23"]) HextRec["anisotropy_v1_eta_semi_angle"] = "%7.1f " % (hpars["e12"]) HextRec["anisotropy_v1_eta_dec"] = "%7.1f " % (hpars["v2_dec"]) HextRec["anisotropy_v1_eta_inc"] = "%7.1f " % (hpars["v2_inc"]) HextRec["anisotropy_v1_zeta_semi_angle"] = "%7.1f " % (hpars["e13"]) HextRec["anisotropy_v1_zeta_dec"] = "%7.1f " % (hpars["v3_dec"]) HextRec["anisotropy_v1_zeta_inc"] = "%7.1f " % (hpars["v3_inc"]) HextRec["anisotropy_v2_eta_semi_angle"] = "%7.1f " % (hpars["e12"]) HextRec["anisotropy_v2_eta_dec"] = "%7.1f " % (hpars["v1_dec"]) HextRec["anisotropy_v2_eta_inc"] = "%7.1f " % (hpars["v1_inc"]) HextRec["anisotropy_v2_zeta_semi_angle"] = "%7.1f " % (hpars["e23"]) HextRec["anisotropy_v2_zeta_dec"] = "%7.1f " % (hpars["v3_dec"]) HextRec["anisotropy_v2_zeta_inc"] = "%7.1f " % (hpars["v3_inc"]) HextRec["anisotropy_v3_eta_semi_angle"] = "%7.1f " % (hpars["e12"]) HextRec["anisotropy_v3_eta_dec"] = "%7.1f " % (hpars["v1_dec"]) HextRec["anisotropy_v3_eta_inc"] = "%7.1f " % (hpars["v1_inc"]) HextRec["anisotropy_v3_zeta_semi_angle"] = "%7.1f " % (hpars["e23"]) HextRec["anisotropy_v3_zeta_dec"] = "%7.1f " % (hpars["v2_dec"]) HextRec["anisotropy_v3_zeta_inc"] = "%7.1f " % (hpars["v2_inc"]) HextRec["magic_method_codes"] = "LP-AN:AE-H" if verbose: print "Hext Statistics: " print " tau_i, V_i_D, V_i_I, V_i_zeta, V_i_zeta_D, V_i_zeta_I, V_i_eta, V_i_eta_D, V_i_eta_I" print HextRec["anisotropy_t1"], HextRec["anisotropy_v1_dec"], HextRec["anisotropy_v1_inc"], HextRec[ "anisotropy_v1_eta_semi_angle" ], HextRec["anisotropy_v1_eta_dec"], HextRec["anisotropy_v1_eta_inc"], HextRec[ "anisotropy_v1_zeta_semi_angle" ], HextRec[ "anisotropy_v1_zeta_dec" ], HextRec[ "anisotropy_v1_zeta_inc" ] print HextRec["anisotropy_t2"], HextRec["anisotropy_v2_dec"], HextRec["anisotropy_v2_inc"], HextRec[ "anisotropy_v2_eta_semi_angle" ], HextRec["anisotropy_v2_eta_dec"], HextRec["anisotropy_v2_eta_inc"], HextRec[ "anisotropy_v2_zeta_semi_angle" ], HextRec[ "anisotropy_v2_zeta_dec" ], HextRec[ "anisotropy_v2_zeta_inc" ] print HextRec["anisotropy_t3"], HextRec["anisotropy_v3_dec"], HextRec["anisotropy_v3_inc"], HextRec[ "anisotropy_v3_eta_semi_angle" ], HextRec["anisotropy_v3_eta_dec"], HextRec["anisotropy_v3_eta_inc"], HextRec[ "anisotropy_v3_zeta_semi_angle" ], HextRec[ "anisotropy_v3_zeta_dec" ], HextRec[ "anisotropy_v3_zeta_inc" ] HextRec["magic_software_packages"] = version_num ResRecs.append(HextRec) if bpars != []: BootRec = {} for key in ResRec.keys(): BootRec[key] = ResRec[key] # copy over stuff BootRec["anisotropy_v1_dec"] = "%7.1f" % (bpars["v1_dec"]) BootRec["anisotropy_v2_dec"] = "%7.1f" % (bpars["v2_dec"]) BootRec["anisotropy_v3_dec"] = "%7.1f" % (bpars["v3_dec"]) BootRec["anisotropy_v1_inc"] = "%7.1f" % (bpars["v1_inc"]) BootRec["anisotropy_v2_inc"] = "%7.1f" % (bpars["v2_inc"]) BootRec["anisotropy_v3_inc"] = "%7.1f" % (bpars["v3_inc"]) BootRec["anisotropy_t1"] = "%10.8f" % (bpars["t1"]) BootRec["anisotropy_t2"] = "%10.8f" % (bpars["t2"]) BootRec["anisotropy_t3"] = "%10.8f" % (bpars["t3"]) BootRec["anisotropy_v1_eta_inc"] = "%7.1f " % (bpars["v1_eta_inc"]) BootRec["anisotropy_v1_eta_dec"] = "%7.1f " % (bpars["v1_eta_dec"]) BootRec["anisotropy_v1_eta_semi_angle"] = "%7.1f " % (bpars["v1_eta"]) BootRec["anisotropy_v1_zeta_inc"] = "%7.1f " % (bpars["v1_zeta_inc"]) BootRec["anisotropy_v1_zeta_dec"] = "%7.1f " % (bpars["v1_zeta_dec"]) BootRec["anisotropy_v1_zeta_semi_angle"] = "%7.1f " % (bpars["v1_zeta"]) BootRec["anisotropy_v2_eta_inc"] = "%7.1f " % (bpars["v2_eta_inc"]) BootRec["anisotropy_v2_eta_dec"] = "%7.1f " % (bpars["v2_eta_dec"]) BootRec["anisotropy_v2_eta_semi_angle"] = "%7.1f " % (bpars["v2_eta"]) BootRec["anisotropy_v2_zeta_inc"] = "%7.1f " % (bpars["v2_zeta_inc"]) BootRec["anisotropy_v2_zeta_dec"] = "%7.1f " % (bpars["v2_zeta_dec"]) BootRec["anisotropy_v2_zeta_semi_angle"] = "%7.1f " % (bpars["v2_zeta"]) BootRec["anisotropy_v3_eta_inc"] = "%7.1f " % (bpars["v3_eta_inc"]) BootRec["anisotropy_v3_eta_dec"] = "%7.1f " % (bpars["v3_eta_dec"]) BootRec["anisotropy_v3_eta_semi_angle"] = "%7.1f " % (bpars["v3_eta"]) BootRec["anisotropy_v3_zeta_inc"] = "%7.1f " % (bpars["v3_zeta_inc"]) BootRec["anisotropy_v3_zeta_dec"] = "%7.1f " % (bpars["v3_zeta_dec"]) BootRec["anisotropy_v3_zeta_semi_angle"] = "%7.1f " % (bpars["v3_zeta"]) BootRec["anisotropy_hext_F"] = "" BootRec["anisotropy_hext_F12"] = "" BootRec["anisotropy_hext_F23"] = "" BootRec["magic_method_codes"] = "LP-AN:AE-H:AE-BS" # regular bootstrap if ipar == 1: BootRec["magic_method_codes"] = "LP-AN:AE-H:AE-BS-P" # parametric bootstrap if verbose: print "Boostrap Statistics: " print " tau_i, V_i_D, V_i_I, V_i_zeta, V_i_zeta_D, V_i_zeta_I, V_i_eta, V_i_eta_D, V_i_eta_I" print BootRec["anisotropy_t1"], BootRec["anisotropy_v1_dec"], BootRec["anisotropy_v1_inc"], BootRec[ "anisotropy_v1_eta_semi_angle" ], BootRec["anisotropy_v1_eta_dec"], BootRec["anisotropy_v1_eta_inc"], BootRec[ "anisotropy_v1_zeta_semi_angle" ], BootRec[ "anisotropy_v1_zeta_dec" ], BootRec[ "anisotropy_v1_zeta_inc" ] print BootRec["anisotropy_t2"], BootRec["anisotropy_v2_dec"], BootRec["anisotropy_v2_inc"], BootRec[ "anisotropy_v2_eta_semi_angle" ], BootRec["anisotropy_v2_eta_dec"], BootRec["anisotropy_v2_eta_inc"], BootRec[ "anisotropy_v2_zeta_semi_angle" ], BootRec[ "anisotropy_v2_zeta_dec" ], BootRec[ "anisotropy_v2_zeta_inc" ] print BootRec["anisotropy_t3"], BootRec["anisotropy_v3_dec"], BootRec["anisotropy_v3_inc"], BootRec[ "anisotropy_v3_eta_semi_angle" ], BootRec["anisotropy_v3_eta_dec"], BootRec["anisotropy_v3_eta_inc"], BootRec[ "anisotropy_v3_zeta_semi_angle" ], BootRec[ "anisotropy_v3_zeta_dec" ], BootRec[ "anisotropy_v3_zeta_inc" ] BootRec["magic_software_packages"] = version_num ResRecs.append(BootRec) k += 1 goon = 1 while goon == 1 and iplot == 1 and verbose: if iboot == 1: print "compare with [d]irection " print " plot [g]reat circle, change [c]oord. system, change [e]llipse calculation, s[a]ve plots, [q]uit " if isite == 1: print " [p]revious, [s]ite, [q]uit, <return> for next " ans = raw_input("") if ans == "q": sys.exit() if ans == "e": iboot, ipar, ihext, ivec = 1, 0, 0, 0 e = raw_input("Do Hext Statistics 1/[0]: ") if e == "1": ihext = 1 e = raw_input("Suppress bootstrap 1/[0]: ") if e == "1": iboot = 0 if iboot == 1: e = raw_input("Parametric bootstrap 1/[0]: ") if e == "1": ipar = 1 e = raw_input("Plot bootstrap eigenvectors: 1/[0]: ") if e == "1": ivec = 1 if iplot == 1: if inittcdf == 0: ANIS["tcdf"] = 3 pmagplotlib.plot_init(ANIS["tcdf"], 5, 5) inittcdf = 1 bpars, hpars = pmagplotlib.plotANIS( ANIS, Ss, iboot, ihext, ivec, ipar, title, iplot, comp, vec, Dir, nb ) if verbose and plots == 0: pmagplotlib.drawFIGS(ANIS) if ans == "c": print "Current Coordinate system is: " if CS == "-1": print " Specimen" if CS == "0": print " Geographic" if CS == "100": print " Tilt corrected" key = raw_input(" Enter desired coordinate system: [s]pecimen, [g]eographic, [t]ilt corrected ") if key == "s": CS = "-1" if key == "g": CS = "0" if key == "t": CS = "100" if CS not in orlist: if len(orlist) > 0: CS = orlist[0] else: CS = "-1" if CS == "-1": crd = "s" if CS == "0": crd = "g" if CS == "100": crd = "t" print "desired coordinate system not available, using available: ", crd k -= 1 goon = 0 if ans == "": if isite == 1: goon = 0 else: print "Good bye " sys.exit() if ans == "d": if initcdf == 0: initcdf = 1 ANIS["vxcdf"], ANIS["vycdf"], ANIS["vzcdf"] = 4, 5, 6 pmagplotlib.plot_init(ANIS["vxcdf"], 5, 5) pmagplotlib.plot_init(ANIS["vycdf"], 5, 5) pmagplotlib.plot_init(ANIS["vzcdf"], 5, 5) Dir, comp = [], 1 print """ Input: Vi D I to compare eigenvector Vi with direction D/I where Vi=1: principal Vi=2: major Vi=3: minor D= declination of comparison direction I= inclination of comparison direction""" con = 1 while con == 1: try: vdi = raw_input("Vi D I: ").split() vec = int(vdi[0]) - 1 Dir = [float(vdi[1]), float(vdi[2])] con = 0 except IndexError: print " Incorrect entry, try again " bpars, hpars = pmagplotlib.plotANIS( ANIS, Ss, iboot, ihext, ivec, ipar, title, iplot, comp, vec, Dir, nb ) Dir, comp = [], 0 if ans == "g": con, cnt = 1, 0 while con == 1: try: print " Input: input pole to great circle ( D I) to plot a great circle: " di = raw_input(" D I: ").split() PDir.append(float(di[0])) PDir.append(float(di[1])) con = 0 except: cnt += 1 if cnt < 10: print " enter the dec and inc of the pole on one line " else: print "ummm - you are doing something wrong - i give up" sys.exit() pmagplotlib.plotC(ANIS["data"], PDir, 90.0, "g") pmagplotlib.plotC(ANIS["conf"], PDir, 90.0, "g") if verbose and plots == 0: pmagplotlib.drawFIGS(ANIS) if ans == "p": k -= 2 goon = 0 if ans == "q": k = plt goon = 0 if ans == "s": keepon = 1 site = raw_input(" print site or part of site desired: ") while keepon == 1: try: k = sitelist.index(site) keepon = 0 except: tmplist = [] for qq in range(len(sitelist)): if site in sitelist[qq]: tmplist.append(sitelist[qq]) print site, " not found, but this was: " print tmplist site = raw_input("Select one or try again\n ") k = sitelist.index(site) goon, ans = 0, "" if ans == "a": locs = pmag.makelist(Locs) title = "LO:_" + locs + "_SI:__" + "_SA:__SP:__CO:_" + crd save(ANIS, fmt, title) goon = 0 else: if verbose: print "skipping plot - not enough data points" k += 1 # put rmag_results stuff here if len(ResRecs) > 0: ResOut, keylist = pmag.fillkeys(ResRecs) pmag.magic_write(outfile, ResOut, "rmag_results") if verbose: print " Good bye "
def main(command_line=True, **kwargs): """ NAME IODP_jr6_magic.py DESCRIPTION converts shipboard .jr6 format files to magic_measurements format files SYNTAX IODP_jr6_magic.py [command line options] OPTIONS -h: prints the help message and quits. -f FILE: specify input file, or -F FILE: specify output file, default is magic_measurements.txt -fsa FILE: specify er_samples.txt file for sample name lookup , default is 'er_samples.txt' -loc HOLE : specify hole name (U1456A) -A: don't average replicate measurements INPUT JR6 .jr6 format file """ def fix_separation(filename, new_filename): old_file = open(filename, 'rU') data = old_file.readlines() new_data = [] for line in data: new_line = line.replace('-', ' -') new_line = new_line.replace(' ', ' ') new_data.append(new_line) new_file = open(new_filename, 'w') for s in new_data: new_file.write(s) old_file.close() new_file.close() return new_filename def old_fix_separation(filename, new_filename): old_file = open(filename, 'rU') data = old_file.readlines() new_data = [] for line in data: new_line = [] for i in line.split(): if '-' in i[1:]: lead_char = '-' if i[0] == '-' else '' if lead_char: v = i[1:].split('-') else: v = i.split('-') new_line.append(lead_char + v[0]) new_line.append('-' + v[1]) else: new_line.append(i) new_line = (' '.join(new_line)) + '\n' new_data.append(new_line) new_file = open(new_filename, 'w') for s in new_data: new_file.write(s) new_file.close() old_file.close() return new_filename # initialize some stuff noave=0 volume=2.5**3 #default volume is a 2.5cm cube inst="" samp_con,Z='5',"" missing=1 demag="N" er_location_name="unknown" citation='This study' args=sys.argv meth_code="LP-NO" version_num=pmag.get_version() dir_path='.' MagRecs=[] samp_file = 'er_samples.txt' meas_file = 'magic_measurements.txt' mag_file = '' # # get command line arguments # if command_line: if '-WD' in sys.argv: ind = sys.argv.index('-WD') dir_path=sys.argv[ind+1] if '-ID' in sys.argv: ind = sys.argv.index('-ID') input_dir_path = sys.argv[ind+1] else: input_dir_path = dir_path output_dir_path = dir_path if "-h" in args: print main.__doc__ return False if '-F' in args: ind=args.index("-F") meas_file = args[ind+1] if '-fsa' in args: ind = args.index("-fsa") samp_file = args[ind+1] if samp_file[0]!='/': samp_file = os.path.join(input_dir_path, samp_file) try: open(samp_file,'rU') ErSamps,file_type=pmag.magic_read(samp_file) except: print samp_file,' not found: ' print ' download csv file and import to MagIC with IODP_samples_magic.py' if '-f' in args: ind = args.index("-f") mag_file= args[ind+1] if "-loc" in args: ind=args.index("-loc") er_location_name=args[ind+1] if "-A" in args: noave=1 if not command_line: dir_path = kwargs.get('dir_path', '.') input_dir_path = kwargs.get('input_dir_path', dir_path) output_dir_path = dir_path meas_file = kwargs.get('meas_file', 'magic_measurements.txt') mag_file = kwargs.get('mag_file', '') samp_file = kwargs.get('samp_file', 'er_samples.txt') specnum = kwargs.get('specnum', 1) samp_con = kwargs.get('samp_con', '1') if len(str(samp_con)) > 1: samp_con, Z = samp_con.split('-') else: Z = '' er_location_name = kwargs.get('er_location_name', '') noave = kwargs.get('noave', 0) # default (0) means DO average meth_code = kwargs.get('meth_code', "LP-NO") # format variables meth_code=meth_code+":FS-C-DRILL-IODP:SP-SS-C:SO-V" meth_code=meth_code.strip(":") if mag_file: mag_file = os.path.join(input_dir_path, mag_file) samp_file = os.path.join(input_dir_path, samp_file) meas_file = os.path.join(output_dir_path, meas_file) # validate variables if not mag_file: print "You must provide an IODP_jr6 format file" return False, "You must provide an IODP_jr6 format file" if not os.path.exists(mag_file): print 'The input file you provided: {} does not exist.\nMake sure you have specified the correct filename AND correct input directory name.'.format(os.path.join(input_dir_path, mag_file)) return False, 'The input file you provided: {} does not exist.\nMake sure you have specified the correct filename AND correct input directory name.'.format(magfile) if not os.path.exists(samp_file): print 'samp_file', samp_file print "Your input directory:\n{}\nmust contain an er_samples.txt file, or you must explicitly provide one".format(input_dir_path) return False, "Your input directory:\n{}\nmust contain an er_samples.txt file, or you must explicitly provide one".format(input_dir_path) # parse data temp = os.path.join(output_dir_path, 'temp.txt') fix_separation(mag_file, temp) #os.rename('temp.txt', mag_file) #data = open(mag_file, 'rU').readlines() data=pd.read_csv(temp, delim_whitespace=True,header=None) os.remove(temp) samples,filetype = pmag.magic_read(samp_file) data.columns=['specname','step','negz','y','x','expon','sample_azimuth','sample_dip','sample_bed_dip_direction','sample_bed_dip','bed_dip_dir2','bed_dip2','param1','param2','param3','param4','measurement_csd'] cart=np.array([data['x'],data['y'],-data['negz']]).transpose() dir= pmag.cart2dir(cart).transpose() data['measurement_dec']=dir[0] data['measurement_inc']=dir[1] data['measurement_magn_volume']=dir[2]*(10.0**data['expon']) # A/m - data in A/m data['measurement_flag']='g' data['measurement_standard']='u' data['measurement_number']='1' data['measurement_temp']='273' data['er_location_name']=er_location_name for rowNum, row in data.iterrows(): MagRec={} spec_text_id=row['specname'].split('_')[1] SampRecs=pmag.get_dictitem(samples,'er_sample_alternatives',spec_text_id,'has') # retrieve sample record for this specimen if len(SampRecs)>0: # found one MagRec['er_specimen_name']=SampRecs[0]['er_sample_name'] MagRec['er_sample_name']=MagRec['er_specimen_name'] MagRec['er_site_name']=MagRec['er_specimen_name'] MagRec["er_citation_names"]="This study" MagRec['er_location_name']=er_location_name MagRec['magic_software_packages']=version_num MagRec["treatment_temp"]='%8.3e' % (273) # room temp in kelvin MagRec["measurement_temp"]='%8.3e' % (273) # room temp in kelvin MagRec["measurement_flag"]='g' MagRec["measurement_standard"]='u' MagRec["measurement_number"]='1' MagRec["treatment_ac_field"]='0' volume=float(SampRecs[0]['sample_volume']) moment=row['measurement_magn_volume'] * volume MagRec["measurement_magn_moment"]=str(moment) MagRec["measurement_magn_volume"]=str(row['measurement_magn_volume']) MagRec["measurement_dec"]='%7.1f'%(row['measurement_dec']) MagRec["measurement_inc"]='%7.1f'%(row['measurement_inc']) if row['step'] == 'NRM': meas_type="LT-NO" elif row['step'][0:2] == 'AD': meas_type="LT-AF-Z" treat=float(row['step'][2:]) MagRec["treatment_ac_field"]='%8.3e' %(treat*1e-3) # convert from mT to tesla elif row['step'][0] == 'TD': meas_type="LT-T-Z" treat=float(row['step'][2:]) MagRec["treatment_temp"]='%8.3e' % (treat+273.) # temp in kelvin elif row['step'][0:3]=='ARM': # meas_type="LT-AF-I" treat=float(row['step'][3:]) MagRec["treatment_ac_field"]='%8.3e' %(treat*1e-3) # convert from mT to tesla MagRec["treatment_dc_field"]='%8.3e' %(50e-6) # assume 50uT DC field MagRec["measurement_description"]='Assumed DC field - actual unknown' elif row['step'][0:3]=='IRM': # meas_type="LT-IRM" treat=float(row['step'][3:]) MagRec["treatment_dc_field"]='%8.3e' %(treat*1e-3) # convert from mT to tesla else: print 'unknown treatment type for ',row return False, 'unknown treatment type for ',row MagRec['magic_method_codes']=meas_type MagRecs.append(MagRec.copy()) else: print 'sample name not found: ',row['specname'] MagOuts=pmag.measurements_methods(MagRecs,noave) file_created, error_message = pmag.magic_write(meas_file,MagOuts,'magic_measurements') if file_created: return True, meas_file else: return False, 'Results not written to file'
def main(): """ NAME zeq_magic.py DESCRIPTION reads in magic_measurements formatted file, makes plots of remanence decay during demagnetization experiments. Reads in prior interpretations saved in a pmag_specimens formatted file and allows re-interpretations of best-fit lines and planes and saves (revised or new) interpretations in a pmag_specimens file. interpretations are saved in the coordinate system used. Also allows judicious editting of measurements to eliminate "bad" measurements. These are marked as such in the magic_measurements input file. they are NOT deleted, just ignored. SYNTAX zeq_magic.py [command line options] OPTIONS -h prints help message and quits -f MEASFILE: sets magic_measurements format input file, default: magic_measurements.txt -fsp SPECFILE: sets pmag_specimens format file with prior interpreations, default: zeq_specimens.txt -Fp PLTFILE: sets filename for saved plot, default is name_type.fmt (where type is zijd, eqarea or decay curve) -crd [s,g,t]: sets coordinate system, g=geographic, t=tilt adjusted, default: specimen coordinate system -fsa SAMPFILE: sets er_samples format file with orientation information, default: er_samples.txt -spc SPEC plots single specimen SPEC, saves plot with specified format with optional -dir settings and quits -dir [L,P,F][beg][end]: sets calculation type for principal component analysis, default is none beg: starting step for PCA calculation end: ending step for PCA calculation [L,P,F]: calculation type for line, plane or fisher mean must be used with -spc option -fmt FMT: set format of saved plot [png,svg,jpg] -A: suppresses averaging of replicate measurements, default is to average -sav: saves all plots without review SCREEN OUTPUT: Specimen, N, a95, StepMin, StepMax, Dec, Inc, calculation type """ # initialize some variables doave,e,b=1,0,0 # average replicates, initial end and beginning step plots,coord=0,'s' noorient=0 version_num=pmag.get_version() verbose=pmagplotlib.verbose beg_pca,end_pca,direction_type="","",'l' calculation_type,fmt="","svg" user,spec_keys,locname="",[],'' plot_file="" sfile="" plot_file="" PriorRecs=[] # empty list for prior interpretations backup=0 specimen="" # can skip everything and just plot one specimen with bounds e,b 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] else: dir_path='.' inspec=dir_path+'/'+'zeq_specimens.txt' meas_file,geo,tilt,ask,samp_file=dir_path+'/magic_measurements.txt',0,0,0,dir_path+'/er_samples.txt' if '-f' in sys.argv: ind=sys.argv.index('-f') meas_file=dir_path+'/'+sys.argv[ind+1] if '-fsp' in sys.argv: ind=sys.argv.index('-fsp') inspec=dir_path+'/'+sys.argv[ind+1] if '-fsa' in sys.argv: ind=sys.argv.index('-fsa') samp_file=dir_path+'/'+sys.argv[ind+1] sfile='ok' if '-crd' in sys.argv: ind=sys.argv.index('-crd') coord=sys.argv[ind+1] if coord=='g' or coord=='t': samp_data,file_type=pmag.magic_read(samp_file) if file_type=='er_samples':sfile='ok' geo=1 if coord=='t':tilt=1 if '-spc' in sys.argv: ind=sys.argv.index('-spc') specimen=sys.argv[ind+1] if '-dir' in sys.argv: ind=sys.argv.index('-dir') direction_type=sys.argv[ind+1] beg_pca=int(sys.argv[ind+2]) end_pca=int(sys.argv[ind+3]) if direction_type=='L':calculation_type='DE-BFL' if direction_type=='P':calculation_type='DE-BFP' if direction_type=='F':calculation_type='DE-FM' if '-Fp' in sys.argv: ind=sys.argv.index('-Fp') plot_file=dir_path+'/'+sys.argv[ind+1] if '-A' in sys.argv: doave=0 if '-sav' in sys.argv: plots=1 verbose=0 if '-fmt' in sys.argv: ind=sys.argv.index('-fmt') fmt=sys.argv[ind+1] # first_save=1 meas_data,file_type=pmag.magic_read(meas_file) changeM,changeS=0,0 # check if data or interpretations have changed if file_type != 'magic_measurements': print file_type print file_type,"This is not a valid magic_measurements file " sys.exit() for rec in meas_data: if "magic_method_codes" not in rec.keys(): rec["magic_method_codes"]="" methods="" tmp=rec["magic_method_codes"].replace(" ","").split(":") for meth in tmp: methods=methods+meth+":" rec["magic_method_codes"]=methods[:-1] # get rid of annoying spaces in Anthony's export files if "magic_instrument_codes" not in rec.keys() :rec["magic_instrument_codes"]="" PriorSpecs=[] PriorRecs,file_type=pmag.magic_read(inspec) if len(PriorRecs)==0: if verbose:print "starting new file ",inspec for Rec in PriorRecs: if 'magic_software_packages' not in Rec.keys():Rec['magic_software_packages']="" if Rec['er_specimen_name'] not in PriorSpecs: if 'specimen_comp_name' not in Rec.keys():Rec['specimen_comp_name']="A" PriorSpecs.append(Rec['er_specimen_name']) else: if 'specimen_comp_name' not in Rec.keys():Rec['specimen_comp_name']="A" if "magic_method_codes" in Rec.keys(): methods=[] tmp=Rec["magic_method_codes"].replace(" ","").split(":") for meth in tmp: methods.append(meth) if 'DE-FM' in methods: Rec['calculation_type']='DE-FM' # this won't be imported but helps if 'DE-BFL' in methods: Rec['calculation_type']='DE-BFL' if 'DE-BFL-A' in methods: Rec['calculation_type']='DE-BFL-A' if 'DE-BFL-O' in methods: Rec['calculation_type']='DE-BFL-O' if 'DE-BFP' in methods: Rec['calculation_type']='DE-BFP' else: Rec['calculation_type']='DE-BFL' # default is to assume a best-fit line # # get list of unique specimen names # sids=pmag.get_specs(meas_data) # # set up plots, angle sets X axis to horizontal, direction_type 'l' is best-fit line # direction_type='p' is great circle # # # draw plots for sample s - default is just to step through zijderveld diagrams # # # define figure numbers for equal area, zijderveld, # and intensity vs. demagnetiztion step respectively ZED={} ZED['eqarea'],ZED['zijd'], ZED['demag']=1,2,3 pmagplotlib.plot_init(ZED['eqarea'],5,5) pmagplotlib.plot_init(ZED['zijd'],6,5) pmagplotlib.plot_init(ZED['demag'],5,5) save_pca=0 if specimen=="": k = 0 else: k=sids.index(specimen) angle,direction_type="","" setangle=0 CurrRecs=[] while k < len(sids): CurrRecs=[] if setangle==0:angle="" method_codes,inst_code=[],"" s=sids[k] PmagSpecRec={} PmagSpecRec["er_analyst_mail_names"]=user PmagSpecRec['magic_software_packages']=version_num PmagSpecRec['specimen_description']="" PmagSpecRec['magic_method_codes']="" if verbose and s!="":print s, k , 'out of ',len(sids) # # collect info for the PmagSpecRec dictionary # s_meas=pmag.get_dictitem(meas_data,'er_specimen_name',s,'T') # fish out this specimen s_meas=pmag.get_dictitem(s_meas,'magic_method_codes','Z','has') # fish out zero field steps if len(s_meas)>0: for rec in s_meas: # fix up a few things for the output record PmagSpecRec["magic_instrument_codes"]=rec["magic_instrument_codes"] # copy over instruments PmagSpecRec["er_citation_names"]="This study" PmagSpecRec["er_specimen_name"]=s PmagSpecRec["er_sample_name"]=rec["er_sample_name"] PmagSpecRec["er_site_name"]=rec["er_site_name"] PmagSpecRec["er_location_name"]=rec["er_location_name"] locname=rec['er_location_name'] if 'er_expedition_name' in rec.keys(): PmagSpecRec["er_expedition_name"]=rec["er_expedition_name"] PmagSpecRec["magic_method_codes"]=rec["magic_method_codes"] if "magic_experiment_name" not in rec.keys(): PmagSpecRec["magic_experiment_names"]="" else: PmagSpecRec["magic_experiment_names"]=rec["magic_experiment_name"] break # # find the data from the meas_data file for this specimen # data,units=pmag.find_dmag_rec(s,meas_data) PmagSpecRec["measurement_step_unit"]= units u=units.split(":") if "T" in units:PmagSpecRec["magic_method_codes"]=PmagSpecRec["magic_method_codes"]+":LP-DIR-AF" if "K" in units:PmagSpecRec["magic_method_codes"]=PmagSpecRec["magic_method_codes"]+":LP-DIR-T" if "J" in units:PmagSpecRec["magic_method_codes"]=PmagSpecRec["magic_method_codes"]+":LP-DIR-M" # # find prior interpretation # if len(CurrRecs)==0: # check if already in beg_pca,end_pca="","" calculation_type="" if inspec !="": if verbose: print " looking up previous interpretations..." precs=pmag.get_dictitem(PriorRecs,'er_specimen_name',s,'T') # get all the prior recs with this specimen name precs=pmag.get_dictitem(precs,'magic_method_codes','LP-DIR','has') # get the directional data PriorRecs=pmag.get_dictitem(PriorRecs,'er_specimen_name',s,'F') # take them all out of prior recs # get the ones that meet the current coordinate system for prec in precs: if 'specimen_tilt_correction' not in prec.keys() or prec['specimen_tilt_correction']=='-1': crd='s' elif prec['specimen_tilt_correction']=='0': crd='g' elif prec['specimen_tilt_correction']=='100': crd='t' else: crd='?' CurrRec={} for key in prec.keys():CurrRec[key]=prec[key] CurrRecs.append(CurrRec) # put in CurrRecs method_codes= CurrRec["magic_method_codes"].replace(" ","").split(':') calculation_type='DE-BFL' if 'DE-FM' in method_codes: calculation_type='DE-FM' if 'DE-BFP' in method_codes: calculation_type='DE-BFP' if 'DE-BFL-A' in method_codes: calculation_type='DE-BFL-A' if 'specimen_dang' not in CurrRec.keys(): if verbose:print 'Run mk_redo.py and zeq_magic_redo.py to get the specimen_dang values' CurrRec['specimen_dang']=-1 if calculation_type!='DE-FM' and crd==coord: # not a fisher mean if verbose:print "Specimen N MAD DANG start end dec inc type component coordinates" if units=='K': if verbose:print '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s %s %s \n' % (CurrRec["er_specimen_name"],int(CurrRec["specimen_n"]),float(CurrRec["specimen_mad"]),float(CurrRec["specimen_dang"]),float(CurrRec["measurement_step_min"])-273,float(CurrRec["measurement_step_max"])-273,float(CurrRec["specimen_dec"]),float(CurrRec["specimen_inc"]),calculation_type,CurrRec['specimen_comp_name'],crd) elif units=='T': if verbose:print '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s %s %s \n' % (CurrRec["er_specimen_name"],int(CurrRec["specimen_n"]),float(CurrRec["specimen_mad"]),float(CurrRec["specimen_dang"]),float(CurrRec["measurement_step_min"])*1e3,float(CurrRec["measurement_step_max"])*1e3,float(CurrRec["specimen_dec"]),float(CurrRec["specimen_inc"]),calculation_type,CurrRec['specimen_comp_name'],crd) elif 'T' in units and 'K' in units: if float(CurrRec['measurement_step_min'])<1.0 : min=float(CurrRec['measurement_step_min'])*1e3 else: min=float(CurrRec['measurement_step_min'])-273 if float(CurrRec['measurement_step_max'])<1.0 : max=float(CurrRec['measurement_step_max'])*1e3 else: max=float(CurrRec['measurement_step_max'])-273 if verbose:print '%s %i %7.1f %i %i %7.1f %7.1f %7.1f, %s %s\n' % (CurrRec["er_specimen_name"],int(CurrRec["specimen_n"]),float(CurrRec["specimen_mad"]),float(CurrRec['specimen_dang']),min,max,float(CurrRec["specimen_dec"]),float(CurrRec["specimen_inc"]),calculation_type,crd) elif 'J' in units: if verbose:print '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s %s %s \n' % (CurrRec["er_specimen_name"],int(CurrRec["specimen_n"]),float(CurrRec["specimen_mad"]),float(CurrRec['specimen_dang']),float(CurrRec["measurement_step_min"]),float(CurrRec["measurement_step_max"]),float(CurrRec["specimen_dec"]),float(CurrRec["specimen_inc"]),calculation_type,CurrRec['specimen_comp_name'],crd) elif calculation_type=='DE-FM' and crd==coord: # fisher mean if verbose:print "Specimen a95 DANG start end dec inc type component coordinates" if units=='K': if verbose:print '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %s %s %s \n' % (CurrRec["er_specimen_name"],int(CurrRec["specimen_n"]),float(CurrRec["specimen_alpha95"]),float(CurrRec["measurement_step_min"])-273,float(CurrRec["measurement_step_max"])-273,float(CurrRec["specimen_dec"]),float(CurrRec["specimen_inc"]),calculation_type,CurrRec['specimen_comp_name'],crd) elif units=='T': if verbose:print '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %s %s %s \n' % (CurrRec["er_specimen_name"],int(CurrRec["specimen_n"]),float(CurrRec["specimen_alpha95"]),float(CurrRec["measurement_step_min"])*1e3,float(CurrRec["measurement_step_max"])*1e3,float(CurrRec["specimen_dec"]),float(CurrRec["specimen_inc"]),calculation_type,CurrRec['specimen_comp_name'],crd) elif 'T' in units and 'K' in units: if float(CurrRec['measurement_step_min'])<1.0 : min=float(CurrRec['measurement_step_min'])*1e3 else: min=float(CurrRec['measurement_step_min'])-273 if float(CurrRec['measurement_step_max'])<1.0 : max=float(CurrRec['measurement_step_max'])*1e3 else: max=float(CurrRec['measurement_step_max'])-273 if verbose:print '%s %i %7.1f %i %i %7.1f %7.1f %s %s \n' % (CurrRec["er_specimen_name"],int(CurrRec["specimen_n"]),float(CurrRec["specimen_alpha95"]),min,max,float(CurrRec["specimen_dec"]),float(CurrRec["specimen_inc"]),calculation_type,crd) elif 'J' in units: if verbose:print '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %s %s %s \n' % (CurrRec["er_specimen_name"],int(CurrRec["specimen_n"]),float(CurrRec["specimen_mad"]),float(CurrRec["measurement_step_min"]),float(CurrRec["measurement_step_max"]),float(CurrRec["specimen_dec"]),float(CurrRec["specimen_inc"]),calculation_type,CurrRec['specimen_comp_name'],crd) if len(CurrRecs)==0:beg_pca,end_pca="","" datablock=data noskip=1 if len(datablock) <3: noskip=0 if backup==0: k+=1 else: k-=1 if len(CurrRecs)>0: for rec in CurrRecs: PriorRecs.append(rec) CurrRecs=[] else: backup=0 if noskip: # # find replicate measurements at given treatment step and average them # # step_meth,avedata=pmag.vspec(data) # if len(avedata) != len(datablock): # if doave==1: # method_codes.append("DE-VM") # datablock=avedata # # # do geo or stratigraphic correction now # if geo==1: # # find top priority orientation method orient,az_type=pmag.get_orient(samp_data,PmagSpecRec["er_sample_name"]) if az_type=='SO-NO': if verbose: print "no orientation data for ",s orient["sample_azimuth"]=0 orient["sample_dip"]=0 noorient=1 method_codes.append("SO-NO") orient["sample_azimuth"]=0 orient["sample_dip"]=0 orient["sample_bed_dip_azimuth"]=0 orient["sample_bed_dip"]=0 noorient=1 method_codes.append("SO-NO") else: noorient=0 # # if stratigraphic selected, get stratigraphic correction # tiltblock,geoblock=[],[] for rec in datablock: d_geo,i_geo=pmag.dogeo(rec[1],rec[2],float(orient["sample_azimuth"]),float(orient["sample_dip"])) geoblock.append([rec[0],d_geo,i_geo,rec[3],rec[4],rec[5],rec[6]]) if tilt==1 and "sample_bed_dip" in orient.keys() and float(orient['sample_bed_dip'])!=0: d_tilt,i_tilt=pmag.dotilt(d_geo,i_geo,float(orient["sample_bed_dip_direction"]),float(orient["sample_bed_dip"])) tiltblock.append([rec[0],d_tilt,i_tilt,rec[3],rec[4],rec[5],rec[6]]) if tilt==1: plotblock=tiltblock if geo==1 and tilt==0:plotblock=geoblock if geo==0 and tilt==0: plotblock=datablock # # set the end pca point to last point if not set if e==0 or e>len(plotblock)-1: e=len(plotblock)-1 if angle=="": angle=plotblock[0][1] # rotate to NRM declination title=s+'_s' if geo==1 and tilt==0 and noorient!=1:title=s+'_g' if tilt==1 and noorient!=1:title=s+'_t' pmagplotlib.plotZED(ZED,plotblock,angle,title,units) if verbose:pmagplotlib.drawFIGS(ZED) if len(CurrRecs)!=0: for prec in CurrRecs: if 'calculation_type' not in prec.keys(): calculation_type='' else: calculation_type=prec["calculation_type"] direction_type=prec["specimen_direction_type"] if calculation_type !="": beg_pca,end_pca="","" for j in range(len(datablock)): if data[j][0]==float(prec["measurement_step_min"]):beg_pca=j if data[j][0]==float(prec["measurement_step_max"]):end_pca=j if beg_pca=="" or end_pca=="": if verbose: print "something wrong with prior interpretation " break if calculation_type!="": if beg_pca=="":beg_pca=0 if end_pca=="":end_pca=len(plotblock)-1 if geo==1 and tilt==0: mpars=pmag.domean(geoblock,beg_pca,end_pca,calculation_type) if mpars["specimen_direction_type"]!="Error": pmagplotlib.plotDir(ZED,mpars,geoblock,angle) if verbose:pmagplotlib.drawFIGS(ZED) if geo==1 and tilt==1: mpars=pmag.domean(tiltblock,beg_pca,end_pca,calculation_type) if mpars["specimen_direction_type"]!="Error": pmagplotlib.plotDir(ZED,mpars,tiltblock,angle) if verbose:pmagplotlib.drawFIGS(ZED) if geo==0 and tilt==0: mpars=pmag.domean(datablock,beg_pca,end_pca,calculation_type) if mpars["specimen_direction_type"]!="Error": pmagplotlib.plotDir(ZED,mpars,plotblock,angle) if verbose:pmagplotlib.drawFIGS(ZED) # # print out data for this sample to screen # recnum=0 for plotrec in plotblock: if units=='T' and verbose: print '%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % (plotrec[5], recnum,plotrec[0]*1e3," mT",plotrec[3],plotrec[1],plotrec[2],plotrec[6]) if units=="K" and verbose: print '%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % (plotrec[5], recnum,plotrec[0]-273,' C',plotrec[3],plotrec[1],plotrec[2],plotrec[6]) if units=="J" and verbose: print '%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % (plotrec[5], recnum,plotrec[0],' J',plotrec[3],plotrec[1],plotrec[2],plotrec[6]) if 'K' in units and 'T' in units: if plotrec[0]>=1. and verbose: print '%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % (plotrec[5], recnum,plotrec[0]-273,' C',plotrec[3],plotrec[1],plotrec[2],plotrec[6]) if plotrec[0]<1. and verbose: print '%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % (plotrec[5], recnum,plotrec[0]*1e3," mT",plotrec[3],plotrec[1],plotrec[2],plotrec[6]) recnum += 1 if specimen!="": if plot_file=="": basename=locname+'_'+s else: basename=plot_file files={} for key in ZED.keys(): files[key]=basename+'_'+key+'.'+fmt pmagplotlib.saveP(ZED,files) sys.exit() else: # interactive if plots==0: ans='b' k+=1 changeS=0 while ans != "": if len(CurrRecs)==0: print """ g/b: indicates good/bad measurement. "bad" measurements excluded from calculation set s[a]ve plot, [b]ounds for pca and calculate, [p]revious, [s]pecimen, change [h]orizontal projection angle, change [c]oordinate systems, [e]dit data, [q]uit: """ else: print """ g/b: indicates good/bad measurement. "bad" measurements excluded from calculation set s[a]ve plot, [b]ounds for pca and calculate, [p]revious, [s]pecimen, change [h]orizontal projection angle, change [c]oordinate systems, [d]elete current interpretation(s), [e]dit data, [q]uit: """ ans=raw_input('<Return> for next specimen \n') setangle=0 if ans=='d': # delete this interpretation CurrRecs=[] k-=1 # replot same specimen ans="" changeS=1 if ans=='q': if changeM==1: ans=raw_input('Save changes to magic_measurements.txt? y/[n] ') if ans=='y': pmag.magic_write(meas_file,meas_data,'magic_measurements') print "Good bye" sys.exit() if ans=='a': if plot_file=="": basename=locname+'_'+s+'_' else: basename=plot_file files={} for key in ZED.keys(): files[key]=basename+'_'+coord+'_'+key+'.'+fmt pmagplotlib.saveP(ZED,files) ans="" if ans=='p': k-=2 ans="" backup=1 if ans=='c': k-=1 # replot same block if tilt==0 and geo ==1:print "You are currently viewing geographic coordinates " if tilt==1 and geo ==1:print "You are currently viewing stratigraphic coordinates " if tilt==0 and geo ==0: print "You are currently viewing sample coordinates " print "\n Which coordinate system do you wish to view? " coord=raw_input(" <Return> specimen, [g] geographic, [t] tilt corrected ") if coord=="g":geo,tilt=1,0 if coord=="t": geo=1 tilt=1 if coord=="": coord='s' geo=0 tilt=0 if geo==1 and sfile=="": samp_file=raw_input(" Input er_samples file for sample orientations [er_samples.txt] " ) if samp_file=="":samp_file="er_samples.txt" samp_data,file_type=pmag.magic_read(samp_file) if file_type != 'er_samples': print file_type print "This is not a valid er_samples file - coordinate system not changed" else: sfile="ok" ans="" if ans=='s': keepon=1 sample=raw_input('Enter desired specimen name (or first part there of): ') while keepon==1: try: k =sids.index(sample) keepon=0 except: tmplist=[] for qq in range(len(sids)): if sample in sids[qq]:tmplist.append(sids[qq]) print sample," not found, but this was: " print tmplist sample=raw_input('Select one or try again\n ') angle,direction_type="","" setangle=0 ans="" if ans=='h': k-=1 angle=raw_input("Enter desired declination for X axis 0-360 ") angle=float(angle) if angle==0:angle=0.001 s=sids[k] setangle=1 ans="" if ans=='e': k-=1 ans="" recnum=0 for plotrec in plotblock: if plotrec[0]<=200 and verbose: print '%s: %i %7.1f %s %8.3e %7.1f %7.1f ' % (plotrec[5], recnum,plotrec[0]*1e3," mT",plotrec[3],plotrec[1],plotrec[2]) if plotrec[0]>200 and verbose: print '%s: %i %7.1f %s %8.3e %7.1f %7.1f ' % (plotrec[5], recnum,plotrec[0]-273,' C',plotrec[3],plotrec[1],plotrec[2]) recnum += 1 answer=raw_input('Enter index of point to change from bad to good or vice versa: ') try: ind=int(answer) meas_data=pmag.mark_dmag_rec(s,ind,meas_data) changeM=1 except: 'bad entry, try again' if ans=='b': if end_pca=="":end_pca=len(plotblock)-1 if beg_pca=="":beg_pca=0 k-=1 # stay on same sample until through GoOn=0 while GoOn==0: print 'Enter index of first point for pca: ','[',beg_pca,']' answer=raw_input('return to keep default ') if answer != "": beg_pca=int(answer) print 'Enter index of last point for pca: ','[',end_pca,']' answer=raw_input('return to keep default ') try: end_pca=int(answer) if plotblock[beg_pca][5]=='b' or plotblock[end_pca][5]=='b': print "Can't select 'bad' measurement for PCA bounds -try again" end_pca=len(plotblock)-1 beg_pca=0 elif beg_pca >=0 and beg_pca<=len(plotblock)-2 and end_pca>0 and end_pca<len(plotblock): GoOn=1 else: print beg_pca,end_pca, " are bad entry of indices - try again" end_pca=len(plotblock)-1 beg_pca=0 except: print beg_pca,end_pca, " are bad entry of indices - try again" end_pca=len(plotblock)-1 beg_pca=0 GoOn=0 while GoOn==0: if calculation_type!="": print "Prior calculation type = ",calculation_type ct=raw_input('Enter new Calculation Type: best-fit line, plane or fisher mean [l]/p/f : ' ) if ct=="" or ct=="l": direction_type="l" calculation_type="DE-BFL" GoOn=1 elif ct=='p': direction_type="p" calculation_type="DE-BFP" GoOn=1 elif ct=='f': direction_type="l" calculation_type="DE-FM" GoOn=1 else: print "bad entry of calculation type: try again. " pmagplotlib.plotZED(ZED,plotblock,angle,s,units) if verbose:pmagplotlib.drawFIGS(ZED) if geo==1 and tilt==0: mpars=pmag.domean(geoblock,beg_pca,end_pca,calculation_type) if mpars['specimen_direction_type']=='Error':break PmagSpecRec["specimen_dec"]='%7.1f ' %(mpars["specimen_dec"]) PmagSpecRec["specimen_inc"]='%7.1f ' %(mpars["specimen_inc"]) if "SO-NO" not in method_codes: PmagSpecRec["specimen_tilt_correction"]='0' method_codes.append("DA-DIR-GEO") else: PmagSpecRec["specimen_tilt_correction"]='-1' pmagplotlib.plotDir(ZED,mpars,geoblock,angle) if verbose:pmagplotlib.drawFIGS(ZED) if geo==1 and tilt==1: mpars=pmag.domean(tiltblock,beg_pca,end_pca,calculation_type) if mpars['specimen_direction_type']=='Error':break PmagSpecRec["specimen_dec"]='%7.1f ' %(mpars["specimen_dec"]) PmagSpecRec["specimen_inc"]='%7.1f ' %(mpars["specimen_inc"]) if "SO-NO" not in method_codes: PmagSpecRec["specimen_tilt_correction"]='100' method_codes.append("DA-DIR-TILT") else: PmagSpecRec["specimen_tilt_correction"]='-1' pmagplotlib.plotDir(ZED,mpars,tiltblock,angle) if verbose:pmagplotlib.drawFIGS(ZED) if geo==0 and tilt==0: mpars=pmag.domean(datablock,beg_pca,end_pca,calculation_type) if mpars['specimen_direction_type']=='Error':break PmagSpecRec["specimen_dec"]='%7.1f ' %(mpars["specimen_dec"]) PmagSpecRec["specimen_inc"]='%7.1f ' %(mpars["specimen_inc"]) PmagSpecRec["specimen_tilt_correction"]='-1' pmagplotlib.plotDir(ZED,mpars,plotblock,angle) if verbose:pmagplotlib.drawFIGS(ZED) PmagSpecRec["measurement_step_min"]='%8.3e ' %(mpars["measurement_step_min"]) PmagSpecRec["measurement_step_max"]='%8.3e ' %(mpars["measurement_step_max"]) PmagSpecRec["specimen_correction"]='u' PmagSpecRec["specimen_dang"]='%7.1f ' %(mpars['specimen_dang']) print 'DANG: ',PmagSpecRec["specimen_dang"] if calculation_type!='DE-FM': PmagSpecRec["specimen_mad"]='%7.1f ' %(mpars["specimen_mad"]) PmagSpecRec["specimen_alpha95"]="" else: PmagSpecRec["specimen_alpha95"]='%7.1f ' %(mpars["specimen_alpha95"]) PmagSpecRec["specimen_mad"]="" PmagSpecRec["specimen_n"]='%i ' %(mpars["specimen_n"]) PmagSpecRec["specimen_direction_type"]=direction_type PmagSpecRec["calculation_type"]=calculation_type # redundant and won't be imported - just for convenience method_codes=PmagSpecRec["magic_method_codes"].split(':') if len(method_codes) != 0: methstring="" for meth in method_codes: ctype=meth.split('-') if 'DE' not in ctype:methstring=methstring+ ":" +meth # don't include old direction estimation methods methstring=methstring+':'+calculation_type PmagSpecRec["magic_method_codes"]= methstring.strip(':') print 'Method codes: ',PmagSpecRec['magic_method_codes'] if calculation_type!='DE-FM': if units=='K': print '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f, %s \n' % (PmagSpecRec["er_specimen_name"],int(PmagSpecRec["specimen_n"]),float(PmagSpecRec["specimen_mad"]),float(PmagSpecRec["specimen_dang"]),float(PmagSpecRec["measurement_step_min"])-273,float(PmagSpecRec["measurement_step_max"])-273,float(PmagSpecRec["specimen_dec"]),float(PmagSpecRec["specimen_inc"]),calculation_type) elif units== 'T': print '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f, %s \n' % (PmagSpecRec["er_specimen_name"],int(PmagSpecRec["specimen_n"]),float(PmagSpecRec["specimen_mad"]),float(PmagSpecRec["specimen_dang"]),float(PmagSpecRec["measurement_step_min"])*1e3,float(PmagSpecRec["measurement_step_max"])*1e3,float(PmagSpecRec["specimen_dec"]),float(PmagSpecRec["specimen_inc"]),calculation_type) elif 'T' in units and 'K' in units: if float(PmagSpecRec['measurement_step_min'])<1.0 : min=float(PmagSpecRec['measurement_step_min'])*1e3 else: min=float(PmagSpecRec['measurement_step_min'])-273 if float(PmagSpecRec['measurement_step_max'])<1.0 : max=float(PmagSpecRec['measurement_step_max'])*1e3 else: max=float(PmagSpecRec['measurement_step_max'])-273 print '%s %i %7.1f %i %i %7.1f %7.1f %7.1f, %s \n' % (PmagSpecRec["er_specimen_name"],int(PmagSpecRec["specimen_n"]),float(PmagSpecRec["specimen_mad"]),float(PmagSpecRec["specimen_dang"]),min,max,float(PmagSpecRec["specimen_dec"]),float(PmagSpecRec["specimen_inc"]),calculation_type) else: print '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f, %s \n' % (PmagSpecRec["er_specimen_name"],int(PmagSpecRec["specimen_n"]),float(PmagSpecRec["specimen_mad"]),float(PmagSpecRec["specimen_dang"]),float(PmagSpecRec["measurement_step_min"]),float(PmagSpecRec["measurement_step_max"]),float(PmagSpecRec["specimen_dec"]),float(PmagSpecRec["specimen_inc"]),calculation_type) else: if 'K' in units: print '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f, %s \n' % (PmagSpecRec["er_specimen_name"],int(PmagSpecRec["specimen_n"]),float(PmagSpecRec["specimen_alpha95"]),float(PmagSpecRec["specimen_dang"]),float(PmagSpecRec["measurement_step_min"])-273,float(PmagSpecRec["measurement_step_max"])-273,float(PmagSpecRec["specimen_dec"]),float(PmagSpecRec["specimen_inc"]),calculation_type) elif 'T' in units: print '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f, %s \n' % (PmagSpecRec["er_specimen_name"],int(PmagSpecRec["specimen_n"]),float(PmagSpecRec["specimen_alpha95"]),float(PmagSpecRec["specimen_dang"]),float(PmagSpecRec["measurement_step_min"])*1e3,float(PmagSpecRec["measurement_step_max"])*1e3,float(PmagSpecRec["specimen_dec"]),float(PmagSpecRec["specimen_inc"]),calculation_type) elif 'T' in units and 'K' in units: if float(PmagSpecRec['measurement_step_min'])<1.0 : min=float(PmagSpecRec['measurement_step_min'])*1e3 else: min=float(PmagSpecRec['measurement_step_min'])-273 if float(PmagSpecRec['measurement_step_max'])<1.0 : max=float(PmagSpecRec['measurement_step_max'])*1e3 else: max=float(PmagSpecRec['measurement_step_max'])-273 print '%s %i %7.1f %i %i %7.1f %7.1f, %s \n' % (PmagSpecRec["er_specimen_name"],int(PmagSpecRec["specimen_n"]),float(PmagSpecRec["specimen_alpha95"]),min,max,float(PmagSpecRec["specimen_dec"]),float(PmagSpecRec["specimen_inc"]),calculation_type) else: print '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f, %s \n' % (PmagSpecRec["er_specimen_name"],int(PmagSpecRec["specimen_n"]),float(PmagSpecRec["specimen_alpha95"]),float(PmagSpecRec["measurement_step_min"]),float(PmagSpecRec["measurement_step_max"]),float(PmagSpecRec["specimen_dec"]),float(PmagSpecRec["specimen_inc"]),calculation_type) saveit=raw_input("Save this interpretation? [y]/n \n") if saveit!="n": changeS=1 # # put in details # angle,direction_type,setangle="","",0 if len(CurrRecs)>0: replace=raw_input(" [0] add new component, or [1] replace existing interpretation(s) [default is replace] ") if replace=="1" or replace=="": CurrRecs=[] PmagSpecRec['specimen_comp_name']='A' CurrRecs.append(PmagSpecRec) else: print 'These are the current component names for this specimen: ' for trec in CurrRecs:print trec['specimen_comp_name'] compnum=raw_input("Enter new component name: ") PmagSpecRec['specimen_comp_name']=compnum print "Adding new component: ",PmagSpecRec['specimen_comp_name'] CurrRecs.append(PmagSpecRec) else: PmagSpecRec['specimen_comp_name']='A' CurrRecs.append(PmagSpecRec) k+=1 ans="" else: ans="" else: # plots=1 k+=1 files={} locname.replace('/','-') print PmagSpecRec for key in ZED.keys(): files[key]="LO:_"+locname+'_SI:_'+PmagSpecRec['er_site_name']+'_SA:_'+PmagSpecRec['er_sample_name']+'_SP:_'+s+'_CO:_'+coord+'_TY:_'+key+'_.'+fmt if pmagplotlib.isServer: black = '#000000' purple = '#800080' titles={} titles['demag']='DeMag Plot' titles['zijd']='Zijderveld Plot' titles['eqarea']='Equal Area Plot' ZED = pmagplotlib.addBorders(ZED,titles,black,purple) pmagplotlib.saveP(ZED,files) if len(CurrRecs)>0: for rec in CurrRecs: PriorRecs.append(rec) if changeS==1: if len(PriorRecs)>0: save_redo(PriorRecs,inspec) else: os.system('rm '+inspec) CurrRecs,beg_pca,end_pca=[],"","" # next up changeS=0 else: k+=1 # skip record - not enough data if changeM==1: pmag.magic_write(meas_file,meas_data,'magic_measurements')
def main(): """ NAME dmag_magic.py DESCRIPTION plots intensity decay curves for demagnetization experiments SYNTAX dmag_magic -h [command line options] INPUT takes magic formatted magic_measurements.txt files OPTIONS -h prints help message and quits -f FILE: specify input file, default is: magic_measurements.txt -obj OBJ: specify object [loc, sit, sam, spc] for plot, default is by location -LT [AF,T,M]: specify lab treatment type, default AF -XLP [PI]: exclude specific lab protocols (for example, method codes like LP-PI) -N do not normalize by NRM magnetization NOTE loc: location (study); sit: site; sam: sample; spc: specimen """ FIG={} # plot dictionary FIG['demag']=1 # demag is figure 1 in_file,plot_key,LT='magic_measurements.txt','er_location_name',"LT-AF-Z" XLP="" norm=1 LT='LT-AF-Z' units,dmag_key='T','treatment_ac_field' plot_key='er_location_name' if len(sys.argv)>1: if '-h' in sys.argv: print main.__doc__ sys.exit() if '-N' in sys.argv: norm=0 if '-f' in sys.argv: ind=sys.argv.index("-f") in_file=sys.argv[ind+1] if '-obj' in sys.argv: ind=sys.argv.index('-obj') plot_by=sys.argv[ind+1] 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 '-XLP' in sys.argv: ind=sys.argv.index("-XLP") XLP=sys.argv[ind+1] # get lab protocol for excluding if '-LT' in sys.argv: ind=sys.argv.index("-LT") LT='LT-'+sys.argv[ind+1]+'-Z' # get lab treatment for plotting if LT=='LT-T-Z': units,dmag_key='K','treatment_temp' elif LT=='LT-AF-Z': units,dmag_key='T','treatment_ac_field' elif LT=='LT-M-Z': units,dmag_key='J','treatment_mw_energy' else: units='U' data,file_type=pmag.magic_read(in_file) sids=pmag.get_specs(data) pmagplotlib.plot_init(FIG['demag'],5,5) print len(data),' records read from ',in_file # # # find desired intensity data # # get plotlist # plotlist,intlist=[],['measurement_magnitude','measurement_magn_moment','measurement_magn_volume','measurement_magn_mass'] IntMeths=[] FixData=[] for rec in data: meths=[] methcodes=rec['magic_method_codes'].split(':') for meth in methcodes:meths.append(meth.strip()) for key in rec.keys(): if key in intlist and rec[key]!="": if key not in IntMeths:IntMeths.append(key) if rec[plot_key] not in plotlist and LT in meths: plotlist.append(rec[plot_key]) if 'measurement_flag' not in rec.keys():rec['measurement_flag']='g' FixData.append(rec) plotlist.sort() if len(IntMeths)==0: print 'No intensity information found' sys.exit() data=FixData int_key=IntMeths[0] # plot first intensity method found - normalized to initial value anyway - doesn't matter which used for plot in plotlist: print plot,'plotting by: ',plot_key PLTblock=pmag.get_dictitem(data,plot_key,plot,'T') # fish out all the data for this type of plot PLTblock=pmag.get_dictitem(PLTblock,'magic_method_codes',LT,'has') # fish out all the dmag for this experiment type PLTblock=pmag.get_dictitem(PLTblock,int_key,'','F') # get all with this intensity key non-blank if XLP!="":PLTblock=pmag.get_dictitem(PLTblock,'magic_method_codes',XLP,'not') # reject data with XLP in method_code if len(PLTblock)>2: title=PLTblock[0][plot_key] spcs=[] for rec in PLTblock: if rec['er_specimen_name'] not in spcs:spcs.append(rec['er_specimen_name']) for spc in spcs: SPCblock=pmag.get_dictitem(PLTblock,'er_specimen_name',spc,'T') # plot specimen by specimen INTblock=[] for rec in SPCblock: INTblock.append([float(rec[dmag_key]),0,0,float(rec[int_key]),1,rec['measurement_flag']]) if len(INTblock)>2: pmagplotlib.plotMT(FIG['demag'],INTblock,title,0,units,norm) pmagplotlib.drawFIGS(FIG) ans=raw_input(" S[a]ve to save plot, [q]uit, Return to continue: ") if ans=='q':sys.exit() if ans=="a": files={} for key in FIG.keys(): files[key]=title+'_'+LT+'.svg' pmagplotlib.saveP(FIG,files) pmagplotlib.clearFIG(FIG['demag'])
def main(): """ NAME convert_samples.py DESCRIPTION takes an er_samples or magic_measurements format file and creates an orient.txt template SYNTAX convert_samples.py [command line options] OPTIONS -f FILE: specify input file, default is er_samples.txt -F FILE: specify output file, default is: orient_LOCATION.txt INPUT FORMAT er_samples.txt or magic_measurements format file OUTPUT orient.txt format file """ # # initialize variables # version_num = pmag.get_version() orient_file, samp_file = "orient", "er_samples.txt" args = sys.argv dir_path, out_path = ".", "." default_outfile = True # # if "-WD" in args: ind = args.index("-WD") dir_path = args[ind + 1] if "-OD" in args: ind = args.index("-OD") out_path = args[ind + 1] if "-h" in args: print main.__doc__ sys.exit() if "-F" in args: ind = args.index("-F") orient_file = sys.argv[ind + 1] default_outfile = False if "-f" in args: ind = args.index("-f") samp_file = sys.argv[ind + 1] orient_file = out_path + "/" + orient_file samp_file = dir_path + "/" + samp_file # # read in file to convert # ErSamples = [] Required = ["sample_class", "sample_type", "sample_lithology", "lat", "long"] Samps, file_type = pmag.magic_read(samp_file) Locs = [] OrKeys = [ "sample_name", "site_name", "mag_azimuth", "field_dip", "sample_class", "sample_type", "sample_lithology", "lat", "long", "stratigraphic_height", "method_codes", "site_description", ] print "file_type", file_type # LJ if file_type.lower() == "er_samples": SampKeys = [ "er_sample_name", "er_site_name", "sample_azimuth", "sample_dip", "sample_class", "sample_type", "sample_lithology", "sample_lat", "sample_lon", "sample_height", "magic_method_codes", "er_sample_description", ] elif file_type.lower() == "magic_measurements": SampKeys = ["er_sample_name", "er_site_name"] else: print "wrong file format; must be er_samples or magic_measurements only" for samp in Samps: if samp["er_location_name"] not in Locs: Locs.append(samp["er_location_name"]) # get all the location names for location_name in Locs: loc_samps = pmag.get_dictitem(Samps, "er_location_name", location_name, "T") OrOut = [] for samp in loc_samps: if samp["er_sample_name"] not in ErSamples: ErSamples.append(samp["er_sample_name"]) OrRec = {} if "sample_date" in samp.keys() and samp["sample_date"].strip() != "": date = samp["sample_date"].split(":") OrRec["date"] = date[1] + "/" + date[2] + "/" + date[0][2:4] for i in range(len(SampKeys)): if SampKeys[i] in samp.keys(): OrRec[OrKeys[i]] = samp[SampKeys[i]] for key in Required: if key not in OrRec.keys(): OrRec[key] = "" # fill in blank required keys OrOut.append(OrRec) loc = location_name.replace(" ", "_") if default_outfile: outfile = orient_file + "_" + loc + ".txt" else: outfile = orient_file pmag.magic_write(outfile, OrOut, location_name) print "Data saved in: ", outfile
def main(): """ NAME irmaq_magic.py DESCRIPTION plots IRM acquisition curves from magic_measurements file SYNTAX irmaq_magic [command line options] INPUT takes magic formatted magic_measurements.txt files OPTIONS -h prints help message and quits -f FILE: specify input file, default is: magic_measurements.txt -obj OBJ: specify object [loc, sit, sam, spc] for plot, default is by location -N ; do not normalize by last point - use original units NOTE loc: location (study); sit: site; sam: sample; spc: specimen """ FIG={} # plot dictionary FIG['exp']=1 # exp is figure 1 dir_path='./' units,dmag_key='T','treatment_dc_field' XLP=[] norm=1 in_file,plot_key,LP='magic_measurements.txt','er_location_name',"LP-IRM" if len(sys.argv)>1: if '-h' in sys.argv: print main.__doc__ sys.exit() if '-N' in sys.argv:norm=0 if '-f' in sys.argv: ind=sys.argv.index("-f") in_file=sys.argv[ind+1] if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] in_file=dir_path+'/'+in_file if '-obj' in sys.argv: ind=sys.argv.index('-obj') plot_by=sys.argv[ind+1] 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' data,file_type=pmag.magic_read(in_file) sids=pmag.get_specs(data) pmagplotlib.plot_init(FIG['exp'],6,6) # # # find desired intensity data # # get plotlist # plotlist,intlist=[],['measurement_magnitude','measurement_magn_moment','measurement_magn_volume','measurement_magn_mass'] IntMeths=[] data=pmag.get_dictitem(data,'magic_method_codes',LP,'has') # get all the records with this lab protocol Ints={} NoInts,int_key=1,"" for key in intlist: Ints[key]=pmag.get_dictitem(data,key,'','F') # get all non-blank data for intensity type if len(Ints[key])>0: NoInts=0 if int_key=="":int_key=key if NoInts==1: print 'No intensity information found' sys.exit() for rec in Ints[int_key]: if rec[plot_key] not in plotlist: plotlist.append(rec[plot_key]) plotlist.sort() for plot in plotlist: print plot INTblock=[] data=pmag.get_dictitem(Ints[int_key],plot_key,plot,'T') # get data with right intensity info whose plot_key matches plot sids=pmag.get_specs(data) # get a list of specimens with appropriate data if len(sids)>0: title=data[0][plot_key] for s in sids: INTblock=[] sdata=pmag.get_dictitem(data,'er_specimen_name',s,'T') # get data for each specimen for rec in sdata: INTblock.append([float(rec[dmag_key]),0,0,float(rec[int_key]),1,'g']) pmagplotlib.plotMT(FIG['exp'],INTblock,title,0,units,norm) pmagplotlib.drawFIGS(FIG) ans=raw_input(" S[a]ve to save plot, [q]uit, Return to continue: ") if ans=='q':sys.exit() if ans=="a": files={} for key in FIG.keys(): files[key]=title+'_'+LP+'.svg' pmagplotlib.saveP(FIG,files) pmagplotlib.clearFIG(FIG['exp'])
def main(): """ NAME foldtest_magic.py DESCRIPTION does a fold test (Tauxe, 2010) on data INPUT FORMAT pmag_specimens format file, er_samples.txt format file (for bedding) SYNTAX foldtest_magic.py [command line options] OPTIONS -h prints help message and quits -f pmag_sites formatted file [default is pmag_sites.txt] -fsa er_samples formatted file [default is er_samples.txt] -exc use pmag_criteria.txt to set acceptance criteria -n NB, set number of bootstraps, default is 1000 -b MIN, MAX, set bounds for untilting, default is -10, 150 -fmt FMT, specify format - default is svg OUTPUT Geographic: is an equal area projection of the input data in original coordinates Stratigraphic: is an equal area projection of the input data in tilt adjusted coordinates % Untilting: The dashed (red) curves are representative plots of maximum eigenvalue (tau_1) as a function of untilting The solid line is the cumulative distribution of the % Untilting required to maximize tau for all the bootstrapped data sets. The dashed vertical lines are 95% confidence bounds on the % untilting that yields the most clustered result (maximum tau_1). Command line: prints out the bootstrapped iterations and finally the confidence bounds on optimum untilting. If the 95% conf bounds include 0, then a pre-tilt magnetization is indicated If the 95% conf bounds include 100, then a post-tilt magnetization is indicated If the 95% conf bounds exclude both 0 and 100, syn-tilt magnetization is possible as is vertical axis rotation or other pathologies """ kappa=0 nb=1000 # number of bootstraps min,max=-10,150 dir_path='.' infile,orfile='pmag_sites.txt','er_samples.txt' critfile='pmag_criteria.txt' fmt='svg' if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] if '-h' in sys.argv: # check if help is needed print main.__doc__ sys.exit() # graceful quit if '-n' in sys.argv: ind=sys.argv.index('-n') nb=int(sys.argv[ind+1]) if '-fmt' in sys.argv: ind=sys.argv.index('-fmt') fmt=sys.argv[ind+1] if '-b' in sys.argv: ind=sys.argv.index('-b') min=int(sys.argv[ind+1]) max=int(sys.argv[ind+2]) if '-f' in sys.argv: ind=sys.argv.index('-f') infile=sys.argv[ind+1] if '-fsa' in sys.argv: ind=sys.argv.index('-fsa') orfile=sys.argv[ind+1] orfile=dir_path+'/'+orfile infile=dir_path+'/'+infile critfile=dir_path+'/'+critfile data,file_type=pmag.magic_read(infile) 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 break # get to work # PLTS={'geo':1,'strat':2,'taus':3} # make plot dictionary pmagplotlib.plot_init(PLTS['geo'],5,5) pmagplotlib.plot_init(PLTS['strat'],5,5) pmagplotlib.plot_init(PLTS['taus'],5,5) GEOrecs=pmag.get_dictitem(data,'site_tilt_correction','0','T') if len(GEOrecs)>0: # have some geographic data DIDDs= [] # set up list for dec inc dip_direction, dip for rec in GEOrecs: # parse data dip,dip_dir=0,-1 Dec=float(rec['site_dec']) Inc=float(rec['site_inc']) orecs=pmag.get_dictitem(ordata,'er_site_name',rec['er_site_name'],'T') if len(orecs)>0: if orecs[0]['sample_bed_dip_direction']!="":dip_dir=float(orecs[0]['sample_bed_dip_direction']) if orecs[0]['sample_bed_dip']!="":dip=float(orecs[0]['sample_bed_dip']) if dip!=0 and dip_dir!=-1: if '-exc' in sys.argv: keep=1 for key in SiteCrit.keys(): if 'site' in key and SiteCrit[key]!="" and rec[key]!="" and key!='site_alpha95': if float(rec[key])<float(SiteCrit[key]): keep=0 print rec['er_site_name'],key,rec[key] if key=='site_alpha95' and SiteCrit[key]!="" and rec[key]!="": if float(rec[key])>float(SiteCrit[key]): keep=0 if keep==1: DIDDs.append([Dec,Inc,dip_dir,dip]) else: DIDDs.append([Dec,Inc,dip_dir,dip]) else: print 'no geographic directional data found' sys.exit() pmagplotlib.plotEQ(PLTS['geo'],DIDDs,'Geographic') data=numpy.array(DIDDs) D,I=pmag.dotilt_V(data) TCs=numpy.array([D,I]).transpose() pmagplotlib.plotEQ(PLTS['strat'],TCs,'Stratigraphic') pmagplotlib.drawFIGS(PLTS) Percs=range(min,max) Cdf,Untilt=[],[] pylab.figure(num=PLTS['taus']) print 'doing ',nb,' iterations...please be patient.....' for n in range(nb): # do bootstrap data sets - plot first 25 as dashed red line if n%50==0:print n Taus=[] # set up lists for taus PDs=pmag.pseudo(DIDDs) if kappa!=0: for k in range(len(PDs)): d,i=pmag.fshdev(kappa) dipdir,dip=pmag.dodirot(d,i,PDs[k][2],PDs[k][3]) PDs[k][2]=dipdir PDs[k][3]=dip for perc in Percs: tilt=numpy.array([1.,1.,1.,0.01*perc]) D,I=pmag.dotilt_V(PDs*tilt) TCs=numpy.array([D,I]).transpose() ppars=pmag.doprinc(TCs) # get principal directions Taus.append(ppars['tau1']) if n<25:pylab.plot(Percs,Taus,'r--') Untilt.append(Percs[Taus.index(numpy.max(Taus))]) # tilt that gives maximum tau Cdf.append(float(n)/float(nb)) pylab.plot(Percs,Taus,'k') pylab.xlabel('% Untilting') pylab.ylabel('tau_1 (red), CDF (green)') Untilt.sort() # now for CDF of tilt of maximum tau pylab.plot(Untilt,Cdf,'g') lower=int(.025*nb) upper=int(.975*nb) pylab.axvline(x=Untilt[lower],ymin=0,ymax=1,linewidth=1,linestyle='--') pylab.axvline(x=Untilt[upper],ymin=0,ymax=1,linewidth=1,linestyle='--') tit= '%i - %i %s'%(Untilt[lower],Untilt[upper],'Percent Unfolding') print tit pylab.title(tit) pmagplotlib.drawFIGS(PLTS) ans= raw_input('S[a]ve all figures, <Return> to quit \n ') if ans!='a': print "Good bye" sys.exit() files={} for key in PLTS.keys(): files[key]=('foldtest_'+'%s'%(key.strip()[:2])+'.'+fmt) pmagplotlib.saveP(PLTS,files)
def main(): """ NAME quick_hyst.py DESCRIPTION makes plots of hysteresis data SYNTAX quick_hyst.py [command line options] OPTIONS -h prints help message and quits -usr USER: identify user, default is "" -f: specify input file, default is magic_measurements.txt -spc SPEC: specify specimen name to plot and quit -sav save all plots and quit -fmt [png,svg,eps,jpg] """ args=sys.argv PLT=1 plots=0 user,meas_file="","magic_measurements.txt" pltspec="" dir_path='.' fmt='png' verbose=pmagplotlib.verbose version_num=pmag.get_version() if '-WD' in args: ind=args.index('-WD') dir_path=args[ind+1] if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind=args.index("-usr") user=args[ind+1] if '-f' in args: ind=args.index("-f") meas_file=args[ind+1] if '-sav' in args: verbose=0 plots=1 if '-spc' in args: ind=args.index("-spc") pltspec= args[ind+1] verbose=0 plots=1 if '-fmt' in args: ind=args.index("-fmt") fmt=args[ind+1] meas_file=dir_path+'/'+meas_file # # meas_data,file_type=pmag.magic_read(meas_file) if file_type!='magic_measurements': print main.__doc__ print 'bad file' sys.exit() # # initialize some variables # define figure numbers for hyst,deltaM,DdeltaM curves HystRecs,RemRecs=[],[] HDD={} HDD['hyst']=1 pmagplotlib.plot_init(HDD['hyst'],5,5) # # get list of unique experiment names and specimen names # experiment_names,sids=[],[] hyst_data=pmag.get_dictitem(meas_data,'magic_method_codes','LP-HYS','has') # get all hysteresis data for rec in hyst_data: if 'er_synthetic_name' in rec.keys() and rec['er_synthetic_name']!="": rec['er_specimen_name']=rec['er_synthetic_name'] if rec['magic_experiment_name'] not in experiment_names:experiment_names.append(rec['magic_experiment_name']) if rec['er_specimen_name'] not in sids:sids.append(rec['er_specimen_name']) if 'measurement_temp' not in rec.keys(): rec['measurement_temp']='300' # assume room T measurement unless otherwise specified # k=0 if pltspec!="": k=sids.index(pltspec) intlist=['measurement_magnitude','measurement_magn_moment','measurement_magn_volume','measurement_magn_mass'] while k < len(sids): locname,site,sample,synth='','','','' s=sids[k] hmeths=[] if verbose:print s, k+1 , 'out of ',len(sids) # # B,M=[],[] #B,M for hysteresis, Bdcd,Mdcd for irm-dcd data spec=pmag.get_dictitem(hyst_data,'er_specimen_name',s,'T') # get all measurements for this specimen if 'er_location_name' in spec[0].keys(): locname=spec[0]['er_location_name'] if 'er_site_name' in spec[0].keys(): site=spec[0]['er_site_name'] if 'er_sample_name' in spec[0].keys(): sample=spec[0]['er_sample_name'] if 'er_synthetic_name' in spec[0].keys(): synth=spec[0]['er_synthetic_name'] for m in intlist: meas_data=pmag.get_dictitem(spec,m,'','F') # get all non-blank data for this specimen if len(meas_data)>0: break c=['k-','b-','c-','g-','m-','r-','y-'] cnum=0 if len(meas_data)>0: Temps=[] xlab,ylab,title='','','' for rec in meas_data: if rec['measurement_temp'] not in Temps:Temps.append(rec['measurement_temp']) for t in Temps: print 'working on t: ',t t_data=pmag.get_dictitem(meas_data,'measurement_temp',t,'T') B,M=[],[] for rec in t_data: B.append(float(rec['measurement_lab_field_dc'])) M.append(float(rec[m])) # now plot the hysteresis curve(s) # if len(B)>0: B=numpy.array(B) M=numpy.array(M) if t==Temps[-1]: xlab='Field (T)' ylab=m title='Hysteresis: '+s if t==Temps[0]: pmagplotlib.clearFIG(HDD['hyst']) pmagplotlib.plotXY(HDD['hyst'],B,M,sym=c[cnum],xlab=xlab,ylab=ylab,title=title) pmagplotlib.plotXY(HDD['hyst'],[1.1*B.min(),1.1*B.max()],[0,0],sym='k-',xlab=xlab,ylab=ylab,title=title) pmagplotlib.plotXY(HDD['hyst'],[0,0],[1.1*M.min(),1.1*M.max()],sym='k-',xlab=xlab,ylab=ylab,title=title) if verbose:pmagplotlib.drawFIGS(HDD) cnum+=1 if cnum==len(c):cnum=0 # files={} if plots: if pltspec!="":s=pltspec files={} for key in HDD.keys(): if synth=='': files[key]="LO:_"+locname+'_SI:_'+site+'_SA:_'+sample+'_SP:_'+s+'_TY:_'+key+'_.'+fmt else: files[key]='SY:_'+synth+'_TY:_'+key+'_.'+fmt pmagplotlib.saveP(HDD,files) if pltspec!="":sys.exit() if verbose: pmagplotlib.drawFIGS(HDD) ans=raw_input("S[a]ve plots, [s]pecimen name, [q]uit, <return> to continue\n ") if ans=="a": files={} for key in HDD.keys(): files[key]="LO:_"+locname+'_SI:_'+site+'_SA:_'+sample+'_SP:_'+s+'_TY:_'+key+'_.'+fmt pmagplotlib.saveP(HDD,files) if ans=='':k+=1 if ans=="p": del HystRecs[-1] k-=1 if ans=='q': print "Good bye" sys.exit() if ans=='s': keepon=1 specimen=raw_input('Enter desired specimen name (or first part there of): ') while keepon==1: try: k =sids.index(specimen) keepon=0 except: tmplist=[] for qq in range(len(sids)): if specimen in sids[qq]:tmplist.append(sids[qq]) print specimen," not found, but this was: " print tmplist specimen=raw_input('Select one or try again\n ') k =sids.index(specimen) else: k+=1 if len(B)==0: if verbose:print 'skipping this one - no hysteresis data' k+=1
def main(): """ NAME pmag_results_extract.py DESCRIPTION make a tab delimited output file from pmag_results table SYNTAX pmag_results_extract.py [command line options] OPTIONS -h prints help message and quits -f RFILE, specify pmag_results table; default is pmag_results.txt -fa AFILE, specify er_ages table; default is NONE -fsp SFILE, specify pmag_specimens table, default is NONE -fcr CFILE, specify pmag_criteria table, default is NONE -g include specimen_grade in table - only works for PmagPy generated pmag_specimen formatted files. -tex, output in LaTeX format """ dir_path='.' res_file='pmag_results.txt' crit_file='' spec_file='' age_file="" latex=0 grade=0 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] if '-f' in sys.argv: ind = sys.argv.index('-f') res_file=sys.argv[ind+1] if '-fsp' in sys.argv: ind = sys.argv.index('-fsp') spec_file=sys.argv[ind+1] if '-fcr' in sys.argv: ind = sys.argv.index('-fcr') crit_file=sys.argv[ind+1] if '-fa' in sys.argv: ind = sys.argv.index('-fa') age_file=sys.argv[ind+1] if '-g' in sys.argv:grade=1 if '-tex' in sys.argv: latex=1 outfile='Directions.tex' Ioutfile='Intensities.tex' Soutfile='SiteNfo.tex' Specout='Specimens.tex' Critout='Criteria.tex' else: latex=0 outfile='Directions.txt' Ioutfile='Intensities.txt' Soutfile='SiteNfo.txt' Specout='Specimens.txt' Critout='Criteria.txt' res_file=dir_path+'/'+res_file if crit_file!="":crit_file=dir_path+'/'+crit_file if spec_file!="":spec_file=dir_path+'/'+spec_file # open output files outfile=dir_path+'/'+outfile Ioutfile=dir_path+'/'+Ioutfile Soutfile=dir_path+'/'+Soutfile Specout=dir_path+'/'+Specout Critout=dir_path+'/'+Critout f=open(outfile,'w') sf=open(Soutfile,'w') fI=open(Ioutfile,'w') cr=open(Critout,'w') # set up column headers Sites,file_type=pmag.magic_read(res_file) if crit_file!="": Crits,file_type=pmag.magic_read(crit_file) else: Crits=[] SiteCols=["Site","Samples","Location","Lat. (N)","Long. (E)","Age ","Age sigma","Units"] SiteKeys=["er_site_names","er_sample_names","average_lat","average_lon","average_age","average_age_sigma","average_age_unit"] DirCols=["Site","Samples",'Comp.',"%TC","Dec.","Inc.","Nl","Np","k ","R","a95","PLat","PLong"] DirKeys=["er_site_names","er_sample_names","pole_comp_name","tilt_correction","average_dec","average_inc","average_n_lines","average_n_planes","average_k","average_r","average_alpha95","vgp_lat","vgp_lon"] IntCols=["Site","Specimens","Samples","N","B (uT)","sigma","sigma perc","VADM","VADM sigma"] IntKeys=["er_site_names","er_specimen_names","er_sample_names","average_int_n","average_int","average_int_sigma",'average_int_sigma_perc',"vadm","vadm_sigma"] AllowedKeys=['specimen_frac','specimen_scat','specimen_gap_max','measurement_step_min', 'measurement_step_max', 'measurement_step_unit', 'specimen_polarity', 'specimen_nrm', 'specimen_direction_type', 'specimen_comp_nmb', 'specimen_mad', 'specimen_alpha95', 'specimen_n', 'specimen_int_sigma', 'specimen_int_sigma_perc', 'specimen_int_rel_sigma', 'specimen_int_rel_sigma_perc', 'specimen_int_mad', 'specimen_int_n', 'specimen_w', 'specimen_q', 'specimen_f', 'specimen_fvds', 'specimen_b_sigma', 'specimen_b_beta', 'specimen_g', 'specimen_dang', 'specimen_md', 'specimen_ptrm', 'specimen_drat', 'specimen_drats', 'specimen_rsc', 'specimen_viscosity_index', 'specimen_magn_moment', 'specimen_magn_volume', 'specimen_magn_mass', 'specimen_int_ptrm_n', 'specimen_delta', 'specimen_theta', 'specimen_gamma', 'sample_polarity', 'sample_nrm', 'sample_direction_type', 'sample_comp_nmb', 'sample_sigma', 'sample_alpha95', 'sample_n', 'sample_n_lines', 'sample_n_planes', 'sample_k', 'sample_r', 'sample_tilt_correction', 'sample_int_sigma', 'sample_int_sigma_perc', 'sample_int_rel_sigma', 'sample_int_rel_sigma_perc', 'sample_int_n', 'sample_magn_moment', 'sample_magn_volume', 'sample_magn_mass', 'site_polarity', 'site_nrm', 'site_direction_type', 'site_comp_nmb', 'site_sigma', 'site_alpha95', 'site_n', 'site_n_lines', 'site_n_planes', 'site_k', 'site_r', 'site_tilt_correction', 'site_int_sigma', 'site_int_sigma_perc', 'site_int_rel_sigma', 'site_int_rel_sigma_perc', 'site_int_n', 'site_magn_moment', 'site_magn_volume', 'site_magn_mass', 'average_age_min', 'average_age_max', 'average_age_sigma', 'average_age_unit', 'average_sigma', 'average_alpha95', 'average_n', 'average_nn', 'average_k', 'average_r', 'average_int_sigma', 'average_int_rel_sigma', 'average_int_rel_sigma_perc', 'average_int_n', 'average_int_nn', 'vgp_dp', 'vgp_dm', 'vgp_sigma', 'vgp_alpha95', 'vgp_n', 'vdm_sigma', 'vdm_n', 'vadm_sigma', 'vadm_n'] if crit_file!="": crit=Crits[0] # get a list of useful keys for key in crit.keys(): if key not in AllowedKeys:del(crit[key]) for key in crit.keys(): if crit[key]=='' or eval(crit[key])>1000 or eval(crit[key])==0:del(crit[key]) # get rid of all blank or too big ones or too little ones CritKeys=crit.keys() if spec_file!="": Specs,file_type=pmag.magic_read(spec_file) fsp=open(Specout,'w') # including specimen intensities if desired SpecCols=["Site","Specimen","B (uT)","MAD","Beta","N","Q","DANG","f-vds","DRATS","T (C)"] SpecKeys=['er_site_name','er_specimen_name','specimen_int','specimen_int_mad','specimen_b_beta','specimen_int_n','specimen_q','specimen_dang','specimen_fvds','specimen_drats','trange'] Xtra=['specimen_frac','specimen_scat','specimen_gmax'] if grade: SpecCols.append('Grade') SpecKeys.append('specimen_grade') for x in Xtra: # put in the new intensity keys if present if x in Specs[0].keys(): SpecKeys.append(x) newkey="" for k in x.split('_')[1:]:newkey=newkey+k+'_' SpecCols.append(newkey.strip('_')) SpecCols.append('Corrections') SpecKeys.append('corrections') Micro=['specimen_int','average_int','average_int_sigma'] # these should be multiplied by 1e6 Zeta=['vadm','vadm_sigma'] # these should be multiplied by 1e21 # write out the header information for each output file if latex: #write out the latex header stuff sep=' & ' end='\\\\' f.write('\\begin{table}\n') sf.write('\\begin{table}\n') fI.write('\\begin{table}\n') if crit_file!="":cr.write('\\begin{table}\n') if spec_file!="": fsp.write('\\begin{table}\n') tabstring='\\begin{tabular}{' fstring=tabstring for k in range(len(SiteCols)):fstring=fstring+'r' f.write(fstring+'}\n') f.write('\hline\n') fstring=tabstring for k in range(len(DirCols)):fstring=fstring+'r' sf.write(fstring+'}\n') sf.write('\hline\n') fstring=tabstring for k in range(len(IntCols)):fstring=fstring+'r' fI.write(fstring+'}\n') fI.write('\hline\n') fstring=tabstring if crit_file!="": for k in range(len(CritKeys)):fstring=fstring+'r' cr.write(fstring+'}\n') cr.write('\hline\n') if spec_file!="": fstring=tabstring for k in range(len(SpecCols)):fstring=fstring+'r' fsp.write(fstring+'}\n') fsp.write('\hline\n') else: # just set the tab and line endings for tab delimited sep=' \t ' end='' # now write out the actual column headers Soutstring,Doutstring,Ioutstring,Spoutstring,Croutstring="","","","","" for k in range(len(SiteCols)): Soutstring=Soutstring+SiteCols[k]+sep Soutstring=Soutstring+end Soutstring=Soutstring.strip(sep) +"\n" sf.write(Soutstring) for k in range(len(DirCols)): Doutstring=Doutstring+DirCols[k]+sep Doutstring=Doutstring+end Doutstring=Doutstring.strip(sep) +"\n" f.write(Doutstring) for k in range(len(IntCols)): Ioutstring=Ioutstring+IntCols[k]+sep Ioutstring=Ioutstring+end Ioutstring=Ioutstring.strip(sep) +"\n" fI.write(Ioutstring) if crit_file!="": for k in range(len(CritKeys)): Croutstring=Croutstring+CritKeys[k]+sep Croutstring=Croutstring+end Croutstring=Croutstring.strip(sep) +"\n" cr.write(Croutstring) if spec_file!="": for k in range(len(SpecCols)): Spoutstring=Spoutstring+SpecCols[k]+sep Spoutstring=Spoutstring+end Spoutstring=Spoutstring.strip(sep) +"\n" fsp.write(Spoutstring) if latex: # put in a horizontal line in latex file f.write('\hline\n') sf.write('\hline\n') fI.write('\hline\n') if crit_file!="":cr.write('\hline\n') if spec_file!="": fsp.write('\hline\n') # do criteria if crit_file!="": for crit in Crits: # Croutstring="" for key in CritKeys: Croutstring=Croutstring+crit[key]+sep Croutstring=Croutstring.strip(sep) +end cr.write(Croutstring+'\n') # do directions VGPs=pmag.get_dictitem(Sites,'vgp_lat','','F') # get all results with VGPs for site in VGPs: if len(site['er_site_names'].split(":"))==1: if 'er_sample_names' not in site.keys():site['er_sample_names']='' if 'pole_comp_name' not in site.keys(): site['pole_comp_name']="A" if 'average_n_lines' not in site.keys():site['average_n_lines']=site['average_nn'] if 'average_n_planes' not in site.keys():site['average_n_planes']="" Soutstring,Doutstring="","" for key in SiteKeys: if key in site.keys():Soutstring=Soutstring+site[key]+sep Soutstring=Soutstring.strip(sep) +end sf.write(Soutstring+'\n') for key in DirKeys: if key in site.keys():Doutstring=Doutstring+site[key]+sep Doutstring=Doutstring.strip(sep) +end f.write(Doutstring+'\n') # now do intensities VADMs=pmag.get_dictitem(Sites,'vadm','','F') for site in VADMs: # do results level stuff if site not in VGPs: Soutstring="" for key in SiteKeys: if key in site.keys(): Soutstring=Soutstring+site[key]+sep else: Soutstring=Soutstring + " " + sep Soutstring=Soutstring.strip(sep) +end sf.write(Soutstring+'\n') if len(site['er_site_names'].split(":"))==1: if 'average_int_sigma_perc' not in site.keys():site['average_int_sigma_perc']="0" if site["average_int_sigma"]=="":site["average_int_sigma"]="0" if site["average_int_sigma_perc"]=="":site["average_int_sigma_perc"]="0" if site["vadm"]=="":site["vadm"]="0" if site["vadm_sigma"]=="":site["vadm_sigma"]="0" for key in site.keys(): # reformat vadms, intensities if key in Micro: site[key]='%7.1f'%(float(site[key])*1e6) if key in Zeta: site[key]='%7.1f'%(float(site[key])*1e-21) outstring="" for key in IntKeys: if key not in site.keys():site[key]="" outstring=outstring+site[key]+sep outstring=outstring.strip(sep)+end +'\n' fI.write(outstring) # VDMs=pmag.get_dictitem(Sites,'vdm','','F') # get non-blank VDMs # for site in VDMs: # do results level stuff # if len(site['er_site_names'].split(":"))==1: # if 'average_int_sigma_perc' not in site.keys():site['average_int_sigma_perc']="0" # if site["average_int_sigma"]=="":site["average_int_sigma"]="0" # if site["average_int_sigma_perc"]=="":site["average_int_sigma_perc"]="0" # if site["vadm"]=="":site["vadm"]="0" # if site["vadm_sigma"]=="":site["vadm_sigma"]="0" # for key in site.keys(): # reformat vadms, intensities # if key in Micro: site[key]='%7.1f'%(float(site[key])*1e6) # if key in Zeta: site[key]='%7.1f'%(float(site[key])*1e-21) # outstring="" # for key in IntKeys: # outstring=outstring+site[key]+sep # fI.write(outstring.strip(sep)+'\n') if spec_file!="": SpecsInts=pmag.get_dictitem(Specs,'specimen_int','','F') for spec in SpecsInts: spec['trange']= '%i'%(int(float(spec['measurement_step_min'])-273))+'-'+'%i'%(int(float(spec['measurement_step_max'])-273)) meths=spec['magic_method_codes'].split(':') corrections='' for meth in meths: if 'DA' in meth:corrections=corrections+meth[3:]+':' corrections=corrections.strip(':') if corrections.strip()=="":corrections="None" spec['corrections']=corrections outstring="" for key in SpecKeys: if key in Micro: spec[key]='%7.1f'%(float(spec[key])*1e6) if key in Zeta: spec[key]='%7.1f'%(float(spec[key])*1e-21) outstring=outstring+spec[key]+sep fsp.write(outstring.strip(sep)+end+'\n') # if latex: # write out the tail stuff f.write('\hline\n') sf.write('\hline\n') fI.write('\hline\n') f.write('\end{tabular}\n') sf.write('\end{tabular}\n') fI.write('\end{tabular}\n') f.write('\end{table}\n') fI.write('\end{table}\n') if spec_file!="": fsp.write('\hline\n') fsp.write('\end{tabular}\n') fsp.write('\end{table}\n') f.close() sf.close() fI.close() print 'data saved in: ',outfile,Ioutfile,Soutfile if spec_file!="": fsp.close() print 'specimen data saved in: ',Specout if crit_file!="": cr.close() print 'Selection criteria saved in: ',Critout
def main(): """ NAME sio_magic.py DESCRIPTION converts SIO .mag format files to magic_measurements format files SYNTAX sio_magic.py [command line options] OPTIONS -h: prints the help message and quits. -usr USER: identify user, default is "" -f FILE: specify .mag format input file, required -fsa SAMPFILE : specify er_samples.txt file relating samples, site and locations names,default is none -F FILE: specify output file, default is magic_measurements.txt -Fsy: specify er_synthetics file, default is er_sythetics.txt -Fsa: specify output er_samples file, default is NONE (only for LDGO formatted files) -LP [colon delimited list of protocols, include all that apply] AF: af demag T: thermal including thellier but not trm acquisition S: Shaw method I: IRM (acquisition) I3d: 3D IRM experiment N: NRM only TRM: trm acquisition ANI: anisotropy experiment D: double AF demag G: triple AF demag (GRM protocol) CR: cooling rate experiment. The treatment coding of the measurement file should be: XXX.00,XXX.10, XXX.20 ...XX.70 etc. (XXX.00 is optional) where XXX in the temperature and .10,.20... are running numbers of the cooling rates steps. XXX.00 is optional zerofield baseline. XXX.70 is alteration check. syntax in sio_magic is: -LP CR xxx,yyy,zzz,.....xx -A where xx, yyy,zzz...xxx are cooling time in [K/minutes], seperated by comma, ordered at the same order as XXX.10,XXX.20 ...XX.70 if you use a zerofield step then no need to specify the cooling rate for the zerofield It is important to add to the command line the -A option so the measurements will not be evraged. But users need to make sure that there are no duplicate meaurements in the file -V [1,2,3] units of IRM field in volts using ASC coil #1,2 or 3 -spc NUM : specify number of characters to designate a specimen, default = 0 -loc LOCNAME : specify location/study name, must have either LOCNAME or SAMPFILE or be a synthetic -syn INST TYPE: sets these specimens as synthetics created at institution INST and of type TYPE -ins INST : specify which demag instrument was used (e.g, SIO-Suzy or SIO-Odette),default is "" -dc B PHI THETA: dc lab field (in micro tesla) and phi,theta, default is none NB: use PHI, THETA = -1 -1 to signal that it changes, i.e. in anisotropy experiment -ac B : peak AF field (in mT) for ARM acquisition, default is none -ncn NCON: specify naming convention: default is #1 below -A: don't average replicate measurements Sample naming convention: [1] XXXXY: where XXXX is an arbitrary length site designation and Y is the single character sample designation. e.g., TG001a is the first sample from site TG001. [default] [2] XXXX-YY: YY sample from site XXXX (XXX, YY of arbitary length) [3] XXXX.YY: YY sample from site XXXX (XXX, YY of arbitary length) [4-Z] XXXX[YYY]: YYY is sample designation with Z characters from site XXX [5] site name same as sample [6] site is entered under a separate column [7-Z] [XXXX]YYY: XXXX is site designation with Z characters with sample name XXXXYYYY NB: all others you will have to customize your self or e-mail [email protected] for help. [8] synthetic - has no site name [9] ODP naming convention INPUT Best to put separate experiments (all AF, thermal, thellier, trm aquisition, Shaw, etc.) in seperate .mag files (eg. af.mag, thermal.mag, etc.) Format of SIO .mag files: Spec Treat CSD Intensity Declination Inclination [optional metadata string] Spec: specimen name Treat: treatment step XXX T in Centigrade XXX AF in mT for special experiments: Thellier: XXX.0 first zero field step XXX.1 first in field step [XXX.0 and XXX.1 can be done in any order] XXX.2 second in-field step at lower temperature (pTRM check) XXX.3 second zero-field step after infield (pTRM check step) XXX.3 MUST be done in this order [XXX.0, XXX.1 [optional XXX.2] XXX.3] AARM: X.00 baseline step (AF in zero bias field - high peak field) X.1 ARM step (in field step) where X is the step number in the 15 position scheme (see Appendix to Lecture 13 - http://magician.ucsd.edu/Essentials_2) ATRM: X.00 optional baseline X.1 ATRM step (+X) X.2 ATRM step (+Y) X.3 ATRM step (+Z) X.4 ATRM step (-X) X.5 ATRM step (-Y) X.6 ATRM step (-Z) X.7 optional alteration check (+X) TRM: XXX.YYY XXX is temperature step of total TRM YYY is dc field in microtesla Intensity assumed to be total moment in 10^3 Am^2 (emu) Declination: Declination in specimen coordinate system Inclination: Declination in specimen coordinate system Optional metatdata string: mm/dd/yy;hh:mm;[dC,mT];xx.xx;UNITS;USER;INST;NMEAS hh in 24 hours. dC or mT units of treatment XXX (see Treat above) for thermal or AF respectively xx.xxx DC field UNITS of DC field (microT, mT) INST: instrument code, number of axes, number of positions (e.g., G34 is 2G, three axes, measured in four positions) NMEAS: number of measurements in a single position (1,3,200...) """ # initialize some stuff infile_type="mag" noave=0 methcode,inst="LP-NO","" phi,theta,peakfield,labfield=0,0,0,0 pTRM,MD,samp_con,Z=0,0,'1',1 dec=[315,225,180,135,45,90,270,270,270,90,180,180,0,0,0] inc=[0,0,0,0,0,-45,-45,0,45,45,45,-45,-90,-45,45] tdec=[0,90,0,180,270,0,0,90,0] tinc=[0,0,90,0,0,-90,0,0,90] missing=1 demag="N" er_location_name="" citation='This study' args=sys.argv fmt='old' syn=0 synfile='er_synthetics.txt' samp_file,ErSamps='',[] trm=0 irm=0 specnum=0 coil="" # # get command line arguments # meas_file="magic_measurements.txt" user="" if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind=args.index("-usr") user=args[ind+1] if '-F' in args: ind=args.index("-F") meas_file=args[ind+1] if '-Fsy' in args: ind=args.index("-Fsy") synfile=args[ind+1] if '-Fsa' in args: ind=args.index("-Fsa") samp_file=args[ind+1] try: open(samp_file,'rU') ErSamps,file_type=pmag.magic_read(samp_file) print 'sample information will be appended to new er_samples.txt file' except: print 'sample information will be stored in new er_samples.txt file' if '-f' in args: ind=args.index("-f") magfile=args[ind+1] try: input=open(magfile,'rU') except: print "bad mag file name" sys.exit() else: print "mag_file field is required option" print main.__doc__ sys.exit() if "-dc" in args: ind=args.index("-dc") labfield=float(args[ind+1])*1e-6 phi=float(args[ind+2]) theta=float(args[ind+3]) if "-ac" in args: ind=args.index("-ac") peakfield=float(args[ind+1])*1e-3 if "-spc" in args: ind=args.index("-spc") specnum=int(args[ind+1]) if specnum!=0:specnum=-specnum if "-loc" in args: ind=args.index("-loc") er_location_name=args[ind+1] if "-fsa" in args: ind=args.index("-fsa") Samps,file_type=pmag.magic_read(args[ind+1]) if '-syn' in args: syn=1 ind=args.index("-syn") institution=args[ind+1] syntype=args[ind+2] if '-fsy' in args: ind=args.index("-fsy") synfile=args[ind+1] if "-ins" in args: ind=args.index("-ins") inst=args[ind+1] if "-A" in args: noave=1 if "-ncn" in args: ind=args.index("-ncn") samp_con=sys.argv[ind+1] if "4-" in samp_con: if "-" not in samp_con: print "option [4] must be in form 4-Z where Z is an integer" sys.exit() else: Z=samp_con.split("-")[1] samp_con="4" if "7-" in samp_con: if "-" not in samp_con: print "option [7] must be in form 7-Z where Z is an integer" sys.exit() else: Z=samp_con.split("-")[1] samp_con="7" if '-LP' in args: ind=args.index("-LP") codelist=args[ind+1] codes=codelist.split(':') if "AF" in codes: demag='AF' if'-dc' not in args: methcode="LT-AF-Z" if'-dc' in args: methcode="LT-AF-I" if "T" in codes: demag="T" if '-dc' not in args: methcode="LT-T-Z" if '-dc' in args: methcode="LT-T-I" if "I" in codes: methcode="LP-IRM" irmunits="mT" if "I3d" in codes: methcode="LT-T-Z:LP-IRM-3D" if "S" in codes: demag="S" methcode="LP-PI-TRM:LP-PI-ALT-AFARM" trm_labfield=labfield ans=raw_input("DC lab field for ARM step: [50uT] ") if ans=="": arm_labfield=50e-6 else: arm_labfield=float(ans)*1e-6 ans=raw_input("temperature for total trm step: [600 C] ") if ans=="": trm_peakT=600+273 # convert to kelvin else: trm_peakT=float(ans)+273 # convert to kelvin if "G" in codes: methcode="LT-AF-G" if "D" in codes: methcode="LT-AF-D" if "TRM" in codes: demag="T" trm=1 if "CR" in codes: demag="T" cooling_rate_experiment=1 ind=args.index("CR") coolling_times=args[ind+1] coolling_times_list=coolling_times.split(',') if "-V" in args: methcode="LP-IRM" ind=args.index("-V") irmunits="V" coil=args[ind+1] if coil not in ["1","2","3"]: print main.__doc__ print 'not a valid coil specification' sys.exit() if demag=="T" and "ANI" in codes: methcode="LP-AN-TRM" if demag=="T" and "CR" in codes: methcode="LP-CR-TRM" if demag=="AF" and "ANI" in codes: methcode="LP-AN-ARM" if labfield==0: labfield=50e-6 if peakfield==0: peakfield=.180 SynRecs,MagRecs=[],[] version_num=pmag.get_version() if 1: #if infile_type=="SIO format": for line in input.readlines(): instcode="" if len(line)>2: SynRec={} MagRec={} MagRec['er_location_name']=er_location_name MagRec['magic_software_packages']=version_num MagRec["treatment_temp"]='%8.3e' % (273) # room temp in kelvin MagRec["measurement_temp"]='%8.3e' % (273) # room temp in kelvin MagRec["treatment_ac_field"]='0' MagRec["treatment_dc_field"]='0' MagRec["treatment_dc_field_phi"]='0' MagRec["treatment_dc_field_theta"]='0' meas_type="LT-NO" rec=line.split() if rec[1]==".00":rec[1]="0.00" treat=rec[1].split('.') if methcode=="LP-IRM": if irmunits=='mT': labfield=float(treat[0])*1e-3 else: labfield=pmag.getfield(irmunits,coil,treat[0]) if rec[1][0]!="-": phi,theta=0.,90. else: phi,theta=0.,-90. meas_type="LT-IRM" MagRec["treatment_dc_field"]='%8.3e'%(labfield) MagRec["treatment_dc_field_phi"]='%7.1f'%(phi) MagRec["treatment_dc_field_theta"]='%7.1f'%(theta) if len(rec)>6: code1=rec[6].split(';') # break e.g., 10/15/02;7:45 indo date and time if len(code1)==2: # old format with AM/PM missing=0 code2=code1[0].split('/') # break date into mon/day/year code3=rec[7].split(';') # break e.g., AM;C34;200 into time;instr/axes/measuring pos;number of measurements yy=int(code2[2]) if yy <90: yyyy=str(2000+yy) else: yyyy=str(1900+yy) mm=int(code2[0]) if mm<10: mm="0"+str(mm) else: mm=str(mm) dd=int(code2[1]) if dd<10: dd="0"+str(dd) else: dd=str(dd) time=code1[1].split(':') hh=int(time[0]) if code3[0]=="PM":hh=hh+12 if hh<10: hh="0"+str(hh) else: hh=str(hh) min=int(time[1]) if min<10: min= "0"+str(min) else: min=str(min) MagRec["measurement_date"]=yyyy+":"+mm+":"+dd+":"+hh+":"+min+":00.00" MagRec["measurement_time_zone"]='SAN' if inst=="": if code3[1][0]=='C':instcode='SIO-bubba' if code3[1][0]=='G':instcode='SIO-flo' else: instcode='' MagRec["measurement_positions"]=code3[1][2] elif len(code1)>2: # newest format (cryo7 or later) if "LP-AN-ARM" not in methcode:labfield=0 fmt='new' date=code1[0].split('/') # break date into mon/day/year yy=int(date[2]) if yy <90: yyyy=str(2000+yy) else: yyyy=str(1900+yy) mm=int(date[0]) if mm<10: mm="0"+str(mm) else: mm=str(mm) dd=int(date[1]) if dd<10: dd="0"+str(dd) else: dd=str(dd) time=code1[1].split(':') hh=int(time[0]) if hh<10: hh="0"+str(hh) else: hh=str(hh) min=int(time[1]) if min<10: min= "0"+str(min) else: min=str(min) MagRec["measurement_date"]=yyyy+":"+mm+":"+dd+":"+hh+":"+min+":00.00" MagRec["measurement_time_zone"]='SAN' if inst=="": if code1[6][0]=='C':instcode='SIO-bubba' if code1[6][0]=='G':instcode='SIO-flo' else: instcode='' if len(code1)>1: MagRec["measurement_positions"]=code1[6][2] else: MagRec["measurement_positions"]=code1[7] # takes care of awkward format with bubba and flo being different if user=="":user=code1[5] if code1[2][-1]=='C': demag="T" if code1[4]=='microT' and float(code1[3])!=0. and "LP-AN-ARM" not in methcode: labfield=float(code1[3])*1e-6 if code1[2]=='mT' and methcode!="LP-IRM": demag="AF" if code1[4]=='microT' and float(code1[3])!=0.: labfield=float(code1[3])*1e-6 if code1[4]=='microT' and labfield!=0. and meas_type!="LT-IRM": phi,theta=0.,-90. if demag=="T": meas_type="LT-T-I" if demag=="AF": meas_type="LT-AF-I" MagRec["treatment_dc_field"]='%8.3e'%(labfield) MagRec["treatment_dc_field_phi"]='%7.1f'%(phi) MagRec["treatment_dc_field_theta"]='%7.1f'%(theta) if code1[4]=='' or labfield==0. and meas_type!="LT-IRM": if demag=='T':meas_type="LT-T-Z" if demag=="AF":meas_type="LT-AF-Z" MagRec["treatment_dc_field"]='0' if syn==0: MagRec["er_specimen_name"]=rec[0] MagRec["er_synthetic_name"]="" MagRec["er_site_name"]="" if specnum!=0: MagRec["er_sample_name"]=rec[0][:specnum] else: MagRec["er_sample_name"]=rec[0] if "-fsa" in args: samp=pmag.get_dictitem(Samps,'er_sample_name',MagRec['er_sample_name'],'T') if len(samp)>0: MagRec["er_location_name"]=samp[0]["er_location_name"] MagRec["er_site_name"]=samp[0]["er_site_name"] else: MagRec['er_location_name']='' MagRec["er_site_name"]='' elif int(samp_con)!=6: site=pmag.parse_site(MagRec['er_sample_name'],samp_con,Z) MagRec["er_site_name"]=site if MagRec['er_site_name']=="": print 'No site name found for: ',MagRec['er_specimen_name'],MagRec['er_sample_name'] if MagRec["er_location_name"]=="": print 'no location name for: ',MagRec["er_specimen_name"] else: if specnum!=0: MagRec["er_sample_name"]=rec[0][:specnum] else: MagRec["er_sample_name"]=rec[0] MagRec["er_site_name"]="" MagRec["er_synthetic_name"]=MagRec["er_specimen_name"] SynRec["er_synthetic_name"]=MagRec["er_specimen_name"] site=pmag.parse_site(MagRec['er_sample_name'],samp_con,Z) SynRec["synthetic_parent_sample"]=site SynRec["er_citation_names"]="This study" SynRec["synthetic_institution"]=institution SynRec["synthetic_type"]=syntype SynRecs.append(SynRec) if float(rec[1])==0: pass elif demag=="AF": if methcode != "LP-AN-ARM": MagRec["treatment_ac_field"]='%8.3e' %(float(rec[1])*1e-3) # peak field in tesla if meas_type=="LT-AF-Z": MagRec["treatment_dc_field"]='0' else: # AARM experiment if treat[1][0]=='0': meas_type="LT-AF-Z:LP-AN-ARM:" MagRec["treatment_ac_field"]='%8.3e' %(peakfield) # peak field in tesla MagRec["treatment_dc_field"]='%8.3e'%(0) if labfield!=0 and methcode!="LP-AN-ARM": print "Warning - inconsistency in mag file with lab field - overriding file with 0" else: meas_type="LT-AF-I:LP-AN-ARM" ipos=int(treat[0])-1 MagRec["treatment_dc_field_phi"]='%7.1f' %(dec[ipos]) MagRec["treatment_dc_field_theta"]='%7.1f'% (inc[ipos]) MagRec["treatment_dc_field"]='%8.3e'%(labfield) MagRec["treatment_ac_field"]='%8.3e' %(peakfield) # peak field in tesla elif demag=="T" and methcode == "LP-AN-TRM": MagRec["treatment_temp"]='%8.3e' % (float(treat[0])+273.) # temp in kelvin if treat[1][0]=='0': meas_type="LT-T-Z:LP-AN-TRM" MagRec["treatment_dc_field"]='%8.3e'%(0) MagRec["treatment_dc_field_phi"]='0' MagRec["treatment_dc_field_theta"]='0' else: MagRec["treatment_dc_field"]='%8.3e'%(labfield) if treat[1][0]=='7': # alteration check as final measurement meas_type="LT-PTRM-I:LP-AN-TRM" else: meas_type="LT-T-I:LP-AN-TRM" # find the direction of the lab field in two ways: # (1) using the treatment coding (XX.1=+x, XX.2=+y, XX.3=+z, XX.4=-x, XX.5=-y, XX.6=-z) ipos_code=int(treat[1][0])-1 # (2) using the magnetization DEC=float(rec[4]) INC=float(rec[5]) if INC < 45 and INC > -45: if DEC>315 or DEC<45: ipos_guess=0 if DEC>45 and DEC<135: ipos_guess=1 if DEC>135 and DEC<225: ipos_guess=3 if DEC>225 and DEC<315: ipos_guess=4 else: if INC >45: ipos_guess=2 if INC <-45: ipos_guess=5 # prefer the guess over the code ipos=ipos_guess MagRec["treatment_dc_field_phi"]='%7.1f' %(tdec[ipos]) MagRec["treatment_dc_field_theta"]='%7.1f'% (tinc[ipos]) # check it if ipos_guess!=ipos_code and treat[1][0]!='7': print "-E- ERROR: check specimen %s step %s, ATRM measurements, coding does not match the direction of the lab field!"%(rec[0],".".join(list(treat))) elif demag=="S": # Shaw experiment if treat[1][1]=='0': if int(treat[0])!=0: MagRec["treatment_ac_field"]='%8.3e' % (float(treat[0])*1e-3) # AF field in tesla MagRec["treatment_dc_field"]='0' meas_type="LT-AF-Z" # first AF else: meas_type="LT-NO" MagRec["treatment_ac_field"]='0' MagRec["treatment_dc_field"]='0' elif treat[1][1]=='1': if int(treat[0])==0: MagRec["treatment_ac_field"]='%8.3e' %(peakfield) # peak field in tesla MagRec["treatment_dc_field"]='%8.3e'%(arm_labfield) MagRec["treatment_dc_field_phi"]='%7.1f'%(phi) MagRec["treatment_dc_field_theta"]='%7.1f'%(theta) meas_type="LT-AF-I" else: MagRec["treatment_ac_field"]='%8.3e' % ( float(treat[0])*1e-3) # AF field in tesla MagRec["treatment_dc_field"]='0' meas_type="LT-AF-Z" elif treat[1][1]=='2': if int(treat[0])==0: MagRec["treatment_ac_field"]='0' MagRec["treatment_dc_field"]='%8.3e'%(trm_labfield) MagRec["treatment_dc_field_phi"]='%7.1f'%(phi) MagRec["treatment_dc_field_theta"]='%7.1f'%(theta) MagRec["treatment_temp"]='%8.3e' % (trm_peakT) meas_type="LT-T-I" else: MagRec["treatment_ac_field"]='%8.3e' % ( float(treat[0])*1e-3) # AF field in tesla MagRec["treatment_dc_field"]='0' meas_type="LT-AF-Z" elif treat[1][1]=='3': if int(treat[0])==0: MagRec["treatment_ac_field"]='%8.3e' %(peakfield) # peak field in tesla MagRec["treatment_dc_field"]='%8.3e'%(arm_labfield) MagRec["treatment_dc_field_phi"]='%7.1f'%(phi) MagRec["treatment_dc_field_theta"]='%7.1f'%(theta) meas_type="LT-AF-I" else: MagRec["treatment_ac_field"]='%8.3e' % ( float(treat[0])*1e-3) # AF field in tesla MagRec["treatment_dc_field"]='0' meas_type="LT-AF-Z" # Cooling rate experient # added by rshaar elif demag=="T" and methcode == "LP-CR-TRM": MagRec["treatment_temp"]='%8.3e' % (float(treat[0])+273.) # temp in kelvin if treat[1][0]=='0': meas_type="LT-T-Z:LP-CR-TRM" MagRec["treatment_dc_field"]='%8.3e'%(0) MagRec["treatment_dc_field_phi"]='0' MagRec["treatment_dc_field_theta"]='0' else: MagRec["treatment_dc_field"]='%8.3e'%(labfield) if treat[1][0]=='7': # alteration check as final measurement meas_type="LT-PTRM-I:LP-CR-TRM" else: meas_type="LT-T-I:LP-CR-TRM" MagRec["treatment_dc_field_phi"]='%7.1f' % (phi) # labfield phi MagRec["treatment_dc_field_theta"]='%7.1f' % (theta) # labfield theta indx=int(treat[1][0])-1 # alteration check matjed as 0.7 in the measurement file if indx==6: cooling_time= coolling_times_list[-1] else: cooling_time=coolling_times_list[indx] MagRec["measurement_description"]="cooling_rate"+":"+cooling_time+":"+"K/min" elif demag!='N': if len(treat)==1:treat.append('0') MagRec["treatment_temp"]='%8.3e' % (float(treat[0])+273.) # temp in kelvin if trm==0: # demag=T and not trmaq if treat[1][0]=='0': meas_type="LT-T-Z" else: MagRec["treatment_dc_field"]='%8.3e' % (labfield) # labfield in tesla (convert from microT) MagRec["treatment_dc_field_phi"]='%7.1f' % (phi) # labfield phi MagRec["treatment_dc_field_theta"]='%7.1f' % (theta) # labfield theta if treat[1][0]=='1':meas_type="LT-T-I" # in-field thermal step if treat[1][0]=='2': meas_type="LT-PTRM-I" # pTRM check pTRM=1 if treat[1][0]=='3': MagRec["treatment_dc_field"]='0' # this is a zero field step meas_type="LT-PTRM-MD" # pTRM tail check else: labfield=float(treat[1])*1e-6 MagRec["treatment_dc_field"]='%8.3e' % (labfield) # labfield in tesla (convert from microT) MagRec["treatment_dc_field_phi"]='%7.1f' % (phi) # labfield phi MagRec["treatment_dc_field_theta"]='%7.1f' % (theta) # labfield theta meas_type="LT-T-I:LP-TRM" # trm acquisition experiment MagRec["measurement_csd"]=rec[2] MagRec["measurement_magn_moment"]='%10.3e'% (float(rec[3])*1e-3) # moment in Am^2 (from emu) MagRec["measurement_dec"]=rec[4] MagRec["measurement_inc"]=rec[5] MagRec["magic_instrument_codes"]=instcode MagRec["er_analyst_mail_names"]=user MagRec["er_citation_names"]=citation if "LP-IRM-3D" in methcode : meas_type=methcode #MagRec["magic_method_codes"]=methcode.strip(':') MagRec["magic_method_codes"]=meas_type MagRec["measurement_flag"]='g' MagRec["er_specimen_name"]=rec[0] if 'std' in rec[0]: MagRec["measurement_standard"]='s' else: MagRec["measurement_standard"]='u' MagRec["measurement_number"]='1' #print MagRec['treatment_temp'] MagRecs.append(MagRec) MagOuts=pmag.measurements_methods(MagRecs,noave) pmag.magic_write(meas_file,MagOuts,'magic_measurements') print "results put in ",meas_file if samp_file!="": pmag.magic_write(samp_file,ErSamps,'er_samples') print "sample orientations put in ",samp_file if len(SynRecs)>0: pmag.magic_write(synfile,SynRecs,'er_synthetics') print "synthetics put in ",synfile
def main(): """ NAME ani_depthplot.py DESCRIPTION plots tau, V3_inc, P and chi versus core_depth SYNTAX ani_depthplot.py [command line optins] OPTIONS -h prints help message and quits -f FILE: specify input rmag_anisotropy format file from magic -fb FILE: specify input magic_measurements format file from magic -fsa FILE: specify input er_samples format file from magic -fa FILE: specify input er_ages format file from magic -d min max [in m] depth range to plot -ds [mcd,mbsf], specify depth scale, default is mbsf -sav save plot without review -fmt specfiy format for figures - default is svg DEFAULTS: Anisotropy file: rmag_anisotropy.txt Bulk susceptibility file: magic_measurements.txt Samples file: er_samples.txt """ fmt='.svg' dir_path="./" pcol=3 verbose=pmagplotlib.verbose plots=0 age_file="" if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] ani_file=dir_path+'/rmag_anisotropy.txt' meas_file=dir_path+'/magic_measurements.txt' samp_file=dir_path+'/er_samples.txt' if '-h' in sys.argv: print main.__doc__ sys.exit() if '-f' in sys.argv: ind=sys.argv.index('-f') ani_file=dir_path+'/'+sys.argv[ind+1] if '-fb' in sys.argv: ind=sys.argv.index('-fb') meas_file=dir_path+'/'+sys.argv[ind+1] if '-fsa' in sys.argv: ind=sys.argv.index('-fsa') samp_file=dir_path+'/'+sys.argv[ind+1] if '-fa' in sys.argv: print main.__doc__ print 'only -fsa OR -fa - not both' sys.exit() elif '-fa' in sys.argv: ind=sys.argv.index('-fa') age_file=dir_path+"/"+sys.argv[ind+1] if '-fmt' in sys.argv: ind=sys.argv.index('-fmt') fmt='.'+sys.argv[ind+1] dmin,dmax=-1,-1 if '-d' in sys.argv: ind=sys.argv.index('-d') dmin=float(sys.argv[ind+1]) dmax=float(sys.argv[ind+2]) if '-ds' in sys.argv and 'mcd' in sys.argv: # sets depth scale to meters composite depth (as opposed to meters below sea floor) depth_scale='sample_composite_depth' elif age_file=="": depth_scale='sample_core_depth' else: depth_scale='age' if '-sav' in sys.argv: plots=1 verbose=0 # # get data read in isbulk=0 # tests if there are bulk susceptibility measurements AniData,file_type=pmag.magic_read(ani_file) # read in tensor elements if age_file=="": Samps,file_type=pmag.magic_read(samp_file) # read in sample depth info from er_sample.txt format file else: Samps,file_type=pmag.magic_read(age_file) # read in sample age info from er_ages.txt format file age_unit=Samps[0]['age_unit'] for s in Samps:s['er_sample_name']=s['er_sample_name'].upper() # change to upper case for every sample name Meas,file_type=pmag.magic_read(meas_file) if file_type=='magic_measurements':isbulk=1 Data=[] Bulks=[] BulkDepths=[] for rec in AniData: samprecs=pmag.get_dictitem(Samps,'er_sample_name',rec['er_sample_name'].upper(),'T') # look for depth record for this sample sampdepths=pmag.get_dictitem(samprecs,depth_scale,'','F') # see if there are non-blank depth data if dmax!=-1: sampdepths=pmag.get_dictitem(sampdepths,depth_scale,dmax,'max') # fishes out records within depth bounds sampdepths=pmag.get_dictitem(sampdepths,depth_scale,dmin,'min') if len(sampdepths)>0: # if there are any.... rec['core_depth'] = sampdepths[0][depth_scale] # set the core depth of this record Data.append(rec) # fish out data with core_depth if isbulk: # if there are bulk data chis=pmag.get_dictitem(Meas,'er_specimen_name',rec['er_specimen_name'],'T') chis=pmag.get_dictitem(chis,'measurement_chi_volume','','F') # get the non-zero values for this specimen if len(chis)>0: # if there are any.... Bulks.append(1e6*float(chis[0]['measurement_chi_volume'])) # put in microSI BulkDepths.append(float(sampdepths[0][depth_scale])) if len(Bulks)>0: # set min and max bulk values bmin=min(Bulks) bmax=max(Bulks) xlab="Depth (m)" if len(Data)>0: location=Data[0]['er_location_name'] else: print 'no data to plot' sys.exit() # collect the data for plotting tau and V3_inc Depths,Tau1,Tau2,Tau3,V3Incs,P=[],[],[],[],[],[] Axs=[] # collect the plot ids if len(Bulks)>0: pcol+=1 s1=pmag.get_dictkey(Data,'anisotropy_s1','f') # get all the s1 values from Data as floats s2=pmag.get_dictkey(Data,'anisotropy_s2','f') s3=pmag.get_dictkey(Data,'anisotropy_s3','f') s4=pmag.get_dictkey(Data,'anisotropy_s4','f') s5=pmag.get_dictkey(Data,'anisotropy_s5','f') s6=pmag.get_dictkey(Data,'anisotropy_s6','f') Depths=pmag.get_dictkey(Data,'core_depth','f') Ss=numpy.array([s1,s4,s5,s4,s2,s6,s5,s6,s3]).transpose() # make an array Ts=numpy.reshape(Ss,(len(Ss),3,-1)) # and re-shape to be n-length array of 3x3 sub-arrays for k in range(len(Depths)): tau,Evecs= pmag.tauV(Ts[k]) # get the sorted eigenvalues and eigenvectors v3=pmag.cart2dir(Evecs[2])[1] # convert to inclination of the minimum eigenvector V3Incs.append(v3) Tau1.append(tau[0]) Tau2.append(tau[1]) Tau3.append(tau[2]) P.append(tau[0]/tau[2]) if len(Depths)>0: if dmax==-1: dmax=max(Depths) dmin=min(Depths) tau_max=max(Tau1) tau_min=min(Tau3) P_max=max(P) P_min=min(P) #dmax=dmax+.05*dmax #dmin=dmin-.05*dmax pylab.figure(1,figsize=(10,8)) # make the figure version_num=pmag.get_version() pylab.figtext(.02,.01,version_num) # attach the pmagpy version number ax=pylab.subplot(1,pcol,1) # make the first column Axs.append(ax) ax.plot(Tau1,Depths,'rs') ax.plot(Tau2,Depths,'b^') ax.plot(Tau3,Depths,'ko') ax.axis([tau_min,tau_max,dmax,dmin]) ax.set_xlabel('Eigenvalues') if depth_scale=='sample_core_depth': ax.set_ylabel('Depth (mbsf)') elif depth_scale=='age': ax.set_ylabel('Age ('+age_unit+')') else: ax.set_ylabel('Depth (mcd)') ax2=pylab.subplot(1,pcol,2) # make the second column ax2.plot(P,Depths,'rs') ax2.axis([P_min,P_max,dmax,dmin]) ax2.set_xlabel('P') ax2.set_title(location) Axs.append(ax2) ax3=pylab.subplot(1,pcol,3) Axs.append(ax3) ax3.plot(V3Incs,Depths,'ko') ax3.axis([0,90,dmax,dmin]) ax3.set_xlabel('V3 Inclination') if pcol==4: ax4=pylab.subplot(1,pcol,4) Axs.append(ax4) ax4.plot(Bulks,BulkDepths,'bo') ax4.axis([bmin-1,bmax+1,dmax,dmin]) ax4.set_xlabel('Bulk Susc. (uSI)') for x in Axs:pmagplotlib.delticks(x) # this makes the x-tick labels more reasonable - they were overcrowded using the defaults figname=location+'_ani-depthplot'+fmt if verbose: pylab.draw() ans=raw_input("S[a]ve plot? Return to quit ") if ans=='a': pylab.savefig(figname) print 'Plot saved as ',figname elif plots: pylab.savefig(figname) print 'Plot saved as ',figname sys.exit() else: print "No data points met your criteria - try again"
def main(): """ NAME lowrie.py DESCRIPTION plots intensity decay curves for Lowrie experiments SYNTAX lowrie -h [command line options] INPUT takes SIO formatted input files OPTIONS -h prints help message and quits -f FILE: specify input file -N do not normalize by maximum magnetization -fmt [svg, pdf, eps, png] specify fmt, default is svg """ fmt='svg' FIG={} # plot dictionary FIG['lowrie']=1 # demag is figure 1 pmagplotlib.plot_init(FIG['lowrie'],6,6) norm=1 # default is to normalize by maximum axis if len(sys.argv)>1: if '-h' in sys.argv: print main.__doc__ sys.exit() if '-N' in sys.argv: norm=0 # don't normalize if '-f' in sys.argv: # sets input filename ind=sys.argv.index("-f") in_file=sys.argv[ind+1] else: print main.__doc__ print 'you must supply a file name' sys.exit() else: print main.__doc__ print 'you must supply a file name' sys.exit() data=open(in_file).readlines() # open the SIO format file PmagRecs=[] # set up a list for the results keys=['specimen','treatment','csd','M','dec','inc'] for line in data: PmagRec={} rec=line.replace('\n','').split() for k in range(len(keys)): PmagRec[keys[k]]=rec[k] PmagRecs.append(PmagRec) specs=pmag.get_dictkey(PmagRecs,'specimen','') sids=[] for spec in specs: if spec not in sids:sids.append(spec) # get list of unique specimen names for spc in sids: # step through the specimen names print spc specdata=pmag.get_dictitem(PmagRecs,'specimen',spc,'T') # get all this one's data DIMs,Temps=[],[] for dat in specdata: # step through the data DIMs.append([float(dat['dec']),float(dat['inc']),float(dat['M'])*1e-3]) Temps.append(float(dat['treatment'])) carts=pmag.dir2cart(DIMs).transpose() #if norm==1: # want to normalize # nrm=max(max(abs(carts[0])),max(abs(carts[1])),max(abs(carts[2]))) # by maximum of x,y,z values # ylab="M/M_max" if norm==1: # want to normalize nrm=(DIMs[0][2]) # normalize by NRM ylab="M/M_o" else: nrm=1. # don't normalize ylab="Magnetic moment (Am^2)" xlab="Temperature (C)" pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[0])/nrm,sym='r-') pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[0])/nrm,sym='ro') # X direction pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[1])/nrm,sym='c-') pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[1])/nrm,sym='cs') # Y direction pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[2])/nrm,sym='k-') pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[2])/nrm,sym='k^',title=spc,xlab=xlab,ylab=ylab) # Z direction pmagplotlib.drawFIGS(FIG) ans=raw_input('S[a]ve figure? [q]uit, <return> to continue ') if ans=='a': files={'lowrie':'lowrie:_'+spc+'_.'+fmt} pmagplotlib.saveP(FIG,files) elif ans=='q': sys.exit() pmagplotlib.clearFIG(FIG['lowrie'])
def main(): """ NAME sites_locations.py DESCRIPTION reads in er_sites.txt file and finds all locations and bounds of locations outputs er_locations.txt file SYNTAX sites_locations.py [command line options] OPTIONS -h prints help message and quits -f: specimen input er_sites format file, default is "er_sites.txt" -F: locations table: default is "er_locations.txt" """ # set defaults site_file = "er_sites.txt" loc_file = "er_locations.txt" Names, user = [], "unknown" Done = [] version_num = pmag.get_version() args = sys.argv dir_path = "." # get command line stuff if "-WD" in args: ind = args.index("-WD") dir_path = args[ind + 1] if "-h" in args: print main.__doc__ sys.exit() if "-f" in args: ind = args.index("-f") site_file = args[ind + 1] if "-F" in args: ind = args.index("-F") loc_file = args[ind + 1] # site_file = dir_path + "/" + site_file loc_file = dir_path + "/" + loc_file Sites, file_type = pmag.magic_read(site_file) if file_type != "er_sites": print file_type print file_type, "This is not a valid er_sites file " sys.exit() # read in site data # LocNames, Locations = [], [] for site in Sites: if site["er_location_name"] not in LocNames: # new location name LocNames.append(site["er_location_name"]) sites_locs = pmag.get_dictitem( Sites, "er_location_name", site["er_location_name"], "T" ) # get all sites for this loc lats = pmag.get_dictkey(sites_locs, "site_lat", "f") # get all the latitudes as floats lons = pmag.get_dictkey(sites_locs, "site_lon", "f") # get all the longitudes as floats LocRec = { "er_citation_names": "This study", "er_location_name": site["er_location_name"], "location_type": "", } LocRec["location_begin_lat"] = str(min(lats)) LocRec["location_end_lat"] = str(max(lats)) LocRec["location_begin_lon"] = str(min(lons)) LocRec["location_end_lon"] = str(max(lons)) Locations.append(LocRec) if len(Locations) > 0: pmag.magic_write(loc_file, Locations, "er_locations") print "Locations written to: ", loc_file
def main(): """ NAME zeq_magic_redo.py DESCRIPTION Calculate principal components through demagnetization data using bounds and calculation type stored in "redo" file SYNTAX zeq_magic_redo.py [command line options] OPTIONS -h prints help message -usr USER: identify user, default is "" -f: specify input file, default is magic_measurements.txt -F: specify output file, default is zeq_specimens.txt -fre REDO: specify redo file, default is "zeq_redo" -fsa SAMPFILE: specify er_samples format file, default is "er_samples.txt" -A : don't average replicate measurements, default is yes -crd [s,g,t] : specify coordinate system [s,g,t] [default is specimen coordinates] are specimen, geographic, and tilt corrected respectively NB: you must have a SAMPFILE in this directory to rotate from specimen coordinates -leg: attaches "Recalculated from original measurements; supercedes published results. " to comment field INPUTS zeq_redo format file is: specimen_name calculation_type[DE-BFL,DE-BFL-A,DE-BFL-O,DE-BFP,DE-FM] step_min step_max component_name[A,B,C] """ dir_path='.' INCL=["LT-NO","LT-AF-Z","LT-T-Z","LT-M-Z"] # looking for demag data beg,end,pole,geo,tilt,askave,save=0,0,[],0,0,0,0 user,doave,comment= "",1,"" geo,tilt=0,0 version_num=pmag.get_version() args=sys.argv if '-WD' in args: ind=args.index('-WD') dir_path=args[ind+1] meas_file,pmag_file,mk_file= dir_path+"/"+"magic_measurements.txt",dir_path+"/"+"zeq_specimens.txt",dir_path+"/"+"zeq_redo" samp_file,coord=dir_path+"/"+"er_samples.txt","" if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind=args.index("-usr") user=sys.argv[ind+1] if "-A" in args:doave=0 if "-leg" in args: comment="Recalculated from original measurements; supercedes published results. " if "-f" in args: ind=args.index("-f") meas_file=dir_path+'/'+sys.argv[ind+1] if "-F" in args: ind=args.index("-F") pmag_file=dir_path+'/'+sys.argv[ind+1] if "-fre" in args: ind=args.index("-fre") mk_file=dir_path+"/"+args[ind+1] try: mk_f=open(mk_file,'rU') except: print "Bad redo file" sys.exit() mkspec,skipped=[],[] speclist=[] for line in mk_f.readlines(): tmp=line.split() mkspec.append(tmp) speclist.append(tmp[0]) if "-fsa" in args: ind=args.index("-fsa") samp_file=dir_path+'/'+sys.argv[ind+1] if "-crd" in args: ind=args.index("-crd") coord=sys.argv[ind+1] if coord=="g":geo,tilt=1,0 if coord=="t":geo,tilt=1,1 # # now get down to bidness if geo==1: samp_data,file_type=pmag.magic_read(samp_file) if file_type != 'er_samples': print file_type print "This is not a valid er_samples file " sys.exit() # # # meas_data,file_type=pmag.magic_read(meas_file) if file_type != 'magic_measurements': print file_type print file_type,"This is not a valid magic_measurements file " sys.exit() # # sort the specimen names # k = 0 print 'Processing ',len(speclist), ' specimens - please wait' PmagSpecs=[] while k < len(speclist): s=speclist[k] recnum=0 PmagSpecRec={} method_codes,inst_codes=[],[] # find the data from the meas_data file for this sample # # collect info for the PmagSpecRec dictionary # meas_meth=[] spec=pmag.get_dictitem(meas_data,'er_specimen_name',s,'T') if len(spec)==0: print 'no data found for specimen: ',s print 'delete from zeq_redo input file...., then try again' else: for rec in spec: # copy of vital stats to PmagSpecRec from first spec record in demag block skip=1 methods=rec["magic_method_codes"].split(":") if len(set(methods) & set(INCL))>0: PmagSpecRec["er_analyst_mail_names"]=user PmagSpecRec["magic_software_packages"]=version_num PmagSpecRec["er_specimen_name"]=s PmagSpecRec["er_sample_name"]=rec["er_sample_name"] PmagSpecRec["er_site_name"]=rec["er_site_name"] PmagSpecRec["er_location_name"]=rec["er_location_name"] if "er_expedition_name" in rec.keys():PmagSpecRec["er_expedition_name"]=rec["er_expedition_name"] PmagSpecRec["er_citation_names"]="This study" if "magic_experiment_name" not in rec.keys(): rec["magic_experiment_name"]="" PmagSpecRec["magic_experiment_names"]=rec["magic_experiment_name"] if "magic_instrument_codes" not in rec.keys(): rec["magic_instrument_codes"]="" inst=rec['magic_instrument_codes'].split(":") for I in inst: if I not in inst_codes: # copy over instruments inst_codes.append(I) meths=rec["magic_method_codes"].split(":") for meth in meths: if meth.strip() not in meas_meth:meas_meth.append(meth) if "LP-DIR-AF" in meas_meth or "LT-AF-Z" in meas_meth: PmagSpecRec["measurement_step_unit"]="T" if "LP-DIR-AF" not in method_codes:method_codes.append("LP-DIR-AF") if "LP-DIR-T" in meas_meth or "LT-T-Z" in meas_meth: PmagSpecRec["measurement_step_unit"]="K" if "LP-DIR-T" not in method_codes:method_codes.append("LP-DIR-T") if "LP-DIR-M" in meas_meth or "LT-M-Z" in meas_meth: PmagSpecRec["measurement_step_unit"]="J" if "LP-DIR-M" not in method_codes:method_codes.append("LP-DIR-M") # # datablock,units=pmag.find_dmag_rec(s,spec) # fish out the demag data for this specimen # if len(datablock) <2 or s not in speclist : k+=1 # print 'skipping ', s,len(datablock) else: # # find replicate measurements at given treatment step and average them # # step_meth,avedata=pmag.vspec(data) # # if len(avedata) != len(datablock): # if doave==1: # method_codes.append("DE-VM") # datablock=avedata # # do geo or stratigraphic correction now # if geo==1 or tilt==1: # find top priority orientation method orient,az_type=pmag.get_orient(samp_data,PmagSpecRec["er_sample_name"]) if az_type not in method_codes:method_codes.append(az_type) # # if tilt selected, get stratigraphic correction # tiltblock,geoblock=[],[] for rec in datablock: if "sample_azimuth" in orient.keys() and orient["sample_azimuth"]!="": d_geo,i_geo=pmag.dogeo(rec[1],rec[2],float(orient["sample_azimuth"]),float(orient["sample_dip"])) geoblock.append([rec[0],d_geo,i_geo,rec[3],rec[4],rec[5]]) if tilt==1 and "sample_bed_dip_direction" in orient.keys(): d_tilt,i_tilt=pmag.dotilt(d_geo,i_geo,float(orient["sample_bed_dip_direction"]),float(orient["sample_bed_dip"])) tiltblock.append([rec[0],d_tilt,i_tilt,rec[3],rec[4],rec[5]]) elif tilt==1: if PmagSpecRec["er_sample_name"] not in skipped: print 'no tilt correction for ', PmagSpecRec["er_sample_name"],' skipping....' skipped.append(PmagSpecRec["er_sample_name"]) else: if PmagSpecRec["er_sample_name"] not in skipped: print 'no geographic correction for ', PmagSpecRec["er_sample_name"],' skipping....' skipped.append(PmagSpecRec["er_sample_name"]) # # get beg_pca, end_pca, pca if PmagSpecRec['er_sample_name'] not in skipped: compnum=-1 for spec in mkspec: if spec[0]==s: CompRec={} for key in PmagSpecRec.keys():CompRec[key]=PmagSpecRec[key] compnum+=1 calculation_type=spec[1] beg=float(spec[2]) end=float(spec[3]) if len(spec)>4: comp_name=spec[4] else: comp_name=string.uppercase[compnum] CompRec['specimen_comp_name']=comp_name if beg < float(datablock[0][0]):beg=float(datablock[0][0]) if end > float(datablock[-1][0]):end=float(datablock[-1][0]) for l in range(len(datablock)): if datablock[l][0]==beg:beg_pca=l if datablock[l][0]==end:end_pca=l if geo==1 and tilt==0: mpars=pmag.domean(geoblock,beg_pca,end_pca,calculation_type) if mpars["specimen_direction_type"]!="Error": CompRec["specimen_dec"]='%7.1f ' %(mpars["specimen_dec"]) CompRec["specimen_inc"]='%7.1f ' %(mpars["specimen_inc"]) CompRec["specimen_tilt_correction"]='0' if geo==1 and tilt==1: mpars=pmag.domean(tiltblock,beg_pca,end_pca,calculation_type) if mpars["specimen_direction_type"]!="Error": CompRec["specimen_dec"]='%7.1f ' %(mpars["specimen_dec"]) CompRec["specimen_inc"]='%7.1f ' %(mpars["specimen_inc"]) CompRec["specimen_tilt_correction"]='100' if geo==0 and tilt==0: mpars=pmag.domean(datablock,beg_pca,end_pca,calculation_type) if mpars["specimen_direction_type"]!="Error": CompRec["specimen_dec"]='%7.1f ' %(mpars["specimen_dec"]) CompRec["specimen_inc"]='%7.1f ' %(mpars["specimen_inc"]) CompRec["specimen_tilt_correction"]='-1' if mpars["specimen_direction_type"]=="Error": pass else: CompRec["measurement_step_min"]='%8.3e '%(datablock[beg_pca][0]) try: CompRec["measurement_step_max"]='%8.3e '%(datablock[end_pca][0] ) except: print 'error in end_pca ',PmagSpecRec['er_specimen_name'] CompRec["specimen_correction"]='u' if calculation_type!='DE-FM': CompRec["specimen_mad"]='%7.1f '%(mpars["specimen_mad"]) CompRec["specimen_alpha95"]="" else: CompRec["specimen_mad"]="" CompRec["specimen_alpha95"]='%7.1f '%(mpars["specimen_alpha95"]) CompRec["specimen_n"]='%i '%(mpars["specimen_n"]) CompRec["specimen_dang"]='%7.1f '%(mpars["specimen_dang"]) CompMeths=[] for meth in method_codes: if meth not in CompMeths:CompMeths.append(meth) if calculation_type not in CompMeths:CompMeths.append(calculation_type) if geo==1: CompMeths.append("DA-DIR-GEO") if tilt==1: CompMeths.append("DA-DIR-TILT") if "DE-BFP" not in calculation_type: CompRec["specimen_direction_type"]='l' else: CompRec["specimen_direction_type"]='p' CompRec["magic_method_codes"]="" if len(CompMeths) != 0: methstring="" for meth in CompMeths: methstring=methstring+ ":" +meth CompRec["magic_method_codes"]=methstring.strip(':') CompRec["specimen_description"]=comment if len(inst_codes) != 0: inststring="" for inst in inst_codes: inststring=inststring+ ":" +inst CompRec["magic_instrument_codes"]=inststring.strip(':') PmagSpecs.append(CompRec) k+=1 pmag.magic_write(pmag_file,PmagSpecs,'pmag_specimens') print "Recalculated specimen data stored in ",pmag_file
def main(): """ NAME aarm_magic.py DESCRIPTION Converts AARM data to best-fit tensor (6 elements plus sigma) Original program ARMcrunch written to accomodate ARM anisotropy data collected from 6 axial directions (+X,+Y,+Z,-X,-Y,-Z) using the off-axis remanence terms to construct the tensor. A better way to do the anisotropy of ARMs is to use 9,12 or 15 measurements in the Hext rotational scheme. SYNTAX aarm_magic.py [-h][command line options] OPTIONS -h prints help message and quits -usr USER: identify user, default is "" -f FILE: specify input file, default is aarm_measurements.txt -crd [s,g,t] specify coordinate system, requires er_samples.txt file -fsa FILE: specify er_samples.txt file, default is er_samples.txt -Fa FILE: specify anisotropy output file, default is arm_anisotropy.txt -Fr FILE: specify results output file, default is aarm_results.txt INPUT Input for the present program is a series of baseline, ARM pairs. The baseline should be the AF demagnetized state (3 axis demag is preferable) for the following ARM acquisition. The order of the measurements is: positions 1,2,3, 6,7,8, 11,12,13 (for 9 positions) positions 1,2,3,4, 6,7,8,9, 11,12,13,14 (for 12 positions) positions 1-15 (for 15 positions) """ # initialize some parameters args=sys.argv user="" meas_file="aarm_measurements.txt" samp_file="er_samples.txt" rmag_anis="arm_anisotropy.txt" rmag_res="aarm_results.txt" dir_path='.' # # get name of file from command line # if '-WD' in args: ind=args.index('-WD') dir_path=args[ind+1] if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind=args.index("-usr") user=sys.argv[ind+1] if "-f" in args: ind=args.index("-f") meas_file=sys.argv[ind+1] coord='-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 "-fsa" in args: ind=args.index("-fsa") samp_file=sys.argv[ind+1] if "-Fa" in args: ind=args.index("-Fa") rmag_anis=args[ind+1] if "-Fr" in args: ind=args.index("-Fr") rmag_res=args[ind+1] meas_file=dir_path+'/'+meas_file samp_file=dir_path+'/'+samp_file rmag_anis=dir_path+'/'+rmag_anis rmag_res=dir_path+'/'+rmag_res # read in data meas_data,file_type=pmag.magic_read(meas_file) meas_data=pmag.get_dictitem(meas_data,'magic_method_codes','LP-AN-ARM','has') if file_type != 'magic_measurements': print file_type print file_type,"This is not a valid magic_measurements file " sys.exit() if coord!='-1': # need to read in sample data samp_data,file_type=pmag.magic_read(samp_file) if file_type != 'er_samples': print file_type print file_type,"This is not a valid er_samples file " print "Only specimen coordinates will be calculated" coord='-1' # # sort the specimen names # ssort=[] for rec in meas_data: spec=rec["er_specimen_name"] if spec not in ssort: ssort.append(spec) if len(ssort)>1: sids=sorted(ssort) else: sids=ssort # # work on each specimen # specimen=0 RmagSpecRecs,RmagResRecs=[],[] while specimen < len(sids): s=sids[specimen] data=[] RmagSpecRec={} RmagResRec={} method_codes=[] # # find the data from the meas_data file for this sample # data=pmag.get_dictitem(meas_data,'er_specimen_name',s,'T') # # find out the number of measurements (9, 12 or 15) # npos=len(data)/2 if npos==9: # # get dec, inc, int and convert to x,y,z # B,H,tmpH=pmag.designAARM(npos) # B matrix made from design matrix for positions X=[] for rec in data: Dir=[] Dir.append(float(rec["measurement_dec"])) Dir.append(float(rec["measurement_inc"])) Dir.append(float(rec["measurement_magn_moment"])) X.append(pmag.dir2cart(Dir)) # # subtract baseline and put in a work array # work=numpy.zeros((npos,3),'f') for i in range(npos): for j in range(3): work[i][j]=X[2*i+1][j]-X[2*i][j] # # calculate tensor elements # first put ARM components in w vector # w=numpy.zeros((npos*3),'f') index=0 for i in range(npos): for j in range(3): w[index]=work[i][j] index+=1 s=numpy.zeros((6),'f') # initialize the s matrix for i in range(6): for j in range(len(w)): s[i]+=B[i][j]*w[j] trace=s[0]+s[1]+s[2] # normalize by the trace for i in range(6): s[i]=s[i]/trace a=pmag.s2a(s) #------------------------------------------------------------ # Calculating dels is different than in the Kappabridge # routine. Use trace normalized tensor (a) and the applied # unit field directions (tmpH) to generate model X,Y,Z # components. Then compare these with the measured values. #------------------------------------------------------------ S=0. comp=numpy.zeros((npos*3),'f') for i in range(npos): for j in range(3): index=i*3+j compare=a[j][0]*tmpH[i][0]+a[j][1]*tmpH[i][1]+a[j][2]*tmpH[i][2] comp[index]=compare for i in range(npos*3): d=w[i]/trace - comp[i] # del values S+=d*d nf=float(npos*3-6) # number of degrees of freedom if S >0: sigma=numpy.sqrt(S/nf) else: sigma=0 RmagSpecRec["rmag_anisotropy_name"]=data[0]["er_specimen_name"] RmagSpecRec["er_location_name"]=data[0]["er_location_name"] RmagSpecRec["er_specimen_name"]=data[0]["er_specimen_name"] RmagSpecRec["er_sample_name"]=data[0]["er_sample_name"] RmagSpecRec["er_site_name"]=data[0]["er_site_name"] RmagSpecRec["magic_experiment_names"]=RmagSpecRec["rmag_anisotropy_name"]+":AARM" RmagSpecRec["er_citation_names"]="This study" RmagResRec["rmag_result_name"]=data[0]["er_specimen_name"]+":AARM" RmagResRec["er_location_names"]=data[0]["er_location_name"] RmagResRec["er_specimen_names"]=data[0]["er_specimen_name"] RmagResRec["er_sample_names"]=data[0]["er_sample_name"] RmagResRec["er_site_names"]=data[0]["er_site_name"] RmagResRec["magic_experiment_names"]=RmagSpecRec["rmag_anisotropy_name"]+":AARM" RmagResRec["er_citation_names"]="This study" if "magic_instrument_codes" in data[0].keys(): RmagSpecRec["magic_instrument_codes"]=data[0]["magic_instrument_codes"] else: RmagSpecRec["magic_instrument_codes"]="" RmagSpecRec["anisotropy_type"]="AARM" RmagSpecRec["anisotropy_description"]="Hext statistics adapted to AARM" if coord!='-1': # need to rotate s # set orientation priorities SO_methods=[] for rec in samp_data: if "magic_method_codes" not in rec: rec['magic_method_codes']='SO-NO' if "magic_method_codes" in rec: methlist=rec["magic_method_codes"] for meth in methlist.split(":"): if "SO" in meth and "SO-POM" not in meth.strip(): if meth.strip() not in SO_methods: SO_methods.append(meth.strip()) SO_priorities=pmag.set_priorities(SO_methods,0) # continue here redo,p=1,0 if len(SO_methods)<=1: az_type=SO_methods[0] orient=pmag.find_samp_rec(RmagSpecRec["er_sample_name"],samp_data,az_type) if orient["sample_azimuth"] !="": method_codes.append(az_type) redo=0 while redo==1: if p>=len(SO_priorities): print "no orientation data for ",s orient["sample_azimuth"]="" orient["sample_dip"]="" method_codes.append("SO-NO") redo=0 else: az_type=SO_methods[SO_methods.index(SO_priorities[p])] orient=pmag.find_samp_rec(PmagSpecRec["er_sample_name"],samp_data,az_type) if orient["sample_azimuth"] !="": method_codes.append(az_type) redo=0 p+=1 az,pl=orient['sample_azimuth'],orient['sample_dip'] s=pmag.dosgeo(s,az,pl) # rotate to geographic coordinates if coord=='100': sampe_bed_dir,sample_bed_dip=orient['sample_bed_dip_direction'],orient['sample_bed_dip'] s=pmag.dostilt(s,bed_dir,bed_dip) # rotate to geographic coordinates hpars=pmag.dohext(nf,sigma,s) # # prepare for output # RmagSpecRec["anisotropy_s1"]='%8.6f'%(s[0]) RmagSpecRec["anisotropy_s2"]='%8.6f'%(s[1]) RmagSpecRec["anisotropy_s3"]='%8.6f'%(s[2]) RmagSpecRec["anisotropy_s4"]='%8.6f'%(s[3]) RmagSpecRec["anisotropy_s5"]='%8.6f'%(s[4]) RmagSpecRec["anisotropy_s6"]='%8.6f'%(s[5]) RmagSpecRec["anisotropy_mean"]='%8.3e'%(trace/3) RmagSpecRec["anisotropy_sigma"]='%8.6f'%(sigma) RmagSpecRec["anisotropy_unit"]="Am^2" RmagSpecRec["anisotropy_n"]='%i'%(npos) RmagSpecRec["anisotropy_tilt_correction"]=coord RmagSpecRec["anisotropy_F"]='%7.1f '%(hpars["F"]) # used by thellier_gui - must be taken out for uploading RmagSpecRec["anisotropy_F_crit"]=hpars["F_crit"] # used by thellier_gui - must be taken out for uploading RmagResRec["anisotropy_t1"]='%8.6f '%(hpars["t1"]) RmagResRec["anisotropy_t2"]='%8.6f '%(hpars["t2"]) RmagResRec["anisotropy_t3"]='%8.6f '%(hpars["t3"]) RmagResRec["anisotropy_v1_dec"]='%7.1f '%(hpars["v1_dec"]) RmagResRec["anisotropy_v2_dec"]='%7.1f '%(hpars["v2_dec"]) RmagResRec["anisotropy_v3_dec"]='%7.1f '%(hpars["v3_dec"]) RmagResRec["anisotropy_v1_inc"]='%7.1f '%(hpars["v1_inc"]) RmagResRec["anisotropy_v2_inc"]='%7.1f '%(hpars["v2_inc"]) RmagResRec["anisotropy_v3_inc"]='%7.1f '%(hpars["v3_inc"]) RmagResRec["anisotropy_ftest"]='%7.1f '%(hpars["F"]) RmagResRec["anisotropy_ftest12"]='%7.1f '%(hpars["F12"]) RmagResRec["anisotropy_ftest23"]='%7.1f '%(hpars["F23"]) RmagResRec["result_description"]='Critical F: '+hpars["F_crit"]+';Critical F12/F13: '+hpars["F12_crit"] if hpars["e12"]>hpars["e13"]: RmagResRec["anisotropy_v1_zeta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v1_zeta_dec"]='%7.1f '%(hpars['v2_dec']) RmagResRec["anisotropy_v1_zeta_inc"]='%7.1f '%(hpars['v2_inc']) RmagResRec["anisotropy_v2_zeta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v2_zeta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v2_zeta_inc"]='%7.1f '%(hpars['v1_inc']) RmagResRec["anisotropy_v1_eta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v1_eta_dec"]='%7.1f '%(hpars['v3_dec']) RmagResRec["anisotropy_v1_eta_inc"]='%7.1f '%(hpars['v3_inc']) RmagResRec["anisotropy_v3_eta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v3_eta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v3_eta_inc"]='%7.1f '%(hpars['v1_inc']) else: RmagResRec["anisotropy_v1_zeta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v1_zeta_dec"]='%7.1f '%(hpars['v3_dec']) RmagResRec["anisotropy_v1_zeta_inc"]='%7.1f '%(hpars['v3_inc']) RmagResRec["anisotropy_v3_zeta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v3_zeta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v3_zeta_inc"]='%7.1f '%(hpars['v1_inc']) RmagResRec["anisotropy_v1_eta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v1_eta_dec"]='%7.1f '%(hpars['v2_dec']) RmagResRec["anisotropy_v1_eta_inc"]='%7.1f '%(hpars['v2_inc']) RmagResRec["anisotropy_v2_eta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v2_eta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v2_eta_inc"]='%7.1f '%(hpars['v1_inc']) if hpars["e23"]>hpars['e12']: RmagResRec["anisotropy_v2_zeta_semi_angle"]='%7.1f '%(hpars['e23']) RmagResRec["anisotropy_v2_zeta_dec"]='%7.1f '%(hpars['v3_dec']) RmagResRec["anisotropy_v2_zeta_inc"]='%7.1f '%(hpars['v3_inc']) RmagResRec["anisotropy_v3_zeta_semi_angle"]='%7.1f '%(hpars['e23']) RmagResRec["anisotropy_v3_zeta_dec"]='%7.1f '%(hpars['v2_dec']) RmagResRec["anisotropy_v3_zeta_inc"]='%7.1f '%(hpars['v2_inc']) RmagResRec["anisotropy_v3_eta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v3_eta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v3_eta_inc"]='%7.1f '%(hpars['v1_inc']) RmagResRec["anisotropy_v2_eta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v2_eta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v2_eta_inc"]='%7.1f '%(hpars['v1_inc']) else: RmagResRec["anisotropy_v2_zeta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v2_zeta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v2_zeta_inc"]='%7.1f '%(hpars['v1_inc']) RmagResRec["anisotropy_v3_eta_semi_angle"]='%7.1f '%(hpars['e23']) RmagResRec["anisotropy_v3_eta_dec"]='%7.1f '%(hpars['v2_dec']) RmagResRec["anisotropy_v3_eta_inc"]='%7.1f '%(hpars['v2_inc']) RmagResRec["anisotropy_v3_zeta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v3_zeta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v3_zeta_inc"]='%7.1f '%(hpars['v1_inc']) RmagResRec["anisotropy_v2_eta_semi_angle"]='%7.1f '%(hpars['e23']) RmagResRec["anisotropy_v2_eta_dec"]='%7.1f '%(hpars['v3_dec']) RmagResRec["anisotropy_v2_eta_inc"]='%7.1f '%(hpars['v3_inc']) RmagResRec["tilt_correction"]='-1' RmagResRec["anisotropy_type"]='AARM' RmagResRec["magic_method_codes"]='LP-AN-ARM:AE-H' RmagSpecRec["magic_method_codes"]='LP-AN-ARM:AE-H' RmagResRec["magic_software_packages"]=pmag.get_version() RmagSpecRec["magic_software_packages"]=pmag.get_version() specimen+=1 RmagSpecRecs.append(RmagSpecRec) RmagResRecs.append(RmagResRec) else: print 'skipping specimen ',s,' only 9 positions supported','; this has ',npos specimen+=1 if rmag_anis=="":rmag_anis="rmag_anisotropy.txt" pmag.magic_write(rmag_anis,RmagSpecRecs,'rmag_anisotropy') print "specimen tensor elements stored in ",rmag_anis if rmag_res=="":rmag_res="rmag_results.txt" pmag.magic_write(rmag_res,RmagResRecs,'rmag_results') print "specimen statistics and eigenparameters stored in ",rmag_res
def main(): """ NAME site_edit_magic.py DESCRIPTION makes equal area projections site by site from pmag_specimens.txt file with Fisher confidence ellipse using McFadden and McElhinny (1988) technique for combining lines and planes allows testing and reject specimens for bad orientations SYNTAX site_edit_magic.py [command line options] OPTIONS -h: prints help and quits -f: specify pmag_specimen format file, default is pmag_specimens.txt -fsa: specify er_samples.txt file -exc: use existing pmag_criteria.txt file -N: reset all sample flags to good OUPUT edited er_samples.txt file """ dir_path='.' FIG={} # plot dictionary FIG['eqarea']=1 # eqarea is figure 1 in_file='pmag_specimens.txt' sampfile='er_samples.txt' out_file="" fmt,plot='svg',1 Crits="" M,N=180.,1 repeat='' renew=0 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] if '-f' in sys.argv: ind=sys.argv.index("-f") in_file=sys.argv[ind+1] if '-fsa' in sys.argv: ind=sys.argv.index("-fsa") sampfile=sys.argv[ind+1] if '-exc' in sys.argv: Crits,file_type=pmag.magic_read(dir_path+'/pmag_criteria.txt') for crit in Crits: if crit['pmag_criteria_code']=='DE-SPEC': M=float(crit['specimen_mad']) N=float(crit['specimen_n']) if '-fmt' in sys.argv: ind=sys.argv.index("-fmt") fmt=sys.argv[ind+1] if '-N' in sys.argv: renew=1 # if in_file[0]!="/":in_file=dir_path+'/'+in_file if sampfile[0]!="/":sampfile=dir_path+'/'+sampfile crd='s' Specs,file_type=pmag.magic_read(in_file) if file_type!='pmag_specimens': print ' bad pmag_specimen input file' sys.exit() Samps,file_type=pmag.magic_read(sampfile) if file_type!='er_samples': print ' bad er_samples input file' sys.exit() SO_methods=[] for rec in Samps: if 'sample_orientation_flag' not in rec.keys(): rec['sample_orientation_flag']='g' if 'sample_description' not in rec.keys(): rec['sample_description']='' if renew==1: rec['sample_orientation_flag']='g' description=rec['sample_description'] if '#' in description: newdesc="" c=0 while description[c]!='#' and c<len(description)-1: # look for first pound sign newdesc=newdesc+description[c] c+=1 while description[c]=='#': c+=1# skip first set of pound signs while description[c]!='#':c+=1 # find second set of pound signs while description[c]=='#' and c<len(description)-1:c+=1 # skip second set of pound signs while c<len(description)-1: # look for first pound sign newdesc=newdesc+description[c] c+=1 rec['sample_description']=newdesc # edit out old comment about orientations if "magic_method_codes" in rec: methlist=rec["magic_method_codes"] for meth in methlist.split(":"): if "SO" in meth.strip() and "SO-POM" not in meth.strip(): if meth.strip() not in SO_methods: SO_methods.append(meth.strip()) pmag.magic_write(sampfile,Samps,'er_samples') SO_priorities=pmag.set_priorities(SO_methods,0) sitelist=[] for rec in Specs: if rec['er_site_name'] not in sitelist: sitelist.append(rec['er_site_name']) sitelist.sort() EQ={} EQ['eqarea']=1 pmagplotlib.plot_init(EQ['eqarea'],5,5) k=0 while k<len(sitelist): site=sitelist[k] print site data=[] ThisSiteSpecs=pmag.get_dictitem(Specs,'er_site_name',site,'T') ThisSiteSpecs=pmag.get_dictitem(ThisSiteSpecs,'specimen_tilt_correction','-1','T') # get all the unoriented data for spec in ThisSiteSpecs: if spec['specimen_mad']!="" and spec['specimen_n']!="" and float(spec['specimen_mad'])<=M and float(spec['specimen_n'])>=N: # good spec, now get orientation.... redo,p=1,0 if len(SO_methods)<=1: az_type=SO_methods[0] orient=pmag.find_samp_rec(spec["er_sample_name"],Samps,az_type) redo=0 while redo==1: if p>=len(SO_priorities): print "no orientation data for ",spec['er_sample_name'] orient["sample_azimuth"]="" orient["sample_dip"]="" redo=0 else: az_type=SO_methods[SO_methods.index(SO_priorities[p])] orient=pmag.find_samp_rec(spec["er_sample_name"],Samps,az_type) if orient["sample_azimuth"] !="": redo=0 p+=1 if orient['sample_azimuth']!="": rec={} for key in spec.keys():rec[key]=spec[key] rec['dec'],rec['inc']=pmag.dogeo(float(spec['specimen_dec']),float(spec['specimen_inc']),float(orient['sample_azimuth']),float(orient['sample_dip'])) rec["tilt_correction"]='1' crd='g' rec['sample_azimuth']=orient['sample_azimuth'] rec['sample_dip']=orient['sample_dip'] data.append(rec) if len(data)>2: print 'specimen, dec, inc, n_meas/MAD,| method codes ' for i in range(len(data)): print '%s: %7.1f %7.1f %s / %s | %s' % (data[i]['er_specimen_name'], data[i]['dec'], data[i]['inc'], data[i]['specimen_n'], data[i]['specimen_mad'], data[i]['magic_method_codes']) fpars=pmag.dolnp(data,'specimen_direction_type') print "\n Site lines planes kappa a95 dec inc" print site, fpars["n_lines"], fpars["n_planes"], fpars["K"], fpars["alpha95"], fpars["dec"], fpars["inc"], fpars["R"] if out_file!="": if float(fpars["alpha95"])<=acutoff and float(fpars["K"])>=kcutoff: out.write('%s %s %s\n'%(fpars["dec"],fpars['inc'],fpars['alpha95'])) pmagplotlib.plotLNP(EQ['eqarea'],site,data,fpars,'specimen_direction_type') pmagplotlib.drawFIGS(EQ) if k!=0 and repeat!='y': ans=raw_input("s[a]ve plot, [q]uit, [e]dit specimens, [p]revious site, <return> to continue:\n ") elif k==0 and repeat!='y': ans=raw_input("s[a]ve plot, [q]uit, [e]dit specimens, <return> to continue:\n ") if ans=="p": k-=2 if ans=="a": files={} files['eqarea']=site+'_'+crd+'_eqarea'+'.'+fmt pmagplotlib.saveP(EQ,files) if ans=="q": sys.exit() if ans=="e" and Samps==[]: print "can't edit samples without orientation file, sorry" elif ans=="e": # k-=1 testspec=raw_input("Enter name of specimen to check: ") for spec in data: if spec['er_specimen_name']==testspec: # first test wrong direction of drill arrows (flip drill direction in opposite direction and re-calculate d,i d,i=pmag.dogeo(float(spec['specimen_dec']),float(spec['specimen_inc']),float(spec['sample_azimuth'])-180.,-float(spec['sample_dip'])) XY=pmag.dimap(d,i) pmagplotlib.plotXY(EQ['eqarea'],[XY[0]],[XY[1]],sym='g^') # first test wrong end of compass (take az-180.) d,i=pmag.dogeo(float(spec['specimen_dec']),float(spec['specimen_inc']),float(spec['sample_azimuth'])-180.,float(spec['sample_dip'])) XY=pmag.dimap(d,i) pmagplotlib.plotXY(EQ['eqarea'],[XY[0]],[XY[1]],sym='kv') # did the sample spin in the hole? # now spin around specimen's z X_up,Y_up,X_d,Y_d=[],[],[],[] for incr in range(0,360,5): d,i=pmag.dogeo(float(spec['specimen_dec'])+incr,float(spec['specimen_inc']),float(spec['sample_azimuth']),float(spec['sample_dip'])) XY=pmag.dimap(d,i) if i>=0: X_d.append(XY[0]) Y_d.append(XY[1]) else: X_up.append(XY[0]) Y_up.append(XY[1]) pmagplotlib.plotXY(EQ['eqarea'],X_d,Y_d,sym='b.') pmagplotlib.plotXY(EQ['eqarea'],X_up,Y_up,sym='c.') pmagplotlib.drawFIGS(EQ) break print "Triangle: wrong arrow for drill direction." print "Delta: wrong end of compass." print "Small circle: wrong mark on sample. [cyan upper hemisphere]" deleteme=raw_input("Mark this sample as bad? y/[n] ") if deleteme=='y': reason=raw_input("Reason: [1] broke, [2] wrong drill direction, [3] wrong compass direction, [4] bad mark, [5] displaced block [6] other ") if reason=='1': description=' sample broke while drilling' if reason=='2': description=' wrong drill direction ' if reason=='3': description=' wrong compass direction ' if reason=='4': description=' bad mark in field' if reason=='5': description=' displaced block' if reason=='6': description=raw_input('Enter brief reason for deletion: ') for samp in Samps: if samp['er_sample_name']==spec['er_sample_name']: samp['sample_orientation_flag']='b' samp['sample_description']=samp['sample_description']+' ## direction deleted because: '+description+'##' # mark description pmag.magic_write(sampfile,Samps,'er_samples') repeat=raw_input("Mark another sample, this site? y/[n] ") if repeat=='y': k-=1 else: print 'skipping site - not enough data with specified coordinate system' k+=1 print "sample flags stored in ",sampfile
def main(): """ NAME specimens_results_magic.py DESCRIPTION combines pmag_specimens.txt file with age, location, acceptance criteria and outputs pmag_results table along with other MagIC tables necessary for uploading to the database SYNTAX specimens_results_magic.py [command line options] OPTIONS -h prints help message and quits -usr USER: identify user, default is "" -f: specimen input magic_measurements format file, default is "magic_measurements.txt" -fsp: specimen input pmag_specimens format file, default is "pmag_specimens.txt" -fsm: sample input er_samples format file, default is "er_samples.txt" -fsi: specimen input er_sites format file, default is "er_sites.txt" -fla: specify a file with paleolatitudes for calculating VADMs, default is not to calculate VADMS format is: site_name paleolatitude (space delimited file) -fa AGES: specify er_ages format file with age information -crd [s,g,t,b]: specify coordinate system (s, specimen, g geographic, t, tilt corrected, b, geographic and tilt corrected) Default is to assume geographic NB: only the tilt corrected data will appear on the results table, if both g and t are selected. -cor [AC:CR:NL]: colon delimited list of required data adjustments for all specimens included in intensity calculations (anisotropy, cooling rate, non-linear TRM) unless specified, corrections will not be applied -pri [TRM:ARM] colon delimited list of priorities for anisotropy correction (-cor must also be set to include AC). default is TRM, then ARM -age MIN MAX UNITS: specify age boundaries and units -exc: use exiting selection criteria (in pmag_criteria.txt file), default is default criteria -C: no acceptance criteria -aD: average directions per sample, default is NOT -aI: average multiple specimen intensities per sample, default is by site -aC: average all components together, default is NOT -pol: calculate polarity averages -sam: save sample level vgps and v[a]dms, default is by site -xSi: skip the site level intensity calculation -p: plot directions and look at intensities by site, default is NOT -fmt: specify output for saved images, default is svg (only if -p set) -lat: use present latitude for calculating VADMs, default is not to calculate VADMs -xD: skip directions -xI: skip intensities OUPUT writes pmag_samples, pmag_sites, pmag_results tables """ # set defaults Comps=[] # list of components version_num=pmag.get_version() args=sys.argv DefaultAge=["none"] skipdirs,coord,excrit,custom,vgps,average,Iaverage,plotsites,opt=1,0,0,0,0,0,0,0,0 get_model_lat=0 # this skips VADM calculation altogether, when get_model_lat=1, uses present day fmt='svg' dir_path="." model_lat_file="" Caverage=0 infile='pmag_specimens.txt' measfile="magic_measurements.txt" sampfile="er_samples.txt" sitefile="er_sites.txt" agefile="er_ages.txt" specout="er_specimens.txt" sampout="pmag_samples.txt" siteout="pmag_sites.txt" resout="pmag_results.txt" critout="pmag_criteria.txt" instout="magic_instruments.txt" sigcutoff,OBJ="","" noDir,noInt=0,0 polarity=0 coords=['0'] Dcrit,Icrit,nocrit=0,0,0 corrections=[] nocorrection=['DA-NL','DA-AC','DA-CR'] priorities=['DA-AC-ARM','DA-AC-TRM'] # priorities for anisotropy correction # get command line stuff if "-h" in args: print main.__doc__ sys.exit() if '-WD' in args: ind=args.index("-WD") dir_path=args[ind+1] if '-cor' in args: ind=args.index('-cor') cors=args[ind+1].split(':') # list of required data adjustments for cor in cors: nocorrection.remove('DA-'+cor) corrections.append('DA-'+cor) if '-pri' in args: ind=args.index('-pri') priorities=args[ind+1].split(':') # list of required data adjustments for p in priorities: p='DA-AC-'+p if '-f' in args: ind=args.index("-f") measfile=args[ind+1] if '-fsp' in args: ind=args.index("-fsp") infile=args[ind+1] if '-fsi' in args: ind=args.index("-fsi") sitefile=args[ind+1] if "-crd" in args: ind=args.index("-crd") coord=args[ind+1] if coord=='s':coords=['-1'] if coord=='g':coords=['0'] if coord=='t':coords=['100'] if coord=='b':coords=['0','100'] if "-usr" in args: ind=args.index("-usr") user=sys.argv[ind+1] else: user="" if "-C" in args: Dcrit,Icrit,nocrit=1,1,1 # no selection criteria if "-sam" in args: vgps=1 # save sample level VGPS/VADMs if "-xSi" in args: nositeints=1 # skip site level intensity else: nositeints=0 if "-age" in args: ind=args.index("-age") DefaultAge[0]=args[ind+1] DefaultAge.append(args[ind+2]) DefaultAge.append(args[ind+3]) Daverage,Iaverage,Caverage=0,0,0 if "-aD" in args: Daverage=1 # average by sample directions if "-aI" in args: Iaverage=1 # average by sample intensities if "-aC" in args: Caverage=1 # average all components together ??? why??? if "-pol" in args: polarity=1 # calculate averages by polarity if '-xD' in args:noDir=1 if '-xI' in args: noInt=1 elif "-fla" in args: if '-lat' in args: print "you should set a paleolatitude file OR use present day lat - not both" sys.exit() ind=args.index("-fla") model_lat_file=dir_path+'/'+args[ind+1] get_model_lat=2 mlat=open(model_lat_file,'rU') ModelLats=[] for line in mlat.readlines(): ModelLat={} tmp=line.split() ModelLat["er_site_name"]=tmp[0] ModelLat["site_model_lat"]=tmp[1] ModelLat["er_sample_name"]=tmp[0] ModelLat["sample_lat"]=tmp[1] ModelLats.append(ModelLat) get_model_lat=2 elif '-lat' in args: get_model_lat=1 if "-p" in args: plotsites=1 if "-fmt" in args: ind=args.index("-fmt") fmt=args[ind+1] if noDir==0: # plot by site - set up plot window import pmagplotlib EQ={} EQ['eqarea']=1 pmagplotlib.plot_init(EQ['eqarea'],5,5) # define figure 1 as equal area projection pmagplotlib.plotNET(EQ['eqarea']) # I don't know why this has to be here, but otherwise the first plot never plots... pmagplotlib.drawFIGS(EQ) if '-WD' in args: infile=dir_path+'/'+infile measfile=dir_path+'/'+measfile instout=dir_path+'/'+instout sampfile=dir_path+'/'+sampfile sitefile=dir_path+'/'+sitefile agefile=dir_path+'/'+agefile specout=dir_path+'/'+specout sampout=dir_path+'/'+sampout siteout=dir_path+'/'+siteout resout=dir_path+'/'+resout critout=dir_path+'/'+critout if "-exc" in args: # use existing pmag_criteria file if "-C" in args: print 'you can not use both existing and no criteria - choose either -exc OR -C OR neither (for default)' sys.exit() crit_data,file_type=pmag.magic_read(critout) print "Acceptance criteria read in from ", critout else : # use default criteria (if nocrit set, then get really loose criteria as default) crit_data=pmag.default_criteria(nocrit) if nocrit==0: print "Acceptance criteria are defaults" else: print "No acceptance criteria used " accept={} for critrec in crit_data: for key in critrec.keys(): if 'sample_int_sigma_uT' in critrec.keys(): critrec['sample_int_sigma']='%10.3e'%(eval(critrec['sample_int_sigma_uT'])*1e-6) if key not in accept.keys() and critrec[key]!='': accept[key]=critrec[key] # # if "-exc" not in args and "-C" not in args: print "args",args pmag.magic_write(critout,[accept],'pmag_criteria') print "\n Pmag Criteria stored in ",critout,'\n' # # now we're done slow dancing # SiteNFO,file_type=pmag.magic_read(sitefile) # read in site data - has the lats and lons SampNFO,file_type=pmag.magic_read(sampfile) # read in site data - has the lats and lons height_nfo=pmag.get_dictitem(SiteNFO,'site_height','','F') # find all the sites with height info. if agefile !="":AgeNFO,file_type=pmag.magic_read(agefile) # read in the age information Data,file_type=pmag.magic_read(infile) # read in specimen interpretations IntData=pmag.get_dictitem(Data,'specimen_int','','F') # retrieve specimens with intensity data comment,orient="",[] samples,sites=[],[] for rec in Data: # run through the data filling in missing keys and finding all components, coordinates available # fill in missing fields, collect unique sample and site names if 'er_sample_name' not in rec.keys(): rec['er_sample_name']="" elif rec['er_sample_name'] not in samples: samples.append(rec['er_sample_name']) if 'er_site_name' not in rec.keys(): rec['er_site_name']="" elif rec['er_site_name'] not in sites: sites.append(rec['er_site_name']) if 'specimen_int' not in rec.keys():rec['specimen_int']='' if 'specimen_comp_name' not in rec.keys() or rec['specimen_comp_name']=="":rec['specimen_comp_name']='A' if rec['specimen_comp_name'] not in Comps:Comps.append(rec['specimen_comp_name']) rec['specimen_tilt_correction']=rec['specimen_tilt_correction'].strip('\n') if "specimen_tilt_correction" not in rec.keys(): rec["specimen_tilt_correction"]="-1" # assume sample coordinates if rec["specimen_tilt_correction"] not in orient: orient.append(rec["specimen_tilt_correction"]) # collect available coordinate systems if "specimen_direction_type" not in rec.keys(): rec["specimen_direction_type"]='l' # assume direction is line - not plane if "specimen_dec" not in rec.keys(): rec["specimen_direction_type"]='' # if no declination, set direction type to blank if "specimen_n" not in rec.keys(): rec["specimen_n"]='' # put in n if "specimen_alpha95" not in rec.keys(): rec["specimen_alpha95"]='' # put in alpha95 if "magic_method_codes" not in rec.keys(): rec["magic_method_codes"]='' # # start parsing data into SpecDirs, SpecPlanes, SpecInts SpecInts,SpecDirs,SpecPlanes=[],[],[] samples.sort() # get sorted list of samples and sites sites.sort() if noInt==0: # don't skip intensities IntData=pmag.get_dictitem(Data,'specimen_int','','F') # retrieve specimens with intensity data if nocrit==0: # use selection criteria for rec in IntData: # do selection criteria kill=pmag.grade(rec,accept,'specimen_int') if len(kill)==0: SpecInts.append(rec) # intensity record to be included in sample, site calculations else: SpecInts=IntData[:] # take everything - no selection criteria # check for required data adjustments if len(corrections)>0 and len(SpecInts)>0: for cor in corrections: SpecInts=pmag.get_dictitem(SpecInts,'magic_method_codes',cor,'has') # only take specimens with the required corrections if len(nocorrection)>0 and len(SpecInts)>0: for cor in nocorrection: SpecInts=pmag.get_dictitem(SpecInts,'magic_method_codes',cor,'not') # exclude the corrections not specified for inclusion # take top priority specimen of its name in remaining specimens (only one per customer) PrioritySpecInts=[] specimens=pmag.get_specs(SpecInts) # get list of uniq specimen names for spec in specimens: ThisSpecRecs=pmag.get_dictitem(SpecInts,'er_specimen_name',spec,'T') # all the records for this specimen if len(ThisSpecRecs)==1: PrioritySpecInts.append(ThisSpecRecs[0]) elif len(ThisSpecRecs)>1: # more than one prec=[] for p in priorities: ThisSpecRecs=pmag.get_dictitem(SpecInts,'magic_method_codes',p,'has') # all the records for this specimen if len(ThisSpecRecs)>0:prec.append(ThisSpecRecs[0]) PrioritySpecInts.append(prec[0]) # take the best one SpecInts=PrioritySpecInts # this has the first specimen record if noDir==0: # don't skip directions AllDirs=pmag.get_dictitem(Data,'specimen_direction_type','','F') # retrieve specimens with directed lines and planes Ns=pmag.get_dictitem(AllDirs,'specimen_n','','F') # get all specimens with specimen_n information if nocrit!=1: # use selection criteria for rec in Ns: # look through everything with specimen_n for "good" data kill=pmag.grade(rec,accept,'specimen_dir') if len(kill)==0: # nothing killed it SpecDirs.append(rec) else: # no criteria SpecDirs=AllDirs[:] # take them all # SpecDirs is now the list of all specimen directions (lines and planes) that pass muster # PmagSamps,SampDirs=[],[] # list of all sample data and list of those that pass the DE-SAMP criteria PmagSites,PmagResults=[],[] # list of all site data and selected results SampInts=[] for samp in samples: # run through the sample names if Daverage==1: # average by sample if desired SampDir=pmag.get_dictitem(SpecDirs,'er_sample_name',samp,'T') # get all the directional data for this sample if len(SampDir)>0: # there are some directions for coord in coords: # step through desired coordinate systems CoordDir=pmag.get_dictitem(SampDir,'specimen_tilt_correction',coord,'T') # get all the directions for this sample if len(CoordDir)>0: # there are some with this coordinate system if Caverage==0: # look component by component for comp in Comps: CompDir=pmag.get_dictitem(CoordDir,'specimen_comp_name',comp,'T') # get all directions from this component if len(CompDir)>0: # there are some PmagSampRec=pmag.lnpbykey(CompDir,'sample','specimen') # get a sample average from all specimens PmagSampRec["er_location_name"]=CompDir[0]['er_location_name'] # decorate the sample record PmagSampRec["er_site_name"]=CompDir[0]['er_site_name'] PmagSampRec["er_sample_name"]=samp PmagSampRec["er_citation_names"]="This study" PmagSampRec["er_analyst_mail_names"]=user PmagSampRec['magic_software_packages']=version_num if nocrit!=1:PmagSampRec['pmag_criteria_codes']="ACCEPT" if agefile != "": PmagSampRec= pmag.get_age(PmagSampRec,"er_site_name","sample_inferred_",AgeNFO,DefaultAge) site_height=pmag.get_dictitem(height_nfo,'er_site_name',PmagSampRec['er_site_name'],'T') if len(site_height)>0:PmagSampRec["sample_height"]=site_height[0]['site_height'] # add in height if available PmagSampRec['sample_comp_name']=comp PmagSampRec['sample_tilt_correction']=coord PmagSampRec['er_specimen_names']= pmag.get_list(CompDir,'er_specimen_name') # get a list of the specimen names used PmagSampRec['magic_method_codes']= pmag.get_list(CompDir,'magic_method_codes') # get a list of the methods used if nocrit!=1: # apply selection criteria kill=pmag.grade(PmagSampRec,accept,'sample_dir') else: kill=[] if len(kill)==0: SampDirs.append(PmagSampRec) if vgps==1: # if sample level VGP info desired, do that now PmagResRec=pmag.getsampVGP(PmagSampRec,SiteNFO) if PmagResRec!="":PmagResults.append(PmagResRec) PmagSamps.append(PmagSampRec) if Caverage==1: # average all components together basically same as above PmagSampRec=pmag.lnpbykey(CoordDir,'sample','specimen') PmagSampRec["er_location_name"]=CoordDir[0]['er_location_name'] PmagSampRec["er_site_name"]=CoordDir[0]['er_site_name'] PmagSampRec["er_sample_name"]=samp PmagSampRec["er_citation_names"]="This study" PmagSampRec["er_analyst_mail_names"]=user PmagSampRec['magic_software_packages']=version_num if nocrit!=1:PmagSampRec['pmag_criteria_codes']="" if agefile != "": PmagSampRec= pmag.get_age(PmagSampRec,"er_site_name","sample_inferred_",AgeNFO,DefaultAge) site_height=pmag.get_dictitem(height_nfo,'er_site_name',site,'T') if len(site_height)>0:PmagSampRec["sample_height"]=site_height[0]['site_height'] # add in height if available PmagSampRec['sample_tilt_correction']=coord PmagSampRec['sample_comp_name']= pmag.get_list(CoordDir,'specimen_comp_name') # get components used PmagSampRec['er_specimen_names']= pmag.get_list(CoordDir,'er_specimen_name') # get specimne names averaged PmagSampRec['magic_method_codes']= pmag.get_list(CoordDir,'magic_method_codes') # assemble method codes if nocrit!=1: # apply selection criteria kill=pmag.grade(PmagSampRec,accept,'sample_dir') if len(kill)==0: # passes the mustard SampDirs.append(PmagSampRec) if vgps==1: PmagResRec=pmag.getsampVGP(PmagSampRec,SiteNFO) if PmagResRec!="":PmagResults.append(PmagResRec) else: # take everything SampDirs.append(PmagSampRec) if vgps==1: PmagResRec=pmag.getsampVGP(PmagSampRec,SiteNFO) if PmagResRec!="":PmagResults.append(PmagResRec) PmagSamps.append(PmagSampRec) if Iaverage==1: # average by sample if desired SampI=pmag.get_dictitem(SpecInts,'er_sample_name',samp,'T') # get all the intensity data for this sample if len(SampI)>0: # there are some PmagSampRec=pmag.average_int(SampI,'specimen','sample') # get average intensity stuff PmagSampRec["sample_description"]="sample intensity" # decorate sample record PmagSampRec["sample_direction_type"]="" PmagSampRec['er_site_name']=SampI[0]["er_site_name"] PmagSampRec['er_sample_name']=samp PmagSampRec['er_location_name']=SampI[0]["er_location_name"] PmagSampRec["er_citation_names"]="This study" PmagSampRec["er_analyst_mail_names"]=user if agefile != "": PmagSampRec=pmag.get_age(PmagSampRec,"er_site_name","sample_inferred_", AgeNFO,DefaultAge) site_height=pmag.get_dictitem(height_nfo,'er_site_name',PmagSampRec['er_site_name'],'T') if len(site_height)>0:PmagSampRec["sample_height"]=site_height[0]['site_height'] # add in height if available PmagSampRec['er_specimen_names']= pmag.get_list(SampI,'er_specimen_name') PmagSampRec['magic_method_codes']= pmag.get_list(SampI,'magic_method_codes') if nocrit!=1: # apply criteria! kill=pmag.grade(PmagSampRec,accept,'sample_int') if len(kill)==0: PmagSampRec['pmag_criteria_codes']="ACCEPT" SampInts.append(PmagSampRec) PmagSamps.append(PmagSampRec) else:PmagSampRec={} # sample rejected else: # no criteria SampInts.append(PmagSampRec) PmagSamps.append(PmagSampRec) PmagSampRec['pmag_criteria_codes']="" if vgps==1 and get_model_lat!=0 and PmagSampRec!={}: # if get_model_lat==1: # use sample latitude PmagResRec=pmag.getsampVDM(PmagSampRec,SampNFO) del(PmagResRec['model_lat']) # get rid of the model lat key elif get_model_lat==2: # use model latitude PmagResRec=pmag.getsampVDM(PmagSampRec,ModelLats) if PmagResRec!={}:PmagResRec['magic_method_codes']=PmagResRec['magic_method_codes']+":IE-MLAT" if PmagResRec!={}: PmagResRec['er_specimen_names']=PmagSampRec['er_specimen_names'] PmagResRec['er_sample_names']=PmagSampRec['er_sample_name'] PmagResRec['pmag_criteria_codes']='ACCEPT' PmagResRec['average_int_sigma_perc']=PmagSampRec['sample_int_sigma_perc'] PmagResRec['average_int_sigma']=PmagSampRec['sample_int_sigma'] PmagResRec['average_int_n']=PmagSampRec['sample_int_n'] PmagResRec['vadm_n']=PmagSampRec['sample_int_n'] PmagResRec['data_type']='i' PmagResults.append(PmagResRec) if len(PmagSamps)>0: TmpSamps,keylist=pmag.fillkeys(PmagSamps) # fill in missing keys from different types of records pmag.magic_write(sampout,TmpSamps,'pmag_samples') # save in sample output file print ' sample averages written to ',sampout # #create site averages from specimens or samples as specified # for site in sites: if Daverage==0: key,dirlist='specimen',SpecDirs # if specimen averages at site level desired if Daverage==1: key,dirlist='sample',SampDirs # if sample averages at site level desired tmp=pmag.get_dictitem(dirlist,'er_site_name',site,'T') # get all the sites with directions tmp1=pmag.get_dictitem(tmp,key+'_tilt_correction',coords[-1],'T') # use only the last coordinate if Caverage==0 sd=pmag.get_dictitem(SiteNFO,'er_site_name',site,'T') # fish out site information (lat/lon, etc.) if len(sd)>0: sitedat=sd[0] if Caverage==0: # do component wise averaging for comp in Comps: siteD=pmag.get_dictitem(tmp1,key+'_comp_name',comp,'T') # get all components comp if len(siteD)>0: # there are some for this site and component name PmagSiteRec=pmag.lnpbykey(siteD,'site',key) # get an average for this site PmagSiteRec['site_comp_name']=comp # decorate the site record PmagSiteRec["er_location_name"]=siteD[0]['er_location_name'] PmagSiteRec["er_site_name"]=siteD[0]['er_site_name'] PmagSiteRec['site_tilt_correction']=coords[-1] PmagSiteRec['site_comp_name']= pmag.get_list(siteD,key+'_comp_name') if Daverage==1: PmagSiteRec['er_sample_names']= pmag.get_list(siteD,'er_sample_name') else: PmagSiteRec['er_specimen_names']= pmag.get_list(siteD,'er_specimen_name') # determine the demagnetization code (DC3,4 or 5) for this site AFnum=len(pmag.get_dictitem(siteD,'magic_method_codes','LP-DIR-AF','has')) Tnum=len(pmag.get_dictitem(siteD,'magic_method_codes','LP-DIR-T','has')) DC=3 if AFnum>0:DC+=1 if Tnum>0:DC+=1 PmagSiteRec['magic_method_codes']= pmag.get_list(siteD,'magic_method_codes')+':'+ 'LP-DC'+str(DC) PmagSiteRec['magic_method_codes'].strip(":") if plotsites==1: print PmagSiteRec['er_site_name'] pmagplotlib.plotSITE(EQ['eqarea'],PmagSiteRec,siteD,key) # plot and list the data pmagplotlib.drawFIGS(EQ) PmagSites.append(PmagSiteRec) else: # last component only siteD=tmp1[:] # get the last orientation system specified if len(siteD)>0: # there are some PmagSiteRec=pmag.lnpbykey(siteD,'site',key) # get the average for this site PmagSiteRec["er_location_name"]=siteD[0]['er_location_name'] # decorate the record PmagSiteRec["er_site_name"]=siteD[0]['er_site_name'] PmagSiteRec['site_comp_name']=comp PmagSiteRec['site_tilt_correction']=coords[-1] PmagSiteRec['site_comp_name']= pmag.get_list(siteD,key+'_comp_name') PmagSiteRec['er_specimen_names']= pmag.get_list(siteD,'er_specimen_name') PmagSiteRec['er_sample_names']= pmag.get_list(siteD,'er_sample_name') AFnum=len(pmag.get_dictitem(siteD,'magic_method_codes','LP-DIR-AF','has')) Tnum=len(pmag.get_dictitem(siteD,'magic_method_codes','LP-DIR-T','has')) DC=3 if AFnum>0:DC+=1 if Tnum>0:DC+=1 PmagSiteRec['magic_method_codes']= pmag.get_list(siteD,'magic_method_codes')+':'+ 'LP-DC'+str(DC) PmagSiteRec['magic_method_codes'].strip(":") if Daverage==0:PmagSiteRec['site_comp_name']= pmag.get_list(siteD,key+'_comp_name') if plotsites==1: pmagplotlib.plotSITE(EQ['eqarea'],PmagSiteRec,siteD,key) pmagplotlib.drawFIGS(EQ) PmagSites.append(PmagSiteRec) else: print 'site information not found in er_sites for site, ',site,' site will be skipped' for PmagSiteRec in PmagSites: # now decorate each dictionary some more, and calculate VGPs etc. for results table PmagSiteRec["er_citation_names"]="This study" PmagSiteRec["er_analyst_mail_names"]=user PmagSiteRec['magic_software_packages']=version_num if agefile != "": PmagSiteRec= pmag.get_age(PmagSiteRec,"er_site_name","site_inferred_",AgeNFO,DefaultAge) PmagSiteRec['pmag_criteria_codes']='ACCEPT' if 'site_n_lines' in PmagSiteRec.keys() and 'site_n_planes' in PmagSiteRec.keys() and PmagSiteRec['site_n_lines']!="" and PmagSiteRec['site_n_planes']!="": if int(PmagSiteRec["site_n_planes"])>0: PmagSiteRec["magic_method_codes"]=PmagSiteRec['magic_method_codes']+":DE-FM-LP" elif int(PmagSiteRec["site_n_lines"])>2: PmagSiteRec["magic_method_codes"]=PmagSiteRec['magic_method_codes']+":DE-FM" kill=pmag.grade(PmagSiteRec,accept,'site_dir') if len(kill)==0: PmagResRec={} # set up dictionary for the pmag_results table entry PmagResRec['data_type']='i' # decorate it a bit PmagResRec['magic_software_packages']=version_num PmagSiteRec['site_description']='Site direction included in results table' PmagResRec['pmag_criteria_codes']='ACCEPT' dec=float(PmagSiteRec["site_dec"]) inc=float(PmagSiteRec["site_inc"]) if 'site_alpha95' in PmagSiteRec.keys() and PmagSiteRec['site_alpha95']!="": a95=float(PmagSiteRec["site_alpha95"]) else:a95=180. sitedat=pmag.get_dictitem(SiteNFO,'er_site_name',PmagSiteRec['er_site_name'],'T')[0] # fish out site information (lat/lon, etc.) lat=float(sitedat['site_lat']) lon=float(sitedat['site_lon']) plong,plat,dp,dm=pmag.dia_vgp(dec,inc,a95,lat,lon) # get the VGP for this site if PmagSiteRec['site_tilt_correction']=='-1':C=' (spec coord) ' if PmagSiteRec['site_tilt_correction']=='0':C=' (geog. coord) ' if PmagSiteRec['site_tilt_correction']=='100':C=' (strat. coord) ' PmagResRec["pmag_result_name"]="VGP Site: "+PmagSiteRec["er_site_name"] # decorate some more PmagResRec["result_description"]="Site VGP, coord system = "+str(coord)+' component: '+comp PmagResRec['er_site_names']=PmagSiteRec['er_site_name'] PmagResRec['pmag_criteria_codes']='ACCEPT' PmagResRec['er_citation_names']='This study' PmagResRec['er_analyst_mail_names']=user PmagResRec["er_location_names"]=PmagSiteRec["er_location_name"] if Daverage==1: PmagResRec["er_sample_names"]=PmagSiteRec["er_sample_names"] else: PmagResRec["er_specimen_names"]=PmagSiteRec["er_specimen_names"] PmagResRec["tilt_correction"]=PmagSiteRec['site_tilt_correction'] PmagResRec["pole_comp_name"]=PmagSiteRec['site_comp_name'] PmagResRec["average_dec"]=PmagSiteRec["site_dec"] PmagResRec["average_inc"]=PmagSiteRec["site_inc"] PmagResRec["average_alpha95"]=PmagSiteRec["site_alpha95"] PmagResRec["average_n"]=PmagSiteRec["site_n"] PmagResRec["average_n_lines"]=PmagSiteRec["site_n_lines"] PmagResRec["average_n_planes"]=PmagSiteRec["site_n_planes"] PmagResRec["vgp_n"]=PmagSiteRec["site_n"] PmagResRec["average_k"]=PmagSiteRec["site_k"] PmagResRec["average_r"]=PmagSiteRec["site_r"] PmagResRec["average_lat"]='%10.4f ' %(lat) PmagResRec["average_lon"]='%10.4f ' %(lon) if agefile != "": PmagResRec= pmag.get_age(PmagResRec,"er_site_names","average_",AgeNFO,DefaultAge) site_height=pmag.get_dictitem(height_nfo,'er_site_name',site,'T') if len(site_height)>0:PmagResRec["average_height"]=site_height[0]['site_height'] PmagResRec["vgp_lat"]='%7.1f ' % (plat) PmagResRec["vgp_lon"]='%7.1f ' % (plong) PmagResRec["vgp_dp"]='%7.1f ' % (dp) PmagResRec["vgp_dm"]='%7.1f ' % (dm) PmagResRec["magic_method_codes"]= PmagSiteRec["magic_method_codes"] if PmagSiteRec['site_tilt_correction']=='0':PmagSiteRec['magic_method_codes']=PmagSiteRec['magic_method_codes']+":DA-DIR-GEO" if PmagSiteRec['site_tilt_correction']=='100':PmagSiteRec['magic_method_codes']=PmagSiteRec['magic_method_codes']+":DA-DIR-TILT" PmagSiteRec['site_polarity']="" if polarity==1: # assign polarity based on angle of pole lat to spin axis - may want to re-think this sometime angle=pmag.angle([0,0],[0,(90-plat)]) if angle <= 55.: PmagSiteRec["site_polarity"]='n' if angle > 55. and angle < 125.: PmagSiteRec["site_polarity"]='t' if angle >= 125.: PmagSiteRec["site_polarity"]='r' PmagResults.append(PmagResRec) if noInt!=1 and nositeints!=1: for site in sites: # now do intensities for each site if plotsites==1:print site if Iaverage==0: key,intlist='specimen',SpecInts # if using specimen level data if Iaverage==1: key,intlist='sample',PmagSamps # if using sample level data Ints=pmag.get_dictitem(intlist,'er_site_name',site,'T') # get all the intensities for this site if len(Ints)>0: # there are some PmagSiteRec=pmag.average_int(Ints,key,'site') # get average intensity stuff for site table PmagResRec=pmag.average_int(Ints,key,'average') # get average intensity stuff for results table if plotsites==1: # if site by site examination requested - print this site out to the screen for rec in Ints:print rec['er_'+key+'_name'],' %7.1f'%(1e6*float(rec[key+'_int'])) if len(Ints)>1: print 'Average: ','%7.1f'%(1e6*float(PmagResRec['average_int'])),'N: ',len(Ints) print 'Sigma: ','%7.1f'%(1e6*float(PmagResRec['average_int_sigma'])),'Sigma %: ',PmagResRec['average_int_sigma_perc'] raw_input('Press any key to continue\n') er_location_name=Ints[0]["er_location_name"] PmagSiteRec["er_location_name"]=er_location_name # decorate the records PmagSiteRec["er_citation_names"]="This study" PmagResRec["er_location_names"]=er_location_name PmagResRec["er_citation_names"]="This study" PmagSiteRec["er_analyst_mail_names"]=user PmagResRec["er_analyst_mail_names"]=user PmagResRec["data_type"]='i' if Iaverage==0: PmagSiteRec['er_specimen_names']= pmag.get_list(Ints,'er_specimen_name') # list of all specimens used PmagResRec['er_specimen_names']= pmag.get_list(Ints,'er_specimen_name') PmagSiteRec['er_sample_names']= pmag.get_list(Ints,'er_sample_name') # list of all samples used PmagResRec['er_sample_names']= pmag.get_list(Ints,'er_sample_name') PmagSiteRec['er_site_name']= site PmagResRec['er_site_names']= site PmagSiteRec['magic_method_codes']= pmag.get_list(Ints,'magic_method_codes') PmagResRec['magic_method_codes']= pmag.get_list(Ints,'magic_method_codes') kill=pmag.grade(PmagSiteRec,accept,'site_int') if nocrit==1 or len(kill)==0: b,sig=float(PmagResRec['average_int']),"" if(PmagResRec['average_int_sigma'])!="":sig=float(PmagResRec['average_int_sigma']) sdir=pmag.get_dictitem(PmagResults,'er_site_names',site,'T') # fish out site direction if len(sdir)>0 and sdir[-1]['average_inc']!="": # get the VDM for this record using last average inclination (hope it is the right one!) inc=float(sdir[0]['average_inc']) # mlat=pmag.magnetic_lat(inc) # get magnetic latitude using dipole formula PmagResRec["vdm"]='%8.3e '% (pmag.b_vdm(b,mlat)) # get VDM with magnetic latitude PmagResRec["vdm_n"]=PmagResRec['average_int_n'] if 'average_int_sigma' in PmagResRec.keys() and PmagResRec['average_int_sigma']!="": vdm_sig=pmag.b_vdm(float(PmagResRec['average_int_sigma']),mlat) PmagResRec["vdm_sigma"]='%8.3e '% (vdm_sig) else: PmagResRec["vdm_sigma"]="" mlat="" # define a model latitude if get_model_lat==1: # use present site latitude mlats=pmag.get_dictitem(SiteNFO,'er_site_name',site,'T') if len(mlats)>0: mlat=mlats[0]['site_lat'] elif get_model_lat==2: # use a model latitude from some plate reconstruction model (or something) mlats=pmag.get_dictitem(ModelLats,'er_site_name',site,'T') if len(mlats)>0: PmagResRec['model_lat']=mlats[0]['site_model_lat'] mlat=PmagResRec['model_lat'] if mlat!="": PmagResRec["vadm"]='%8.3e '% (pmag.b_vdm(b,float(mlat))) # get the VADM using the desired latitude if sig!="": vdm_sig=pmag.b_vdm(float(PmagResRec['average_int_sigma']),float(mlat)) PmagResRec["vadm_sigma"]='%8.3e '% (vdm_sig) PmagResRec["vadm_n"]=PmagResRec['average_int_n'] else: PmagResRec["vadm_sigma"]="" sitedat=pmag.get_dictitem(SiteNFO,'er_site_name',PmagSiteRec['er_site_name'],'T') # fish out site information (lat/lon, etc.) if len(sitedat)>0: sitedat=sitedat[0] PmagResRec['average_lat']=sitedat['site_lat'] PmagResRec['average_lon']=sitedat['site_lon'] else: PmagResRec['average_lon']='UNKNOWN' PmagResRec['average_lon']='UNKNOWN' PmagResRec['magic_software_packages']=version_num PmagResRec["pmag_result_name"]="V[A]DM: Site "+site PmagResRec["result_description"]="V[A]DM of site" PmagResRec["pmag_criteria_codes"]="ACCEPT" if agefile != "": PmagResRec= pmag.get_age(PmagResRec,"er_site_names","average_",AgeNFO,DefaultAge) site_height=pmag.get_dictitem(height_nfo,'er_site_name',site,'T') if len(site_height)>0:PmagResRec["average_height"]=site_height[0]['site_height'] PmagSites.append(PmagSiteRec) PmagResults.append(PmagResRec) if len(PmagSites)>0: Tmp,keylist=pmag.fillkeys(PmagSites) pmag.magic_write(siteout,Tmp,'pmag_sites') print ' sites written to ',siteout else: print "No Site level table" if len(PmagResults)>0: TmpRes,keylist=pmag.fillkeys(PmagResults) pmag.magic_write(resout,TmpRes,'pmag_results') print ' results written to ',resout else: print "No Results level table"
def main(): """ NAME vgpmap_magic.py DESCRIPTION makes a map of vgps and a95/dp,dm for site means in a pmag_results table SYNTAX vgpmap_magic.py [command line options] OPTIONS -h prints help and quits -eye ELAT ELON [specify eyeball location], default is 90., 0. -f FILE pmag_results format file, [default is pmag_results.txt] -res [c,l,i,h] specify resolution (crude, low, intermediate, high] -etp plot the etopo20 topographpy data (requires high resolution data set) -prj PROJ, specify one of the following: ortho = orthographic lcc = lambert conformal moll = molweide merc = mercator -sym SYM SIZE: choose a symbol and size, examples: ro 5 : small red circles bs 10 : intermediate blue squares g^ 20 : large green triangles -ell plot dp/dm or a95 ellipses -rev RSYM RSIZE : flip reverse poles to normal antipode -S: plot antipodes of all poles -age : plot the ages next to the poles -crd [g,t] : choose coordinate system, default is to plot all site VGPs -fmt [pdf, png, eps...] specify output format, default is pdf DEFAULTS FILE: pmag_results.txt res: c prj: mercator ELAT,ELON = 0,0 SYM SIZE: ro 8 RSYM RSIZE: g^ 8 """ dir_path='.' res,ages='c',0 proj='npstere' results_file='pmag_results.txt' ell,flip=0,0 lat_0,lon_0=90.,0. fmt='pdf' sym,size='ro',8 rsym,rsize='g^',8 anti=0 fancy=0 coord="" if '-WD' in sys.argv: ind = sys.argv.index('-WD') dir_path=sys.argv[ind+1] if '-h' in sys.argv: print main.__doc__ sys.exit() if '-S' in sys.argv:anti=1 if '-fmt' in sys.argv: ind = sys.argv.index('-fmt') fmt=sys.argv[ind+1] if '-res' in sys.argv: ind = sys.argv.index('-res') res=sys.argv[ind+1] if '-etp' in sys.argv:fancy=1 if '-prj' in sys.argv: ind = sys.argv.index('-prj') proj=sys.argv[ind+1] if '-rev' in sys.argv: flip=1 ind = sys.argv.index('-rev') rsym=(sys.argv[ind+1]) rsize=int(sys.argv[ind+2]) if '-sym' in sys.argv: ind = sys.argv.index('-sym') sym=(sys.argv[ind+1]) size=int(sys.argv[ind+2]) if '-eye' in sys.argv: ind = sys.argv.index('-eye') lat_0=float(sys.argv[ind+1]) lon_0=float(sys.argv[ind+2]) if '-ell' in sys.argv: ell=1 if '-age' in sys.argv: ages=1 if '-f' in sys.argv: ind = sys.argv.index('-f') results_file=sys.argv[ind+1] if '-crd' in sys.argv: ind = sys.argv.index('-crd') crd=sys.argv[ind+1] if crd=='g':coord='0' if crd=='t':coord='100' results_file=dir_path+'/'+results_file data,file_type=pmag.magic_read(results_file) if file_type!='pmag_results': print "bad results file" sys.exit() FIG={'map':1} pmagplotlib.plot_init(FIG['map'],6,6) # read in er_sites file lats,lons,dp,dm,a95=[],[],[],[],[] Pars=[] dates,rlats,rlons=[],[],[] Results=pmag.get_dictitem(data,'data_type','i','T') # get all site level data Results=pmag.get_dictitem(Results,'vgp_lat','','F') # get all non-blank latitudes Results=pmag.get_dictitem(Results,'vgp_lon','','F') # get all non-blank longitudes if coord!="":Results=pmag.get_dictitem(Results,'tilt_correction',coord,'T') # get specified coordinate system for rec in Results: if 'average_age' in rec.keys() and rec['average_age']!="" and ages==1: dates.append(rec['average_age']) lat=float(rec['vgp_lat']) lon=float(rec['vgp_lon']) if flip==0: lats.append(lat) lons.append(lon) elif flip==1: if lat<0: rlats.append(-lat) lon=lon+180. if lon>360:lon=lon-360. rlons.append(lon) else: lats.append(lat) lons.append(lon) elif anti==1: lats.append(-lat) lon=lon+180. if lon>360:lon=lon-360. lons.append(lon) ppars=[] ppars.append(lon) ppars.append(lat) ell1,ell2="","" if 'vgp_dm' in rec.keys() and rec['vgp_dm']!="":ell1=float(rec['vgp_dm']) if 'vgp_dp' in rec.keys() and rec['vgp_dp']!="":ell2=float(rec['vgp_dp']) if 'vgp_alpha95' in rec.keys() and rec['vgp_alpha95']!="":ell1,ell2=float(rec['vgp_alpha95']),float(rec['vgp_alpha95']) if ell1!="" and ell2!="": ppars=[] ppars.append(lons[-1]) ppars.append(lats[-1]) ppars.append(ell1) ppars.append(lons[-1]) isign=abs(lats[-1])/lats[-1] ppars.append(lats[-1]-isign*90.) ppars.append(ell2) ppars.append(lons[-1]+90.) ppars.append(0.) Pars.append(ppars) Opts={'latmin':-90,'latmax':90,'lonmin':0.,'lonmax':360.,'lat_0':lat_0,'lon_0':lon_0,'proj':proj,'sym':'bs','symsize':3,'pltgrid':0,'res':res,'boundinglat':0.} Opts['details']={'coasts':1,'rivers':0, 'states':0, 'countries':0,'ocean':1,'fancy':fancy} pmagplotlib.plotMAP(FIG['map'],[90.],[0.],Opts) # make the base map with a blue triangle at the pole` Opts['pltgrid']=-1 Opts['sym']=sym Opts['symsize']=size if len(dates)>0:Opts['names']=dates if len(lats)>0:pmagplotlib.plotMAP(FIG['map'],lats,lons,Opts) # add the lats and lons of the poles Opts['names']=[] if len(rlats)>0: Opts['sym']=rsym Opts['symsize']=rsize pmagplotlib.plotMAP(FIG['map'],rlats,rlons,Opts) # add the lats and lons of the poles pmagplotlib.drawFIGS(FIG) if ell==1: # add ellipses if desired. Opts['details']={'coasts':0,'rivers':0, 'states':0, 'countries':0,'ocean':0} Opts['pltgrid']=-1 # turn off meridian replotting Opts['symsize']=2 Opts['sym']='g-' for ppars in Pars: if ppars[2]!=0: PTS=pmagplotlib.plotELL(FIG['map'],ppars,'g.',0,0) elats,elons=[],[] for pt in PTS: elons.append(pt[0]) elats.append(pt[1]) pmagplotlib.plotMAP(FIG['map'],elats,elons,Opts) # make the base map with a blue triangle at the pole` pmagplotlib.drawFIGS(FIG) files={} for key in FIG.keys(): files[key]='VGP_map'+'.'+fmt if pmagplotlib.isServer: black = '#000000' purple = '#800080' titles={} titles['eq']='VGP Map' FIG = pmagplotlib.addBorders(FIG,titles,black,purple) pmagplotlib.saveP(FIG,files) else: ans=raw_input(" S[a]ve to save plot, Return to quit: ") if ans=="a": pmagplotlib.saveP(FIG,files) else: print "Good bye" sys.exit()
def main(): """ NAME lowrie_magic.py DESCRIPTION plots intensity decay curves for Lowrie experiments SYNTAX lowrie -h [command line options] INPUT takes magic_measurements formatted input files OPTIONS -h prints help message and quits -f FILE: specify input file, default is magic_measurements.txt -N do not normalize by maximum magnetization -fmt [svg, pdf, eps, png] specify fmt, default is svg """ fmt='svg' FIG={} # plot dictionary FIG['lowrie']=1 # demag is figure 1 pmagplotlib.plot_init(FIG['lowrie'],6,6) norm=1 # default is to normalize by maximum axis in_file,dir_path='magic_measurements.txt','.' if len(sys.argv)>1: if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] if '-h' in sys.argv: print main.__doc__ sys.exit() if '-N' in sys.argv: norm=0 # don't normalize if '-f' in sys.argv: # sets input filename ind=sys.argv.index("-f") in_file=sys.argv[ind+1] else: print main.__doc__ print 'you must supply a file name' sys.exit() in_file=dir_path+'/'+in_file print in_file PmagRecs,file_type=pmag.magic_read(in_file) if file_type!="magic_measurements": print 'bad input file' sys.exit() PmagRecs=pmag.get_dictitem(PmagRecs,'magic_method_codes','LP-IRM-3D','has') # get all 3D IRM records if len(PmagRecs)==0: print 'no records found' sys.exit() specs=pmag.get_dictkey(PmagRecs,'er_specimen_name','') sids=[] for spec in specs: if spec not in sids:sids.append(spec) # get list of unique specimen names for spc in sids: # step through the specimen names print spc specdata=pmag.get_dictitem(PmagRecs,'er_specimen_name',spc,'T') # get all this one's data DIMs,Temps=[],[] for dat in specdata: # step through the data DIMs.append([float(dat['measurement_dec']),float(dat['measurement_inc']),float(dat['measurement_magn_moment'])]) Temps.append(float(dat['treatment_temp'])-273.) carts=pmag.dir2cart(DIMs).transpose() if norm==1: # want to normalize nrm=(DIMs[0][2]) # normalize by NRM ylab="M/M_o" else: nrm=1. # don't normalize ylab="Magnetic moment (Am^2)" xlab="Temperature (C)" pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[0])/nrm,sym='r-') pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[0])/nrm,sym='ro') # X direction pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[1])/nrm,sym='c-') pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[1])/nrm,sym='cs') # Y direction pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[2])/nrm,sym='k-') pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[2])/nrm,sym='k^',title=spc,xlab=xlab,ylab=ylab) # Z direction pmagplotlib.drawFIGS(FIG) ans=raw_input('S[a]ve figure? [q]uit, <return> to continue ') if ans=='a': files={'lowrie':'lowrie:_'+spc+'_.'+fmt} pmagplotlib.saveP(FIG,files) elif ans=='q': sys.exit() pmagplotlib.clearFIG(FIG['lowrie'])
def main(): """ NAME magic_select.py DESCRIPTION picks out records and dictitem options saves to magic_special file SYNTAX magic_select.py [command line optins] OPTIONS -h prints help message and quits -f FILE: specify input magic format file -F FILE: specify output magic format file -key KEY string [T,F,has, not, eval,min,max] returns records where the value of the key either: matches exactly the string (T) does not match the string (F) contains the string (has) does not contain the string (not) the value equals the numerical value of the string (eval) the value is greater than the numerical value of the string (min) the value is less than the numerical value of the string (max) NOTES for age range: use KEY: age (converts to Ma, takes mid point of low, high if no value for age. for paleolat: use KEY: model_lat (uses lat, if age<5 Ma, else, model_lat, or attempts calculation from average_inc if no model_lat.) returns estimate in model_lat key """ dir_path="." flag='' if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] if '-h' in sys.argv: print main.__doc__ sys.exit() if '-f' in sys.argv: ind=sys.argv.index('-f') magic_file=dir_path+'/'+sys.argv[ind+1] else: print main.__doc__ sys.exit() if '-F' in sys.argv: ind=sys.argv.index('-F') outfile=dir_path+'/'+sys.argv[ind+1] else: print main.__doc__ sys.exit() if '-key' in sys.argv: ind=sys.argv.index('-key') grab_key=sys.argv[ind+1] v=sys.argv[ind+2] flag=sys.argv[ind+3] else: print main.__doc__ print '-key is required' sys.exit() # # get data read in Data,file_type=pmag.magic_read(magic_file) if grab_key =='age': grab_key='average_age' Data=pmag.convert_ages(Data) if grab_key =='model_lat': Data=pmag.convert_lat(Data) Data=pmag.convert_ages(Data) Selection=pmag.get_dictitem(Data,grab_key,v,flag) if len(Selection)>0: pmag.magic_write(outfile,Selection,file_type) print len(Selection),' records written to ',outfile else: print 'no data matched your criteria'
def main(command_line=True, **kwargs): """ NAME IODP_dscr_magic.py DESCRIPTION converts ODP LIMS discrete sample format files to magic_measurements format files SYNTAX IODP_descr_magic.py [command line options] OPTIONS -h: prints the help message and quits. -f FILE: specify input .csv file, default is all in directory -F FILE: specify output measurements file, default is magic_measurements.txt -A : don't average replicate measurements INPUTS IODP discrete sample .csv file format exported from LIMS database """ # # initialize defaults version_num = pmag.get_version() meas_file = "magic_measurements.txt" csv_file = "" MagRecs, Specs = [], [] citation = "This study" dir_path, demag = ".", "NRM" args = sys.argv noave = 0 # get command line args if command_line: if "-WD" in args: ind = args.index("-WD") dir_path = args[ind + 1] if "-ID" in args: ind = args.index("-ID") input_dir_path = args[ind + 1] else: input_dir_path = dir_path output_dir_path = dir_path if "-h" in args: print main.__doc__ return False if "-A" in args: noave = 1 if "-f" in args: ind = args.index("-f") csv_file = args[ind + 1] if "-F" in args: ind = args.index("-F") meas_file = args[ind + 1] if not command_line: dir_path = kwargs.get("dir_path", ".") input_dir_path = kwargs.get("input_dir_path", dir_path) output_dir_path = dir_path # rename dir_path after input_dir_path is set noave = kwargs.get("noave", 0) # default (0) is DO average csv_file = kwargs.get("csv_file", "") meas_file = kwargs.get("meas_file", "magic_measurements.txt") # format variables meas_file = os.path.join(output_dir_path, meas_file) if csv_file == "": filelist = os.listdir(input_dir_path) # read in list of files to import else: csv_file = os.path.join(input_dir_path, csv_file) filelist = [csv_file] # parsing the data file_found = False for file in filelist: # parse each file if file[-3:].lower() == "csv": file_found = True print "processing: ", file input = open(file, "rU").readlines() keys = input[0].replace("\n", "").split(",") # splits on underscores interval_key = "Offset (cm)" demag_key = "Demag level (mT)" offline_demag_key = "Treatment Value (mT or °C)" offline_treatment_type = "Treatment type" run_key = "Test No." if "Inclination background + tray corrected (deg)" in keys: inc_key = "Inclination background + tray corrected (deg)" if "Inclination background & tray corrected (deg)" in keys: inc_key = "Inclination background & tray corrected (deg)" if "Declination background + tray corrected (deg)" in keys: dec_key = "Declination background + tray corrected (deg)" if "Declination background & tray corrected (deg)" in keys: dec_key = "Declination background & tray corrected (deg)" if "Intensity background + tray corrected (A/m)" in keys: int_key = "Intensity background + tray corrected (A/m)" if "Intensity background & tray corrected (A/m)" in keys: int_key = "Intensity background & tray corrected (A/m)" type = "Type" sect_key = "Sect" half_key = "A/W" # need to add volume_key to LORE format! if "Sample volume (cm^3)" in keys: volume_key = "Sample volume (cm^3)" if "Sample volume (cc)" in keys: volume_key = "Sample volume (cc)" if "Sample volume (cm³)" in keys: volume_key = "Sample volume (cm³)" for line in input[1:]: InRec = {} for k in range(len(keys)): InRec[keys[k]] = line.split(",")[k] inst = "IODP-SRM" MagRec = {} expedition = InRec["Exp"] location = InRec["Site"] + InRec["Hole"] offsets = InRec[interval_key].split( "." ) # maintain consistency with er_samples convention of using top interval if len(offsets) == 1: offset = int(offsets[0]) else: offset = int(offsets[0]) - 1 # interval=str(offset+1)# maintain consistency with er_samples convention of using top interval interval = str(offset) # maintain consistency with er_samples convention of using top interval specimen = ( expedition + "-" + location + "-" + InRec["Core"] + InRec[type] + "-" + InRec[sect_key] + "_" + InRec[half_key] + "_" + interval ) if specimen not in Specs: Specs.append(specimen) MagRec["er_expedition_name"] = expedition MagRec["er_location_name"] = location MagRec["er_site_name"] = specimen MagRec["er_citation_names"] = citation MagRec["er_specimen_name"] = specimen MagRec["er_sample_name"] = specimen MagRec["er_site_name"] = specimen # set up measurement record - default is NRM MagRec["magic_software_packages"] = version_num MagRec["treatment_temp"] = "%8.3e" % (273) # room temp in kelvin MagRec["measurement_temp"] = "%8.3e" % (273) # room temp in kelvin MagRec["treatment_ac_field"] = "0" MagRec["treatment_dc_field"] = "0" MagRec["treatment_dc_field_phi"] = "0" MagRec["treatment_dc_field_theta"] = "0" MagRec["measurement_flag"] = "g" # assume all data are "good" MagRec["measurement_standard"] = "u" # assume all data are "good" MagRec["measurement_csd"] = "0" # assume all data are "good" volume = InRec[volume_key] MagRec["magic_method_codes"] = "LT-NO" sort_by = "treatment_ac_field" # set default to AF demag if InRec[demag_key] != "0": MagRec["magic_method_codes"] = "LT-AF-Z" inst = inst + ":IODP-SRM-AF" # measured on shipboard in-line 2G AF treatment_value = float(InRec[demag_key].strip('"')) * 1e-3 # convert mT => T if sort_by == "treatment_ac_field": MagRec["treatment_ac_field"] = treatment_value # AF demag in treat mT => T else: MagRec["treatment_ac_field"] = str(treatment_value) # AF demag in treat mT => T elif offline_treatment_type in InRec.keys() and InRec[offline_treatment_type] != "": if "Lowrie" in InRec["Comments"]: MagRec["magic_method_codes"] = "LP-IRM-3D" treatment_value = float(InRec[offline_demag_key].strip('"')) + 273.0 # convert C => K MagRec["treatment_temp"] = treatment_value MagRec["treatment_ac_field"] = "0" sort_by = "treatment_temp" elif "Isothermal" in InRec[offline_treatment_type]: MagRec["magic_method_codes"] = "LT-IRM" treatment_value = float(InRec[offline_demag_key].strip('"')) * 1e-3 # convert mT => T MagRec["treatment_dc_field"] = treatment_value MagRec["treatment_ac_field"] = "0" sort_by = "treatment_dc_field" MagRec["measurement_standard"] = "u" # assume all data are "good" vol = float(volume) * 1e-6 # convert from cc to m^3 if run_key in InRec.keys(): run_number = InRec[run_key] MagRec["external_database_ids"] = run_number MagRec["external_database_names"] = "LIMS" else: MagRec["external_database_ids"] = "" MagRec["external_database_names"] = "" MagRec["measurement_description"] = "sample orientation: " + InRec["Sample orientation"] MagRec["measurement_inc"] = InRec[inc_key].strip('"') MagRec["measurement_dec"] = InRec[dec_key].strip('"') intens = InRec[int_key].strip('"') MagRec["measurement_magn_moment"] = "%8.3e" % ( float(intens) * vol ) # convert intensity from A/m to Am^2 using vol MagRec["magic_instrument_codes"] = inst MagRec["measurement_number"] = "1" MagRec["measurement_positions"] = "" MagRecs.append(MagRec) if not file_found: print "No .csv files were found" return False, "No .csv files were found" MagOuts = [] for spec in Specs: Speclist = pmag.get_dictitem(MagRecs, "er_specimen_name", spec, "T") sorted = pmag.sort_diclist(Speclist, sort_by) for rec in sorted: for key in rec.keys(): rec[key] = str(rec[key]) MagOuts.append(rec) Fixed = pmag.measurements_methods(MagOuts, noave) Out, keys = pmag.fillkeys(Fixed) if pmag.magic_write(meas_file, Out, "magic_measurements"): print "data stored in ", meas_file return True, meas_file else: print "no data found. bad magfile?" return False, "no data found. bad magfile?"
def main(): """ NAME thellier_magic_redo.py DESCRIPTION Calculates paleointensity parameters for thellier-thellier type data using bounds stored in the "redo" file SYNTAX thellier_magic_redo [command line options] OPTIONS -h prints help message -usr USER: identify user, default is "" -fcr CRIT, set criteria for grading -f IN: specify input file, default is magic_measurements.txt -fre REDO: specify redo file, default is "thellier_redo" -F OUT: specify output file, default is thellier_specimens.txt -leg: attaches "Recalculated from original measurements; supercedes published results. " to comment field -CR PERC TYPE: apply a blanket cooling rate correction if none supplied in the er_samples.txt file PERC should be a percentage of original (say reduce to 90%) TYPE should be one of the following: EG (for educated guess); PS (based on pilots); TRM (based on comparison of two TRMs) -ANI: perform anisotropy correction -fsa SAMPFILE: er_samples.txt file with cooling rate correction information, default is NO CORRECTION -Fcr CRout: specify pmag_specimen format file for cooling rate corrected data -fan ANIFILE: specify rmag_anisotropy format file, default is rmag_anisotropy.txt -Fac ACout: specify pmag_specimen format file for anisotropy corrected data default is AC_specimens.txt -fnl NLTFILE: specify magic_measurments format file, default is magic_measurements.txt -Fnl NLTout: specify pmag_specimen format file for non-linear trm corrected data default is NLT_specimens.txt -z use z component differenences for pTRM calculation INPUT a thellier_redo file is Specimen_name Tmin Tmax (where Tmin and Tmax are in Centigrade) """ dir_path = "." critout = "" version_num = pmag.get_version() field, first_save = -1, 1 spec, recnum, start, end = 0, 0, 0, 0 crfrac = 0 NltRecs, PmagSpecs, AniSpecRecs, NltSpecRecs, CRSpecs = [], [], [], [], [] meas_file, pmag_file, mk_file = "magic_measurements.txt", "thellier_specimens.txt", "thellier_redo" anis_file = "rmag_anisotropy.txt" anisout, nltout = "AC_specimens.txt", "NLT_specimens.txt" crout = "CR_specimens.txt" nlt_file = "" samp_file = "" comment, user = "", "unknown" anis, nltrm = 0, 0 jackknife = 0 # maybe in future can do jackknife args = sys.argv Zdiff = 0 if "-WD" in args: ind = args.index("-WD") dir_path = args[ind + 1] if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind = args.index("-usr") user = sys.argv[ind + 1] if "-leg" in args: comment = "Recalculated from original measurements; supercedes published results. " cool = 0 if "-CR" in args: cool = 1 ind = args.index("-CR") crfrac = 0.01 * float(sys.argv[ind + 1]) crtype = "DA-CR-" + sys.argv[ind + 2] if "-Fcr" in args: ind = args.index("-Fcr") crout = sys.argv[ind + 1] if "-f" in args: ind = args.index("-f") meas_file = sys.argv[ind + 1] if "-F" in args: ind = args.index("-F") pmag_file = sys.argv[ind + 1] if "-fre" in args: ind = args.index("-fre") mk_file = args[ind + 1] if "-fsa" in args: ind = args.index("-fsa") samp_file = dir_path + "/" + args[ind + 1] Samps, file_type = pmag.magic_read(samp_file) SampCRs = pmag.get_dictitem(Samps, "cooling_rate_corr", "", "F") # get samples cooling rate corrections cool = 1 if file_type != "er_samples": print "not a valid er_samples.txt file" sys.exit() # # if "-ANI" in args: anis = 1 ind = args.index("-ANI") if "-Fac" in args: ind = args.index("-Fac") anisout = args[ind + 1] if "-fan" in args: ind = args.index("-fan") anis_file = args[ind + 1] # if "-NLT" in args: if "-Fnl" in args: ind = args.index("-Fnl") nltout = args[ind + 1] if "-fnl" in args: ind = args.index("-fnl") nlt_file = args[ind + 1] if "-z" in args: Zdiff = 1 if "-fcr" in sys.argv: ind = args.index("-fcr") critout = sys.argv[ind + 1] # # start reading in data: # meas_file = dir_path + "/" + meas_file mk_file = dir_path + "/" + mk_file accept = pmag.default_criteria(1)[0] # set criteria to none if critout != "": critout = dir_path + "/" + critout crit_data, file_type = pmag.magic_read(critout) if file_type != "pmag_criteria": print "bad pmag_criteria file, using no acceptance criteria" print "Acceptance criteria read in from ", critout for critrec in crit_data: if "sample_int_sigma_uT" in critrec.keys(): # accommodate Shaar's new criterion critrec["sample_int_sigma"] = "%10.3e" % (eval(critrec["sample_int_sigma_uT"]) * 1e-6) for key in critrec.keys(): if key not in accept.keys() and critrec[key] != "": accept[key] = critrec[key] meas_data, file_type = pmag.magic_read(meas_file) if file_type != "magic_measurements": print file_type print file_type, "This is not a valid magic_measurements file " sys.exit() try: mk_f = open(mk_file, "rU") except: print "Bad redo file" sys.exit() mkspec = [] speclist = [] for line in mk_f.readlines(): tmp = line.split() mkspec.append(tmp) speclist.append(tmp[0]) if anis == 1: anis_file = dir_path + "/" + anis_file anis_data, file_type = pmag.magic_read(anis_file) if file_type != "rmag_anisotropy": print file_type print file_type, "This is not a valid rmag_anisotropy file " sys.exit() if nlt_file == "": nlt_data = pmag.get_dictitem( meas_data, "magic_method_codes", "LP-TRM", "has" ) # look for trm acquisition data in the meas_data file else: nlt_file = dir_path + "/" + nlt_file nlt_data, file_type = pmag.magic_read(nlt_file) if len(nlt_data) > 0: nltrm = 1 # # sort the specimen names and step through one by one # sids = pmag.get_specs(meas_data) # print "Processing ", len(speclist), " specimens - please wait " while spec < len(speclist): s = speclist[spec] recnum = 0 datablock = [] PmagSpecRec = {} PmagSpecRec["er_analyst_mail_names"] = user PmagSpecRec["er_citation_names"] = "This study" PmagSpecRec["magic_software_packages"] = version_num methcodes, inst_code = [], "" # # find the data from the meas_data file for this specimen # datablock = pmag.get_dictitem(meas_data, "er_specimen_name", s, "T") datablock = pmag.get_dictitem( datablock, "magic_method_codes", "LP-PI-TRM", "has" ) # pick out the thellier experiment data if len(datablock) > 0: for rec in datablock: if "magic_instrument_codes" not in rec.keys(): rec["magic_instrument_codes"] = "unknown" # # collect info for the PmagSpecRec dictionary # rec = datablock[0] PmagSpecRec["er_specimen_name"] = s PmagSpecRec["er_sample_name"] = rec["er_sample_name"] PmagSpecRec["er_site_name"] = rec["er_site_name"] PmagSpecRec["er_location_name"] = rec["er_location_name"] PmagSpecRec["measurement_step_unit"] = "K" PmagSpecRec["specimen_correction"] = "u" if "er_expedition_name" in rec.keys(): PmagSpecRec["er_expedition_name"] = rec["er_expedition_name"] if "magic_instrument_codes" not in rec.keys(): PmagSpecRec["magic_instrument_codes"] = "unknown" else: PmagSpecRec["magic_instrument_codes"] = rec["magic_instrument_codes"] if "magic_experiment_name" not in rec.keys(): rec["magic_experiment_name"] = "" else: PmagSpecRec["magic_experiment_names"] = rec["magic_experiment_name"] meths = rec["magic_experiment_name"].split(":") for meth in meths: if meth.strip() not in methcodes and "LP-" in meth: methcodes.append(meth.strip()) # # sort out the data into first_Z, first_I, ptrm_check, ptrm_tail # araiblock, field = pmag.sortarai(datablock, s, Zdiff) first_Z = araiblock[0] first_I = araiblock[1] ptrm_check = araiblock[2] ptrm_tail = araiblock[3] if len(first_I) < 3 or len(first_Z) < 4: spec += 1 print "skipping specimen ", s else: # # get start, end # for redospec in mkspec: if redospec[0] == s: b, e = float(redospec[1]), float(redospec[2]) break if e > float(first_Z[-1][0]): e = float(first_Z[-1][0]) for recnum in range(len(first_Z)): if first_Z[recnum][0] == b: start = recnum if first_Z[recnum][0] == e: end = recnum nsteps = end - start if nsteps > 2: zijdblock, units = pmag.find_dmag_rec(s, meas_data) pars, errcode = pmag.PintPars(datablock, araiblock, zijdblock, start, end, accept) if "specimen_scat" in pars.keys(): PmagSpecRec["specimen_scat"] = pars["specimen_scat"] if "specimen_frac" in pars.keys(): PmagSpecRec["specimen_frac"] = "%5.3f" % (pars["specimen_frac"]) if "specimen_gmax" in pars.keys(): PmagSpecRec["specimen_gmax"] = "%5.3f" % (pars["specimen_gmax"]) pars["measurement_step_unit"] = units pars["specimen_lab_field_dc"] = field pars["specimen_int"] = -1 * field * pars["specimen_b"] PmagSpecRec["measurement_step_min"] = "%8.3e" % (pars["measurement_step_min"]) PmagSpecRec["measurement_step_max"] = "%8.3e" % (pars["measurement_step_max"]) PmagSpecRec["specimen_int_n"] = "%i" % (pars["specimen_int_n"]) PmagSpecRec["specimen_lab_field_dc"] = "%8.3e" % (pars["specimen_lab_field_dc"]) PmagSpecRec["specimen_int"] = "%9.4e " % (pars["specimen_int"]) PmagSpecRec["specimen_b"] = "%5.3f " % (pars["specimen_b"]) PmagSpecRec["specimen_q"] = "%5.1f " % (pars["specimen_q"]) PmagSpecRec["specimen_f"] = "%5.3f " % (pars["specimen_f"]) PmagSpecRec["specimen_fvds"] = "%5.3f" % (pars["specimen_fvds"]) PmagSpecRec["specimen_b_beta"] = "%5.3f" % (pars["specimen_b_beta"]) PmagSpecRec["specimen_int_mad"] = "%7.1f" % (pars["specimen_int_mad"]) PmagSpecRec["specimen_Z"] = "%7.1f" % (pars["specimen_Z"]) PmagSpecRec["specimen_gamma"] = "%7.1f" % (pars["specimen_gamma"]) if pars["method_codes"] != "" and pars["method_codes"] not in methcodes: methcodes.append(pars["method_codes"]) PmagSpecRec["specimen_dec"] = "%7.1f" % (pars["specimen_dec"]) PmagSpecRec["specimen_inc"] = "%7.1f" % (pars["specimen_inc"]) PmagSpecRec["specimen_tilt_correction"] = "-1" PmagSpecRec["specimen_direction_type"] = "l" PmagSpecRec["direction_type"] = "l" # this is redudant, but helpful - won't be imported PmagSpecRec["specimen_dang"] = "%7.1f " % (pars["specimen_dang"]) PmagSpecRec["specimen_drats"] = "%7.1f " % (pars["specimen_drats"]) PmagSpecRec["specimen_drat"] = "%7.1f " % (pars["specimen_drat"]) PmagSpecRec["specimen_int_ptrm_n"] = "%i " % (pars["specimen_int_ptrm_n"]) PmagSpecRec["specimen_rsc"] = "%6.4f " % (pars["specimen_rsc"]) PmagSpecRec["specimen_md"] = "%i " % (int(pars["specimen_md"])) if PmagSpecRec["specimen_md"] == "-1": PmagSpecRec["specimen_md"] = "" PmagSpecRec["specimen_b_sigma"] = "%5.3f " % (pars["specimen_b_sigma"]) if "IE-TT" not in methcodes: methcodes.append("IE-TT") methods = "" for meth in methcodes: methods = methods + meth + ":" PmagSpecRec["magic_method_codes"] = methods.strip(":") PmagSpecRec["magic_software_packages"] = version_num PmagSpecRec["specimen_description"] = comment if critout != "": kill = pmag.grade(PmagSpecRec, accept, "specimen_int") if len(kill) > 0: Grade = "F" # fails else: Grade = "A" # passes PmagSpecRec["specimen_grade"] = Grade else: PmagSpecRec["specimen_grade"] = "" # not graded if nltrm == 0 and anis == 0 and cool != 0: # apply cooling rate correction SCR = pmag.get_dictitem( SampCRs, "er_sample_name", PmagSpecRec["er_sample_name"], "T" ) # get this samples, cooling rate correction CrSpecRec = pmag.cooling_rate(PmagSpecRec, SCR, crfrac, crtype) if CrSpecRec["er_specimen_name"] != "none": CrSpecs.append(CrSpecRec) PmagSpecs.append(PmagSpecRec) NltSpecRec = "" # # check on non-linear TRM correction # if nltrm == 1: # # find the data from the nlt_data list for this specimen # TRMs, Bs = [], [] NltSpecRec = "" NltRecs = pmag.get_dictitem( nlt_data, "er_specimen_name", PmagSpecRec["er_specimen_name"], "has" ) # fish out all the NLT data for this specimen if len(NltRecs) > 2: for NltRec in NltRecs: Bs.append(float(NltRec["treatment_dc_field"])) TRMs.append(float(NltRec["measurement_magn_moment"])) NLTpars = nlt.NLtrm( Bs, TRMs, float(PmagSpecRec["specimen_int"]), float(PmagSpecRec["specimen_lab_field_dc"]), 0, ) if NLTpars["banc"] > 0: NltSpecRec = {} for key in PmagSpecRec.keys(): NltSpecRec[key] = PmagSpecRec[key] NltSpecRec["specimen_int"] = "%9.4e" % (NLTpars["banc"]) NltSpecRec["magic_method_codes"] = PmagSpecRec["magic_method_codes"] + ":DA-NL" NltSpecRec["specimen_correction"] = "c" NltSpecRec["specimen_grade"] = PmagSpecRec["specimen_grade"] NltSpecRec["magic_software_packages"] = version_num print NltSpecRec["er_specimen_name"], " Banc= ", float(NLTpars["banc"]) * 1e6 if anis == 0 and cool != 0: SCR = pmag.get_dictitem( SampCRs, "er_sample_name", NltSpecRec["er_sample_name"], "T" ) # get this samples, cooling rate correction CrSpecRec = pmag.cooling_rate(NltSpecRec, SCR, crfrac, crtype) if CrSpecRec["er_specimen_name"] != "none": CrSpecs.append(CrSpecRec) NltSpecRecs.append(NltSpecRec) # # check on anisotropy correction if anis == 1: if NltSpecRec != "": Spc = NltSpecRec else: # find uncorrected data Spc = PmagSpecRec AniSpecs = pmag.get_dictitem( anis_data, "er_specimen_name", PmagSpecRec["er_specimen_name"], "T" ) if len(AniSpecs) > 0: AniSpec = AniSpecs[0] AniSpecRec = pmag.doaniscorr(Spc, AniSpec) AniSpecRec["specimen_grade"] = PmagSpecRec["specimen_grade"] AniSpecRec["magic_instrument_codes"] = PmagSpecRec["magic_instrument_codes"] AniSpecRec["specimen_correction"] = "c" AniSpecRec["magic_software_packages"] = version_num if cool != 0: SCR = pmag.get_dictitem( SampCRs, "er_sample_name", AniSpecRec["er_sample_name"], "T" ) # get this samples, cooling rate correction CrSpecRec = pmag.cooling_rate(AniSpecRec, SCR, crfrac, crtype) if CrSpecRec["er_specimen_name"] != "none": CrSpecs.append(CrSpecRec) AniSpecRecs.append(AniSpecRec) elif anis == 1: AniSpecs = pmag.get_dictitem( anis_data, "er_specimen_name", PmagSpecRec["er_specimen_name"], "T" ) if len(AniSpecs) > 0: AniSpec = AniSpecs[0] AniSpecRec = pmag.doaniscorr(PmagSpecRec, AniSpec) AniSpecRec["specimen_grade"] = PmagSpecRec["specimen_grade"] AniSpecRec["magic_instrument_codes"] = PmagSpecRec["magic_instrument_codes"] AniSpecRec["specimen_correction"] = "c" AniSpecRec["magic_software_packages"] = version_num if crfrac != 0: CrSpecRec = {} for key in AniSpecRec.keys(): CrSpecRec[key] = AniSpecRec[key] inten = frac * float(CrSpecRec["specimen_int"]) CrSpecRec["specimen_int"] = "%9.4e " % ( inten ) # adjust specimen intensity by cooling rate correction CrSpecRec["magic_method_codes"] = CrSpecRec["magic_method_codes"] + ":DA-CR-" + crtype CRSpecs.append(CrSpecRec) AniSpecRecs.append(AniSpecRec) spec += 1 else: print "skipping ", s spec += 1 pmag_file = dir_path + "/" + pmag_file pmag.magic_write(pmag_file, PmagSpecs, "pmag_specimens") print "uncorrected thellier data saved in: ", pmag_file if anis == 1 and len(AniSpecRecs) > 0: anisout = dir_path + "/" + anisout pmag.magic_write(anisout, AniSpecRecs, "pmag_specimens") print "anisotropy corrected data saved in: ", anisout if nltrm == 1 and len(NltSpecRecs) > 0: nltout = dir_path + "/" + nltout pmag.magic_write(nltout, NltSpecRecs, "pmag_specimens") print "non-linear TRM corrected data saved in: ", nltout if crfrac != 0: crout = dir_path + "/" + crout pmag.magic_write(crout, CRSpecs, "pmag_specimens") print "cooling rate corrected data saved in: ", crout
def main(command_line=True, **kwargs): """ NAME IODP_jr6_magic.py DESCRIPTION converts shipboard .jr6 format files to magic_measurements format files SYNTAX IODP_jr6_magic.py [command line options] OPTIONS -h: prints the help message and quits. -f FILE: specify input file, or -F FILE: specify output file, default is magic_measurements.txt -fsa FILE: specify er_samples.txt file for sample name lookup , default is 'er_samples.txt' -loc HOLE : specify hole name (U1456A) -A: don't average replicate measurements INPUT JR6 .jr6 format file """ def fix_separation(filename, new_filename): old_file = open(filename, "rU") data = old_file.readlines() new_data = [] for line in data: new_line = line.replace("-", " -") new_line = new_line.replace(" ", " ") new_data.append(new_line) new_file = open(new_filename, "w") for s in new_data: new_file.write(s) old_file.close() new_file.close() return new_filename def old_fix_separation(filename, new_filename): old_file = open(filename, "rU") data = old_file.readlines() new_data = [] for line in data: new_line = [] for i in line.split(): if "-" in i[1:]: lead_char = "-" if i[0] == "-" else "" if lead_char: v = i[1:].split("-") else: v = i.split("-") new_line.append(lead_char + v[0]) new_line.append("-" + v[1]) else: new_line.append(i) new_line = (" ".join(new_line)) + "\n" new_data.append(new_line) new_file = open(new_filename, "w") for s in new_data: new_file.write(s) new_file.close() old_file.close() return new_filename # initialize some stuff noave = 0 volume = 2.5 ** 3 # default volume is a 2.5cm cube inst = "" samp_con, Z = "5", "" missing = 1 demag = "N" er_location_name = "unknown" citation = "This study" args = sys.argv meth_code = "LP-NO" version_num = pmag.get_version() dir_path = "." MagRecs = [] samp_file = "er_samples.txt" meas_file = "magic_measurements.txt" mag_file = "" # # get command line arguments # if command_line: if "-WD" in sys.argv: ind = sys.argv.index("-WD") dir_path = sys.argv[ind + 1] if "-ID" in sys.argv: ind = sys.argv.index("-ID") input_dir_path = sys.argv[ind + 1] else: input_dir_path = dir_path output_dir_path = dir_path if "-h" in args: print main.__doc__ return False if "-F" in args: ind = args.index("-F") meas_file = args[ind + 1] if "-fsa" in args: ind = args.index("-fsa") samp_file = args[ind + 1] if samp_file[0] != "/": samp_file = os.path.join(input_dir_path, samp_file) try: open(samp_file, "rU") ErSamps, file_type = pmag.magic_read(samp_file) except: print samp_file, " not found: " print " download csv file and import to MagIC with IODP_samples_magic.py" if "-f" in args: ind = args.index("-f") mag_file = args[ind + 1] if "-loc" in args: ind = args.index("-loc") er_location_name = args[ind + 1] if "-A" in args: noave = 1 if not command_line: dir_path = kwargs.get("dir_path", ".") input_dir_path = kwargs.get("input_dir_path", dir_path) output_dir_path = dir_path meas_file = kwargs.get("meas_file", "magic_measurements.txt") mag_file = kwargs.get("mag_file", "") samp_file = kwargs.get("samp_file", "er_samples.txt") specnum = kwargs.get("specnum", 1) samp_con = kwargs.get("samp_con", "1") if len(str(samp_con)) > 1: samp_con, Z = samp_con.split("-") else: Z = "" er_location_name = kwargs.get("er_location_name", "") noave = kwargs.get("noave", 0) # default (0) means DO average meth_code = kwargs.get("meth_code", "LP-NO") # format variables meth_code = meth_code + ":FS-C-DRILL-IODP:SP-SS-C:SO-V" meth_code = meth_code.strip(":") if mag_file: mag_file = os.path.join(input_dir_path, mag_file) samp_file = os.path.join(input_dir_path, samp_file) meas_file = os.path.join(output_dir_path, meas_file) # validate variables if not mag_file: print "You must provide an IODP_jr6 format file" return False, "You must provide an IODP_jr6 format file" if not os.path.exists(mag_file): print "The input file you provided: {} does not exist.\nMake sure you have specified the correct filename AND correct input directory name.".format( mag_file ) return ( False, "The input file you provided: {} does not exist.\nMake sure you have specified the correct filename AND correct input directory name.".format( mag_file ), ) if not os.path.exists(samp_file): print "Your input directory:\n{}\nmust contain an er_samples.txt file, or you must explicitly provide one".format( input_dir_path ) return ( False, "Your input directory:\n{}\nmust contain an er_samples.txt file, or you must explicitly provide one".format( input_dir_path ), ) # parse data temp = os.path.join(output_dir_path, "temp.txt") fix_separation(mag_file, temp) samples, filetype = pmag.magic_read(samp_file) lines = open(temp, "rU").readlines() os.remove(temp) for line in lines: MagRec = {} line = line.split() spec_text_id = line[0].split("_")[1] SampRecs = pmag.get_dictitem(samples, "er_sample_alternatives", spec_text_id, "has") if len(SampRecs) > 0: # found one MagRec["er_specimen_name"] = SampRecs[0]["er_sample_name"] MagRec["er_sample_name"] = MagRec["er_specimen_name"] MagRec["er_site_name"] = MagRec["er_specimen_name"] MagRec["er_citation_names"] = "This study" MagRec["er_location_name"] = er_location_name MagRec["magic_software_packages"] = version_num MagRec["treatment_temp"] = "%8.3e" % (273) # room temp in kelvin MagRec["measurement_temp"] = "%8.3e" % (273) # room temp in kelvin MagRec["measurement_flag"] = "g" MagRec["measurement_standard"] = "u" MagRec["measurement_number"] = "1" MagRec["treatment_ac_field"] = "0" volume = float(SampRecs[0]["sample_volume"]) x = float(line[4]) y = float(line[3]) negz = float(line[2]) cart = np.array([x, y, -negz]).transpose() direction = pmag.cart2dir(cart).transpose() expon = float(line[5]) magn_volume = direction[2] * (10.0 ** expon) moment = magn_volume * volume MagRec["measurement_magn_moment"] = str(moment) MagRec["measurement_magn_volume"] = str(magn_volume) # str(direction[2] * (10.0 ** expon)) MagRec["measurement_dec"] = "%7.1f" % (direction[0]) MagRec["measurement_inc"] = "%7.1f" % (direction[1]) step = line[1] if step == "NRM": meas_type = "LT-NO" elif step[0:2] == "AD": meas_type = "LT-AF-Z" treat = float(step[2:]) MagRec["treatment_ac_field"] = "%8.3e" % (treat * 1e-3) # convert from mT to tesla elif step[0:2] == "TD": meas_type = "LT-T-Z" treat = float(step[2:]) MagRec["treatment_temp"] = "%8.3e" % (treat + 273.0) # temp in kelvin elif step[0:3] == "ARM": # meas_type = "LT-AF-I" treat = float(row["step"][3:]) MagRec["treatment_ac_field"] = "%8.3e" % (treat * 1e-3) # convert from mT to tesla MagRec["treatment_dc_field"] = "%8.3e" % (50e-6) # assume 50uT DC field MagRec["measurement_description"] = "Assumed DC field - actual unknown" elif step[0:3] == "IRM": # meas_type = "LT-IRM" treat = float(step[3:]) MagRec["treatment_dc_field"] = "%8.3e" % (treat * 1e-3) # convert from mT to tesla else: print "unknown treatment type for ", row return False, "unknown treatment type for ", row MagRec["magic_method_codes"] = meas_type MagRecs.append(MagRec.copy()) else: print "sample name not found: ", row["specname"] MagOuts = pmag.measurements_methods(MagRecs, noave) file_created, error_message = pmag.magic_write(meas_file, MagOuts, "magic_measurements") if file_created: return True, meas_file else: return False, "Results not written to file"
def main(): """ NAME scalc_magic.py DESCRIPTION calculates Sb from pmag_results files SYNTAX scalc_magic -h [command line options] INPUT takes magic formatted pmag_results table pmag_result_name must start with "VGP: Site" must have average_lat if spin axis is reference OPTIONS -h prints help message and quits -f FILE: specify input results file, default is 'pmag_results.txt' -c cutoff: specify VGP colatitude cutoff value -k cutoff: specify kappa cutoff -crd [s,g,t]: specify coordinate system, default is geographic -v : use the VanDammme criterion -a: use antipodes of reverse data: default is to use only normal -C: use all data without regard to polarity -r: use reverse data only -p: do relative to principle axis -b: do bootstrap confidence bounds OUTPUT: if option -b used: N, S_B, lower and upper bounds otherwise: N, S_B, cutoff """ in_file='pmag_results.txt' coord,kappa,cutoff="0",1.,90. nb,anti,spin,v,boot=1000,0,1,0,0 coord_key='tilt_correction' rev=0 if '-h' in sys.argv: print main.__doc__ sys.exit() if '-f' in sys.argv: ind=sys.argv.index("-f") in_file=sys.argv[ind+1] if '-c' in sys.argv: ind=sys.argv.index('-c') cutoff=float(sys.argv[ind+1]) if '-k' in sys.argv: ind=sys.argv.index('-k') kappa=float(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 '-a' in sys.argv: anti=1 if '-C' in sys.argv: cutoff=180. # no cutoff if '-r' in sys.argv: rev=1 if '-p' in sys.argv: spin=0 if '-v' in sys.argv: v=1 if '-b' in sys.argv: boot=1 data,file_type=pmag.magic_read(in_file) # # # find desired vgp lat,lon, kappa,N_site data: # # # A,Vgps,Pvgps=180.,[],[] VgpRecs=pmag.get_dictitem(data,'vgp_lat','','F') # get all non-blank vgp latitudes VgpRecs=pmag.get_dictitem(VgpRecs,'vgp_lon','','F') # get all non-blank vgp longitudes SiteRecs=pmag.get_dictitem(VgpRecs,'data_type','i','T') # get VGPs (as opposed to averaged) SiteRecs=pmag.get_dictitem(SiteRecs,coord_key,coord,'T') # get right coordinate system for rec in SiteRecs: if anti==1: if 90.-abs(float(rec['vgp_lat']))<=cutoff and float(rec['average_k'])>=kappa: if float(rec['vgp_lat'])<0: rec['vgp_lat']='%7.1f'%(-1*float(rec['vgp_lat'])) rec['vgp_lon']='%7.1f'%(float(rec['vgp_lon'])-180.) Vgps.append(rec) Pvgps.append([float(rec['vgp_lon']),float(rec['vgp_lat'])]) elif rev==0: # exclude normals if 90.-(float(rec['vgp_lat']))<=cutoff and float(rec['average_k'])>=kappa: Vgps.append(rec) Pvgps.append([float(rec['vgp_lon']),float(rec['vgp_lat'])]) else: # include normals if 90.-abs(float(rec['vgp_lat']))<=cutoff and float(rec['average_k'])>=kappa: if float(rec['vgp_lat'])<0: rec['vgp_lat']='%7.1f'%(-1*float(rec['vgp_lat'])) rec['vgp_lon']='%7.1f'%(float(rec['vgp_lon'])-180.) Vgps.append(rec) Pvgps.append([float(rec['vgp_lon']),float(rec['vgp_lat'])]) if spin==0: # do transformation to pole ppars=pmag.doprinc(Pvgps) for vgp in Vgps: vlon,vlat=pmag.dodirot(float(vgp['vgp_lon']),float(vgp['vgp_lat']),ppars['dec'],ppars['inc']) vgp['vgp_lon']=vlon vgp['vgp_lat']=vlat vgp['average_k']="0" S_B= pmag.get_Sb(Vgps) A=cutoff if v==1: thetamax,A=181.,180. vVgps,cnt=[],0 for vgp in Vgps:vVgps.append(vgp) # make a copy of Vgps while thetamax>A: thetas=[] A=1.8*S_B+5 cnt+=1 for vgp in vVgps:thetas.append(90.-(float(vgp['vgp_lat']))) thetas.sort() thetamax=thetas[-1] if thetamax<A:break nVgps=[] for vgp in vVgps: if 90.-(float(vgp['vgp_lat']))<thetamax:nVgps.append(vgp) vVgps=[] for vgp in nVgps:vVgps.append(vgp) S_B= pmag.get_Sb(vVgps) Vgps=[] for vgp in vVgps:Vgps.append(vgp) # make a new Vgp list SBs=[] if boot==1: for i in range(nb): # now do bootstrap BVgps=[] if i%100==0: print i,' out of ',nb for k in range(len(Vgps)): ind=random.randint(0,len(Vgps)-1) random.jumpahead(int(ind*1000)) BVgps.append(Vgps[ind]) SBs.append(pmag.get_Sb(BVgps)) SBs.sort() low=int(.025*nb) high=int(.975*nb) print len(Vgps),'%7.1f _ %7.1f ^ %7.1f %7.1f'%(S_B,SBs[low],SBs[high],A) else: print len(Vgps),'%7.1f %7.1f '%(S_B,A)
def main(): """ NAME atrm_magic.py DESCRIPTION Converts ATRM data to best-fit tensor (6 elements plus sigma) Original program ARMcrunch written to accomodate ARM anisotropy data collected from 6 axial directions (+X,+Y,+Z,-X,-Y,-Z) using the off-axis remanence terms to construct the tensor. A better way to do the anisotropy of ARMs is to use 9,12 or 15 measurements in the Hext rotational scheme. SYNTAX atrm_magic.py [-h][command line options] OPTIONS -h prints help message and quits -usr USER: identify user, default is "" -f FILE: specify input file, default is atrm_measurements.txt -Fa FILE: specify anisotropy output file, default is trm_anisotropy.txt -Fr FILE: specify results output file, default is atrm_results.txt INPUT Input for the present program is a TRM acquisition data with an optional baseline. The order of the measurements is: Decs=[0,90,0,180,270,0,0,90,0] Incs=[0,0,90,0,0,-90,0,0,90] The last two measurements are optional """ # initialize some parameters args=sys.argv user="" meas_file="atrm_measurements.txt" rmag_anis="trm_anisotropy.txt" rmag_res="atrm_results.txt" dir_path='.' # # get name of file from command line # if '-WD' in args: ind=args.index('-WD') dir_path=args[ind+1] if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind=args.index("-usr") user=sys.argv[ind+1] if "-f" in args: ind=args.index("-f") meas_file=sys.argv[ind+1] if "-Fa" in args: ind=args.index("-Fa") rmag_anis=args[ind+1] if "-Fr" in args: ind=args.index("-Fr") rmag_res=args[ind+1] meas_file=dir_path+'/'+meas_file rmag_anis=dir_path+'/'+rmag_anis rmag_res=dir_path+'/'+rmag_res # read in data meas_data,file_type=pmag.magic_read(meas_file) meas_data=pmag.get_dictitem(meas_data,'magic_method_codes','LP-AN-TRM','has') if file_type != 'magic_measurements': print file_type print file_type,"This is not a valid magic_measurements file " sys.exit() # # # get sorted list of unique specimen names ssort=[] for rec in meas_data: spec=rec["er_specimen_name"] if spec not in ssort:ssort.append(spec) sids=sorted(ssort) # # # work on each specimen # specimen,npos=0,6 RmagSpecRecs,RmagResRecs=[],[] while specimen < len(sids): nmeas=0 s=sids[specimen] RmagSpecRec={} RmagResRec={} BX,X=[],[] method_codes=[] Spec0="" # # find the data from the meas_data file for this sample # and get dec, inc, int and convert to x,y,z # data=pmag.get_dictitem(meas_data,'er_specimen_name',s,'T') # fish out data for this specimen name if len(data)>5: RmagSpecRec["rmag_anisotropy_name"]=data[0]["er_specimen_name"] RmagSpecRec["er_location_name"]=data[0]["er_location_name"] RmagSpecRec["er_specimen_name"]=data[0]["er_specimen_name"] RmagSpecRec["er_sample_name"]=data[0]["er_sample_name"] RmagSpecRec["er_site_name"]=data[0]["er_site_name"] RmagSpecRec["magic_experiment_names"]=RmagSpecRec["rmag_anisotropy_name"]+":ATRM" RmagSpecRec["er_citation_names"]="This study" RmagResRec["rmag_result_name"]=data[0]["er_specimen_name"]+":ATRM" RmagResRec["er_location_names"]=data[0]["er_location_name"] RmagResRec["er_specimen_names"]=data[0]["er_specimen_name"] RmagResRec["er_sample_names"]=data[0]["er_sample_name"] RmagResRec["er_site_names"]=data[0]["er_site_name"] RmagResRec["magic_experiment_names"]=RmagSpecRec["rmag_anisotropy_name"]+":ATRM" RmagResRec["er_citation_names"]="This study" RmagSpecRec["anisotropy_type"]="ATRM" if "magic_instrument_codes" in data[0].keys(): RmagSpecRec["magic_instrument_codes"]=data[0]["magic_instrument_codes"] else: RmagSpecRec["magic_instrument_codes"]="" RmagSpecRec["anisotropy_description"]="Hext statistics adapted to ATRM" for rec in data: meths=rec['magic_method_codes'].strip().split(':') Dir=[] Dir.append(float(rec["measurement_dec"])) Dir.append(float(rec["measurement_inc"])) Dir.append(float(rec["measurement_magn_moment"])) if "LT-T-Z" in meths: BX.append(pmag.dir2cart(Dir)) # append baseline steps elif "LT-T-I" in meths: X.append(pmag.dir2cart(Dir)) nmeas+=1 # if len(BX)==1: for i in range(len(X)-1):BX.append(BX[0]) # assume first 0 field step as baseline elif len(BX)== 0: # assume baseline is zero for i in range(len(X)):BX.append([0.,0.,0.]) # assume baseline of 0 elif len(BX)!= len(X): # if BX isn't just one measurement or one in between every infield step, just assume it is zero print 'something odd about the baselines - just assuming zero' for i in range(len(X)):BX.append([0.,0.,0.]) # assume baseline of 0 if nmeas<6: # must have at least 6 measurements right now - print 'skipping specimen ',s,' too few measurements' specimen+=1 else: B,H,tmpH=pmag.designATRM(npos) # B matrix made from design matrix for positions # # subtract optional baseline and put in a work array # work=numpy.zeros((nmeas,3),'f') for i in range(nmeas): for j in range(3): work[i][j]=X[i][j]-BX[i][j] # subtract baseline, if available # # calculate tensor elements # first put ARM components in w vector # w=numpy.zeros((npos*3),'f') index=0 for i in range(npos): for j in range(3): w[index]=work[i][j] index+=1 s=numpy.zeros((6),'f') # initialize the s matrix for i in range(6): for j in range(len(w)): s[i]+=B[i][j]*w[j] trace=s[0]+s[1]+s[2] # normalize by the trace for i in range(6): s[i]=s[i]/trace a=pmag.s2a(s) #------------------------------------------------------------ # Calculating dels is different than in the Kappabridge # routine. Use trace normalized tensor (a) and the applied # unit field directions (tmpH) to generate model X,Y,Z # components. Then compare these with the measured values. #------------------------------------------------------------ S=0. comp=numpy.zeros((npos*3),'f') for i in range(npos): for j in range(3): index=i*3+j compare=a[j][0]*tmpH[i][0]+a[j][1]*tmpH[i][1]+a[j][2]*tmpH[i][2] comp[index]=compare for i in range(npos*3): d=w[i]/trace - comp[i] # del values S+=d*d nf=float(npos*3.-6.) # number of degrees of freedom if S >0: sigma=numpy.sqrt(S/nf) else: sigma=0 hpars=pmag.dohext(nf,sigma,s) # # prepare for output # RmagSpecRec["anisotropy_s1"]='%8.6f'%(s[0]) RmagSpecRec["anisotropy_s2"]='%8.6f'%(s[1]) RmagSpecRec["anisotropy_s3"]='%8.6f'%(s[2]) RmagSpecRec["anisotropy_s4"]='%8.6f'%(s[3]) RmagSpecRec["anisotropy_s5"]='%8.6f'%(s[4]) RmagSpecRec["anisotropy_s6"]='%8.6f'%(s[5]) RmagSpecRec["anisotropy_mean"]='%8.3e'%(trace/3) RmagSpecRec["anisotropy_sigma"]='%8.6f'%(sigma) RmagSpecRec["anisotropy_unit"]="Am^2" RmagSpecRec["anisotropy_n"]='%i'%(npos) RmagSpecRec["anisotropy_tilt_correction"]='-1' RmagSpecRec["anisotropy_F"]='%7.1f '%(hpars["F"]) # used by thellier_gui - must be taken out for uploading RmagSpecRec["anisotropy_F_crit"]=hpars["F_crit"] # used by thellier_gui - must be taken out for uploading RmagResRec["anisotropy_t1"]='%8.6f '%(hpars["t1"]) RmagResRec["anisotropy_t2"]='%8.6f '%(hpars["t2"]) RmagResRec["anisotropy_t3"]='%8.6f '%(hpars["t3"]) RmagResRec["anisotropy_v1_dec"]='%7.1f '%(hpars["v1_dec"]) RmagResRec["anisotropy_v2_dec"]='%7.1f '%(hpars["v2_dec"]) RmagResRec["anisotropy_v3_dec"]='%7.1f '%(hpars["v3_dec"]) RmagResRec["anisotropy_v1_inc"]='%7.1f '%(hpars["v1_inc"]) RmagResRec["anisotropy_v2_inc"]='%7.1f '%(hpars["v2_inc"]) RmagResRec["anisotropy_v3_inc"]='%7.1f '%(hpars["v3_inc"]) RmagResRec["anisotropy_ftest"]='%7.1f '%(hpars["F"]) RmagResRec["anisotropy_ftest12"]='%7.1f '%(hpars["F12"]) RmagResRec["anisotropy_ftest23"]='%7.1f '%(hpars["F23"]) RmagResRec["result_description"]='Critical F: '+hpars["F_crit"]+';Critical F12/F13: '+hpars["F12_crit"] if hpars["e12"]>hpars["e13"]: RmagResRec["anisotropy_v1_zeta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v1_zeta_dec"]='%7.1f '%(hpars['v2_dec']) RmagResRec["anisotropy_v1_zeta_inc"]='%7.1f '%(hpars['v2_inc']) RmagResRec["anisotropy_v2_zeta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v2_zeta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v2_zeta_inc"]='%7.1f '%(hpars['v1_inc']) RmagResRec["anisotropy_v1_eta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v1_eta_dec"]='%7.1f '%(hpars['v3_dec']) RmagResRec["anisotropy_v1_eta_inc"]='%7.1f '%(hpars['v3_inc']) RmagResRec["anisotropy_v3_eta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v3_eta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v3_eta_inc"]='%7.1f '%(hpars['v1_inc']) else: RmagResRec["anisotropy_v1_zeta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v1_zeta_dec"]='%7.1f '%(hpars['v3_dec']) RmagResRec["anisotropy_v1_zeta_inc"]='%7.1f '%(hpars['v3_inc']) RmagResRec["anisotropy_v3_zeta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v3_zeta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v3_zeta_inc"]='%7.1f '%(hpars['v1_inc']) RmagResRec["anisotropy_v1_eta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v1_eta_dec"]='%7.1f '%(hpars['v2_dec']) RmagResRec["anisotropy_v1_eta_inc"]='%7.1f '%(hpars['v2_inc']) RmagResRec["anisotropy_v2_eta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v2_eta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v2_eta_inc"]='%7.1f '%(hpars['v1_inc']) if hpars["e23"]>hpars['e12']: RmagResRec["anisotropy_v2_zeta_semi_angle"]='%7.1f '%(hpars['e23']) RmagResRec["anisotropy_v2_zeta_dec"]='%7.1f '%(hpars['v3_dec']) RmagResRec["anisotropy_v2_zeta_inc"]='%7.1f '%(hpars['v3_inc']) RmagResRec["anisotropy_v3_zeta_semi_angle"]='%7.1f '%(hpars['e23']) RmagResRec["anisotropy_v3_zeta_dec"]='%7.1f '%(hpars['v2_dec']) RmagResRec["anisotropy_v3_zeta_inc"]='%7.1f '%(hpars['v2_inc']) RmagResRec["anisotropy_v3_eta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v3_eta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v3_eta_inc"]='%7.1f '%(hpars['v1_inc']) RmagResRec["anisotropy_v2_eta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v2_eta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v2_eta_inc"]='%7.1f '%(hpars['v1_inc']) else: RmagResRec["anisotropy_v2_zeta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v2_zeta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v2_zeta_inc"]='%7.1f '%(hpars['v1_inc']) RmagResRec["anisotropy_v3_eta_semi_angle"]='%7.1f '%(hpars['e23']) RmagResRec["anisotropy_v3_eta_dec"]='%7.1f '%(hpars['v2_dec']) RmagResRec["anisotropy_v3_eta_inc"]='%7.1f '%(hpars['v2_inc']) RmagResRec["anisotropy_v3_zeta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v3_zeta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v3_zeta_inc"]='%7.1f '%(hpars['v1_inc']) RmagResRec["anisotropy_v2_eta_semi_angle"]='%7.1f '%(hpars['e23']) RmagResRec["anisotropy_v2_eta_dec"]='%7.1f '%(hpars['v3_dec']) RmagResRec["anisotropy_v2_eta_inc"]='%7.1f '%(hpars['v3_inc']) RmagResRec["tilt_correction"]='-1' RmagResRec["anisotropy_type"]='ATRM' RmagResRec["magic_method_codes"]='LP-AN-TRM:AE-H' RmagSpecRec["magic_method_codes"]='LP-AN-TRM:AE-H' RmagResRec["magic_software_packages"]=pmag.get_version() RmagSpecRec["magic_software_packages"]=pmag.get_version() RmagSpecRecs.append(RmagSpecRec) RmagResRecs.append(RmagResRec) specimen+=1 pmag.magic_write(rmag_anis,RmagSpecRecs,'rmag_anisotropy') print "specimen tensor elements stored in ",rmag_anis pmag.magic_write(rmag_res,RmagResRecs,'rmag_results') print "specimen statistics and eigenparameters stored in ",rmag_res