def main(): """ NAME thellier_magic.py DESCRIPTION plots Thellier-Thellier, allowing interactive setting of bounds and customizing of selection criteria. Saves and reads interpretations from a pmag_specimen formatted table, default: thellier_specimens.txt SYNTAX thellier_magic.py [command line options] OPTIONS -h prints help message and quits -f MEAS, set magic_measurements input file -fsp PRIOR, set pmag_specimen prior interpretations file -fan ANIS, set rmag_anisotropy file for doing the anisotropy corrections -fcr CRIT, set criteria file for grading. -fmt [svg,png,jpg], format for images - default is svg -sav, saves plots with out review (default format) -spc SPEC, plots single specimen SPEC, saves plot with specified format with optional -b bounds adn quits -b BEG END: sets bounds for calculation BEG: starting step for slope calculation END: ending step for slope calculation -z use only z component difference for pTRM calculation DEFAULTS MEAS: magic_measurements.txt REDO: thellier_redo CRIT: NONE PRIOR: NONE OUTPUT figures: ALL: numbers refer to temperature steps in command line window 1) Arai plot: closed circles are zero-field first/infield open circles are infield first/zero-field triangles are pTRM checks squares are pTRM tail checks VDS is vector difference sum diamonds are bounds for interpretation 2) Zijderveld plot: closed (open) symbols are X-Y (X-Z) planes X rotated to NRM direction 3) (De/Re)Magnetization diagram: circles are NRM remaining squares are pTRM gained 4) Optional: TRM acquisition 5) Optional: TDS normalization command line window: list is: temperature step numbers, temperatures (C), Dec, Inc, Int (units of magic_measuements) list of possible commands: type letter followed by return to select option saving of plots creates .svg format files with specimen_name, plot type as name """ # # initializations # meas_file,critout,inspec="magic_measurements.txt","","thellier_specimens.txt" first=1 inlt=0 version_num=pmag.get_version() TDinit,Tinit,field,first_save=0,0,-1,1 user,comment,AniSpec="",'',"" ans,specimen,recnum,start,end=0,0,0,0,0 plots,pmag_out,samp_file,style=0,"","","svg" fmt='.'+style # # default acceptance criteria # accept_keys=['specimen_int_ptrm_n','specimen_md','specimen_fvds','specimen_b_beta','specimen_dang','specimen_drats','specimen_Z'] accept={} accept['specimen_int_ptrm_n']=2 accept['specimen_md']=10 accept['specimen_fvds']=0.35 accept['specimen_b_beta']=.1 accept['specimen_int_mad']=7 accept['specimen_dang']=10 accept['specimen_drats']=10 accept['specimen_Z']=10 # # parse command line options # Zdiff,anis=0,0 spc,BEG,END="","","" if '-h' in sys.argv: print main.__doc__ sys.exit() if '-f' in sys.argv: ind=sys.argv.index('-f') meas_file=sys.argv[ind+1] if '-fsp' in sys.argv: ind=sys.argv.index('-fsp') inspec=sys.argv[ind+1] if '-fan' in sys.argv: ind=sys.argv.index('-fan') anisfile=sys.argv[ind+1] anis=1 anis_data,file_type=pmag.magic_read(anisfile) if pmagplotlib.verbose: print "Anisotropy data read in from ", anisfile if '-fmt' in sys.argv: ind=sys.argv.index('-fmt') fmt='.'+sys.argv[ind+1] if '-sav' in sys.argv: plots=1 if '-z' in sys.argv: Zdiff=1 if '-spc' in sys.argv: ind=sys.argv.index('-spc') spc=sys.argv[ind+1] if '-b' in sys.argv: ind=sys.argv.index('-b') BEG=int(sys.argv[ind+1]) END=int(sys.argv[ind+2]) if '-fcr' in sys.argv: ind=sys.argv.index('-fcr') critout=sys.argv[ind+1] crit_data,file_type=pmag.magic_read(critout) if pmagplotlib.verbose: print "Acceptance criteria read in from ", critout accept={} accept['specimen_int_ptrm_n']=2.0 for critrec in crit_data: if critrec["pmag_criteria_code"]=="IE-SPEC": for key in accept_keys: if key not in critrec.keys(): accept[key]=-1 else: accept[key]=float(critrec[key]) try: open(inspec,'rU') PriorRecs,file_type=pmag.magic_read(inspec) if file_type != 'pmag_specimens': print file_type print file_type,inspec," is not a valid pmag_specimens file " sys.exit() for rec in PriorRecs: if 'magic_software_packages' not in rec.keys():rec['magic_software_packages']="" except IOError: PriorRecs=[] if pmagplotlib.verbose:print "starting new specimen interpretation file: ",inspec 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() backup=0 # define figure numbers for arai, zijderveld and # de-,re-magization diagrams AZD={} AZD['deremag'], AZD['zijd'],AZD['arai'],AZD['eqarea']=1,2,3,4 pmagplotlib.plot_init(AZD['arai'],5,5) pmagplotlib.plot_init(AZD['zijd'],5,5) pmagplotlib.plot_init(AZD['deremag'],5,5) pmagplotlib.plot_init(AZD['eqarea'],5,5) # # # # get list of unique specimen names # CurrRec=[] sids=pmag.get_specs(meas_data) # get plots for specimen s - default is just to step through arai diagrams # if spc!="": specimen =sids.index(spc) while specimen < len(sids): methcodes=[] if pmagplotlib.verbose: print sids[specimen],specimen+1, 'of ', len(sids) MeasRecs=[] s=sids[specimen] datablock,trmblock,tdsrecs=[],[],[] PmagSpecRec={} if first==0: for key in keys:PmagSpecRec[key]="" # make sure all new records have same set of keys PmagSpecRec["er_analyst_mail_names"]=user PmagSpecRec["specimen_correction"]='u' # # find the data from the meas_data file for this specimen # for rec in meas_data: if rec["er_specimen_name"]==s: MeasRecs.append(rec) methods=rec["magic_method_codes"].split(":") meths=[] for meth in methods: meths.append(meth.strip()) # take off annoying spaces methods="" for meth in meths: if meth.strip() not in methcodes and "LP-" in meth:methcodes.append(meth.strip()) methods=methods+meth+":" methods=methods[:-1] rec["magic_method_codes"]=methods if "LP-PI-TRM" in meths: datablock.append(rec) if "LP-TRM" in meths: trmblock.append(rec) if "LP-TRM-TD" in meths: tdsrecs.append(rec) if len(trmblock)>2 and inspec!="": if Tinit==0: Tinit=1 AZD['TRM']=5 pmagplotlib.plot_init(AZD['TRM'],5,5) elif Tinit==1: # clear the TRM figure if not needed pmagplotlib.clearFIG(AZD['TRM']) if len(tdsrecs)>2: if TDinit==0: TDinit=1 AZD['TDS']=6 pmagplotlib.plot_init(AZD['TDS'],5,5) elif TDinit==1: # clear the TDS figure if not needed pmagplotlib.clearFIG(AZD['TDS']) if len(datablock) <4: if backup==0: specimen+=1 if pmagplotlib.verbose: print 'skipping specimen - moving forward ', s else: specimen-=1 if pmagplotlib.verbose: print 'skipping specimen - moving backward ', s # # collect info for the PmagSpecRec dictionary # else: rec=datablock[0] 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"] if "magic_instrument_codes" not in rec.keys():rec["magic_instrument_codes"]="" PmagSpecRec["magic_instrument_codes"]=rec["magic_instrument_codes"] PmagSpecRec["measurement_step_unit"]="K" if "magic_experiment_name" not in rec.keys(): rec["magic_experiment_name"]="" else: PmagSpecRec["magic_experiment_names"]=rec["magic_experiment_name"] meths=rec["magic_method_codes"].split() # sort data into types araiblock,field=pmag.sortarai(datablock,s,Zdiff) first_Z=araiblock[0] GammaChecks=araiblock[5] if len(first_Z)<3: if backup==0: specimen+=1 if pmagplotlib.verbose: print 'skipping specimen - moving forward ', s else: specimen-=1 if pmagplotlib.verbose: print 'skipping specimen - moving backward ', s else: backup=0 zijdblock,units=pmag.find_dmag_rec(s,meas_data) recnum=0 if pmagplotlib.verbose: print "index step Dec Inc Int Gamma" for plotrec in zijdblock: if GammaChecks!="": gamma="" for g in GammaChecks: if g[0]==plotrec[0]-273: gamma=g[1] break if gamma!="": print '%i %i %7.1f %7.1f %8.3e %7.1f' % (recnum,plotrec[0]-273,plotrec[1],plotrec[2],plotrec[3],gamma) else: print '%i %i %7.1f %7.1f %8.3e ' % (recnum,plotrec[0]-273,plotrec[1],plotrec[2],plotrec[3]) recnum += 1 pmagplotlib.plotAZ(AZD,araiblock,zijdblock,s,units[0]) if len(tdsrecs)>2: # a TDS experiment tdsblock=[] # make a list for the TDS data Mkeys=['measurement_magnitude','measurement_magn_moment','measurement_magn_volume','measuruement_magn_mass'] mkey,k="",0 while mkey=="" and k<len(Mkeys)-1: # find which type of intensity key= Mkeys[k] if key in tdsrecs[0].keys() and tdsrecs[0][key]!="": mkey=key k+=1 if mkey=="":break # get outta here Tnorm="" for tdrec in tdsrecs: meths=tdrec['magic_method_codes'].split(":") for meth in meths: meth.replace(" ","") # strip off potential nasty spaces if 'LT-T-I' in meths and Tnorm=="": # found first total TRM Tnorm=float(tdrec[mkey]) # normalize by total TRM tdsblock.append([273,zijdblock[0][3]/Tnorm,1.]) # put in the zero step if 'LT-T-Z' in meths and Tnorm!="": # found a LP-TRM-TD demag step, now need complementary LT-T-Z from zijdblock step=float(tdrec['treatment_temp']) Tint="" if mkey!="": Tint=float(tdrec[mkey]) if Tint!="": for zrec in zijdblock: if zrec[0]==step: # found matching tdsblock.append([step,zrec[3]/Tnorm,Tint/Tnorm]) break if len(tdsblock)>2: pmagplotlib.plotTDS(AZD['TDS'],tdsblock,s+':LP-PI-TDS:') else: print "Something wrong here" if anis==1: # look up anisotropy data for this specimen AniSpec="" for aspec in anis_data: if aspec["er_specimen_name"]==PmagSpecRec["er_specimen_name"]: AniSpec=aspec if pmagplotlib.verbose: print 'Found anisotropy record...' break if inspec !="": if pmagplotlib.verbose: print 'Looking up saved interpretation....' found = 0 for k in range(len(PriorRecs)): try: if PriorRecs[k]["er_specimen_name"]==s: found =1 CurrRec.append(PriorRecs[k]) for j in range(len(zijdblock)): if float(zijdblock[j][0])==float(PriorRecs[k]["measurement_step_min"]):start=j if float(zijdblock[j][0])==float(PriorRecs[k]["measurement_step_max"]):end=j pars,errcode=pmag.PintPars(araiblock,zijdblock,start,end) pars['measurement_step_unit']="K" pars['experiment_type']='LP-PI-TRM' del PriorRecs[k] # put in CurrRec, take out of PriorRecs if errcode!=1: pars["specimen_lab_field_dc"]=field pars["specimen_int"]=-1*field*pars["specimen_b"] pars["er_specimen_name"]=s if pmagplotlib.verbose: print 'Saved interpretation: ' pars=pmag.scoreit(pars,PmagSpecRec,accept,'',0) pmagplotlib.plotB(AZD,araiblock,zijdblock,pars) if len(trmblock)>2: blab=field best=pars["specimen_int"] Bs,TRMs=[],[] for trec in trmblock: Bs.append(float(trec['treatment_dc_field'])) TRMs.append(float(trec['measurement_magn_moment'])) NLpars=nlt.NLtrm(Bs,TRMs,best,blab,0) # calculate best fit parameters through TRM acquisition data, and get new banc Mp,Bp=[],[] for k in range(int(max(Bs)*1e6)): Bp.append(float(k)*1e-6) npred=nlt.TRM(Bp[-1],NLpars['xopt'][0],NLpars['xopt'][1]) # predicted NRM for this field Mp.append(npred) pmagplotlib.plotTRM(AZD['TRM'],Bs,TRMs,Bp,Mp,NLpars,trec['magic_experiment_name']) PmagSpecRec['specimen_int']=NLpars['banc'] if pmagplotlib.verbose: print 'Banc= ',float(NLpars['banc'])*1e6 pmagplotlib.drawFIGS(AZD) if AniSpec!="": AniSpecRec=pmag.thellier_anis_corr(PmagSpecRec,AniSpec) print 'Anisotropy corrected intensity= ',float(AniSpecRec['specimen_int'])*1e6 else: print 'error on specimen ',s except: pass if pmagplotlib.verbose and found==0: print ' None found :( ' if spc!="": if BEG!="": pars,errcode=pmag.PintPars(araiblock,zijdblock,BEG,END) pars['measurement_step_unit']="K" pars["specimen_lab_field_dc"]=field pars["specimen_int"]=-1*field*pars["specimen_b"] pars["er_specimen_name"]=s pars['specimen_grade']='' # ungraded pmagplotlib.plotB(AZD,araiblock,zijdblock,pars) if len(trmblock)>2: if inlt==0: inlt=1 blab=field best=pars["specimen_int"] Bs,TRMs=[],[] for trec in trmblock: Bs.append(float(trec['treatment_dc_field'])) TRMs.append(float(trec['measurement_magn_moment'])) NLpars=nlt.NLtrm(Bs,TRMs,best,blab,0) # calculate best fit parameters through TRM acquisition data, and get new banc # Mp,Bp=[],[] for k in range(int(max(Bs)*1e6)): Bp.append(float(k)*1e-6) npred=nlt.TRM(Bp[-1],NLpars['xopt'][0],NLpars['xopt'][1]) # predicted NRM for this field files={} for key in AZD.keys(): files[key]=s+'_'+key+fmt pmagplotlib.saveP(AZD,files) sys.exit() if plots==0: ans='b' while ans != "": print """ s[a]ve plot, set [b]ounds for calculation, [d]elete current interpretation, [p]revious, [s]ample, [q]uit: """ ans=raw_input('Return for next specimen \n') if ans=="": specimen +=1 if ans=="d": save_redo(PriorRecs,inspec) CurrRec=[] pmagplotlib.plotAZ(AZD,araiblock,zijdblock,s,units[0]) pmagplotlib.drawFIGS(AZD) if ans=='a': files={} for key in AZD.keys(): files[key]=s+'_'+key+fmt pmagplotlib.saveP(AZD,files) ans="" if ans=='q': print "Good bye" sys.exit() if ans=='p': specimen =specimen -1 backup = 1 ans="" if ans=='s': keepon=1 spec=raw_input('Enter desired specimen name (or first part there of): ') while keepon==1: try: specimen =sids.index(spec) keepon=0 except: tmplist=[] for qq in range(len(sids)): if spec in sids[qq]:tmplist.append(sids[qq]) print specimen," not found, but this was: " print tmplist spec=raw_input('Select one or try again\n ') ans="" if ans=='b': if end==0 or end >=len(zijdblock):end=len(zijdblock)-1 GoOn=0 while GoOn==0: print 'Enter index of first point for calculation: ','[',start,']' answer=raw_input('return to keep default ') if answer != "":start=int(answer) print 'Enter index of last point for calculation: ','[',end,']' answer=raw_input('return to keep default ') if answer != "": end=int(answer) if start >=0 and start <len(zijdblock)-2 and end >0 and end <len(zijdblock) or start>=end: GoOn=1 else: print "Bad endpoints - try again! " start,end=0,len(zijdblock) s=sids[specimen] pars,errcode=pmag.PintPars(araiblock,zijdblock,start,end) pars['measurement_step_unit']="K" pars["specimen_lab_field_dc"]=field pars["specimen_int"]=-1*field*pars["specimen_b"] pars["er_specimen_name"]=s pars=pmag.scoreit(pars,PmagSpecRec,accept,'',0) PmagSpecRec["measurement_step_min"]='%8.3e' % (pars["measurement_step_min"]) PmagSpecRec["measurement_step_max"]='%8.3e' % (pars["measurement_step_max"]) PmagSpecRec["measurement_step_unit"]="K" 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"]) PmagSpecRec["specimen_grade"]=pars["specimen_grade"] if pars["method_codes"]!="": tmpcodes=pars["method_codes"].split(":") for t in tmpcodes: if t.strip() not in methcodes:methcodes.append(t.strip()) 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_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[:-1] PmagSpecRec["specimen_description"]=comment PmagSpecRec["magic_software_packages"]=version_num pmagplotlib.plotAZ(AZD,araiblock,zijdblock,s,units[0]) pmagplotlib.plotB(AZD,araiblock,zijdblock,pars) if len(trmblock)>2: blab=field best=pars["specimen_int"] Bs,TRMs=[],[] for trec in trmblock: Bs.append(float(trec['treatment_dc_field'])) TRMs.append(float(trec['measurement_magn_moment'])) NLpars=nlt.NLtrm(Bs,TRMs,best,blab,0) # calculate best fit parameters through TRM acquisition data, and get new banc Mp,Bp=[],[] for k in range(int(max(Bs)*1e6)): Bp.append(float(k)*1e-6) npred=nlt.TRM(Bp[-1],NLpars['xopt'][0],NLpars['xopt'][1]) # predicted NRM for this field Mp.append(npred) pmagplotlib.plotTRM(AZD['TRM'],Bs,TRMs,Bp,Mp,NLpars,trec['magic_experiment_name']) print 'Non-linear TRM corrected intensity= ',float(NLpars['banc'])*1e6 pmagplotlib.drawFIGS(AZD) pars["specimen_lab_field_dc"]=field pars["specimen_int"]=-1*field*pars["specimen_b"] saveit=raw_input("Save this interpretation? [y]/n \n") if saveit!='n': PriorRecs.append(PmagSpecRec) # put back an interpretation specimen+=1 if first==1: first=0 PriorRecs,keys=pmag.fillkeys(PriorRecs) save_redo(PriorRecs,inspec) ans="" else: specimen+=1 if fmt != ".pmag": basename=s+'_thellier'+fmt files={} for key in AZD.keys(): files[key]=s+'_'+key+fmt if pmagplotlib.isServer: black = '#000000' purple = '#800080' titles={} titles['deremag']='DeReMag Plot' titles['zijd']='Zijderveld Plot' titles['arai']='Arai Plot' AZD = pmagplotlib.addBorders(AZD,titles,black,purple) pmagplotlib.saveP(AZD,files) # pmagplotlib.combineFigs(s,files,3) else: # save in pmag format script="grep "+s+" output.mag | thellier -mfsi" script=script+' %8.4e'%(field) min='%i'%((pars["measurement_step_min"]-273)) Max='%i'%((pars["measurement_step_max"]-273)) script=script+" "+min+" "+Max script=script+" |plotxy;cat mypost >>thellier.ps\n" pltf.write(script) pmag.domagicmag(outf,MeasRecs) if len(CurrRec)>0: for rec in CurrRec: PriorRecs.append(rec) CurrRec=[] if plots!=1: ans=raw_input(" Save last plot? 1/[0] ") if ans=="1": if fmt != ".pmag": files={} for key in AZD.keys(): files[key]=s+'_'+key+fmt pmagplotlib.saveP(AZD,files) else: print "\n Good bye\n" sys.exit() if len(CurrRec)>0:PriorRecs.append(CurrRec) # put back an interpretation if len(PriorRecs)>0: save_redo(PriorRecs,inspec) print 'Updated interpretations saved in ',inspec if pmagplotlib.verbose: print "Good bye"
def main(): """ NAME 2G_bin_magic.py DESCRIPTION takes the binary 2G format magnetometer files and converts them to magic_measurements, er_samples.txt and er_sites.txt file SYNTAX 2G_magic.py [command line options] OPTIONS -f FILE: specify input 2G (binary) file -F FILE: specify magic_measurements output file, default is: magic_measurements.txt -Fsa FILE: specify output file, default is: er_samples.txt -Fsi FILE: specify output file, default is: er_sies.txt -ncn NCON: specify naming convention: default is #2 below -ocn OCON: specify orientation convention, default is #5 below -mcd: specify sampling method codes as a colon delimited string: [default is: FS-FD:SO-POM] FS-FD field sampling done with a drill FS-H field sampling done with hand samples FS-LOC-GPS field location done with GPS FS-LOC-MAP field location done with map SO-POM a Pomeroy orientation device was used SO-ASC an ASC orientation device was used SO-MAG orientation with magnetic compass SO-SUN orientation with sun compass -loc: location name, default="unknown" -spc NUM : specify number of characters to designate a specimen, default = 0 -ins INST : specify instsrument name -a: average replicate measurements INPUT FORMAT Input files are horrible mag binary format (who knows why?) Orientation convention: [1] Lab arrow azimuth= mag_azimuth; Lab arrow dip=-field_dip i.e., field_dip is degrees from vertical down - the hade [default] [2] Lab arrow azimuth = mag_azimuth-90; Lab arrow dip = -field_dip i.e., mag_azimuth is strike and field_dip is hade [3] Lab arrow azimuth = mag_azimuth; Lab arrow dip = 90-field_dip i.e., lab arrow same as field arrow, but field_dip was a hade. [4] lab azimuth and dip are same as mag_azimuth, field_dip [5] lab azimuth is same as mag_azimuth,lab arrow dip=field_dip-90 [6] Lab arrow azimuth = mag_azimuth-90; Lab arrow dip = 90-field_dip [7] all others you will have to either customize your self or e-mail [email protected] for help. Magnetic declination convention: Az will use supplied declination to correct azimuth 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. OUTPUT output saved in magic_measurements.txt & er_samples.txt formatted files will overwrite any existing files """ # # initialize variables # specnum = 0 ub_file, samp_file, or_con, corr, meas_file = "", "er_samples.txt", "3", "1", "magic_measurements.txt" pos_file, site_file = "", "er_sites.txt" noave = 1 args = sys.argv bed_dip, bed_dip_dir = "", "" samp_con, Z, average_bedding = "2", 1, "0" meths = "FS-FD" sclass, lithology, type = "", "", "" user, inst = "", "" DecCorr = 0.0 location_name = "unknown" months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] gmeths = "" # # dir_path = "." if "-WD" in args: ind = args.index("-WD") dir_path = sys.argv[ind + 1] if "-h" in args: print main.__doc__ sys.exit() if "-f" in args: ind = args.index("-f") mag_file = sys.argv[ind + 1] if "-fpos" in args: ind = args.index("-fpos") pos_file = sys.argv[ind + 1] if "-F" in args: ind = args.index("-F") meas_file = sys.argv[ind + 1] if "-Fsa" in args: ind = args.index("-Fsa") samp_file = sys.argv[ind + 1] if "-Fsi" in args: ind = args.index("-Fsi") site_file = sys.argv[ind + 1] if "-ocn" in args: ind = args.index("-ocn") or_con = sys.argv[ind + 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 "6" in samp_con: try: Samps, file_type = pmag.magic_read(dir_path + "/er_samples.txt") except: print "there is no er_samples.txt file available - you can't use naming convention #6" sys.exit() if "-mcd" in args: ind = args.index("-mcd") gmeths = sys.argv[ind + 1] if "-loc" in args: ind = args.index("-loc") location_name = sys.argv[ind + 1] if "-spc" in args: ind = args.index("-spc") specnum = int(args[ind + 1]) if specnum != 0: specnum = -specnum if "-ins" in args: ind = args.index("-ins") inst = args[ind + 1] if "-a" in args: noave = 0 # # mag_file = dir_path + "/" + mag_file samp_file = dir_path + "/" + samp_file site_file = dir_path + "/" + site_file meas_file = dir_path + "/" + meas_file samplist = [] try: Samps, file_type = pmag.magic_read(samp_file) for samp in Samps: if samp["er_sample_name"] not in samplist: samplist.append(samp["er_sample_name"]) except: Samps = [] MagRecs = [] f = open(mag_file, "rU") input = f.read() f.close() firstline, date = 1, "" d = input.split("\xcd") for line in d: rec = line.split("\x00") if firstline == 1: firstline = 0 spec, vol = "", 1 for c in line[15:23]: if c != "\x00": spec = spec + c # check for bad sample name test = spec.split(".") date = "" if len(test) > 1: spec = test[0] kk = 24 while line[kk] != "\x01" and line[kk] != "\x00": kk += 1 vcc = line[24:kk] el = 10 while rec[el].strip() != "": el += 1 date, comments = rec[el + 7], [] else: el = 9 while rec[el] != "\x01": el += 1 vcc, date, comments = rec[el - 3], rec[el + 7], [] specname = spec.lower() print "importing ", specname el += 8 while rec[el].isdigit() == False: comments.append(rec[el]) el += 1 while rec[el] == "": el += 1 az = float(rec[el]) el += 1 while rec[el] == "": el += 1 pl = float(rec[el]) el += 1 while rec[el] == "": el += 1 bed_dip_dir = float(rec[el]) el += 1 while rec[el] == "": el += 1 bed_dip = float(rec[el]) el += 1 while rec[el] == "": el += 1 if rec[el] == "\x01": bed_dip = 180.0 - bed_dip el += 1 while rec[el] == "": el += 1 fold_az = float(rec[el]) el += 1 while rec[el] == "": el += 1 fold_pl = rec[el] el += 1 while rec[el] == "": el += 1 if rec[el] != "" and rec[el] != "\x02" and rec[el] != "\x01": deccorr = float(rec[el]) az += deccorr bed_dip_dir += deccorr fold_az += deccorr if bed_dip_dir >= 360: bed_dip_dir = bed_dip_dir - 360.0 if az >= 360.0: az = az - 360.0 if fold_az >= 360.0: fold_az = fold_az - 360.0 else: deccorr = 0 if specnum != 0: sample = specname[:specnum] else: sample = specname SampRec = {} SampRec["er_sample_name"] = sample SampRec["er_location_name"] = location_name SampRec["er_citation_names"] = "This study" labaz, labdip = pmag.orient(az, pl, or_con) # convert to labaz, labpl # # parse information common to all orientation methods # SampRec["sample_bed_dip"] = "%7.1f" % (bed_dip) SampRec["sample_bed_dip_direction"] = "%7.1f" % (bed_dip_dir) SampRec["sample_dip"] = "%7.1f" % (labdip) SampRec["sample_azimuth"] = "%7.1f" % (labaz) if vcc.strip() != "": vol = float(vcc) * 1e-6 # convert to m^3 from cc SampRec["sample_volume"] = "%10.3e" % (vol) # SampRec["sample_class"] = sclass SampRec["sample_lithology"] = lithology SampRec["sample_type"] = type SampRec["sample_declination_correction"] = "%7.1f" % (deccorr) methods = gmeths.split(":") if deccorr != "0": if "SO-MAG" in methods: del methods[methods.index("SO-MAG")] methods.append("SO-CMD-NORTH") meths = "" for meth in methods: meths = meths + meth + ":" meths = meths[:-1] SampRec["magic_method_codes"] = meths if int(samp_con) < 6: site = pmag.parse_site(SampRec["er_sample_name"], samp_con, Z) # parse out the site name SampRec["er_site_name"] = site elif len(Samps) > 1: site, location = "", "" for samp in Samps: if samp["er_sample_name"] == SampRec["er_sample_name"]: site = samp["er_site_name"] location = samp["er_location_name"] break SampRec["er_location_name"] = samp["er_location_name"] SampRec["er_site_name"] = samp["er_site_name"] if sample not in samplist: samplist.append(sample) Samps.append(SampRec) else: MagRec = {} 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" MagRec["measurement_flag"] = "g" MagRec["measurement_standard"] = "u" MagRec["measurement_number"] = "1" MagRec["er_specimen_name"] = specname MagRec["er_sample_name"] = SampRec["er_sample_name"] MagRec["er_site_name"] = SampRec["er_site_name"] MagRec["er_location_name"] = location_name el, demag = 1, "" treat = rec[el] if treat[-1] == "C": demag = "T" elif treat != "NRM": demag = "AF" el += 1 while rec[el] == "": el += 1 MagRec["measurement_dec"] = rec[el] cdec = float(rec[el]) el += 1 while rec[el] == "": el += 1 MagRec["measurement_inc"] = rec[el] cinc = float(rec[el]) el += 1 while rec[el] == "": el += 1 gdec = rec[el] el += 1 while rec[el] == "": el += 1 ginc = rec[el] el = skip(2, el, rec) # skip bdec,binc # el=skip(4,el,rec) # skip gdec,ginc,bdec,binc # print 'moment emu: ',rec[el] MagRec["measurement_magn_moment"] = "%10.3e" % (float(rec[el]) * 1e-3) # moment in Am^2 (from emu) MagRec["measurement_magn_volume"] = "%10.3e" % (float(rec[el]) * 1e-3 / vol) # magnetization in A/m el = skip(2, el, rec) # skip to xsig MagRec["measurement_sd_x"] = "%10.3e" % (float(rec[el]) * 1e-3) # convert from emu el = skip(3, el, rec) # skip to ysig MagRec["measurement_sd_y"] = "%10.3e" % (float(rec[el]) * 1e-3) # convert from emu el = skip(3, el, rec) # skip to zsig MagRec["measurement_sd_z"] = "%10.3e" % (float(rec[el]) * 1e-3) # convert from emu el += 1 # skip to positions MagRec["measurement_positions"] = rec[el] # el=skip(5,el,rec) # skip to date # mm=str(months.index(date[0])) # if len(mm)==1: # mm='0'+str(mm) # else: # mm=str(mm) # dstring=date[2]+':'+mm+':'+date[1]+":"+date[3] # MagRec['measurement_date']=dstring MagRec["magic_instrument_codes"] = inst MagRec["er_analyst_mail_names"] = "" MagRec["er_citation_names"] = "This study" MagRec["magic_method_codes"] = meas_type if demag == "AF": MagRec["treatment_ac_field"] = "%8.3e" % (float(treat[:-2]) * 1e-3) # peak field in tesla meas_type = "LT-AF-Z" MagRec["treatment_dc_field"] = "0" elif demag == "T": MagRec["treatment_temp"] = "%8.3e" % (float(treat[:-1]) + 273.0) # temp in kelvin meas_type = "LT-T-Z" MagRec["magic_method_codes"] = meas_type MagRecs.append(MagRec) MagOuts = pmag.measurements_methods(MagRecs, noave) pmag.magic_write(meas_file, MagOuts, "magic_measurements") print "Measurements put in ", meas_file SampsOut, sampkeys = pmag.fillkeys(Samps) pmag.magic_write(samp_file, SampsOut, "er_samples") Sites = [] for samp in Samps: SiteRec = {} SiteRec["er_site_name"] = samp["er_site_name"] SiteRec["er_location_name"] = samp["er_location_name"] SiteRec["site_definition"] = "s" SiteRec["er_citation_names"] = "This study" if "sample_class" in samp.keys(): SiteRec["site_class"] = samp["sample_class"] if "sample_lithology" in samp.keys(): SiteRec["site_lithology"] = samp["sample_lithology"] if "sample_type" in samp.keys(): SiteRec["site_lithology"] = samp["sample_lithology"] if "sample_lat" in samp.keys(): SiteRec["site_lat"] = samp["sample_lat"] else: SiteRec["site_lat"] = "-999" if "sample_lon" in samp.keys(): SiteRec["site_lon"] = samp["sample_lon"] else: SiteRec["site_lon"] = "-999" if "sample_height" in samp.keys(): SiteRec["site_height"] = samp["sample_height"] Sites.append(SiteRec) pmag.magic_write(site_file, Sites, "er_sites")
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 IODP_csv_magic.py DESCRIPTION converts ODP LIMS sample format files to magic_measurements format files SYNTAX IODP_csv_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 -Fsp FILE: specify output er_specimens.txt file, default is er_specimens.txt -Fsa FILE: specify output er_samples.txt file, default is er_samples.txt -Fsi FILE: specify output er_sites.txt file, default is er_sites.txt -A : don't average replicate measurements INPUTS IODP .csv file format exported from LIMS database """ # # version_num=pmag.get_version() meas_file='magic_measurements.txt' spec_file='er_specimens.txt' samp_file='er_samples.txt' site_file='er_sites.txt' csv_file='' ErSpecs,ErSamps,ErSites,ErLocs,ErCits=[],[],[],[],[] MagRecs=[] citation="This study" dir_path,demag='.','NRM' args=sys.argv noave=0 depth_method='a' if '-WD' in args: ind=args.index("-WD") dir_path=args[ind+1] print "dir_path", dir_path if "-h" in args: print main.__doc__ sys.exit() if "-A" in args: noave=1 if '-f' in args: ind=args.index("-f") # csv_file=args[ind+1] # original csv_file=dir_path + '/' + args[ind+1] # LJ if '-F' in args: ind=args.index("-F") meas_file=args[ind+1] if '-Fsp' in args: ind=args.index("-Fsp") spec_file=dir_path+'/'+args[ind+1] Specs,file_type=pmag.magic_read(spec_file) else: spec_file=dir_path+'/'+spec_file if '-Fsi' in args: ind=args.index("-Fsi") site_file=args[ind+1] if '-Fsa' in args: ind=args.index("-Fsa") samp_file=dir_path+'/'+args[ind+1] ErSamps,file_type=pmag.magic_read(samp_file) else: samp_file=dir_path+'/'+samp_file site_file=dir_path+'/'+site_file meas_file=dir_path+'/'+meas_file if csv_file=="": filelist=os.listdir(dir_path) # read in list of files to import else: filelist=[csv_file] specimens,samples,sites=[],[],[] MagRecs,SpecRecs,SampRecs,SiteRecs=[],[],[],[] for samp in ErSamps: if samp['er_sample_name'] not in samples: samples.append(samp['er_sample_name']) SampRecs.append(samp) print "filelist", filelist # LJ for file in filelist: # parse each file if file[-3:].lower()=='csv': print 'processing: ',file input=open(file,'rU').readlines() keys=input[0].replace('\n','').split(',') # splits on underscores if "Interval Top (cm) on SHLF" in keys:interval_key="Interval Top (cm) on SHLF" if " Interval Bot (cm) on SECT" in keys:interval_key=" Interval Bot (cm) on SECT" if "Top Depth (m)" in keys:depth_key="Top Depth (m)" if "CSF-A Top (m)" in keys:depth_key="CSF-A Top (m)" if "CSF-B Top (m)" in keys: comp_depth_key="CSF-B Top (m)" # use this model if available else: comp_depth_key="" if "Demag level (mT)" in keys:demag_key="Demag level (mT)" if "Demag Level (mT)" in keys: demag_key="Demag Level (mT)" if "Inclination (Tray- and Bkgrd-Corrected) (deg)" in keys:inc_key="Inclination (Tray- and Bkgrd-Corrected) (deg)" if "Inclination background + tray corrected (deg)" in keys:inc_key="Inclination background + tray corrected (deg)" if "Inclination background + tray corrected (\xc2\xb0)" in keys:inc_key="Inclination background + tray corrected (\xc2\xb0)" if "Declination (Tray- and Bkgrd-Corrected) (deg)" in keys:dec_key="Declination (Tray- and Bkgrd-Corrected) (deg)" if "Declination background + tray corrected (deg)" in keys:dec_key="Declination background + tray corrected (deg)" if "Declination background + tray corrected (\xc2\xb0)" in keys:dec_key="Declination background + tray corrected (\xc2\xb0)" if "Intensity (Tray- and Bkgrd-Corrected) (A/m)" in keys:int_key="Intensity (Tray- and Bkgrd-Corrected) (A/m)" if "Intensity background + tray corrected (A/m)" in keys:int_key="Intensity background + tray corrected (A/m)" if "Core Type" in keys: type="Core Type" else: type="Type" for line in input[1:]: InRec={} for k in range(len(keys)):InRec[keys[k]]=line.split(',')[k] try: run_number="" inst="ODP-SRM" volume='15.59' # set default volume to this MagRec,SpecRec,SampRec,SiteRec={},{},{},{} expedition=InRec['Exp'] location=InRec['Site']+InRec['Hole'] # Maintain backward compatibility for the ever-changing LIMS format (Argh!) while len(InRec['Core'])<3: InRec['Core']='0'+InRec['Core'] if "Last Tray Measurment" in InRec.keys() and "Discrete" in InRec['Last Tray Measurement'] or 'dscr' in csv_file : # assume discrete sample specimen=expedition+'-'+location+'-'+InRec['Core']+InRec[type]+"-"+InRec['Section']+'-'+InRec['Section Half']+'-'+InRec[interval_key] else: # mark as continuous measurements specimen=expedition+'-'+location+'-'+InRec['Core']+InRec[type]+"_"+InRec['Section']+InRec['Section Half']+'-'+InRec[interval_key] SpecRec['er_expedition_name']=expedition SpecRec['er_location_name']=location SpecRec['er_site_name']=specimen SpecRec['er_citation_names']=citation for key in SpecRec.keys():SampRec[key]=SpecRec[key] for key in SpecRec.keys():SiteRec[key]=SpecRec[key] SampRec['sample_azimuth']='0' SampRec['sample_dip']='0' SampRec['sample_core_depth']=InRec[depth_key] if comp_depth_key!='': SampRec['sample_composite_depth']=InRec[comp_depth_key] if "Discrete" in InRec['Last Tray Measurement']: SampRec['magic_method_codes']='FS-C-DRILL-IODP:SP-SS-C:SO-V' else: SampRec['magic_method_codes']='FS-C-DRILL-IODP:SO-V' SpecRec['er_specimen_name']=specimen SpecRec['er_sample_name']=specimen SampRec['er_sample_name']=specimen SampRec['er_specimen_names']=specimen SiteRec['er_specimen_names']=specimen for key in SpecRec.keys():MagRec[key]=SpecRec[key] # set up measurement record - default is NRM MagRec['er_analyst_mail_names']=InRec['Test Entered By'] 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" SpecRec['er_specimen_alternatives']=InRec['Text Id'] if 'Sample Area (cm?)' in InRec.keys() and InRec['Sample Area (cm?)']!= "": volume=InRec['Sample Area (cm?)'] if InRec['Run Number']!= "": run_number=InRec['Run Number'] datestamp=InRec['Test Changed On'].split() # date time is second line of file mmddyy=datestamp[0].split('/') # break into month day year if len(mmddyy[0])==1: mmddyy[0]='0'+mmddyy[0] # make 2 characters if len(mmddyy[1])==1: mmddyy[1]='0'+mmddyy[1] # make 2 characters if len(datestamp[1])==1: datestamp[1]='0'+datestamp[1] # make 2 characters date='20'+mmddyy[2]+':'+mmddyy[0]+":"+mmddyy[1] +':' +datestamp[1]+":00.00" MagRec["measurement_date"]=date MagRec["magic_method_codes"]='LT-NO' if InRec[demag_key]!="0": MagRec['magic_method_codes'] = 'LT-AF-Z' inst=inst+':ODP-SRM-AF' # measured on shipboard in-line 2G AF treatment_value=float(InRec[demag_key].strip('"'))*1e-3 # convert mT => T MagRec["treatment_ac_field"]=treatment_value # AF demag in treat mT => T if InRec['Treatment Type']!="": if 'Alternating Frequency' in InRec['Treatment Type']: MagRec['magic_method_codes'] = 'LT-AF-Z' inst=inst+':ODP-DTECH' # measured on shipboard Dtech D2000 treatment_value=float(InRec['Treatment Value'])*1e-3 # convert mT => T MagRec["treatment_ac_field"]=treatment_value # AF demag in treat mT => T elif 'Thermal' in InRec['Treatment Type']: MagRec['magic_method_codes'] = 'LT-T-Z' inst=inst+':ODP-TDS' # measured on shipboard Schonstedt thermal demagnetizer treatment_value=float(InRec['Treatment Value'])+273 # convert C => K MagRec["treatment_temp"]='%8.3e'%(treatment_value) # MagRec["measurement_standard"]='u' # assume all data are "good" vol=float(volume)*1e-6 # convert from cc to m^3 if run_number!="": MagRec['external_database_ids']=run_number MagRec['external_database_names']='LIMS' else: MagRec['external_database_ids']="" MagRec['external_database_names']='' 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_csd']='' MagRec['measurement_positions']='' MagRecs.append(MagRec) if specimen not in specimens: specimens.append(specimen) SpecRecs.append(SpecRec) if MagRec['er_sample_name'] not in samples: samples.append(MagRec['er_sample_name']) SampRecs.append(SampRec) if MagRec['er_site_name'] not in sites: sites.append(MagRec['er_site_name']) SiteRecs.append(SiteRec) except: pass if len(SpecRecs)>0: pmag.magic_write(spec_file,SpecRecs,'er_specimens') print 'specimens stored in ',spec_file if len(SampRecs)>0: SampOut,keys=pmag.fillkeys(SampRecs) pmag.magic_write(samp_file,SampOut,'er_samples') print 'samples stored in ',samp_file if len(SiteRecs)>0: pmag.magic_write(site_file,SiteRecs,'er_sites') print 'sites stored in ',site_file MagSort=pmag.sortbykeys(MagRecs,["er_specimen_name","treatment_ac_field"]) MagOuts=[] for MagRec in MagSort: MagRec["treatment_ac_field"]='%8.3e'%(MagRec['treatment_ac_field']) # convert to string MagOuts.append(MagRec) Fixed=pmag.measurements_methods(MagOuts,noave) pmag.magic_write(meas_file,Fixed,'magic_measurements') print 'data stored in ',meas_file
def main(): """ NAME ODP_dcs_magic.py DESCRIPTION converts ODP discrete sample format files to magic_measurements format files SYNTAX ODP_dsc_magic.py [command line options] OPTIONS -h: prints the help message and quits. -F FILE: specify output measurements file, default is magic_measurements.txt -Fsp FILE: specify output er_specimens.txt file, default is er_specimens.txt -Fsa FILE: specify output er_samples.txt file for appending, default is er_samples.txt -Fsi FILE: specify output er_sites.txt file, default is er_sites.txt -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 -A : don't average replicate measurements INPUT Put data from separate experiments (all AF, thermal, thellier, trm aquisition, Shaw, etc.) in separate directory """ # # version_num=pmag.get_version() meas_file='magic_measurements.txt' spec_file='er_specimens.txt' samp_file='er_samples.txt' site_file='er_sites.txt' ErSpecs,ErSamps,ErSites,ErLocs,ErCits=[],[],[],[],[] MagRecs=[] citation="This study" dir_path,demag='.','NRM' args=sys.argv noave=0 if '-WD' in args: ind=args.index("-WD") dir_path=args[ind+1] if "-h" in args: print main.__doc__ sys.exit() if "-A" in args: noave=1 if '-F' in args: ind=args.index("-F") meas_file=args[ind+1] if '-Fsp' in args: ind=args.index("-Fsp") spec_file=args[ind+1] if '-Fsa' in args: ind=args.index("-Fsa") samp_file=dir_path+'/'+args[ind+1] ErSamps,file_type=pmag.magic_read(samp_file) else: samp_file=dir_path+'/'+samp_file 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" 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 demag=="T" and "ANI" in codes: methcode="LP-AN-TRM" if demag=="AF" and "ANI" in codes: methcode="LP-AN-ARM" if labfield==0: labfield=50e-6 if peakfield==0: peakfield=.180 spec_file=dir_path+'/'+spec_file site_file=dir_path+'/'+site_file meas_file=dir_path+'/'+meas_file filelist=os.listdir(dir_path) # read in list of files to import specimens,samples,sites=[],[],[] MagRecs,SpecRecs,SampRecs=[],[],[] for samp in ErSamps: if samp['er_sample_name'] not in samples: samples.append(samp['er_sample_name']) SampRecs.append(samp) for file in filelist: # parse each file if file[-3:].lower()=='dsc': print 'processing: ',file MagRec,SpecRec,SampRec={},{},{} treatment_type,treatment_value,user="","","" inst="ODP-SRM" input=open(dir_path+'/'+file,'rU').readlines() IDs=file.split('_') # splits on underscores pieces=IDs[0].split('-') expedition=pieces[0] location=pieces[1] if file[0]!='_': while len(pieces[2])<4:pieces[2]='0'+pieces[2] # pad core to be 3 characters specimen="" else: specimen="test" for piece in pieces: specimen=specimen+piece+'-' specimen=specimen[:-1] alt_spec=IDs[1] # alternate specimen is second field in field name # set up specimen record for Er_specimens table SpecRec['er_expedition_name']=expedition SpecRec['er_location_name']=location SpecRec['er_site_name']=specimen SpecRec['er_sample_name']=specimen SpecRec['er_citation_names']=citation for key in SpecRec.keys():SampRec[key]=SpecRec[key] SampRec['sample_azimuth']='0' SampRec['sample_dip']='0' SampRec['magic_method_codes']='FS-C-DRILL-IODP:FS-SS-C:SO-V' SpecRec['er_specimen_name']=specimen for key in SpecRec.keys():MagRec[key]=SpecRec[key] # set up measurement record - default is NRM MagRec['er_analyst_mail_names']=user MagRec['magic_method_codes']='LT-NO' 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"]='' # set csd to blank SpecRec['er_specimen_alternatives']=alt_spec vol=7e-6 # assume 7 cc samples datestamp=input[1].split() # date time is second line of file mmddyy=datestamp[0].split('/') # break into month day year date=mmddyy[2]+':'+mmddyy[0]+":"+mmddyy[1] +':' +datestamp[1] MagRec["measurement_date"]=date for k in range(len(input)): fields= input[k].split("=") if 'treatment_type' in fields[0]: if "Alternating Frequency Demagnetization" in fields[1]: MagRec['magic_method_codes'] = 'LT-AF-Z' inst=inst+':ODP-DTECH' # measured on shipboard AF DTECH D2000 treatment_type="AF" if "Anhysteretic Remanent Magnetization" in fields[1]: MagRec['magic_method_codes'] = 'LT-AF-I' inst=inst+':ODP-DTECH' # measured on shipboard AF DTECH D2000 treatment_type="ARM" if "Isothermal Remanent Magnetization" in fields[1]: MagRec['magic_method_codes'] = 'LT-IRM' inst=inst+':ODP-IMP' # measured on shipboard ASC IMPULSE magnetizer treatment_type="IRM" if "treatment_value" in fields[0]: values=fields[1].split(',') value=values[0] if value!=" \n": if treatment_type=="AF": treatment_value=float(value)*1e-3 MagRec["treatment_ac_field"]=treatment_value # AF demag in treat mT => T elif treatment_type=="IRM": treatment_value=float(value)*1e-3 MagRec["treatment_dc_field"]='%8.3e'%(treatment_value) # IRM treat mT => T if treatment_type=="ARM": treatment_value=float(value)*1e-3 dc_value=float(values[1])*1e-3 MagRec["treatment_ac_field"]=treatment_value # AF demag in treat mT => T MagRec["treatment_dc_field"]='%8.3e'%(dc_value) # DC mT => T if 'user' in fields[0]: user=fields[-1] MagRec["er_analyst_mail_names"]=user if 'sample_orientation' in fields[0]: MagRec["measurement_description"]=fields[-1] MagRec["measurement_standard"]='u' # assume all data are "good" if 'sample_area' in fields[0]: vol=float(fields[1])*1e-6 # takes volume (cc) and converts to m^3 if 'run_number' in fields[0]: MagRec['external_database_ids']=fields[1] # run number is the LIMS measurement number MagRec['external_database_names']='LIMS' if input[k][0:7]=='<MULTI>': rec=input[k+1].split(',') # list of data for item in rec: items=item.split('=') if items[0].strip()=='demag_level' and treatment_value=="" : treat= float(items[1]) if treat!=0: MagRec['magic_method_codes']='LT-AF-Z' inst=inst+':ODP-SRM-AF' MagRec["treatment_ac_field"]=treat*1e-3 # AF demag in treat mT => T if items[0].strip()=='inclination_w_tray_w_bkgrd': MagRec['measurement_inc']=items[1] if items[0].strip()=='declination_w_tray_w_bkgrd': MagRec['measurement_dec']=items[1] if items[0].strip()=='intensity_w_tray_w_bkgrd': MagRec['measurement_magn_moment']='%8.3e'%(float(items[1])*vol) # convert intensity from A/m to Am^2 using vol if items[0].strip()=='x_stdev':MagRec['measurement_x_sd']=items[1] if items[0].strip()=='y_stdev':MagRec['measurement_y_sd']=items[1] if items[0].strip()=='z_stdev':MagRec['measurement_z_sd']=items[1] MagRec['magic_instrument_codes']=inst MagRec['measurement_number']='1' MagRecs.append(MagRec) if specimen not in specimens: specimens.append(specimen) SpecRecs.append(SpecRec) if MagRec['er_sample_name'] not in samples: samples.append(MagRec['er_sample_name']) SampRecs.append(SampRec) MagOuts=pmag.sort_diclist(MagRecs,'treatment_ac_field') for MagRec in MagOuts: MagRec["treatment_ac_field"]='%8.3e'%(MagRec["treatment_ac_field"]) # convert to string pmag.magic_write(spec_file,SpecRecs,'er_specimens') if len(SampRecs)>0: SampOut,keys=pmag.fillkeys(SampRecs) pmag.magic_write(samp_file,SampOut,'er_samples') print 'samples stored in ',samp_file pmag.magic_write(samp_file,SampRecs,'er_samples') print 'specimens stored in ',spec_file Fixed=pmag.measurements_methods(MagOuts,noave) pmag.magic_write(meas_file,Fixed,'magic_measurements') print 'data stored in ',meas_file
def main(): """ ODP_samples_magic.py OPTIONS: -f FILE, input csv file -Fsa FILE, output er_samples.txt file for updating, default is to overwrite er_samples.txt` """ samp_out="er_samples.txt" dir_path='.' 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") samp_file=sys.argv[ind+1] else: print "must specify -f samp_file" sys.exit() samp_file=dir_path+'/'+samp_file Samps=[] if '-Fsa' in sys.argv: ind=sys.argv.index("-Fsa") samp_out=dir_path+'/'+sys.argv[ind+1] Samps,file_type=pmag.magic_read(samp_out) print len(Samps), ' read in from: ',samp_out input=open(samp_file,"rU").readlines() keys=input[0].replace('\n','').split(',') ErSamples,samples=[],[] for line in input[1:]: ODPRec,SampRec={},{} rec=line.replace('\n','').split(',') for k in range(len(keys)):ODPRec[keys[k]]=rec[k] SampRec['er_sample_alternatives']=ODPRec['Text Id'] label=ODPRec['Label Id'].split() if len(label)>1 and 'PMAG' not in label[0]: interval=label[1].split('/')[0] pieces=label[0].split('-') core=pieces[2] while len(core)<4:core='0'+core SampRec['magic_method_codes']='FS-C-DRILL-IODP:FS-SS-C:SO-V' SampRec['er_sample_name']=pieces[0]+'-'+pieces[1]+'-'+core+'-'+pieces[3]+'-'+pieces[4]+'-'+interval SampRec['er_site_name']=SampRec['er_sample_name'] pieces=SampRec['er_sample_name'].split('-') SampRec['er_expedition_name']=pieces[0] SampRec['er_location_name']=pieces[1] SampRec['er_citation_names']="This study" SampRec['sample_dip']="0" SampRec['sample_azimuth']="0" SampRec['sample_core_depth']=ODPRec['Top Depth (m)'] dates=ODPRec['Sample Date Logged'].split() mmddyy=dates[0].split('/') yyyy='20'+mmddyy[2] mm=mmddyy[0] if len(mm)==1:mm='0'+mm dd=mmddyy[1] if len(dd)==1:dd='0'+dd date=yyyy+':'+mm+':'+dd+':'+dates[1]+":00.00" SampRec['sample_date']=date ErSamples.append(SampRec) samples.append(SampRec['er_sample_name']) if len(Samps)>0: for samp in Samps: if samp['er_sample_name'] not in samples: ErSamples.append(samp) Recs,keys=pmag.fillkeys(ErSamples) pmag.magic_write(samp_out,Recs,'er_samples') print('sample information written to er_samples.txt')
def main(): """ ODP_samples_magic.py OPTIONS: -f FILE, input csv file -Fsa FILE, output er_samples.txt file for updating, default is to overwrite er_samples.txt """ dir_path = "." comp_depth_key = "" 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") samp_file = sys.argv[ind + 1] else: print "must specify -f samp_file" sys.exit() samp_file = dir_path + "/" + samp_file Samps = [] if "-Fsa" in sys.argv: ind = sys.argv.index("-Fsa") samp_out = dir_path + "/" + sys.argv[ind + 1] Samps, file_type = pmag.magic_read(samp_out) print len(Samps), " read in from: ", samp_out else: samp_out = dir_path + "/er_samples.txt" input = open(samp_file, "rU").readlines() keys = input[0].replace("\n", "").split(",") if "CSF-B Top (m)" in keys: comp_depth_key = "CSF-B Top (m)" if "Top Depth (m)" in keys: # incorporate changes to LIMS data model, while maintaining backward compatibility depth_key = "Top Depth (m)" elif "CSF-A Top (m)" in keys: depth_key = "CSF-A Top (m)" elif "Top depth CSF-A (m)" in keys: depth_key = "Top depth CSF-A (m)" if "Text Id" in keys: text_key = "Text Id" elif "Text identifier" in keys: text_key = "Text identifier" if "Sample Date Logged" in keys: date_key = "Sample Date Logged" elif "Sample date logged" in keys: date_key = "Sample date logged" ErSamples, samples, format = [], [], "old" for line in input[1:]: ODPRec, SampRec = {}, {} interval, core = "", "" rec = line.replace("\n", "").split(",") for k in range(len(keys)): ODPRec[keys[k]] = rec[k].strip('"') SampRec["er_sample_alternatives"] = ODPRec[text_key] if "Label Id" in keys: # old format label = ODPRec["Label Id"].split() if len(label) > 1: interval = label[1].split("/")[0] pieces = label[0].split("-") core = pieces[2] while len(core) < 4: core = "0" + core # my way else: # new format format = "new" pieces = [ ODPRec["Exp"], ODPRec["Site"] + ODPRec["Hole"], ODPRec["Core"] + ODPRec["Type"], ODPRec["Sect"], ODPRec["A/W"], ] interval = ODPRec["Top offset (cm)"].split(".")[0].strip() # only integers allowed! core = ODPRec["Core"] + ODPRec["Type"] if core != "" and interval != "": SampRec["magic_method_codes"] = "FS-C-DRILL-IODP:SP-SS-C:SO-V" if format == "old": SampRec["er_sample_name"] = ( pieces[0] + "-" + pieces[1] + "-" + core + "-" + pieces[3] + "-" + pieces[4] + "-" + interval ) else: SampRec["er_sample_name"] = ( pieces[0] + "-" + pieces[1] + "-" + core + "-" + pieces[3] + "_" + pieces[4] + "_" + interval ) # change in sample name convention SampRec["er_site_name"] = SampRec["er_sample_name"] # pieces=SampRec['er_sample_name'].split('-') SampRec["er_expedition_name"] = pieces[0] SampRec["er_location_name"] = pieces[1] SampRec["er_citation_names"] = "This study" SampRec["sample_dip"] = "0" SampRec["sample_azimuth"] = "0" SampRec["sample_core_depth"] = ODPRec[depth_key] if comp_depth_key != "": SampRec["sample_composite_depth"] = ODPRec[comp_depth_key] dates = ODPRec[date_key].split() if "/" in dates[0]: # have a date mmddyy = dates[0].split("/") yyyy = "20" + mmddyy[2] mm = mmddyy[0] if len(mm) == 1: mm = "0" + mm dd = mmddyy[1] if len(dd) == 1: dd = "0" + dd date = yyyy + ":" + mm + ":" + dd + ":" + dates[1] + ":00.00" else: date = "" SampRec["sample_date"] = date ErSamples.append(SampRec) samples.append(SampRec["er_sample_name"]) if len(Samps) > 0: for samp in Samps: if samp["er_sample_name"] not in samples: ErSamples.append(samp) Recs, keys = pmag.fillkeys(ErSamples) pmag.magic_write(samp_out, Recs, "er_samples") print "sample information written to: ", samp_out
def main(): """ NAME sufar4-asc_magic.py DESCRIPTION converts ascii files generated by SUFAR ver.4.0 to MagIC formated files for use with PmagPy plotting software SYNTAX sufar4-asc_magic.py -h [command line options] OPTIONS -h: prints the help message and quits -f FILE: specify .asc input file name -F MFILE: specify magic_measurements output file -Fa AFILE: specify rmag_anisotropy output file -Fr RFILE: specify rmag_results output file -Fs SFILE: specify er_specimens output file with location, sample, site, etc. information -usr USER: specify who made the measurements -loc LOC: specify location name for study -ins INST: specify instrument used -spc SPEC: specify number of characters to specify specimen from sample -ncn NCON: specify naming convention: default is #2 below -k15 : specify static 15 position mode - default is spinning -new : replace all existing magic files DEFAULTS AFILE: rmag_anisotropy.txt RFILE: rmag_results.txt SFILE: default is to create new er_specimen.txt file USER: "" LOC: "unknown" INST: "" SPEC: 0 sample name is same as site (if SPEC is 1, sample is all but last character) appends to 'er_specimens.txt, er_samples.txt, er_sites.txt' files 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] This is a synthetic [9] ODP naming convention """ citation = "This study" cont = 0 samp_con, Z = "1", 1 AniRecSs, AniRecs, SpecRecs, SampRecs, SiteRecs, MeasRecs = [], [], [], [], [], [] user, locname, specfile = "", "unknown", "er_specimens.txt" isspec, inst, specnum = "0", "", 0 spin, new = 1, 0 dir_path = "." if "-WD" in sys.argv: ind = sys.argv.index("-WD") dir_path = sys.argv[ind + 1] aoutput, routput, moutput = ( dir_path + "/rmag_anisotropy.txt", dir_path + "/rmag_results.txt", dir_path + "/magic_measurements.txt", ) if "-h" in sys.argv: print main.__doc__ sys.exit() if "-usr" in sys.argv: ind = sys.argv.index("-usr") user = sys.argv[ind + 1] if "-ncn" in sys.argv: ind = sys.argv.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 "-k15" in sys.argv: spin = 0 if "-ins" in sys.argv: ind = sys.argv.index("-ins") inst = sys.argv[ind + 1] if "-f" in sys.argv: ind = sys.argv.index("-f") ascfile = dir_path + "/" + sys.argv[ind + 1] if "-F" in sys.argv: ind = sys.argv.index("-F") moutput = dir_path + "/" + sys.argv[ind + 1] if "-Fa" in sys.argv: ind = sys.argv.index("-Fa") aoutput = dir_path + "/" + sys.argv[ind + 1] if "-Fr" in sys.argv: ind = sys.argv.index("-Fr") routput = dir_path + "/" + sys.argv[ind + 1] if "-Fs" in sys.argv: ind = sys.argv.index("-Fs") specfile = dir_path + "/" + sys.argv[ind + 1] isspec = "1" elif "-loc" in sys.argv: ind = sys.argv.index("-loc") locname = sys.argv[ind + 1] if "-spc" in sys.argv: ind = sys.argv.index("-spc") specnum = -(int(sys.argv[ind + 1])) if specnum != 0: specnum = -specnum if isspec == "1": specs, file_type = pmag.magic_read(specfile) specnames, sampnames, sitenames = [], [], [] if "-new" not in sys.argv: # see if there are already specimen,sample, site files lying around try: SpecRecs, file_type = pmag.magic_read(dir_path + "/er_specimens.txt") for spec in SpecRecs: if spec["er_specimen_name"] not in specnames: specnames.append(samp["er_specimen_name"]) except: SpecRecs, specs = [], [] try: SampRecs, file_type = pmag.magic_read(dir_path + "/er_samples.txt") for samp in SampRecs: if samp["er_sample_name"] not in sampnames: sampnames.append(samp["er_sample_name"]) except: sampnames, SampRecs = [], [] try: SiteRecs, file_type = pmag.magic_read(dir_path + "/er_sites.txt") for site in SiteRecs: if site["er_site_names"] not in sitenames: sitenames.append(site["er_site_name"]) except: sitenames, SiteRecs = [], [] try: input = open(ascfile, "rU") except: print "Error opening file: ", ascfile Data = input.readlines() k = 0 while k < len(Data): line = Data[k] words = line.split() if "ANISOTROPY" in words: # first line of data for the spec MeasRec, AniRec, SpecRec, SampRec, SiteRec = {}, {}, {}, {}, {} specname = words[0] AniRec["er_specimen_name"] = specname if isspec == "1": for spec in specs: if spec["er_specimen_name"] == specname: AniRec["er_sample_name"] = spec["er_sample_name"] AniRec["er_site_name"] = spec["er_site_name"] AniRec["er_location_name"] = spec["er_location_name"] break elif isspec == "0": if specnum != 0: sampname = specname[:specnum] else: sampname = specname AniRec["er_sample_name"] = sampname SpecRec["er_specimen_name"] = specname SpecRec["er_sample_name"] = sampname SampRec["er_sample_name"] = sampname SiteRec["er_sample_name"] = sampname SiteRec["site_description"] = "s" if samp_con != "9": AniRec["er_site_name"] = pmag.parse_site(AniRec["er_sample_name"], samp_con, Z) SpecRec["er_site_name"] = pmag.parse_site(AniRec["er_sample_name"], samp_con, Z) SampRec["er_site_name"] = pmag.parse_site(AniRec["er_sample_name"], samp_con, Z) SiteRec["er_site_name"] = pmag.parse_site(AniRec["er_sample_name"], samp_con, Z) else: AniRec["er_site_name"] = specname SpecRec["er_site_name"] = specname SampRec["er_site_name"] = specname SiteRec["er_site_name"] = specname pieces = specname.split("-") AniRec["er_expedition_name"] = pieces[0] SpecRec["er_expedition_name"] = pieces[0] SampRec["er_expedition_name"] = pieces[0] SiteRec["er_expedition_name"] = pieces[0] location = pieces[1] AniRec["er_location_name"] = locname SpecRec["er_location_name"] = locname SampRec["er_location_name"] = locname SiteRec["er_location_name"] = locname AniRec["er_citation_names"] = "This study" SpecRec["er_citation_names"] = "This study" SampRec["er_citation_names"] = "This study" SiteRec["er_citation_names"] = "This study" AniRec["er_citation_names"] = "This study" AniRec["magic_instrument_codes"] = inst AniRec["magic_method_codes"] = "LP-X:AE-H:LP-AN-MS" AniRec["magic_experiment_names"] = specname + ":" + "LP-AN-MS" AniRec["er_analyst_mail_names"] = user for key in AniRec.keys(): MeasRec[key] = AniRec[key] MeasRec["measurement_flag"] = "g" AniRec["anisotropy_flag"] = "g" MeasRec["measurement_standard"] = "u" MeasRec["measurement_description"] = "Bulk sucsecptibility measurement" AniRec["anisotropy_type"] = "AMS" AniRec["anisotropy_unit"] = "Normalized by trace - bulk in measurements table" if spin == 1: AniRec["anisotropy_n"] = "192" else: AniRec["anisotropy_n"] = "15" if "Azi" in words and isspec == "0": SampRec["sample_azimuth"] = words[1] labaz = float(words[1]) if "Dip" in words: SampRec["sample_dip"] = "%7.1f" % (-float(words[1])) SpecRec["specimen_vol"] = "%8.3e" % (float(words[10]) * 1e-6) # convert actual volume to m^3 from cm^3 labdip = float(words[1]) if "T1" in words and "F1" in words: k += 2 # read in fourth line down line = Data[k] rec = line.split() dd = rec[1].split("/") dip_direction = int(dd[0]) + 90 SampRec["sample_bed_dip_direction"] = "%i" % (dip_direction) SampRec["sample_bed_dip"] = dd[1] bed_dip = float(dd[1]) if "Mean" in words: k += 4 # read in fourth line down line = Data[k] rec = line.split() MeasRec["measurement_chi_volume"] = rec[1] sigma = 0.01 * float(rec[2]) / 3.0 AniRec["anisotropy_sigma"] = "%7.4f" % (sigma) AniRec["anisotropy_unit"] = "SI" if "factors" in words: k += 4 # read in second line down line = Data[k] rec = line.split() if "Specimen" in words: # first part of specimen data AniRec["anisotropy_s1"] = "%7.4f" % (float(words[5]) / 3.0) # eigenvalues sum to unity - not 3 AniRec["anisotropy_s2"] = "%7.4f" % (float(words[6]) / 3.0) AniRec["anisotropy_s3"] = "%7.4f" % (float(words[7]) / 3.0) k += 1 line = Data[k] rec = line.split() AniRec["anisotropy_s4"] = "%7.4f" % (float(rec[5]) / 3.0) # eigenvalues sum to unity - not 3 AniRec["anisotropy_s5"] = "%7.4f" % (float(rec[6]) / 3.0) AniRec["anisotropy_s6"] = "%7.4f" % (float(rec[7]) / 3.0) AniRec["anisotropy_tilt_correction"] = "-1" AniRecs.append(AniRec) AniRecG, AniRecT = {}, {} for key in AniRec.keys(): AniRecG[key] = AniRec[key] for key in AniRec.keys(): AniRecT[key] = AniRec[key] sbar = [] sbar.append(float(AniRec["anisotropy_s1"])) sbar.append(float(AniRec["anisotropy_s2"])) sbar.append(float(AniRec["anisotropy_s3"])) sbar.append(float(AniRec["anisotropy_s4"])) sbar.append(float(AniRec["anisotropy_s5"])) sbar.append(float(AniRec["anisotropy_s6"])) sbarg = pmag.dosgeo(sbar, labaz, labdip) AniRecG["anisotropy_s1"] = "%12.10f" % (sbarg[0]) AniRecG["anisotropy_s2"] = "%12.10f" % (sbarg[1]) AniRecG["anisotropy_s3"] = "%12.10f" % (sbarg[2]) AniRecG["anisotropy_s4"] = "%12.10f" % (sbarg[3]) AniRecG["anisotropy_s5"] = "%12.10f" % (sbarg[4]) AniRecG["anisotropy_s6"] = "%12.10f" % (sbarg[5]) AniRecG["anisotropy_tilt_correction"] = "0" AniRecs.append(AniRecG) if bed_dip != "" and bed_dip != 0: # have tilt correction sbart = pmag.dostilt(sbarg, dip_direction, bed_dip) AniRecT["anisotropy_s1"] = "%12.10f" % (sbart[0]) AniRecT["anisotropy_s2"] = "%12.10f" % (sbart[1]) AniRecT["anisotropy_s3"] = "%12.10f" % (sbart[2]) AniRecT["anisotropy_s4"] = "%12.10f" % (sbart[3]) AniRecT["anisotropy_s5"] = "%12.10f" % (sbart[4]) AniRecT["anisotropy_s6"] = "%12.10f" % (sbart[5]) AniRecT["anisotropy_tilt_correction"] = "100" AniRecs.append(AniRecT) MeasRecs.append(MeasRec) if SpecRec["er_specimen_name"] not in specnames: SpecRecs.append(SpecRec) specnames.append(SpecRec["er_specimen_name"]) if SampRec["er_sample_name"] not in sampnames: SampRecs.append(SampRec) sampnames.append(SampRec["er_sample_name"]) if SiteRec["er_site_name"] not in sitenames: SiteRecs.append(SiteRec) sitenames.append(SiteRec["er_site_name"]) k += 1 # skip to next specimen pmag.magic_write(aoutput, AniRecs, "rmag_anisotropy") print "anisotropy tensors put in ", aoutput pmag.magic_write(moutput, MeasRecs, "magic_measurements") print "bulk measurements put in ", moutput if isspec == "0": SpecOut, keys = pmag.fillkeys(SpecRecs) output = dir_path + "/er_specimens.txt" pmag.magic_write(output, SpecOut, "er_specimens") print "specimen info put in ", output output = dir_path + "/er_samples.txt" SampOut, keys = pmag.fillkeys(SampRecs) pmag.magic_write(output, SampOut, "er_samples") print "sample info put in ", output output = dir_path + "/er_sites.txt" SiteOut, keys = pmag.fillkeys(SiteRecs) pmag.magic_write(output, SiteOut, "er_sites") print "site info put in ", output print """"
def main(): """ NAME agm_magic.py DESCRIPTION converts Micromag agm files to magic format SYNTAX agm_magic.py [-h] [command line options] OPTIONS -usr USER: identify user, default is "" - put in quotation marks! -bak: this is a IRM backfield curve -f FILE, specify input file, required -fsa SAMPFILE, specify er_samples.txt file relating samples, site and locations names,default is none -F MFILE, specify magic measurements formatted output file, default is agm_measurements.txt -spn SPEC, specimen name, default is base of input file name, e.g. SPECNAME.agm -spc NUM, specify number of characters to designate a specimen, default = 0 -Fsp SPECFILE : name of er_specimens.txt file for appending data to [default: er_specimens.txt] -ncn NCON,: specify naming convention: default is #1 below -syn SYN, synthetic specimen name -loc LOCNAME : specify location/study name, should have either LOCNAME or SAMPFILE (unless synthetic) -ins INST : specify which instrument was used (e.g, SIO-Maud), default is "" -u units: [cgs,SI], default is cgs 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 [8] specimen is a synthetic - it has no sample, site, location information NB: all others you will have to customize your self or e-mail [email protected] for help. OUTPUT MagIC format files: magic_measurements, er_specimens, er_sample, er_site """ citation='This study' MeasRecs=[] units='cgs' meth="LP-HYS" version_num=pmag.get_version() args=sys.argv fmt='old' er_sample_name,er_site_name,er_location_name="","","" inst="" er_location_name="unknown" er_synthetic_name="" user="" er_site_name="" dir_path='.' if "-WD" in args: ind=args.index("-WD") dir_path=args[ind+1] specfile=dir_path+'/er_specimens.txt' output=dir_path+"/agm_measurements.txt" if "-h" in args: print main.__doc__ sys.exit() if "-bak" in args: meth="LP-IRM-DCD" output=dir_path+"/irm_measurements.txt" if "-new" in args: fmt='new' if "-usr" in args: ind=args.index("-usr") user=args[ind+1] if '-F' in args: ind=args.index("-F") output=dir_path+'/'+args[ind+1] if '-f' in args: ind=args.index("-f") agm_file=dir_path+'/'+args[ind+1] er_specimen_name=args[ind+1].split('.')[0] else: print "agm_file field is required option" print main.__doc__ sys.exit() if '-Fsp' in args: ind=args.index("-Fsp") specfile=dir_path+'/'+args[ind+1] specnum,samp_con,Z=0,'1',1 if "-spc" in args: ind=args.index("-spc") specnum=int(args[ind+1]) if specnum!=0:specnum=-specnum if "-spn" in args: ind=args.index("-spn") er_specimen_name=args[ind+1] elif "-syn" not in args: print "you must specify a specimen name" sys.exit() if "-syn" in args: ind=args.index("-syn") er_synthetic_name=args[ind+1] er_specimen_name="" if "-loc" in args: ind=args.index("-loc") er_location_name=args[ind+1] if "-fsa" in args: ind=args.index("-fsa") sampfile=dir_path+'/'+args[ind+1] Samps,file_type=pmag.magic_read(sampfile) print 'sample_file successfully read in' 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 "-ins" in args: ind=args.index("-ins") inst=args[ind+1] if "-u" in args: ind=args.index("-u") units=args[ind+1] ErSpecRecs,filetype=pmag.magic_read(specfile) ErSpecRec,MeasRec={},{} ErSpecRec['er_citation_names']="This study" ErSpecRec['er_specimen_name']=er_specimen_name ErSpecRec['er_synthetic_name']=er_synthetic_name if specnum!=0: ErSpecRec["er_sample_name"]=er_specimen_name[:specnum] else: ErSpecRec["er_sample_name"]=er_specimen_name if "-fsa" in args and er_synthetic_name=="": for samp in Samps: if samp["er_sample_name"] == ErSpecRec["er_sample_name"]: ErSpecRec["er_location_name"]=samp["er_location_name"] ErSpecRec["er_site_name"]=samp["er_site_name"] break elif int(samp_con)!=6 and int(samp_con)!=8: site=pmag.parse_site(ErSpecRec['er_sample_name'],samp_con,Z) ErSpecRec["er_site_name"]=site ErSpecRec["er_location_name"]=er_location_name ErSpecRec['er_scientist_mail_names']=user.strip() insert=1 for rec in ErSpecRecs: if rec['er_specimen_name']==er_specimen_name: insert=0 break if insert==1: ErSpecRecs.append(ErSpecRec) ErSpecRecs,keylist=pmag.fillkeys(ErSpecRecs) pmag.magic_write(specfile,ErSpecRecs,'er_specimens') print "specimen name put in ",specfile f=open(agm_file,'rU') Data=f.readlines() if "ASCII" not in Data[0]:fmt='new' measnum,start=1,"" if fmt=='new': # new Micromag formatted file end=2 for skip in range(len(Data)): line=Data[skip] rec=line.split() if 'Units' in line:units=rec[-1] if "Raw" in rec: start=skip+2 if "Field" in rec and "Moment" in rec and start=="": start=skip+2 break else: start = 2 end=1 for i in range(start,len(Data)-end): # skip header stuff MeasRec={} for key in ErSpecRec.keys(): MeasRec[key]=ErSpecRec[key] MeasRec['magic_instrument_codes']=inst MeasRec['magic_method_codes']=meth if 'er_synthetic_name' in MeasRec.keys() and MeasRec['er_synthetic_name']!="": MeasRec['magic_experiment_name']=er_synthetic_name+':'+meth else: MeasRec['magic_experiment_name']=er_specimen_name+':'+meth line=Data[i] rec=line.split(',') # data comma delimited if rec[0]!='\n': if units=='cgs': field =float(rec[0])*1e-4 # convert from oe to tesla else: field =float(rec[0]) # field in tesla if meth=="LP-HYS": MeasRec['measurement_lab_field_dc']='%10.3e'%(field) MeasRec['treatment_dc_field']='' else: MeasRec['measurement_lab_field_dc']='' MeasRec['treatment_dc_field']='%10.3e'%(field) if units=='cgs': MeasRec['measurement_magn_moment']='%10.3e'%(float(rec[1])*1e-3) # convert from emu to Am^2 else: MeasRec['measurement_magn_moment']='%10.3e'%(float(rec[1])) # Am^2 MeasRec['treatment_temp']='273' # temp in kelvin MeasRec['measurement_temp']='273' # temp in kelvin MeasRec['measurement_flag']='g' MeasRec['measurement_standard']='u' MeasRec['measurement_number']='%i'%(measnum) measnum+=1 MeasRec['magic_software_packages']=version_num MeasRecs.append(MeasRec) # now we have to relabel LP-HYS method codes. initial loop is LP-IMT, minor loops are LP-M - do this in measurements_methods function if meth=='LP-HYS': recnum=0 while float(MeasRecs[recnum]['measurement_lab_field_dc'])<float(MeasRecs[recnum+1]['measurement_lab_field_dc']) and recnum+1<len(MeasRecs): # this is LP-IMAG MeasRecs[recnum]['magic_method_codes']='LP-IMAG' MeasRecs[recnum]['magic_experiment_name']=MeasRecs[recnum]['er_specimen_name']+":"+'LP-IMAG' recnum+=1 # pmag.magic_write(output,MeasRecs,'magic_measurements') print "results put in ",output
def main(): """ NAME azdip_magic.py DESCRIPTION takes space delimited AzDip file and converts to MagIC formatted tables SYNTAX azdip_magic.py [command line options] OPTIONS -f FILE: specify input file -Fsa FILE: specify output file, default is: er_samples.txt -ncn NCON: specify naming convention: default is #1 below -mcd: specify sampling method codes as a colon delimited string: [default is: FS-FD] FS-FD field sampling done with a drill FS-H field sampling done with hand samples FS-LOC-GPS field location done with GPS FS-LOC-MAP field location done with map SO-POM a Pomeroy orientation device was used SO-ASC an ASC orientation device was used SO-MAG orientation with magnetic compass -loc: location name, default="unknown" -app appends to existing er_samples.txt file, default is to overwrite INPUT FORMAT Input files must be space delimited: Samp Az Dip Strike Dip Orientation convention: Lab arrow azimuth = mag_azimuth; Lab arrow dip = 90-field_dip e.g. field_dip is degrees from horizontal of drill direction Magnetic declination convention: Az is already corrected in file 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. OUTPUT output saved in er_samples.txt will overwrite any existing files """ # # initialize variables # DEBUG = 0 version_num = pmag.get_version() orient_file, samp_file, or_con, corr = "orient.txt", "er_samples.txt", "3", "1" args = sys.argv date, lat, lon = "", "", "" # date of sampling, latitude (pos North), longitude (pos East) bed_dip, bed_dip_dir = "", "" participantlist = "" sites = [] # list of site names Lats, Lons = [], [] # list of latitudes and longitudes SampRecs, SiteRecs, ImageRecs, imagelist = [], [], [], [] # lists of Sample records and Site records samp_con, Z, average_bedding = "1", 1, "0" newbaseline, newbeddir, newbeddip = "", "", "" meths = "FS-FD" delta_u = "0" sclass, lithology, type = "", "", "" newclass, newlith, newtype = "", "", "" user = "" corr == "3" DecCorr = 0.0 location_name = "unknown" # # if "-h" in args: print main.__doc__ sys.exit() if "-f" in args: ind = args.index("-f") orient_file = sys.argv[ind + 1] if "-Fsa" in args: ind = args.index("-Fsa") samp_file = sys.argv[ind + 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 "-mcd" in args: ind = args.index("-mcd") meths = sys.argv[ind + 1] if "-loc" in args: ind = args.index("-loc") location_name = sys.argv[ind + 1] if "-app" in args: try: SampRecs, file_type = pmag.magic_read(samp_file) print "sample data to be appended to: ", samp_file except: print "problem with existing samp file: ", samp_file, " will create new" # # read in file to convert # azfile = open(orient_file, "rU") AzDipDat = azfile.readlines() azfile.close() SampOut, samplist = [], [] for line in AzDipDat: orec = line.split() if len(orec) > 2: labaz, labdip = pmag.orient(float(orec[1]), float(orec[2]), or_con) bed_dip = float(orec[4]) if bed_dip != 0: bed_dip_dir = float(orec[3]) - 90.0 # assume dip to right of strike else: bed_dip_dir = float(orec[3]) # assume dip to right of strike MagRec = {} MagRec["er_location_name"] = location_name MagRec["er_citation_names"] = "This study" # # parse information common to all orientation methods # MagRec["er_sample_name"] = orec[0] MagRec["sample_bed_dip"] = "%7.1f" % (bed_dip) MagRec["sample_bed_dip_direction"] = "%7.1f" % (bed_dip_dir) MagRec["sample_dip"] = "%7.1f" % (labdip) MagRec["sample_azimuth"] = "%7.1f" % (labaz) methods = meths.replace(" ", "").split(":") OR = 0 for method in methods: type = method.split("-") if "SO" in type: OR = 1 if OR == 0: meths = meths + ":SO-NO" MagRec["magic_method_codes"] = meths site = pmag.parse_site(orec[0], samp_con, Z) # parse out the site name MagRec["er_site_name"] = site MagRec["magic_software_packages"] = version_num SampOut.append(MagRec) if MagRec["er_sample_name"] not in samplist: samplist.append(MagRec["er_sample_name"]) for samp in SampRecs: if samp not in samplist: SampOut.append(samp) Samps, keys = pmag.fillkeys(SampOut) pmag.magic_write(samp_file, Samps, "er_samples") print "Data saved in ", samp_file
def main(): """ NAME curie_magic.py DESCTIPTION plots and interprets curie temperature data. the 1st derivative is calculated from smoothed M-T curve (convolution with trianfular window with width= <-w> degrees) the 2nd derivative is calculated from smoothed 1st derivative curve ( using the same sliding window width) the estinated curie temp. is the maximum of the 2nd derivative - the temperature steps should be in multiples of 1.0 degrees INPUT magic_measurements formatted file SYNTAX curie_magic.py [command line options] OPTIONS -h prints help message and quits -f FILE, sets M,T magic_measurements formatted file, default is MsT_measurements.txt -F RMAG, sets Rmag_results format file for appending results, default is not -w size of sliding window in degrees (default - 3 degrees) -t <min> <max> temperature range (optional) """ fmt,dir_path='svg','.' if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] meas_file=dir_path+'/MsT_measurements.txt' if '-h' in sys.argv: print main.__doc__ sys.exit() if '-f' in sys.argv: ind=sys.argv.index('-f') meas_file=dir_path+'/'+sys.argv[ind+1] Results,rmag_file=[],"" if '-F' in sys.argv: ind=sys.argv.index('-F') rmag_file=dir_path+'/'+sys.argv[ind+1] try: Results,file_type=pmag.magic_read(rmag_file) if file_type!='rmag_results': print 'bad results file, starting new one' except: pass if '-w' in sys.argv: ind=sys.argv.index('-w') window_len=int(sys.argv[ind+1]) else: window_len=3 if '-t' in sys.argv: ind=sys.argv.index('-t') t_begin=int(sys.argv[ind+1]) t_end=int(sys.argv[ind+2]) else: t_begin='' t_end='' # read data from file Data,file_type=pmag.magic_read(meas_file) if file_type!='magic_measurements': print 'bad measurements file' sys.exit() specs=[] for rec in Data: specname="" if 'er_specimen_name' in rec.keys() and rec['er_specimen_name']!="": specname=rec['er_specimen_name'] else: rec['er_specimen_name']="" if 'er_synthetic_name' in rec.keys() and rec['er_synthetic_name']!="": specname=rec['er_synthetic_name'] else: rec['er_synthetic_name']="" if specname not in specs:specs.append(specname) for spec in specs: print 'processing: ',spec M,T,curieT=[],[],0 for rec in Data: if rec['er_specimen_name'] or rec['er_synthetic_name']==spec: location,sample,site="","","" if 'er_location_name' in rec.keys():location=rec['er_location_name'] if 'er_sample_name' in rec.keys():sample=rec['er_sample_name'] if 'er_site_name' in rec.keys():site=rec['er_site_name'] syn="" if 'er_synthetic_name' in rec.keys():syn=rec['er_synthetic_name'] meths=rec['magic_method_codes'].strip().split(':') expnames=rec['magic_experiment_name'].strip().split(':') if 'LP-MW-I' in meths and 'Curie' in expnames: method=rec['magic_method_codes'] expname=rec['magic_experiment_name'] T.append(float(rec['measurment_temp'])-273) M.append(float(rec['measurement_magnitude'])) # cut the data if -t is one of the flags if len(M)<10: print 'not enough data for processing' sys.exit() if t_begin: while T[0]<t_begin: M.pop(0);T.pop(0) while T[-1]>t_end: M.pop(-1);T.pop(-1) # prepare the signal: # from M(T) array with unequal deltaT # to M(T) array with deltaT=(1 degree). # if delataT is larger, then points are added using linear fit between # consecutive data points. # exit if deltaT is not integer i=0 while i<(len(T)-1): if (T[i+1]-T[i])%1>0.001: print "delta T should be integer, this program will not work!" print "temperature range:",T[i],T[i+1] sys.exit() if (T[i+1]-T[i])==0.: M[i]=average([M[i],M[i+1]]) M.pop(i+1);T.pop(i+1) elif (T[i+1]-T[i])<0.: M.pop(i+1);T.pop(i+1) print "check data in T=%.0f ,M[T] is ignored"%(T[i]) elif (T[i+1]-T[i])>1.: slope,b=polyfit([T[i],T[i+1]],[M[i],M[i+1]],1) for j in range(int(T[i+1])-int(T[i])-1): M.insert(i+1,slope*(T[i]+1.)+b) T.insert(i+1,(T[i]+1.)) i=i+1 i=i+1 # calculate the smoothed signal M=array(M,'f') T=array(T,'f') M_smooth=[] M_smooth=smooth(M,window_len) #plot the original data and the smooth data PLT={'M_T':1,'der1':2,'der2':3,'Curie':4} pmagplotlib.plot_init(PLT['M_T'],5,5) string='M-T (sliding window=%i)'%int(window_len) pmagplotlib.plotXY(PLT['M_T'],T,M,'--','Temperature C','Magnetization',string) plot(T,M_smooth,'-') #calculate first derivative d1,T_d1=[],[] for i in range(len(M_smooth)-1): Dy=M_smooth[i-1]-M_smooth[i+1] Dx=T[i-1]-T[i+1] d1.append(Dy/Dx) T_d1=T[1:len(T-1)] d1=array(d1,'f') d1_smooth=smooth(d1,window_len) #plot the first derivative pmagplotlib.plot_init(PLT['der1'],5,5) string='1st dervative (sliding window=%i)'%int(window_len) pmagplotlib.plotXY(PLT['der1'],T_d1,d1_smooth,'-','temperatue C','',string) plot(T_d1,d1,'--b') #calculate second derivative d2,T_d2=[],[] for i in range(len(d1_smooth)-1): Dy=d1_smooth[i-1]-d1_smooth[i+1] Dx=T[i-1]-T[i+1] #print Dy/Dx d2.append(Dy/Dx) T_d2=T[2:len(T-2)] d2=array(d2,'f') d2_smooth=smooth(d2,window_len) #plot the second derivative pmagplotlib.plot_init(PLT['der2'],5,5) string='2nd dervative (sliding window=%i)'%int(window_len) pmagplotlib.plotXY(PLT['der2'],T_d2,d2,'-','temperatue C','',string) d2=list(d2) print 'second deriative maximum is at T=%i'%int(T_d2[d2.index(max(d2))]) # calculate Curie temperature for different width of sliding windows curie,curie_1=[],[] wn=range(5,50,1) for win in wn: # calculate the smoothed signal M_smooth=[] M_smooth=smooth(M,win) #calculate first derivative d1,T_d1=[],[] for i in range(len(M_smooth)-1): Dy=M_smooth[i-1]-M_smooth[i+1] Dx=T[i-1]-T[i+1] d1.append(Dy/Dx) T_d1=T[1:len(T-1)] d1=array(d1,'f') d1_smooth=smooth(d1,win) #calculate second derivative d2,T_d2=[],[] for i in range(len(d1_smooth)-1): Dy=d1_smooth[i-1]-d1_smooth[i+1] Dx=T[i-1]-T[i+1] d2.append(Dy/Dx) T_d2=T[2:len(T-2)] d2=array(d2,'f') d2_smooth=smooth(d2,win) d2=list(d2) d2_smooth=list(d2_smooth) curie.append(T_d2[d2.index(max(d2))]) if curie[-1]>curieT:curieT=curie[-1] # find maximum curie T curie_1.append(T_d2[d2_smooth.index(max(d2_smooth))]) #plot Curie temp for different sliding window length pmagplotlib.plot_init(PLT['Curie'],5,5) pmagplotlib.plotXY(PLT['Curie'],wn,curie,'.','sliding window width (degrees)','curie temp','Inferred Curie Temperatures') print 'Curie T is: ',curieT pmagplotlib.drawFIGS(PLT) files={} for key in PLT.keys(): files[key]=spec+'_'+key+'.'+fmt ans=raw_input(" S[a]ve to save plot, [q]uit, or return to continue: ") if ans=='q':sys.exit() if ans=='a': pmagplotlib.saveP(PLT,files) if rmag_file!="": ResRec={} ResRec['rmag_result_name']='Curie T: '+spec ResRec['er_location_names']=location ResRec['er_sample_names']=sample ResRec['er_site_names']=site ResRec['er_synthetic_names']=syn if syn!="": ResRec['er_specimen_names']=spec else: ResRec['er_specimen_names']="" ResRec['magic_experiment_names']=expname ResRec['magic_method_codes']=method+':SM-2DMAX' ResRec['critical_temp']='%10.1f'%(curieT) ResRec['critical_temp_type']="Curie" ResRec['er_citation_names']="This study" Results.append(ResRec) if len(Results)>0 and rmag_file!="": ResOuts,keys=pmag.fillkeys(Results) pmag.magic_write(rmag_file,ResOuts,'rmag_results') print 'Results stored in ',rmag_file
def main(): """ NAME replace_AC_specimens.py DESCRIPTION finds anisotropy corrected data and replaces that specimen with it. puts in pmag_specimen format file SYNTAX replace_AC_specimens.py [command line options] OPTIONS -h prints help message and quits -i allows interactive setting of file names -fu TFILE uncorrected pmag_specimen format file with thellier interpretations created by thellier_magic_redo.py -fc AFILE anisotropy corrected pmag_specimen format file created by thellier_magic_redo.py -F FILE pmag_specimens format output file DEFAULTS TFILE: thellier_specimens.txt AFILE: AC_specimens.txt FILE: TorAC_specimens.txt """ dir_path='.' tspec="thellier_specimens.txt" aspec="AC_specimens.txt" ofile="TorAC_specimens.txt" critfile="pmag_criteria.txt" ACSamplist,Samplist,sigmin=[],[],10000 GoodSamps,SpecOuts=[],[] # get arguments from command line if '-h' in sys.argv: print main.__doc__ sys.exit() if '-fu' in sys.argv: ind=sys.argv.index('-fu') tspec=sys.argv[ind+1] if '-fc' in sys.argv: ind=sys.argv.index('-fc') aspec=sys.argv[ind+1] if '-F' in sys.argv: ind=sys.argv.index('-F') ofile=sys.argv[ind+1] if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] # read in pmag_specimens file tspec=dir_path+'/'+tspec aspec=dir_path+'/'+aspec ofile=dir_path+'/'+ofile Specs,file_type=pmag.magic_read(tspec) Specs,file_type=pmag.magic_read(tspec) Speclist=pmag.get_specs(Specs) ACSpecs,file_type=pmag.magic_read(aspec) ACspeclist=pmag.get_specs(ACSpecs) for spec in Specs: if spec["er_sample_name"] not in Samplist:Samplist.append(spec["er_sample_name"]) for spec in ACSpecs: if spec["er_sample_name"] not in ACSamplist:ACSamplist.append(spec["er_sample_name"]) # for samp in Samplist: useAC,Ints,ACInts,GoodSpecs,AC,UC=0,[],[],[],[],[] for spec in Specs: if spec["er_sample_name"].lower()==samp.lower(): UC.append(spec) if samp in ACSamplist: for spec in ACSpecs: if spec["er_sample_name"].lower()==samp.lower(): AC.append(spec) if len(AC)>0: AClist=[] for spec in AC: SpecOuts.append(spec) AClist.append(spec['er_specimen_name']) print 'using AC: ',spec['er_specimen_name'],'%7.1f'%(1e6*float(spec['specimen_int'])) for spec in UC: if spec['er_specimen_name'] not in AClist: SpecOuts.append(spec) # print 'using UC: ',spec['er_specimen_name'],'%7.1f'%(1e6*float(spec['specimen_int'])) else: for spec in UC: SpecOuts.append(spec) # print 'using UC: ',spec['er_specimen_name'],'%7.1f'%(1e6*float(spec['specimen_int'])) SpecOuts,keys=pmag.fillkeys(SpecOuts) pmag.magic_write(ofile,SpecOuts,'pmag_specimens') print 'thellier data assessed for AC correction put in ', ofile
def main(): """ NAME UR_jr6_magic.py DESCRIPTION converts University of Rome JR6 format files to magic_measurements format files SYNTAX UR_jr6_magic.py [command line options] OPTIONS -h: prints the help message and quits. -F FILE: specify output measurements file, default is magic_measurements.txt -Fsa FILE: specify output er_samples.txt file for appending, default is er_samples.txt -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 -A : don't average replicate measurements -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 -mcd: specify sampling method codes as a colon delimited string: [default is: FS-FD:SO-POM:SO-SUN] FS-FD field sampling done with a drill FS-H field sampling done with hand samples FS-LOC-GPS field location done with GPS FS-LOC-MAP field location done with map SO-POM a Pomeroy orientation device was used SO-SUN orientations are from a sun compass SO-MAG orientations are from a magnetic compass SO-MAG-CMD orientations declination corrected magnetic compass -ncn NCON: specify naming convention: default is #1 below 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 Put data from separate experiments (all AF, thermal, thellier, trm aquisition, Shaw, etc.) in separate directory """ # # version_num=pmag.get_version() er_location_name="" ErSpecs,ErSamps,ErSites,ErLocs,ErCits=[],[],[],[],[] MagRecs=[] citation="This study" dir_path,demag='.','NRM' args=sys.argv noave=0 specnum=0 sampmeths='FS-FD:SO-POM:SO-SUN' samp_con,Z="4","2" if '-WD' in args: ind=args.index("-WD") dir_path=args[ind+1] meas_file=dir_path+'/'+'magic_measurements.txt' samp_file=dir_path+'/'+'er_samples.txt' if "-h" in args: print main.__doc__ sys.exit() if "-A" in args: noave=1 if '-F' in args: ind=args.index("-F") meas_file=dir_path+'/'+args[ind+1] if '-Fsa' in args: ind=args.index("-Fsa") samp_file=dir_path+'/'+args[ind+1] ErSamps,file_type=pmag.magic_read(samp_file) 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 [4] must be in form 7-Z where Z is an integer" sys.exit() else: Z=samp_con.split("-")[1] samp_con="4" if "-mcd" in args: ind=args.index("-mcd") sampmeths=(sys.argv[ind+1]) if "-loc" in args: ind=args.index("-loc") er_location_name=args[ind+1] if "-spc" in args: ind=args.index("-spc") specnum=int(args[ind+1]) if specnum!=0:specnum=-specnum 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" 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 demag=="T" and "ANI" in codes: methcode="LP-AN-TRM" if demag=="AF" and "ANI" in codes: methcode="LP-AN-ARM" if labfield==0: labfield=50e-6 if peakfield==0: peakfield=.180 filelist=os.listdir(dir_path) # read in list of files to import samples=[] MagRecs,SampRecs=[],[] for samp in ErSamps: if samp['er_sample_name'] not in samples: samples.append(samp['er_sample_name']) SampRecs.append(samp) for file in filelist: # parse each file parts=file.split('.') if parts[1].upper()=='JR6': print 'processing: ',file treatment_type,treatment_value,user="","","" inst="UR-JR6" input=open(dir_path+'/'+file,'rU').readlines() for line in input: newline=line.replace('-',' -') rec=newline.split() MagRec,SampRec={},{} specimen=rec[0] if specnum!=0: SampRec['er_sample_name']=specimen[:specnum] else: SampRec['er_sample_name']=specimen er_site_name=pmag.parse_site(SampRec['er_sample_name'],samp_con,Z) SampRec['er_site_name']=er_site_name SampRec['er_location_name']=er_location_name for key in SampRec.keys():MagRec[key]=SampRec[key] SampRec['sample_azimuth']=rec[7] SampRec['sample_dip']='-'+rec[8] SampRec['sample_bed_dip_direction']=rec[9] SampRec['sample_bed_dip']=rec[10] SampRec['magic_method_codes']=sampmeths MagRec['er_specimen_name']=specimen MagRec['er_analyst_mail_names']=user MagRec['magic_software_packages']=version_num MagRec["measurement_temp"]='%8.3e' % (273) # room temp in kelvin MagRec["treatment_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"]='' # set csd to blank MagRec["treatment_temp"]='%8.3e' % (273) # room temp in kelvin MagRec['magic_method_codes']='LT-NO' if rec[2]=='C': temp=float(rec[1])+273. if temp>298: MagRec["treatment_temp"]='%8.3e' % (temp) # room temp in kelvin MagRec['magic_method_codes']='LT-T-Z' else: # measurement is in oe AC=float(rec[1])*1e-4 # convert to tesla if AC!=0.: MagRec["treatment_ac_field"]='%8.3e' %(AC) MagRec['magic_method_codes']='LT-AF-Z' vol=10.8*1e-6 # standard Roma lab volume MagRec['magic_instrument_codes']=inst MagRec['measurement_number']='1' mexp=10**(float(rec[6])) x,y,z=mexp*float(rec[3]),mexp*float(rec[4]),mexp*float(rec[5]) Cart=[x,y,z] Dir=pmag.cart2dir(Cart) MagRec['measurement_dec']='%7.1f'%(Dir[0]) MagRec['measurement_inc']='%7.1f'%(Dir[1]) MagRec['measurement_magn_volume']='%8.3e'%(Dir[2]) MagRec['measurement_magn_moment']='%8.3e'%(Dir[2]*vol) MagRec['measurement_description']='converted A/m to Am^2 using volume of '+str(vol)+' m^3' MagRecs.append(MagRec) if MagRec['er_sample_name'] not in samples: samples.append(MagRec['er_sample_name']) SampRecs.append(SampRec) if len(SampRecs)>0: SampOut,keys=pmag.fillkeys(SampRecs) pmag.magic_write(samp_file,SampOut,'er_samples') print 'samples stored in ',samp_file Fixed=pmag.measurements_methods(MagRecs,noave) pmag.magic_write(meas_file,Fixed,'magic_measurements') print 'data stored in ',meas_file
def main(command_line=True, **kwargs): """ NAME 2G_bin_magic.py DESCRIPTION takes the binary 2G format magnetometer files and converts them to magic_measurements, er_samples.txt and er_sites.txt file SYNTAX 2G_bin_magic.py [command line options] OPTIONS -f FILE: specify input 2G (binary) file -F FILE: specify magic_measurements output file, default is: magic_measurements.txt -Fsa FILE: specify output file, default is: er_samples.txt -Fsi FILE: specify output file, default is: er_sites.txt -ncn NCON: specify naming convention: default is #2 below -ocn OCON: specify orientation convention, default is #5 below -mcd: specify sampling method codes as a colon delimited string: [default is: FS-FD:SO-POM] FS-FD field sampling done with a drill FS-H field sampling done with hand samples FS-LOC-GPS field location done with GPS FS-LOC-MAP field location done with map SO-POM a Pomeroy orientation device was used SO-ASC an ASC orientation device was used SO-MAG orientation with magnetic compass SO-SUN orientation with sun compass -loc: location name, default="unknown" -spc NUM : specify number of characters to designate a specimen, default = 0 -ins INST : specify instsrument name -a: average replicate measurements INPUT FORMAT Input files are horrible mag binary format (who knows why?) Orientation convention: [1] Lab arrow azimuth= mag_azimuth; Lab arrow dip=-field_dip i.e., field_dip is degrees from vertical down - the hade [default] [2] Lab arrow azimuth = mag_azimuth-90; Lab arrow dip = -field_dip i.e., mag_azimuth is strike and field_dip is hade [3] Lab arrow azimuth = mag_azimuth; Lab arrow dip = 90-field_dip i.e., lab arrow same as field arrow, but field_dip was a hade. [4] lab azimuth and dip are same as mag_azimuth, field_dip [5] lab azimuth is same as mag_azimuth,lab arrow dip=field_dip-90 [6] Lab arrow azimuth = mag_azimuth-90; Lab arrow dip = 90-field_dip [7] all others you will have to either customize your self or e-mail [email protected] for help. Magnetic declination convention: Az will use supplied declination to correct azimuth 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. OUTPUT output saved in magic_measurements.txt & er_samples.txt formatted files will overwrite any existing files """ # # initialize variables # mag_file = '' specnum=0 ub_file,samp_file,or_con,corr,meas_file = "","er_samples.txt","3","1","magic_measurements.txt" pos_file,site_file="","er_sites.txt" noave=1 args=sys.argv bed_dip,bed_dip_dir="","" samp_con,Z,average_bedding="2",1,"0" meths='FS-FD' sclass,lithology,_type="","","" user,inst="","" DecCorr=0. location_name="unknown" months=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] gmeths="" # # dir_path='.' if command_line: if '-WD' in args: ind=args.index("-WD") dir_path=sys.argv[ind+1] if "-h" in args: print main.__doc__ return False if "-f" in args: ind=args.index("-f") mag_file=sys.argv[ind+1] if "-fpos" in args: ind=args.index("-fpos") pos_file=sys.argv[ind+1] if "-F" in args: ind=args.index("-F") meas_file=sys.argv[ind+1] if "-Fsa" in args: ind=args.index("-Fsa") samp_file=sys.argv[ind+1] if "-Fsi" in args: ind=args.index("-Fsi") site_file=sys.argv[ind+1] if "-ocn" in args: ind=args.index("-ocn") or_con=sys.argv[ind+1] if "-ncn" in args: ind=args.index("-ncn") samp_con=sys.argv[ind+1] if "-mcd" in args: ind=args.index("-mcd") gmeths=(sys.argv[ind+1]) if "-loc" in args: ind=args.index("-loc") location_name=(sys.argv[ind+1]) if "-spc" in args: ind=args.index("-spc") specnum=int(args[ind+1]) if "-ins" in args: ind=args.index("-ins") inst=args[ind+1] if "-a" in args: noave=0 # ID = False if '-ID' in args: ind = args.index('-ID') ID = args[ind+1] # if not command_line: dir_path = kwargs.get('dir_path', '.') mag_file = kwargs.get('mag_file', '') pos_file = kwargs.get('pos_file', '') meas_file = kwargs.get('meas_file', 'magic_measurements.txt') samp_file = kwargs.get('samp_file', 'er_samples.txt') site_file = kwargs.get('site_file', 'er_sites.txt') or_con = kwargs.get('or_con', '3') samp_con = kwargs.get('samp_con', '2') corr = kwargs.get('corr', '1') gmeths = kwargs.get('gmeths', '') location_name = kwargs.get('location_name', '') specnum = int(kwargs.get('specnum', 0)) inst = kwargs.get('inst', '') noave = kwargs.get('noave', 1) # default is DO average ID = kwargs.get('ID', '') # format and fix variables acquired from command line args or input with **kwargs if specnum!=0:specnum=-specnum if ID: input_dir_path = ID else: input_dir_path = dir_path if samp_con: if "4" in samp_con: if "-" not in samp_con: print "option [4] must be in form 4-Z where Z is an integer" return False, "option [4] must be in form 4-Z where Z is an integer" 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" return False, "option [7] must be in form 7-Z where Z is an integer" else: Z=samp_con.split("-")[1] samp_con="7" if "6" in samp_con: try: Samps,file_type=pmag.magic_read(os.path.join(input_dir_path, 'er_samples.txt')) except: print "there is no er_samples.txt file in your input directory - you can't use naming convention #6" return False, "there is no er_samples.txt file in your input directory - you can't use naming convention #6" if file_type == 'bad_file': print "there is no er_samples.txt file in your input directory - you can't use naming convention #6" return False, "there is no er_samples.txt file in your input directory - you can't use naming convention #6" if not mag_file: print "mag file is required input" return False, "mag file is required input" output_dir_path = dir_path mag_file = os.path.join(input_dir_path, mag_file) samp_file = output_dir_path+'/'+samp_file site_file = output_dir_path+'/'+site_file meas_file= output_dir_path+'/'+meas_file samplist=[] try: Samps,file_type=pmag.magic_read(samp_file) for samp in Samps: if samp['er_sample_name'] not in samplist: samplist.append(samp['er_sample_name']) except: Samps=[] MagRecs=[] try: f=open(mag_file,'rU') input=f.read() f.close() except Exception as ex: print 'ex', ex print "bad mag file" return False, "bad mag file" firstline,date=1,"" d=input.split('\xcd') for line in d: rec=line.split('\x00') if firstline==1: firstline=0 spec,vol="",1 for c in line[15:23]: if c!='\x00':spec=spec+c # check for bad sample name test=spec.split('.') date="" if len(test)>1: spec=test[0] kk=24 while line[kk]!='\x01' and line[kk]!='\x00': kk+=1 vcc=line[24:kk] el=10 while rec[el].strip()!='':el+=1 date,comments=rec[el+7],[] else: el=9 while rec[el]!='\x01':el+=1 vcc,date,comments=rec[el-3],rec[el+7],[] specname=spec.lower() print 'importing ',specname el+=8 while rec[el].isdigit()==False: comments.append(rec[el]) el+=1 while rec[el]=="":el+=1 az=float(rec[el]) el+=1 while rec[el]=="":el+=1 pl=float(rec[el]) el+=1 while rec[el]=="":el+=1 bed_dip_dir=float(rec[el]) el+=1 while rec[el]=="":el+=1 bed_dip=float(rec[el]) el+=1 while rec[el]=="":el+=1 if rec[el]=='\x01': bed_dip=180.-bed_dip el+=1 while rec[el]=="":el+=1 fold_az=float(rec[el]) el+=1 while rec[el]=="":el+=1 fold_pl=rec[el] el+=1 while rec[el]=="":el+=1 if rec[el]!="" and rec[el]!='\x02' and rec[el]!='\x01': deccorr=float(rec[el]) az+=deccorr bed_dip_dir+=deccorr fold_az+=deccorr if bed_dip_dir>=360:bed_dip_dir=bed_dip_dir-360. if az>=360.:az=az-360. if fold_az>=360.:fold_az=fold_az-360. else: deccorr=0 if specnum!=0: sample=specname[:specnum] else: sample=specname SampRec={} SampRec["er_sample_name"]=sample SampRec["er_location_name"]=location_name SampRec["er_citation_names"]="This study" labaz,labdip=pmag.orient(az,pl,or_con) # convert to labaz, labpl # # parse information common to all orientation methods # SampRec["sample_bed_dip"]='%7.1f'%(bed_dip) SampRec["sample_bed_dip_direction"]='%7.1f'%(bed_dip_dir) SampRec["sample_dip"]='%7.1f'%(labdip) SampRec["sample_azimuth"]='%7.1f'%(labaz) if vcc.strip()!="":vol=float(vcc)*1e-6 # convert to m^3 from cc SampRec["sample_volume"]='%10.3e'%(vol) # SampRec["sample_class"]=sclass SampRec["sample_lithology"]=lithology SampRec["sample_type"]=_type SampRec["sample_declination_correction"]='%7.1f'%(deccorr) methods=gmeths.split(':') if deccorr!="0": if 'SO-MAG' in methods:del methods[methods.index('SO-MAG')] methods.append('SO-CMD-NORTH') meths="" for meth in methods:meths=meths+meth+":" meths=meths[:-1] SampRec["magic_method_codes"]=meths if int(samp_con)<6 or int(samp_con) == 7: site=pmag.parse_site(SampRec["er_sample_name"],samp_con,Z) # parse out the site name SampRec["er_site_name"]=site elif len(Samps)>1: site,location="","" for samp in Samps: if samp["er_sample_name"] == SampRec["er_sample_name"]: site=samp["er_site_name"] location=samp["er_location_name"] break SampRec["er_location_name"]=samp["er_location_name"] SampRec["er_site_name"]=samp["er_site_name"] if sample not in samplist: samplist.append(sample) Samps.append(SampRec) else: MagRec={} 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" MagRec["measurement_flag"]='g' MagRec["measurement_standard"]='u' MagRec["measurement_number"]='1' MagRec["er_specimen_name"]=specname MagRec["er_sample_name"]=SampRec['er_sample_name'] MagRec["er_site_name"]=SampRec['er_site_name'] MagRec["er_location_name"]=location_name el,demag=1,'' treat=rec[el] if treat[-1]=='C': demag='T' elif treat!='NRM': demag='AF' el+=1 while rec[el]=="":el+=1 MagRec["measurement_dec"]=rec[el] cdec=float(rec[el]) el+=1 while rec[el]=="":el+=1 MagRec["measurement_inc"]=rec[el] cinc=float(rec[el]) el+=1 while rec[el]=="":el+=1 gdec=rec[el] el+=1 while rec[el]=="":el+=1 ginc=rec[el] el=skip(2,el,rec) # skip bdec,binc # el=skip(4,el,rec) # skip gdec,ginc,bdec,binc # print 'moment emu: ',rec[el] MagRec["measurement_magn_moment"]='%10.3e'% (float(rec[el])*1e-3) # moment in Am^2 (from emu) MagRec["measurement_magn_volume"]='%10.3e'% (float(rec[el])*1e-3/vol) # magnetization in A/m el=skip(2,el,rec) # skip to xsig MagRec["measurement_sd_x"]='%10.3e'% (float(rec[el])*1e-3) # convert from emu el=skip(3,el,rec) # skip to ysig MagRec["measurement_sd_y"]='%10.3e'% (float(rec[el])*1e-3) # convert from emu el=skip(3,el,rec) # skip to zsig MagRec["measurement_sd_z"]='%10.3e'% (float(rec[el])*1e-3) # convert from emu el+=1 # skip to positions MagRec["measurement_positions"]=rec[el] # el=skip(5,el,rec) # skip to date # mm=str(months.index(date[0])) # if len(mm)==1: # mm='0'+str(mm) # else: # mm=str(mm) # dstring=date[2]+':'+mm+':'+date[1]+":"+date[3] # MagRec['measurement_date']=dstring MagRec["magic_instrument_codes"]=inst MagRec["er_analyst_mail_names"]="" MagRec["er_citation_names"]="This study" MagRec["magic_method_codes"]=meas_type if demag=="AF": MagRec["treatment_ac_field"]='%8.3e' %(float(treat[:-2])*1e-3) # peak field in tesla meas_type="LT-AF-Z" MagRec["treatment_dc_field"]='0' elif demag=="T": MagRec["treatment_temp"]='%8.3e' % (float(treat[:-1])+273.) # temp in kelvin meas_type="LT-T-Z" MagRec['magic_method_codes']=meas_type MagRecs.append(MagRec) MagOuts=pmag.measurements_methods(MagRecs,noave) MagOuts, keylist = pmag.fillkeys(MagOuts) pmag.magic_write(meas_file,MagOuts,'magic_measurements') print "Measurements put in ",meas_file SampsOut,sampkeys=pmag.fillkeys(Samps) pmag.magic_write(samp_file,SampsOut,"er_samples") Sites=[] for samp in Samps: SiteRec={} SiteRec['er_site_name']=samp['er_site_name'] SiteRec['er_location_name']=samp['er_location_name'] SiteRec['site_definition']='s' SiteRec['er_citation_names']='This study' if 'sample_class' in samp.keys():SiteRec['site_class']=samp['sample_class'] if 'sample_lithology' in samp.keys():SiteRec['site_lithology']=samp['sample_lithology'] if 'sample_type' in samp.keys():SiteRec['site_lithology']=samp['sample_lithology'] if 'sample_lat' in samp.keys(): SiteRec['site_lat']=samp['sample_lat'] else: SiteRec['site_lat']="-999" if 'sample_lon' in samp.keys(): SiteRec['site_lon']=samp['sample_lon'] else: SiteRec['site_lon']="-999" if 'sample_height' in samp.keys():SiteRec['site_height']=samp['sample_height'] Sites.append(SiteRec) pmag.magic_write(site_file,Sites,'er_sites') return True, meas_file
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(): """ 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 save_redo(SpecRecs,inspec): SpecRecs,keys=pmag.fillkeys(SpecRecs) pmag.magic_write(inspec,SpecRecs,'pmag_specimens')
def main(): """ NAME orientation_magic.py DESCRIPTION takes tab delimited field notebook information and converts to MagIC formatted tables SYNTAX orientation_magic.py [command line options] OPTIONS -f FILE: specify input file, default is: orient.txt -Fsa FILE: specify output file, default is: er_samples.txt -Fsi FILE: specify output site location file, default is: er_sites.txt -app append/update these data in existing er_samples.txt, er_sites.txt files -ocn OCON: specify orientation convention, default is #1 below -dcn DCON [DEC]: specify declination convention, default is #1 below if DCON = 2, you must supply the declination correction -BCN don't correct bedding_dip_dir for magnetic declination -already corrected -ncn NCON: specify naming convention: default is #1 below -a: averages all bedding poles and uses average for all samples: default is NO -gmt HRS: specify hours to subtract from local time to get GMT: default is 0 -mcd: specify sampling method codes as a colon delimited string: [default is: FS-FD:SO-POM] FS-FD field sampling done with a drill FS-H field sampling done with hand samples FS-LOC-GPS field location done with GPS FS-LOC-MAP field location done with map SO-POM a Pomeroy orientation device was used SO-ASC an ASC orientation device was used INPUT FORMAT Input files must be tab delimited and have in the first line: tab location_name Note: The "location_name" will facilitate searching in the MagIC database. Data from different "locations" should be put in separate files. The definition of a "location" is rather loose. Also this is the word 'tab' not a tab, which will be indicated by '\t'. The second line has the names of the columns (tab delimited), e.g.: site_name sample_name mag_azimuth field_dip date lat long sample_lithology sample_type sample_class shadow_angle hhmm stratigraphic_height bedding_dip_direction bedding_dip GPS_baseline image_name image_look image_photographer participants method_codes site_description sample_description GPS_Az, sample_igsn, sample_texture, sample_cooling_rate, cooling_rate_corr, cooling_rate_mcd Notes: 1) column order doesn't matter but the NAMES do. 2) sample_name, sample_lithology, sample_type, sample_class, lat and long are required. all others are optional. 3) If subsequent data are the same (e.g., date, bedding orientation, participants, stratigraphic_height), you can leave the field blank and the program will fill in the last recorded information. BUT if you really want a blank stratigraphic_height, enter a '-1'. These will not be inherited and must be specified for each entry: image_name, look, photographer or method_codes 4) hhmm must be in the format: hh:mm and the hh must be in 24 hour time. date must be mm/dd/yy (years < 50 will be converted to 20yy and >50 will be assumed 19yy) 5) image_name, image_look and image_photographer are colon delimited lists of file name (e.g., IMG_001.jpg) image look direction and the name of the photographer respectively. If all images had same look and photographer, just enter info once. The images will be assigned to the site for which they were taken - not at the sample level. 6) participants: Names of who helped take the samples. These must be a colon delimited list. 7) method_codes: Special method codes on a sample level, e.g., SO-GT5 which means the orientation is has an uncertainty of >5 degrees for example if it broke off before orienting.... 8) GPS_Az is the place to put directly determined GPS Azimuths, using, e.g., points along the drill direction. 9) sample_cooling_rate is the cooling rate in K per Ma 10) int_corr_cooling_rate 11) cooling_rate_mcd: data adjustment method code for cooling rate correction; DA-CR-EG is educated guess; DA-CR-PS is percent estimated from pilot samples; DA-CR-TRM is comparison between 2 TRMs acquired with slow and rapid cooling rates. is the percent cooling rate factor to apply to specimens from this sample, DA-CR-XX is the method code Orientation convention: Samples are oriented in the field with a "field arrow" and measured in the laboratory with a "lab arrow". The lab arrow is the positive X direction of the right handed coordinate system of the specimen measurements. The lab and field arrows may not be the same. In the MagIC database, we require the orientation (azimuth and plunge) of the X direction of the measurements (lab arrow). Here are some popular conventions that convert the field arrow azimuth (mag_azimuth in the orient.txt file) and dip (field_dip in orient.txt) to the azimuth and plunge of the laboratory arrow (sample_azimuth and sample_dip in er_samples.txt). The two angles, mag_azimuth and field_dip are explained below. [1] Standard Pomeroy convention of azimuth and hade (degrees from vertical down) of the drill direction (field arrow). lab arrow azimuth= sample_azimuth = mag_azimuth; lab arrow dip = sample_dip =-field_dip. i.e. the lab arrow dip is minus the hade. [2] Field arrow is the strike of the plane orthogonal to the drill direction, Field dip is the hade of the drill direction. Lab arrow azimuth = mag_azimuth-90 Lab arrow dip = -field_dip [3] Lab arrow is the same as the drill direction; hade was measured in the field. Lab arrow azimuth = mag_azimuth; Lab arrow dip = 90-field_dip [4] lab azimuth and dip are same as mag_azimuth, field_dip : use this for unoriented samples too [5] Same as AZDIP convention explained below - azimuth and inclination of the drill direction are mag_azimuth and field_dip; lab arrow is as in [1] above. lab azimuth is same as mag_azimuth,lab arrow dip=field_dip-90 [6] Lab arrow azimuth = mag_azimuth-90; Lab arrow dip = 90-field_dip [7] all others you will have to either customize your self or e-mail [email protected] for help. Magnetic declination convention: [1] Use the IGRF value at the lat/long and date supplied [default] [2] Will supply declination correction [3] mag_az is already corrected in file [4] Correct mag_az but not bedding_dip_dir 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 = sample name [6] site name entered in site_name column in the orient.txt format input file [7-Z] [XXX]YYY: XXX is site designation with Z characters from samples XXXYYY NB: all others you will have to either customize your self or e-mail [email protected] for help. OUTPUT output saved in er_samples.txt and er_sites.txt - will overwrite any existing files """ # # initialize variables # stratpos="" args=sys.argv date,lat,lon="","","" # date of sampling, latitude (pos North), longitude (pos East) bed_dip,bed_dip_dir="","" participantlist="" Lats,Lons=[],[] # list of latitudes and longitudes SampOuts,SiteOuts,ImageOuts=[],[],[] # lists of Sample records and Site records samplelist,sitelist,imagelist=[],[],[] samp_con,Z,average_bedding,DecCorr="1",1,"0",0. newbaseline,newbeddir,newbeddip="","","" meths='' delta_u="0" sclass,lithology,type="","","" newclass,newlith,newtype='','','' user="" BPs=[]# bedding pole declinations, bedding pole inclinations # # dir_path,AddTo='.',0 if "-WD" in args: ind=args.index("-WD") dir_path=sys.argv[ind+1] orient_file,samp_file,or_con,corr = dir_path+"/orient.txt",dir_path+"/er_samples.txt","1","1" site_file=dir_path+"/er_sites.txt" image_file=dir_path+"/er_images.txt" SampRecs,SiteRecs,ImageRecs=[],[],[] if "-h" in args: print main.__doc__ sys.exit() if "-f" in args: ind=args.index("-f") orient_file=dir_path+'/'+sys.argv[ind+1] if "-Fsa" in args: ind=args.index("-Fsa") samp_file=dir_path+'/'+sys.argv[ind+1] if "-Fsi" in args: ind=args.index("-Fsi") site_file=dir_path+'/'+sys.argv[ind+1] if '-app' in args: AddTo=1 try: SampRecs,file_type=pmag.magic_read(samp_file) print 'sample data to be appended to: ', samp_file except: print 'problem with existing file: ',samp_file, ' will create new.' try: SiteRecs,file_type=pmag.magic_read(site_file) print 'site data to be appended to: ',site_file except: print 'problem with existing file: ',site_file,' will create new.' try: ImageRecs,file_type=pmag.magic_read(image_file) print 'image data to be appended to: ',image_file except: print 'problem with existing file: ',image_file,' will create new.' if "-ocn" in args: ind=args.index("-ocn") or_con=sys.argv[ind+1] if "-dcn" in args: ind=args.index("-dcn") corr=sys.argv[ind+1] if corr=="2": DecCorr=float(sys.argv[ind+2]) elif corr=="3": DecCorr=0. if '-BCN' in args: BedCorr=0 else: BedCorr=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 "-gmt" in args: ind=args.index("-gmt") delta_u=(sys.argv[ind+1]) if "-mcd" in args: ind=args.index("-mcd") meths=(sys.argv[ind+1]) if "-a" in args: average_bedding="1" # # read in file to convert # OrData,location_name=pmag.magic_read(orient_file) # # step through the data sample by sample # for OrRec in OrData: if 'mag_azimuth' not in OrRec.keys():OrRec['mag_azimuth']="" if 'field_dip' not in OrRec.keys():OrRec['field_dip']="" if OrRec['mag_azimuth']==" ":OrRec["mag_azimuth"]="" if OrRec['field_dip']==" ":OrRec["field_dip"]="" if 'sample_description' in OrRec.keys(): sample_description=OrRec['sample_description'] else: sample_description="" if 'sample_igsn' in OrRec.keys(): sample_igsn=OrRec['sample_igsn'] else: sample_igsn="" if 'sample_texture' in OrRec.keys(): sample_texture=OrRec['sample_texture'] else: sample_texture="" if 'sample_cooling_rate' in OrRec.keys(): sample_cooling_rate=OrRec['sample_cooling_rate'] else: sample_cooling_rate="" if 'cooling_rate_corr' in OrRec.keys(): cooling_rate_corr=OrRec['cooling_rate_corr'] if 'cooling_rate_mcd' in OrRec.keys(): cooling_rate_mcd=OrRec['cooling_rate_mcd'] else: cooling_rate_mcd='DA-CR' else: cooling_rate_corr="" cooling_rate_mcd="" sample_orientation_flag='g' if 'sample_orientation_flag' in OrRec.keys(): if OrRec['sample_orientation_flag']=='b' or OrRec["mag_azimuth"]=="": sample_orientation_flag='b' methcodes=meths # initialize method codes if meths!='': if 'method_codes' in OrRec.keys() and OrRec['method_codes'].strip()!="":methcodes=methcodes+":"+OrRec['method_codes'] # add notes else: if 'method_codes' in OrRec.keys() and OrRec['method_codes'].strip()!="":methcodes=OrRec['method_codes'] # add notes codes=methcodes.replace(" ","").split(":") MagRec={} MagRec["er_location_name"]=location_name MagRec["er_citation_names"]="This study" MagRec['sample_orientation_flag']=sample_orientation_flag MagRec['sample_igsn']=sample_igsn MagRec['sample_texture']=sample_texture MagRec['sample_cooling_rate']=sample_cooling_rate MagRec['cooling_rate_corr']=cooling_rate_corr MagRec['cooling_rate_mcd']=cooling_rate_mcd # # parse information common to all orientation methods # MagRec["er_sample_name"]=OrRec["sample_name"] if "IGSN" in OrRec.keys(): MagRec["sample_igsn"]=OrRec["IGSN"] else: MagRec["sample_igsn"]="" MagRec["sample_height"],MagRec["sample_bed_dip_direction"],MagRec["sample_bed_dip"]="","","" if "er_sample_alternatives" in OrRec.keys():MagRec["er_sample_alternatives"]=OrRec["sample_alternatives"] sample=OrRec["sample_name"] if OrRec['mag_azimuth']=="" and OrRec['field_dip']!="": OrRec['mag_azimuth']='999' if OrRec["mag_azimuth"]!="": labaz,labdip=pmag.orient(float(OrRec["mag_azimuth"]),float(OrRec["field_dip"]),or_con) if labaz<0:labaz+=360. else: labaz,labdip="","" if OrRec['mag_azimuth']=='999':labaz="" if "GPS_baseline" in OrRec.keys() and OrRec['GPS_baseline']!="":newbaseline=OrRec["GPS_baseline"] if newbaseline!="":baseline=float(newbaseline) if 'participants' in OrRec.keys() and OrRec['participants']!="" and OrRec['participants']!=participantlist: participantlist=OrRec['participants'] MagRec['er_scientist_mail_names']=participantlist newlat=OrRec["lat"] if newlat!="":lat=float(newlat) if lat=="": print "No latitude specified for ! ",sample sys.exit() MagRec["sample_lat"]='%11.5f'%(lat) newlon=OrRec["long"] if newlon!="":lon=float(newlon) if lon=="": print "No longitude specified for ! ",sample sys.exit() MagRec["sample_lon"]='%11.5f'%(lon) if 'bedding_dip_direction' in OrRec.keys(): newbeddir=OrRec["bedding_dip_direction"] if newbeddir!="":bed_dip_dir=OrRec['bedding_dip_direction'] if 'bedding_dip' in OrRec.keys(): newbeddip=OrRec["bedding_dip"] if newbeddip!="":bed_dip=OrRec['bedding_dip'] MagRec["sample_bed_dip"]=bed_dip MagRec["sample_bed_dip_direction"]=bed_dip_dir if "sample_class" in OrRec.keys():newclass=OrRec["sample_class"] if newclass!="":sclass=newclass if sclass=="": sclass="Not Specified" MagRec["sample_class"]=sclass if "sample_lithology" in OrRec.keys():newlith=OrRec["sample_lithology"] if newlith!="":lithology=newlith if lithology=="": lithology="Not Specified" MagRec["sample_lithology"]=lithology if "sample_type" in OrRec.keys():newtype=OrRec["sample_type"] if newtype!="":type=newtype if type=="": type="Not Specified" MagRec["sample_type"]=type if labdip!="": MagRec["sample_dip"]='%7.1f'%labdip else: MagRec["sample_dip"]="" if "date" in OrRec.keys(): newdate=OrRec["date"] if newdate!="":date=newdate mmddyy=date.split('/') yy=int(mmddyy[2]) if yy>50: yy=1900+yy else: yy=2000+yy decimal_year=yy+float(mmddyy[0])/12 sample_date='%i:%s:%s'%(yy,mmddyy[0],mmddyy[1]) MagRec["sample_date"]=sample_date if labaz!="": MagRec["sample_azimuth"]='%7.1f'%(labaz) else: MagRec["sample_azimuth"]="" if "stratigraphic_height" in OrRec.keys(): if OrRec["stratigraphic_height"]!="": MagRec["sample_height"]=OrRec["stratigraphic_height"] stratpos=OrRec["stratigraphic_height"] elif OrRec["stratigraphic_height"]=='-1': MagRec["sample_height"]="" # make empty else: MagRec["sample_height"]=stratpos # keep last record if blank # if corr=="1" and MagRec['sample_azimuth']!="": # get magnetic declination (corrected with igrf value) x,y,z,f=pmag.doigrf(lon,lat,0,decimal_year) Dir=pmag.cart2dir( (x,y,z)) DecCorr=Dir[0] if "bedding_dip" in OrRec.keys(): if OrRec["bedding_dip"]!="": MagRec["sample_bed_dip"]=OrRec["bedding_dip"] bed_dip=OrRec["bedding_dip"] else: MagRec["sample_bed_dip"]=bed_dip else: MagRec["sample_bed_dip"]='0' if "bedding_dip_direction" in OrRec.keys(): if OrRec["bedding_dip_direction"]!="" and BedCorr==1: dd=float(OrRec["bedding_dip_direction"])+DecCorr if dd>360.:dd=dd-360. MagRec["sample_bed_dip_direction"]='%7.1f'%(dd) dip_dir=MagRec["sample_bed_dip_direction"] else: MagRec["sample_bed_dip_direction"]=OrRec['bedding_dip_direction'] else: MagRec["sample_bed_dip_direction"]='0' if average_bedding!="0": BPs.append([float(MagRec["sample_bed_dip_direction"]),float(MagRec["sample_bed_dip"])-90.,1.]) if MagRec['sample_azimuth']=="" and MagRec['sample_dip']=="": MagRec["sample_declination_correction"]='' methcodes=methcodes+':SO-NO' MagRec["magic_method_codes"]=methcodes MagRec['sample_description']=sample_description # # work on the site stuff too if 'site_name' in OrRec.keys(): site=OrRec['site_name'] else: site=pmag.parse_site(OrRec["sample_name"],samp_con,Z) # parse out the site name MagRec["er_site_name"]=site site_description="" # overwrite any prior description if 'site_description' in OrRec.keys() and OrRec['site_description']!="": site_description=OrRec['site_description'].replace(",",";") if "image_name" in OrRec.keys(): images=OrRec["image_name"].split(":") if "image_look" in OrRec.keys(): looks=OrRec['image_look'].split(":") else: looks=[] if "image_photographer" in OrRec.keys(): photographers=OrRec['image_photographer'].split(":") else: photographers=[] for image in images: if image !="" and image not in imagelist: imagelist.append(image) ImageRec={} ImageRec['er_image_name']=image ImageRec['image_type']="outcrop" ImageRec['image_date']=sample_date ImageRec['er_citation_names']="This study" ImageRec['er_location_name']=location_name ImageRec['er_site_name']=MagRec['er_site_name'] k=images.index(image) if len(looks)>k: ImageRec['er_image_description']="Look direction: "+looks[k] elif len(looks)>=1: ImageRec['er_image_description']="Look direction: "+looks[-1] else: ImageRec['er_image_description']="Look direction: unknown" if len(photographers)>k: ImageRec['er_photographer_mail_names']=photographers[k] elif len(photographers)>=1: ImageRec['er_photographer_mail_names']=photographers[-1] else: ImageRec['er_photographer_mail_names']="unknown" ImageOuts.append(ImageRec) if site not in sitelist: sitelist.append(site) # collect unique site names SiteRec={} SiteRec["er_site_name"]=site SiteRec["site_definition"]="s" SiteRec["er_location_name"]=location_name SiteRec["er_citation_names"]="This study" SiteRec["site_lat"]=MagRec["sample_lat"] SiteRec["site_lon"]=MagRec["sample_lon"] SiteRec["site_height"]=MagRec["sample_height"] SiteRec["site_class"]=MagRec["sample_class"] SiteRec["site_lithology"]=MagRec["sample_lithology"] SiteRec["site_type"]=MagRec["sample_type"] SiteRec["site_description"]=site_description SiteOuts.append(SiteRec) if sample not in samplelist: samplelist.append(sample) if MagRec['sample_azimuth']!="": # assume magnetic compass only MagRec['magic_method_codes']=MagRec['magic_method_codes']+':SO-MAG' MagRec['magic_method_codes']=MagRec['magic_method_codes'].strip(":") SampOuts.append(MagRec) if MagRec['sample_azimuth']!="" and corr!='3': az=labaz+DecCorr if az>360.:az=az-360. CMDRec={} for key in MagRec.keys(): CMDRec[key]=MagRec[key] # make a copy of MagRec CMDRec["sample_azimuth"]='%7.1f'%(az) CMDRec["magic_method_codes"]=methcodes+':SO-CMD-NORTH' CMDRec["magic_method_codes"]=CMDRec['magic_method_codes'].strip(':') CMDRec["sample_declination_correction"]='%7.1f'%(DecCorr) if corr=='1': CMDRec['sample_description']=sample_description+':Declination correction calculated from IGRF' else: CMDRec['sample_description']=sample_description+':Declination correction supplied by user' CMDRec["sample_description"]=CMDRec['sample_description'].strip(':') SampOuts.append(CMDRec) if "mag_az_bs" in OrRec.keys() and OrRec["mag_az_bs"] !="" and OrRec["mag_az_bs"]!=" ": SRec={} for key in MagRec.keys(): SRec[key]=MagRec[key] # make a copy of MagRec labaz=float(OrRec["mag_az_bs"]) az=labaz+DecCorr if az>360.:az=az-360. SRec["sample_azimuth"]='%7.1f'%(az) SRec["sample_declination_correction"]='%7.1f'%(DecCorr) SRec["magic_method_codes"]=methcodes+':SO-SIGHT-BACK:SO-CMD-NORTH' SampOuts.append(SRec) # # check for suncompass data # if "shadow_angle" in OrRec.keys() and OrRec["shadow_angle"]!="": # there are sun compass data if delta_u=="": delta_u=raw_input("Enter hours to SUBTRACT from time for GMT: [0] ") if delta_u=="":delta_u="0" SunRec,sundata={},{} shad_az=float(OrRec["shadow_angle"]) sundata["date"]='%i:%s:%s:%s'%(yy,mmddyy[0],mmddyy[1],OrRec["hhmm"]) # if eval(delta_u)<0: # MagRec["sample_time_zone"]='GMT'+delta_u+' hours' # else: # MagRec["sample_time_zone"]='GMT+'+delta_u+' hours' sundata["delta_u"]=delta_u sundata["lon"]='%7.1f'%(lon) sundata["lat"]='%7.1f'%(lat) sundata["shadow_angle"]=OrRec["shadow_angle"] sundec=pmag.dosundec(sundata) for key in MagRec.keys(): SunRec[key]=MagRec[key] # make a copy of MagRec SunRec["sample_azimuth"]='%7.1f'%(sundec) SunRec["sample_declination_correction"]='' SunRec["magic_method_codes"]=methcodes+':SO-SUN' SunRec["magic_method_codes"]=SunRec['magic_method_codes'].strip(':') SampOuts.append(SunRec) # # check for differential GPS data # if "prism_angle" in OrRec.keys() and OrRec["prism_angle"]!="": # there are diff GPS data GPSRec={} for key in MagRec.keys(): GPSRec[key]=MagRec[key] # make a copy of MagRec prism_angle=float(OrRec["prism_angle"]) laser_angle=float(OrRec["laser_angle"]) if OrRec["GPS_baseline"]!="": baseline=float(OrRec["GPS_baseline"]) # new baseline gps_dec=baseline+laser_angle+prism_angle-90. while gps_dec>360.: gps_dec=gps_dec-360. while gps_dec<0: gps_dec=gps_dec+360. for key in MagRec.keys(): GPSRec[key]=MagRec[key] # make a copy of MagRec GPSRec["sample_azimuth"]='%7.1f'%(gps_dec) GPSRec["sample_declination_correction"]='' GPSRec["magic_method_codes"]=methcodes+':SO-GPS-DIFF' SampOuts.append(GPSRec) if "GPS_Az" in OrRec.keys() and OrRec["GPS_Az"]!="": # there are differential GPS Azimuth data GPSRec={} for key in MagRec.keys(): GPSRec[key]=MagRec[key] # make a copy of MagRec GPSRec["sample_azimuth"]='%7.1f'%(float(OrRec["GPS_Az"])) GPSRec["sample_declination_correction"]='' GPSRec["magic_method_codes"]=methcodes+':SO-GPS-DIFF' SampOuts.append(GPSRec) if average_bedding!="0": fpars=pmag.fisher_mean(BPs) print 'over-writing all bedding with average ' Samps=[] for rec in SampOuts: if average_bedding!="0": rec['sample_bed_dip_direction']='%7.1f'%(fpars['dec']) rec['sample_bed_dip']='%7.1f'%(fpars['inc']+90.) Samps.append(rec) else: Samps.append(rec) for rec in SampRecs: if rec['er_sample_name'] not in samplelist: # overwrite prior for this sample Samps.append(rec) for rec in SiteRecs: if rec['er_site_name'] not in sitelist: # overwrite prior for this sample SiteOuts.append(rec) for rec in ImageRecs: if rec['er_image_name'] not in imagelist: # overwrite prior for this sample ImageOuts.append(rec) print 'saving data...' SampsOut,keys=pmag.fillkeys(Samps) Sites,keys=pmag.fillkeys(SiteOuts) pmag.magic_write(samp_file,SampsOut,"er_samples") pmag.magic_write(site_file,Sites,"er_sites") print "Data saved in ", samp_file,' and ',site_file if len(ImageOuts)>0: Images,keys=pmag.fillkeys(ImageOuts) pmag.magic_write(image_file,Images,"er_images") print "Image info saved in ",image_file
def main(): """ NAME combine_magic.py DESCRIPTION Combines magic format files of the same type together. SYNTAX combine_magic.py [-h] [-i] -out filename -in file1 file2 .... OPTIONS -h prints help message -i allows interactive entry of input and output filenames -F specify output file name [must come BEFORE input file names] -f specify input file names [ must come last] """ # # set up magic meta data type requirements # filenames=[] datasets=[] dir_path='.' # 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") output=dir_path+'/'+sys.argv[ind+1] if "-f" in sys.argv: ind=sys.argv.index("-f") for k in range(ind+1,len(sys.argv)): filenames.append(dir_path+'/'+sys.argv[k]) for infile in filenames: dataset,file_type=pmag.magic_read(infile) print "File ",infile," read in with ",len(dataset), " records" for rec in dataset: datasets.append(rec) if '-i' in sys.argv: quit,dataset,datasets=0,[],[] while quit==0: infile=raw_input('\n\n Enter magic files for combining, <return> when done: ') if infile=='': quit = 1 break dataset,file_type=pmag.magic_read(infile) print "File ",infile," read in with ",len(dataset), " records" for rec in dataset: datasets.append(rec) # # collect all the keys from all the files # Recs,keys=pmag.fillkeys(datasets) # # write out the datasets into a combined file # pmag.magic_write(output,Recs,file_type) print "All records stored in ",output
def main(): """ NAME customize_criteria.py DESCRIPTION Allows user to specify acceptance criteria, saves them in pmag_criteria.txt SYNTAX customize_criteria.py [-h][command line options] OPTIONS -h prints help message and quits -f IFILE, reads in existing criteria -F OFILE, writes to pmag_criteria format file DEFAULTS IFILE: pmag_criteria.txt OFILE: pmag_criteria.txt OUTPUT creates a pmag_criteria.txt formatted output file """ infile,critout="","pmag_criteria.txt" SpecCrit={} # # set some sort of quasi-reasonable default criteria # SpecCrit['pmag_criteria_code']='DE-SPEC' SpecCrit['specimen_mad']='5.49' SpecCrit['specimen_alpha95']='5.49' SpecCrit['specimen_n']='4' SpecIntCrit={} SpecIntCrit['pmag_criteria_code']='IE-SPEC' SpecIntCrit['specimen_int_ptrm_n']='2' SpecIntCrit['specimen_drats']='20.5' SpecIntCrit['specimen_b_beta']='0.1' SpecIntCrit['specimen_md']='15' SpecIntCrit['specimen_fvds']='0.7' SpecIntCrit['specimen_q']='1.0' SpecIntCrit['specimen_dang']='10.5' SpecIntCrit['specimen_int_mad']='10.5' SpecIntCrit['specimen_Z']='4' #SpecIntCrit['measurement_step_min']='373' #SpecIntCrit['measurement_step_max']='623' SampCrit={} SampCrit['pmag_criteria_code']='DE-SAMP' SampCrit['sample_alpha95']='10.49' SampIntCrit={} SampIntCrit['pmag_criteria_code']='IE-SAMP' SampIntCrit['sample_int_n']='2' SampIntCrit['sample_int_sigma']='5.5e-6' SampIntCrit['sample_int_sigma_perc']='15.5' SiteIntCrit={} SiteIntCrit['pmag_criteria_code']='IE-SITE' SiteIntCrit['site_int_n']='2' SiteIntCrit['site_int_sigma']='5.5e-6' SiteIntCrit['site_int_sigma_perc']='15.5' SiteCrit={} SiteCrit['pmag_criteria_code']='DE-SITE' SiteCrit['site_n']='5' SiteCrit['site_n_lines']='4' SiteCrit['site_k']='100' SiteCrit['site_alpha95']='180' NpoleCrit={} NpoleCrit['pmag_criteria_code']='NPOLE' NpoleCrit['site_polarity']="n" RpoleCrit={} RpoleCrit['pmag_criteria_code']='RPOLE' RpoleCrit['site_polarity']="r" # parse command line options if '-h' in sys.argv: print main.__doc__ sys.exit() if '-f' in sys.argv: ind=sys.argv.index('-f') infile=sys.argv[ind+1] crit_data,file_type=pmag.magic_read(infile) if file_type!='pmag_criteria': print 'bad input file' print main.__doc__ sys.exit() for critrec in crit_data: if critrec["pmag_criteria_code"]=="DE-SPEC": SpecCrit=critrec if critrec["pmag_criteria_code"]=="IE-SPEC": SpecIntCrit=critrec if critrec["pmag_criteria_code"]=="DE-SAMP": SampCrit=critrec if critrec["pmag_criteria_code"]=="IE-SAMP": SampIntCrit=critrec if critrec["pmag_criteria_code"]=="IE-SITE": SiteIntCrit=critrec if critrec["pmag_criteria_code"]=="DE-SITE": SiteCrit=critrec if critrec["pmag_criteria_code"]=="NPOLE": NpoleCrit=critrec if critrec["pmag_criteria_code"]=="RPOLE": RpoleCrit=critrec print "Acceptance criteria read in from ", infile if '-F' in sys.argv: ind=sys.argv.index('-F') critout=sys.argv[ind+1] Dcrit,Icrit,nocrit=0,0,0 custom='1' crit=raw_input(" [0] Use no acceptance criteria?\n [1] full vector\n [2] direction only\n [3] intensity only \n ") if crit=="0": nocrit=1 if crit=="1": Dcrit,Icrit=1,1 if crit=="2": Dcrit,Icrit=1,0 if crit=="3": Dcrit,Icrit=0,1 if nocrit==1: print 'Using no selection criteria ' SpecCrit={} SpecCrit['pmag_criteria_code']='DE-SPEC' SpecCrit['specimen_mad']='180.' SpecCrit['specimen_alpha95']='180.' SpecCrit['specimen_n']='0' SpecIntCrit={} SpecIntCrit['pmag_criteria_code']='IE-SPEC' SpecIntCrit['specimen_int_ptrm_n']='0' SpecIntCrit['specimen_drats']='100' SpecIntCrit['specimen_b_beta']='5' SpecIntCrit['specimen_md']='100' SpecIntCrit['specimen_fvds']='0' SpecIntCrit['specimen_q']='0' SpecIntCrit['specimen_dang']='180.' SpecIntCrit['specimen_Z']='100.' SpecIntCrit['specimen_int_mad']='180.' #SpecIntCrit['measurement_step_min']='373' SpecIntCrit['measurement_step_max']='0' SampCrit={} SampCrit['pmag_criteria_code']='DE-SAMP' SampCrit['sample_alpha95']='180.' SampIntCrit={} SampIntCrit['pmag_criteria_code']='IE-SAMP' SampIntCrit['sample_int_n']='0' SampIntCrit['sample_int_sigma']='1000' SampIntCrit['sample_int_sigma_perc']='500' SiteIntCrit={} SiteIntCrit['pmag_criteria_code']='IE-SITE' SiteIntCrit['site_int_n']='0' SiteIntCrit['site_int_sigma']='1000' SiteIntCrit['site_int_sigma_perc']='500' SiteCrit={} SiteCrit['pmag_criteria_code']='DE-SITE' SiteCrit['site_n']='0' SiteCrit['site_n_lines']='0' SiteCrit['site_k']='0' SiteCrit['site_alpha95']='180' NpoleCrit={} NpoleCrit['pmag_criteria_code']='NPOLE' NpoleCrit['site_polarity']="n" RpoleCrit={} RpoleCrit['pmag_criteria_code']='RPOLE' RpoleCrit['site_polarity']="r" while custom=='1': if Dcrit==1: for key in SpecCrit.keys(): if key!='pmag_criteria_code' and key!='er_citation_names' and key!='criteria_definition' and SpecCrit[key]!="": print key, SpecCrit[key] new=raw_input("Enter new criterion (return to keep default) ") if new != "": SpecCrit[key]=(new) for key in SampCrit.keys(): if key!='pmag_criteria_code' and key!='er_citation_names' and key!='criteria_definition' and SampCrit[key]!="": print key, SampCrit[key] new=raw_input("Enter new criterion (return to keep default) ") if new != "": SampCrit[key]=(new) for key in SiteCrit.keys(): if key!='pmag_criteria_code' and key!='er_citation_names' and key!='criteria_definition' and SiteCrit[key]!="": print key, SiteCrit[key] new=raw_input("Enter new criterion (return to keep default) ") if new != "": SiteCrit[key]=(new) if Icrit==1: for key in SpecIntCrit.keys(): if key!='pmag_criteria_code' and key!='er_citation_names' and key!='criteria_definition' and SpecIntCrit[key]!="": print key, SpecIntCrit[key] new=raw_input("Enter new criterion (return to keep default) ") if new != "": SpecIntCrit[key]=(new) for key in SiteIntCrit.keys(): if key!='pmag_criteria_code' and key!='er_citation_names' and key!='criteria_definition' and SiteIntCrit[key]!="": print key, SiteIntCrit[key] new=raw_input("Enter new criterion (return to keep default) ") if new != "": SiteIntCrit[key]=(new) custom=raw_input("Customize criteria again ? 1/[0]") SpecCrit['er_citation_names']="This study" SpecIntCrit['er_citation_names']="This study" SampCrit['er_citation_names']="This study" SampIntCrit['er_citation_names']="This study" SiteIntCrit['er_citation_names']="This study" SiteCrit['er_citation_names']="This study" NpoleCrit['er_citation_names']="This study" RpoleCrit['er_citation_names']="This study" SpecCrit['criteria_definition']="Criteria for selection of specimen direction" SpecIntCrit['criteria_definition']="Criteria for selection of specimen intensity" SampCrit['criteria_definition']="Criteria for selection of sample direction" SiteIntCrit['criteria_definition']="Criteria for selection of site intensity" SiteCrit['criteria_definition']="Criteria for selection of site direction" NpoleCrit['criteria_definition']="Criteria for inclusion in normal mean" RpoleCrit['criteria_definition']="Criteria for inclusion in reverse mean" TmpCrits,PmagCrits=[],[] TmpCrits.append(SpecCrit) TmpCrits.append(SpecIntCrit) TmpCrits.append(SampCrit) TmpCrits.append(SampIntCrit) TmpCrits.append(SiteIntCrit) TmpCrits.append(SiteCrit) TmpCrits.append(NpoleCrit) TmpCrits.append(RpoleCrit) # # assemble criteria keys # PmagCrits,critkeys=pmag.fillkeys(TmpCrits) pmag.magic_write(critout,PmagCrits,'pmag_criteria') print "Criteria saved in pmag_criteria.txt" pmag.magic_write(critout,TmpCrits,'pmag_criteria') print "\n Pmag Criteria stored in ",critout,'\n'