def main(): """ NAME change_case_magic.py DESCRIPTION picks out key and converts to upper or lower case SYNTAX change_case_magic.py [command line options] OPTIONS -h prints help message and quits -f FILE: specify input magic format file -F FILE: specify output magic format file , default is to overwrite input file -keys KEY1:KEY2 specify colon delimited list of keys to convert -[U,l] : specify [U]PPER or [l]ower case, default is lower """ dir_path = "./" change = "l" if "-WD" in sys.argv: ind = sys.argv.index("-WD") dir_path = sys.argv[ind + 1] if "-h" in sys.argv: print main.__doc__ sys.exit() if "-f" in sys.argv: ind = sys.argv.index("-f") magic_file = dir_path + "/" + sys.argv[ind + 1] else: print main.__doc__ sys.exit() if "-F" in sys.argv: ind = sys.argv.index("-F") out_file = dir_path + "/" + sys.argv[ind + 1] else: out_file = magic_file if "-keys" in sys.argv: ind = sys.argv.index("-keys") grab_keys = sys.argv[ind + 1].split(":") else: print main.__doc__ sys.exit() if "-U" in sys.argv: change = "U" # # # get data read in Data, file_type = pmag.magic_read(magic_file) if len(Data) > 0: for grab_key in grab_keys: for rec in Data: if change == "l": rec[grab_key] = rec[grab_key].lower() else: rec[grab_key] = rec[grab_key].upper() else: print "bad file name" pmag.magic_write(out_file, Data, file_type)
def main(): """ NAME extract_methods.py DESCRIPTION reads in a magic table and creates a file with method codes SYNTAX extract_methods.py [command line options] OPTIONS -h: prints the help message and quits. -f FILE: specify magic format input file, default is magic_measurements.txt -F FILE: specify method code output file, default is magic_methods.txt """ citation='This study' args=sys.argv outfile='magic_methods.txt' infile='magic_measurements.txt' # # get command line arguments # dir_path='.' if '-WD' in args: ind=args.index("-WD") dir_path=args[ind+1] if "-h" in args: print main.__doc__ sys.exit() if '-F' in args: ind=args.index("-F") outfile=args[ind+1] if '-f' in args: ind=args.index("-f") infile=args[ind+1] infile=dir_path+'/'+infile outfile=dir_path+'/'+outfile data,file_type=pmag.magic_read(infile) MethRecs=[] methods=[] for rec in data: meths=rec['magic_method_codes'].split(":") for meth in meths: if meth not in methods: MethRec={} methods.append(meth) MethRec['magic_method_code']=meth MethRecs.append(MethRec) pmag.magic_write(outfile,MethRecs,'magic_methods')
def main(): """ ODP_fix_sample_names.py DESCRIPTION: pads core to three digits and makes upper case OPTIONS: -f FILE, input ODP magic file for sample name conversion """ dir_path='.' if '-WD' in sys.argv: ind=sys.argv.index("-WD") dir_path=sys.argv[ind+1] if '-f' in sys.argv: ind=sys.argv.index("-f") infile=dir_path+'/'+sys.argv[ind+1] else: print "must specify -f input_file" sys.exit() Data,file_type=pmag.magic_read(infile) Fixed=[] for rec in Data: pieces=rec['er_specimen_name'].split('-') if len(pieces)==6: while len(pieces[2])<4:pieces[2]='0'+pieces[2] # pad core to be 3 characters specimen="" for piece in pieces: specimen=specimen+piece+'-' specimen=specimen[:-1].upper() rec['er_specimen_name']=specimen rec['er_sample_name']=specimen rec['er_site_name']=specimen rec['er_location_name']=pieces[1] rec['er_expedition_name']=pieces[0] Fixed.append(rec) else: print 'problem with this data record: ',rec['er_specimen_name'] print 'deleting from file ', infile pmag.magic_write(infile,Fixed,file_type) print 'new specimen names written to: ',infile
def main(): """ NAME HUJI_magic.py DESCRIPTION converts HUJI format files to magic_measurements format files SYNTAX HUJI_magic.py [command line options] OPTIONS -h: prints the help message and quits. -usr USER: identify user, default is "" -f FILE: specify input file, required -F FILE: specify output file, default is magic_measurements.txt -LP [colon delimited list of protocols, include all that apply] AF: af demag T: thermal including thellier but not trm acquisition N: NRM only TRM: trm acquisition ANI: anisotropy experiment CR: cooling rate experiment. The treatment coding of the measurement file should be: XXX.00,XXX.10, XXX.20 ...XX.70 etc. (XXX.00 is optional) where XXX in the temperature and .10,.20... are running numbers of the cooling rates steps. XXX.00 is optional zerofield baseline. XXX.70 is alteration check. syntax in sio_magic is: -LP CR xxx,yyy,zzz,.....xx where xx, yyy,zzz...xxx are cooling time in [K/minutes], seperated by comma, ordered at the same order as XXX.10,XXX.20 ...XX.70 if you use a zerofield step then no need to specify the cooling rate for the zerofield -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 -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 # to do! -ac B : peak AF field (in mT) for ARM acquisition, default is none -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 separate experiments ( AF, thermal, thellier, trm aquisition) should be seperate files (eg. af.txt, thermal.txt, etc.) HUJI masurement file format (space delimited text): Spec lab-running-numbe-code Date Hour Treatment-type(T/N/A) Treatment(XXX.XX) dec(geo) inc(geo) dec(tilt) inc(tilt) --------- conventions: Spec: specimen name Treat: treatment step XXX T in Centigrade XXX AF in mT for special experiments: Thellier: XXX.0 first zero field step XXX.1 first in field step [XXX.0 and XXX.1 can be done in any order] XXX.2 second in-field step at lower temperature (pTRM check) ATRM: X.00 optional baseline X.1 ATRM step (+X) X.2 ATRM step (+Y) X.3 ATRM step (+Z) X.4 ATRM step (-X) X.5 ATRM step (-Y) X.6 ATRM step (-Z) X.7 optional alteration check (+X) TRM: XXX.YYY XXX is temperature step of total TRM YYY is dc field in microtesla Intensity assumed to be total moment in 10^3 Am^2 (emu) Declination: Declination in specimen coordinate system Inclination: Inclination in specimen coordinate system Optional metatdata string: mm/dd/yy;hh:mm;[dC,mT];xx.xx;UNITS;USER;INST;NMEAS hh in 24 hours. dC or mT units of treatment XXX (see Treat above) for thermal or AF respectively xx.xxx DC field UNITS of DC field (microT, mT) INST: instrument code, number of axes, number of positions (e.g., G34 is 2G, three axes, measured in four positions) NMEAS: number of measurements in a single position (1,3,200...) """ args=sys.argv meas_file="magic_measurements.txt" user="" if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind=args.index("-usr") user=args[ind+1] else: user="" if '-F' in args: ind=args.index("-F") meas_file=args[ind+1] if '-f' in args: ind=args.index("-f") magfile=args[ind+1] try: input=open(magfile,'rU') except: print "bad mag file name" sys.exit() else: print "mag_file field is required option" print main.__doc__ sys.exit() if "-dc" in args: ind=args.index("-dc") labfield=float(args[ind+1])*1e-6 phi=float(args[ind+2]) theta=float(args[ind+3]) if "-ac" in args: ind=args.index("-ac") peakfield=float(args[ind+1])*1e-3 if "-spc" in args: ind=args.index("-spc") specnum=int(args[ind+1]) if specnum!=0:specnum=-specnum if "-loc" in args: ind=args.index("-loc") er_location_name=args[ind+1] if "-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=int(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=int(samp_con.split("-")[1]) samp_con="7" # lab process: if '-LP' in args: ind=args.index("-LP") codelist=args[ind+1] codes=codelist.split(':') if "AF" in codes: demag='AF' LPcode="LP-DIR-AF" if "T" in codes: demag="T" if '-dc' not in args: LPcode="LP-DIR-T" if '-dc' in args: LPcode="LP-PI-TRM" if "ANI" in codes: if '-dc' not in args: print "missing option -dc exiting" exit() LPcode="LP-AN-TRM" if "TRM" in codes: demag="T" LPcode="LP-TRM" #trm=1 if "CR" in codes: demag="T" # dc should be in the code if '-dc' not in args: print "missing option -dc exiting" exit() LPcode="LP-TRM-CR" # TRM in different cooling rates ind=args.index("-LP") CR_cooling_times=args[ind+2].split(",") #print CR_cooling_time ,"CR_cooling_time" version_num=pmag.get_version() MagRecs=[] #-------------------------------------- # Read the file # Assumption: # 1. different lab protocolsa are in different files # 2. measurements are in the correct order #-------------------------------------- Data={} line_no=0 for line in input.readlines(): line_no+=1 this_line_data={} line_no+=1 instcode="" if len(line)<2: continue if line[0]=="#": #HUJI way of marking bad data points continue rec=line.strip('\n').split() specimen=rec[0] date=rec[2].split("/") hour=rec[3].split(":") treatment_type=rec[4] treatment=rec[5].split(".") dec=rec[6] inc=rec[7] dec_tilted=rec[8] inc_tilted=rec[9] moment_emu=float(rec[10]) if specimen not in Data.keys(): Data[specimen]=[] # check duplicate treatments: # if yes, delete the first and use the second if len(Data[specimen])>0: if treatment==Data[specimen][-1]['treatment']: del(Data[specimen][-1]) print "-W- Identical treatimens in file %s magfile line %i: specimen %s, treatment %s deleting the first. " %(magfile, line_no, specimen,".".join(treatment)) this_line_data={} this_line_data['specimen']=specimen this_line_data['date']=date this_line_data['hour']=hour this_line_data['treatment_type']=treatment_type this_line_data['treatment']=treatment this_line_data['dec']=dec this_line_data['inc']=inc this_line_data['dec_tilted']=dec_tilted this_line_data['inc_tilted']=inc_tilted this_line_data['moment_emu']=moment_emu Data[specimen].append(this_line_data) print "-I- done reading file %s"%magfile #-------------------------------------- # Convert to MagIC #-------------------------------------- specimens_list=Data.keys() specimens_list.sort() MagRecs=[] for specimen in specimens_list: for i in range(len(Data[specimen])): #print LPcode this_line_data=Data[specimen][i] methcode="" MagRec={} MagRec["er_specimen_name"]=this_line_data['specimen'] if specnum!=0: MagRec["er_sample_name"]=this_line_data['specimen'][:specnum] else: MagRec["er_sample_name"]=this_line_data['specimen'] if samp_con=="1": MagRec["er_site_name"]=MagRec["er_sample_name"][:-1] elif samp_con=="2": parts=MagRec["er_sample_name"].split('-') MagRec["er_site_name"]= parts[0] elif samp_con=="3": parts=MagRec["er_sample_name"].split('.') MagRec["er_site_name"]= parts[0] elif samp_con=='4': MagRec["er_site_name"]=MagRec["er_sample_name"][0:-Z] elif samp_con=='5': MagRec["er_site_name"]=MagRec["er_sample_name"] elif samp_con=='7': MagRec["er_site_name"]=MagRec["er_sample_name"][0:Z] else: MagRec["er_site_name"]=MagRec["er_sample_name"] # site=sample by default if "-loc" in args: MagRec['er_location_name']=er_location_name else: MagRec['er_location_name']=MagRec["er_site_name"] MagRec["measurement_temp"]='%8.3e' % (273) # room temp in kelvin MagRec["measurement_magn_moment"]='%10.3e'% (float(this_line_data['moment_emu'])*1e-3) # moment in Am^2 (from emu) MagRec["measurement_dec"]=this_line_data['dec'] MagRec["measurement_inc"]=this_line_data['inc'] date=this_line_data['date'] hour=this_line_data['hour'] if float(date[2])>80: yyyy="19"+date[2] else: yyyy="20"+date[2] if len (date[0])==1: date[0]="0"+date[0] if len (date[1])==1: date[1]="0"+date[1] MagRec["measurement_date"]=":".join([yyyy,date[0],date[1],hour[0],hour[1],"00.00"]) #print MagRec["measurement_date"]," Ron check please" MagRec["measurement_time_zone"]='JER' MagRec['er_analyst_mail_names'] =user MagRec["er_citation_names"]="This study" MagRec["magic_instrument_codes"]="HUJI-2G" MagRec["measurement_flag"]="g" MagRec["measurement_positions"]="1" MagRec["measurement_positions"]="1" MagRec["measurement_standard"]="u" MagRec["measurement_description"]="" MagRec["treatment_temp"]='%8.3e' % (float(treatment[0])+273.) # temp in kelvin #---------------------------------------- # AF demag # do not support AARM yet #---------------------------------------- if demag=="AF": # demag in zero field if LPcode != "LP-AN-ARM": MagRec["treatment_ac_field"]='%8.3e' %(float(this_line_data['treatment'][0])*1e-3) # peak field in tesla MagRec["treatment_dc_field"]='0' MagRec["treatment_dc_field_phi"]='0' MagRec["treatment_dc_field_theta"]='0' if treatment_type=="N": methcode="LP-DIR-AF:LT-NO" elif treatment_type=="A": methcode="LP-DIR-AF:LT-AF-Z" else: print "ERROR in treatment field line %i... exiting until you fix the problem" %line_no exit() # AARM experiment else: print "Dont supprot AARM in HUJI format yet. sorry... do be DONE" MagRec["magic_method_codes"]=methcode MagRec["magic_experiment_name"]=specimen+ ":" + LPcode MagRec["measurement_number"]="%i"%i MagRec["measurement_description"]="" MagRecs.append(MagRec) #continue #---------------------------------------- # Thermal: # Thellier experiment: "IZ", "ZI", "IZZI", pTRM checks # Thermal demag # Thermal cooling rate experiment # Thermal NLT #---------------------------------------- if demag=="T": treatment=this_line_data['treatment'] treatment_type=this_line_data['treatment_type'] #---------------------------------------- # Thellier experimet #---------------------------------------- if LPcode == "LP-PI-TRM" : # Thelllier experiment MagRec["magic_experiment_name"]=specimen+ ":" + LPcode methcode=LPcode if treatment_type=="N" or ( (treatment[1]=='0' or treatment[1]=='00') and float(treatment[0])==0): LT_code="LT-NO" MagRec["treatment_dc_field_phi"]='0' MagRec["treatment_dc_field_theta"]='0' MagRec["treatment_dc_field"]='0' MagRec["treatment_temp"]='273.' elif treatment[1]=='0' or treatment[1]=='00': LT_code="LT-T-Z" MagRec["treatment_dc_field_phi"]='0' MagRec["treatment_dc_field_theta"]='0' MagRec["treatment_dc_field"]='%8.3e'%(0) MagRec["treatment_temp"]='%8.3e' % (float(treatment[0])+273.) # temp in kelvin # check if this is ZI or IZ: # check if the same temperature already measured: methcode="LP-PI-TRM:LP-PI-TRM-ZI" for j in range (0,i): if Data[specimen][j]['treatment'][0] == treatment[0]: if Data[specimen][j]['treatment'][1] == '1' or Data[specimen][j]['treatment'][1] == '10': methcode="LP-PI-TRM:LP-PI-TRM-IZ" else: methcode="LP-PI-TRM:LP-PI-TRM-ZI" elif treatment[1]=='1' or treatment[1]=='10': LT_code="LT-T-I" MagRec["treatment_dc_field"]='%8.3e' % (labfield) # labfield in tesla (convert from microT) MagRec["treatment_dc_field_phi"]='%7.1f' % (phi) # labfield phi MagRec["treatment_dc_field_theta"]='%7.1f' % (theta) # labfield theta MagRec["treatment_temp"]='%8.3e' % (float(treatment[0])+273.) # temp in kelvin # check if this is ZI or IZ: # check if the same temperature already measured: methcode="LP-PI-TRM:LP-PI-TRM-IZ" for j in range (0,i): if Data[specimen][j]['treatment'][0] == treatment[0]: if Data[specimen][j]['treatment'][1] == '0' or Data[specimen][j]['treatment'][1] == '00': methcode="LP-PI-TRM:LP-PI-TRM-ZI" else: methcode="LP-PI-TRM:LP-PI-TRM-IZ" elif treatment[1]=='2' or treatment[1]=='20': LT_code="LT-PTRM-I" MagRec["treatment_dc_field"]='%8.3e' % (labfield) # labfield in tesla (convert from microT) MagRec["treatment_dc_field_phi"]='%7.1f' % (phi) # labfield phi MagRec["treatment_dc_field_theta"]='%7.1f' % (theta) # labfield theta MagRec["treatment_temp"]='%8.3e' % (float(treatment[0])+273.) # temp in kelvin methcode="LP-PI-TRM:LP-PI-TRM-IZ" else: print "ERROR in treatment field line %i... exiting until you fix the problem" %line_no exit() MagRec["magic_method_codes"]=LT_code+":"+methcode MagRec["measurement_number"]="%i"%i MagRec["measurement_description"]="" MagRecs.append(MagRec) #continue #---------------------------------------- # demag experimet #---------------------------------------- if LPcode == "LP-DIR-T" : MagRec["magic_experiment_name"]=specimen+ ":" + LPcode methcode=LPcode if treatment_type=="N": LT_code="LT-NO" else: LT_code="LT-T-Z" methcode=LPcode+":"+"LT-T-Z" MagRec["treatment_dc_field_phi"]='0' MagRec["treatment_dc_field_theta"]='0' MagRec["treatment_dc_field"]='%8.3e'%(0) MagRec["treatment_temp"]='%8.3e' % (float(treatment[0])+273.) # temp in kelvin MagRec["magic_method_codes"]=LT_code+":"+methcode MagRec["measurement_number"]="%i"%i MagRec["measurement_description"]="" MagRecs.append(MagRec) #continue #---------------------------------------- # ATRM measurements # The direction of the magnetization is used to determine the # direction of the lab field. #---------------------------------------- if LPcode =="LP-AN-TRM" : MagRec["magic_experiment_name"]=specimen+ ":" + LPcode methcode=LPcode if float(treatment[1])==0: MagRec["magic_method_codes"]="LP-AN-TRM:LT-T-Z" MagRec["treatment_dc_field_phi"]='0' MagRec["treatment_dc_field_theta"]='0' MagRec["treatment_temp"]='%8.3e' % (float(treatment[0])+273.) # temp in kelvin MagRec["treatment_dc_field"]='0' else: if float(treatment[1])==7: # alteration check methcode="LP-AN-TRM:LT-PTRM-I" MagRec["measurement_number"]='7'# -z else: MagRec["magic_method_codes"]="LP-AN-TRM:LT-T-I" inc=float(MagRec["measurement_inc"]);dec=float(MagRec["measurement_dec"]) if abs(inc)<45 and (dec<45 or dec>315): # +x tdec,tinc=0,0 MagRec["measurement_number"]='1' if abs(inc)<45 and (dec<135 and dec>45): tdec,tinc=90,0 MagRec["measurement_number"]='2' # +y if inc>45 : tdec,tinc=0,90 MagRec["measurement_number"]='3' # +z if abs(inc)<45 and (dec<225 and dec>135): tdec,tinc=180,0 MagRec["measurement_number"]='4' # -x if abs(inc)<45 and (dec<315 and dec>225): tdec,tinc=270,0 MagRec["measurement_number"]='5'# -y if inc<-45 : tdec,tinc=0,-90 MagRec["measurement_number"]='6'# -z MagRec["treatment_dc_field_phi"]='%7.1f' %(tdec) MagRec["treatment_dc_field_theta"]='%7.1f'% (tinc) MagRec["treatment_temp"]='%8.3e' % (float(treatment[0])+273.) # temp in kelvin MagRec["treatment_dc_field"]='%8.3e'%(labfield) MagRec["measurement_description"]="" MagRecs.append(MagRec) #continue #---------------------------------------- # NLT measurements # or TRM acquisistion experiment #---------------------------------------- if LPcode == "LP-TRM" : MagRec["magic_experiment_name"]=specimen+ ":" + LPcode MagRec["magic_method_codes"]="LP-TRM:LT-T-I" if float(treatment[1])==0: labfield=0 else: labfield=float(float(treatment[1]))*1e-6 MagRec["treatment_temp"]='%8.3e' % (float(treatment[0])+273.) # temp in kelvin MagRec["treatment_dc_field"]='%8.3e' % (labfield) # labfield in tesla (convert from microT) MagRec["treatment_dc_field_phi"]='%7.1f' % (phi) # labfield phi MagRec["treatment_dc_field_theta"]='%7.1f' % (theta) # labfield theta MagRec["measurement_number"]="%i"%i MagRec["measurement_description"]="" MagRecs.append(MagRec) #continue #---------------------------------------- # Cooling rate experiments #---------------------------------------- if LPcode =="LP-TRM-CR": index=int(treatment[1][0]) #print index,"index" #print CR_cooling_times,"CR_cooling_times" #print CR_cooling_times[index-1] #print CR_cooling_times[0:index-1] CR_cooling_time=CR_cooling_times[index-1] if CR_cooling_time in CR_cooling_times[0:index-1]: MagRec["magic_method_codes"]="LP-TRM-CR"+":" +"LT-PTRM-I" else: MagRec["magic_method_codes"]="LP-TRM-CR" MagRec["magic_experiment_name"]=specimen+ ":" + LPcode MagRec["treatment_temp"]='%8.3e' % (float(treatment[0])+273.) # temp in kelvin MagRec["treatment_dc_field"]='%8.3e' % (labfield) # labfield in tesla (convert from microT) MagRec["treatment_dc_field_phi"]='%7.1f' % (phi) # labfield phi MagRec["treatment_dc_field_theta"]='%7.1f' % (theta) # labfield theta MagRec["measurement_number"]="%i"%index MagRec["measurement_description"]="%i minutes cooling time"%int(CR_cooling_time) MagRecs.append(MagRec) #continue pmag.magic_write(meas_file,MagRecs,'magic_measurements') print "-I- results put in ",meas_file
def main(): """ NAME download_magic.py DESCRIPTION unpacks a magic formatted smartbook .txt file from the MagIC database into the tab delimited MagIC format txt files for use with the MagIC-Py programs. SYNTAX download_magic.py command line options] INPUT takes either the upload.txt file created by upload_magic.py or the file exported by the MagIC v2.2 console software (downloaded from the MagIC database or output by the Console on your PC). OPTIONS -h prints help message and quits -i allows interactive entry of filename -f FILE specifies input file name """ dir_path='.' if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] if '-i' in sys.argv: file=raw_input("Magic txt file for unpacking? ") elif '-f' in sys.argv: ind=sys.argv.index("-f") file=sys.argv[ind+1] else: print main.__doc__ sys.exit() f=open(dir_path+'/'+file,'rU') File=f.readlines() LN=0 type_list=[] filenum=0 while LN<len(File)-1: line=File[LN] file_type=line.split('\t')[1] file_type=file_type.lower() if file_type=='delimited':file_type=Input[skip].split('\t')[2] if file_type[-1]=="\n":file_type=file_type[:-1] print 'working on: ',file_type if file_type not in type_list: type_list.append(file_type) else: filenum+=1 LN+=1 line=File[LN] keys=line.split('\t') LN+=1 Recs=[] while LN<len(File): line=File[LN] if line[:4]==">>>>" and len(Recs)>0: if filenum==0: outfile=dir_path+"/"+file_type.strip()+'.txt' else: outfile=dir_path+"/"+file_type.strip()+'_'+str(filenum)+'.txt' NewRecs=[] for rec in Recs: if 'magic_method_codes' in rec.keys(): meths=rec['magic_method_codes'].split(":") if len(meths)>0: methods="" for meth in meths: methods=methods+meth.strip()+":" # get rid of nasty spaces!!!!!! rec['magic_method_codes']=methods[:-1] NewRecs.append(rec) pmag.magic_write(outfile,Recs,file_type) print file_type," data put in ",outfile Recs=[] LN+=1 break else: rec=line.split('\t') Rec={} for k in range(len(keys)): Rec[keys[k]]=rec[k] Recs.append(Rec) LN+=1
def main(command_line=True, **kwargs): """ NAME BGC_magic.py DESCRIPTION converts Berkeley Geochronology Center (BGC) format files to magic_measurements format files SYNTAX BGC_magic.py [command line options] OPTIONS -h: prints the help message and quits. -f FILE: specify input file, or -F FILE: specify output file, default is magic_measurements.txt -Fsa: specify er_samples format file for appending, default is new er_samples.txt (Not working yet) -loc LOCNAME : specify location/study name -site SITENAME : specify site name -A: don't average replicate measurements -mcd [SO-MAG,SO-SUN,SO-SIGHT...] supply how these samples were oriented -v NUM : specify the volume in cc of the sample, default 2.5^3cc. Will use vol in data file if volume!=0 in file. INPUT BGC paleomag format file """ # initialize some stuff noave = 0 volume = 0.025 ** 3 # default volume is a 2.5cm cube # inst="" # samp_con,Z='1',"" # missing=1 # demag="N" er_location_name = "unknown" er_site_name = "unknown" # citation='This study' args = sys.argv meth_code = "LP-NO" # specnum=1 version_num = pmag.get_version() mag_file = "" dir_path = "." MagRecs = [] SampOuts = [] samp_file = "er_samples.txt" meas_file = "magic_measurements.txt" meth_code = "" # # get command line arguments # if command_line: if "-WD" in sys.argv: ind = sys.argv.index("-WD") dir_path = sys.argv[ind + 1] if "-ID" in sys.argv: ind = sys.argv.index("-ID") input_dir_path = sys.argv[ind + 1] else: input_dir_path = dir_path output_dir_path = dir_path if "-h" in args: print main.__doc__ return False if "-F" in args: ind = args.index("-F") meas_file = args[ind + 1] if "-Fsa" in args: ind = args.index("-Fsa") samp_file = args[ind + 1] # try: # open(samp_file,'rU') # ErSamps,file_type=pmag.magic_read(samp_file) # print 'sample information will be appended to ', samp_file # except: # print samp_file,' not found: sample information will be stored in new er_samples.txt file' # samp_file = output_dir_path+'/er_samples.txt' if "-f" in args: ind = args.index("-f") mag_file = args[ind + 1] if "-loc" in args: ind = args.index("-loc") er_location_name = args[ind + 1] if "-site" in args: ind = args.index("-site") er_site_name = args[ind + 1] if "-A" in args: noave = 1 if "-mcd" in args: ind = args.index("-mcd") meth_code = args[ind + 1] # samp_con='5' if "-v" in args: ind = args.index("-v") volume = float(args[ind + 1]) * 1e-6 # enter volume in cc, convert to m^3 if not command_line: dir_path = kwargs.get("dir_path", ".") input_dir_path = kwargs.get("input_dir_path", dir_path) output_dir_path = dir_path meas_file = kwargs.get("meas_file", "magic_measurements.txt") mag_file = kwargs.get("mag_file") samp_file = kwargs.get("samp_file", "er_samples.txt") er_location_name = kwargs.get("er_location_name", "") er_site_name = kwargs.get("er_site_name", "") noave = kwargs.get("noave", 0) # default (0) means DO average meth_code = kwargs.get("meth_code", "LP-NO") volume = float(kwargs.get("volume", 0)) if not volume: volume = 0.025 ** 3 # default volume is a 2.5 cm cube, translated to meters cubed else: # convert cm^3 to m^3 volume *= 1e-6 # format variables if not mag_file: return False, "You must provide a BCG format file" mag_file = os.path.join(input_dir_path, mag_file) meas_file = os.path.join(output_dir_path, meas_file) samp_file = os.path.join(output_dir_path, samp_file) ErSampRec = {} # parse data # Open up the BGC file and read the header information print "mag_file in BGC_magic", mag_file pre_data = open(mag_file, "rU") line = pre_data.readline() line_items = line.split(" ") sample_name = line_items[2] sample_name = sample_name.replace("\n", "") line = pre_data.readline() line = pre_data.readline() line_items = line.split("\t") sample_azimuth = float(line_items[1]) sample_dip = 90.0 - float(line_items[2]) sample_bed_dip = line_items[3] sample_bed_azimuth = line_items[4] sample_lon = line_items[5] sample_lat = line_items[6] tmp_volume = line_items[7] if tmp_volume != 0.0: volume = float(tmp_volume) * 1e-6 pre_data.close() data = pd.read_csv(mag_file, sep="\t", header=3, index_col=False) # print "\ndata\n", data cart = np.array([data["X"], data["Y"], data["Z"]]).transpose() direction = pmag.cart2dir(cart).transpose() data["measurement_dec"] = direction[0] data["measurement_inc"] = direction[1] data["measurement_magn_moment"] = direction[2] * 1000 * volume # the data are in EMU - this converts to Am^2 data["measurement_magn_volume"] = direction[2] * 1000 # EMU - data converted to A/m # DGEOs, IGEOs = [], [] # print "len(data)=",len(data) # for ind in range(len(data)): # dgeo,igeo=pmag.dogeo(data.ix[ind]['measurement_dec'],data.ix[ind]['measurement_inc'],90-sample_azimuth,sample_dip) # DGEOs.append(dgeo) # IGEOs.append(igeo) # data['specimen_dec']=DGEOs # data['specimen_inc']=IGEOs # data['specimen_tilt']='1' # print "data specimn_dec=",DGEOs # print "data specimn_inc=",IGEOs # Configure the er_sample table ErSampRec["er_sample_name"] = sample_name ErSampRec["sample_azimuth"] = sample_azimuth ErSampRec["sample_dip"] = sample_dip ErSampRec["sample_bed_dip_direction"] = sample_bed_azimuth ErSampRec["sample_bed_dip"] = sample_bed_dip ErSampRec["sample_lat"] = sample_lat ErSampRec["sample_lon"] = sample_lon ErSampRec["magic_method_codes"] = meth_code ErSampRec["er_location_name"] = er_location_name ErSampRec["er_site_name"] = er_site_name ErSampRec["er_citation_names"] = "This study" SampOuts.append(ErSampRec.copy()) # Configure the magic_measurements table for rowNum, row in data.iterrows(): MagRec = {} MagRec["measurement_description"] = "Date: " + str(row["Date"]) + " Time: " + str(row["Time"]) MagRec["er_citation_names"] = "This study" MagRec["er_location_name"] = er_location_name MagRec["er_site_name"] = er_site_name MagRec["er_sample_name"] = sample_name MagRec["magic_software_packages"] = version_num MagRec["treatment_temp"] = "%8.3e" % (273) # room temp in kelvin MagRec["measurement_temp"] = "%8.3e" % (273) # room temp in kelvin MagRec["measurement_flag"] = "g" MagRec["measurement_standard"] = "u" MagRec["measurement_number"] = "1" MagRec["er_specimen_name"] = sample_name MagRec["treatment_ac_field"] = "0" if row["DM Val"] == "0": meas_type = "LT-NO" elif int(row["DM Type"]) > 0.0: meas_type = "LT-AF-Z" treat = float(row["DM Val"]) MagRec["treatment_ac_field"] = "%8.3e" % (treat * 1e-3) # convert from mT to tesla elif int(row["DM Type"]) == -1: meas_type = "LT-T-Z" treat = float(row["DM Val"]) MagRec["treatment_temp"] = "%8.3e" % (treat + 273.0) # temp in kelvin else: print "measurement type unknown:", row["DM Type"], " in row ", rowNum MagRec["measurement_magn_moment"] = str(row["measurement_magn_moment"]) MagRec["measurement_magn_volume"] = str(row["measurement_magn_volume"]) MagRec["measurement_dec"] = str(row["measurement_dec"]) MagRec["measurement_inc"] = str(row["measurement_inc"]) MagRec["magic_method_codes"] = meas_type MagRec["measurement_csd"] = "0.0" # added due to magic.write error MagRec["measurement_positions"] = "1" # added due to magic.write error MagRecs.append(MagRec.copy()) pmag.magic_write(samp_file, SampOuts, "er_samples") print "sample orientations put in ", samp_file MagOuts = pmag.measurements_methods(MagRecs, noave) pmag.magic_write(meas_file, MagOuts, "magic_measurements") print "results put in ", meas_file print "exit!" return True, meas_file
def main(): """ NAME thellier_magic_redo.py DESCRIPTION Calculates paleointensity parameters for thellier-thellier type data using bounds stored in the "redo" file SYNTAX thellier_magic_redo [command line options] OPTIONS -h prints help message -usr USER: identify user, default is "" -fcr CRIT, set criteria for grading -f IN: specify input file, default is magic_measurements.txt -fre REDO: specify redo file, default is "thellier_redo" -F OUT: specify output file, default is thellier_specimens.txt -leg: attaches "Recalculated from original measurements; supercedes published results. " to comment field -CR PERC TYPE: apply a blanket cooling rate correction if none supplied in the er_samples.txt file PERC should be a percentage of original (say reduce to 90%) TYPE should be one of the following: EG (for educated guess); PS (based on pilots); TRM (based on comparison of two TRMs) -ANI: perform anisotropy correction -fsa SAMPFILE: er_samples.txt file with cooling rate correction information, default is NO CORRECTION -Fcr CRout: specify pmag_specimen format file for cooling rate corrected data -fan ANIFILE: specify rmag_anisotropy format file, default is rmag_anisotropy.txt -Fac ACout: specify pmag_specimen format file for anisotropy corrected data default is AC_specimens.txt -fnl NLTFILE: specify magic_measurments format file, default is magic_measurements.txt -Fnl NLTout: specify pmag_specimen format file for non-linear trm corrected data default is NLT_specimens.txt -z use z component differenences for pTRM calculation INPUT a thellier_redo file is Specimen_name Tmin Tmax (where Tmin and Tmax are in Centigrade) """ dir_path = "." critout = "" version_num = pmag.get_version() field, first_save = -1, 1 spec, recnum, start, end = 0, 0, 0, 0 crfrac = 0 NltRecs, PmagSpecs, AniSpecRecs, NltSpecRecs, CRSpecs = [], [], [], [], [] meas_file, pmag_file, mk_file = "magic_measurements.txt", "thellier_specimens.txt", "thellier_redo" anis_file = "rmag_anisotropy.txt" anisout, nltout = "AC_specimens.txt", "NLT_specimens.txt" crout = "CR_specimens.txt" nlt_file = "" samp_file = "" comment, user = "", "unknown" anis, nltrm = 0, 0 jackknife = 0 # maybe in future can do jackknife args = sys.argv Zdiff = 0 if "-WD" in args: ind = args.index("-WD") dir_path = args[ind + 1] if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind = args.index("-usr") user = sys.argv[ind + 1] if "-leg" in args: comment = "Recalculated from original measurements; supercedes published results. " cool = 0 if "-CR" in args: cool = 1 ind = args.index("-CR") crfrac = 0.01 * float(sys.argv[ind + 1]) crtype = "DA-CR-" + sys.argv[ind + 2] if "-Fcr" in args: ind = args.index("-Fcr") crout = sys.argv[ind + 1] if "-f" in args: ind = args.index("-f") meas_file = sys.argv[ind + 1] if "-F" in args: ind = args.index("-F") pmag_file = sys.argv[ind + 1] if "-fre" in args: ind = args.index("-fre") mk_file = args[ind + 1] if "-fsa" in args: ind = args.index("-fsa") samp_file = dir_path + "/" + args[ind + 1] Samps, file_type = pmag.magic_read(samp_file) SampCRs = pmag.get_dictitem(Samps, "cooling_rate_corr", "", "F") # get samples cooling rate corrections cool = 1 if file_type != "er_samples": print "not a valid er_samples.txt file" sys.exit() # # if "-ANI" in args: anis = 1 ind = args.index("-ANI") if "-Fac" in args: ind = args.index("-Fac") anisout = args[ind + 1] if "-fan" in args: ind = args.index("-fan") anis_file = args[ind + 1] # if "-NLT" in args: if "-Fnl" in args: ind = args.index("-Fnl") nltout = args[ind + 1] if "-fnl" in args: ind = args.index("-fnl") nlt_file = args[ind + 1] if "-z" in args: Zdiff = 1 if "-fcr" in sys.argv: ind = args.index("-fcr") critout = sys.argv[ind + 1] # # start reading in data: # meas_file = dir_path + "/" + meas_file mk_file = dir_path + "/" + mk_file accept = pmag.default_criteria(1)[0] # set criteria to none if critout != "": critout = dir_path + "/" + critout crit_data, file_type = pmag.magic_read(critout) if file_type != "pmag_criteria": print "bad pmag_criteria file, using no acceptance criteria" print "Acceptance criteria read in from ", critout for critrec in crit_data: if "sample_int_sigma_uT" in critrec.keys(): # accommodate Shaar's new criterion critrec["sample_int_sigma"] = "%10.3e" % (eval(critrec["sample_int_sigma_uT"]) * 1e-6) for key in critrec.keys(): if key not in accept.keys() and critrec[key] != "": accept[key] = critrec[key] meas_data, file_type = pmag.magic_read(meas_file) if file_type != "magic_measurements": print file_type print file_type, "This is not a valid magic_measurements file " sys.exit() try: mk_f = open(mk_file, "rU") except: print "Bad redo file" sys.exit() mkspec = [] speclist = [] for line in mk_f.readlines(): tmp = line.split() mkspec.append(tmp) speclist.append(tmp[0]) if anis == 1: anis_file = dir_path + "/" + anis_file anis_data, file_type = pmag.magic_read(anis_file) if file_type != "rmag_anisotropy": print file_type print file_type, "This is not a valid rmag_anisotropy file " sys.exit() if nlt_file == "": nlt_data = pmag.get_dictitem( meas_data, "magic_method_codes", "LP-TRM", "has" ) # look for trm acquisition data in the meas_data file else: nlt_file = dir_path + "/" + nlt_file nlt_data, file_type = pmag.magic_read(nlt_file) if len(nlt_data) > 0: nltrm = 1 # # sort the specimen names and step through one by one # sids = pmag.get_specs(meas_data) # print "Processing ", len(speclist), " specimens - please wait " while spec < len(speclist): s = speclist[spec] recnum = 0 datablock = [] PmagSpecRec = {} PmagSpecRec["er_analyst_mail_names"] = user PmagSpecRec["er_citation_names"] = "This study" PmagSpecRec["magic_software_packages"] = version_num methcodes, inst_code = [], "" # # find the data from the meas_data file for this specimen # datablock = pmag.get_dictitem(meas_data, "er_specimen_name", s, "T") datablock = pmag.get_dictitem( datablock, "magic_method_codes", "LP-PI-TRM", "has" ) # pick out the thellier experiment data if len(datablock) > 0: for rec in datablock: if "magic_instrument_codes" not in rec.keys(): rec["magic_instrument_codes"] = "unknown" # # collect info for the PmagSpecRec dictionary # rec = datablock[0] PmagSpecRec["er_specimen_name"] = s PmagSpecRec["er_sample_name"] = rec["er_sample_name"] PmagSpecRec["er_site_name"] = rec["er_site_name"] PmagSpecRec["er_location_name"] = rec["er_location_name"] PmagSpecRec["measurement_step_unit"] = "K" PmagSpecRec["specimen_correction"] = "u" if "er_expedition_name" in rec.keys(): PmagSpecRec["er_expedition_name"] = rec["er_expedition_name"] if "magic_instrument_codes" not in rec.keys(): PmagSpecRec["magic_instrument_codes"] = "unknown" else: PmagSpecRec["magic_instrument_codes"] = rec["magic_instrument_codes"] if "magic_experiment_name" not in rec.keys(): rec["magic_experiment_name"] = "" else: PmagSpecRec["magic_experiment_names"] = rec["magic_experiment_name"] meths = rec["magic_experiment_name"].split(":") for meth in meths: if meth.strip() not in methcodes and "LP-" in meth: methcodes.append(meth.strip()) # # sort out the data into first_Z, first_I, ptrm_check, ptrm_tail # araiblock, field = pmag.sortarai(datablock, s, Zdiff) first_Z = araiblock[0] first_I = araiblock[1] ptrm_check = araiblock[2] ptrm_tail = araiblock[3] if len(first_I) < 3 or len(first_Z) < 4: spec += 1 print "skipping specimen ", s else: # # get start, end # for redospec in mkspec: if redospec[0] == s: b, e = float(redospec[1]), float(redospec[2]) break if e > float(first_Z[-1][0]): e = float(first_Z[-1][0]) for recnum in range(len(first_Z)): if first_Z[recnum][0] == b: start = recnum if first_Z[recnum][0] == e: end = recnum nsteps = end - start if nsteps > 2: zijdblock, units = pmag.find_dmag_rec(s, meas_data) pars, errcode = pmag.PintPars(datablock, araiblock, zijdblock, start, end, accept) if "specimen_scat" in pars.keys(): PmagSpecRec["specimen_scat"] = pars["specimen_scat"] if "specimen_frac" in pars.keys(): PmagSpecRec["specimen_frac"] = "%5.3f" % (pars["specimen_frac"]) if "specimen_gmax" in pars.keys(): PmagSpecRec["specimen_gmax"] = "%5.3f" % (pars["specimen_gmax"]) pars["measurement_step_unit"] = units pars["specimen_lab_field_dc"] = field pars["specimen_int"] = -1 * field * pars["specimen_b"] PmagSpecRec["measurement_step_min"] = "%8.3e" % (pars["measurement_step_min"]) PmagSpecRec["measurement_step_max"] = "%8.3e" % (pars["measurement_step_max"]) PmagSpecRec["specimen_int_n"] = "%i" % (pars["specimen_int_n"]) PmagSpecRec["specimen_lab_field_dc"] = "%8.3e" % (pars["specimen_lab_field_dc"]) PmagSpecRec["specimen_int"] = "%9.4e " % (pars["specimen_int"]) PmagSpecRec["specimen_b"] = "%5.3f " % (pars["specimen_b"]) PmagSpecRec["specimen_q"] = "%5.1f " % (pars["specimen_q"]) PmagSpecRec["specimen_f"] = "%5.3f " % (pars["specimen_f"]) PmagSpecRec["specimen_fvds"] = "%5.3f" % (pars["specimen_fvds"]) PmagSpecRec["specimen_b_beta"] = "%5.3f" % (pars["specimen_b_beta"]) PmagSpecRec["specimen_int_mad"] = "%7.1f" % (pars["specimen_int_mad"]) PmagSpecRec["specimen_Z"] = "%7.1f" % (pars["specimen_Z"]) PmagSpecRec["specimen_gamma"] = "%7.1f" % (pars["specimen_gamma"]) if pars["method_codes"] != "" and pars["method_codes"] not in methcodes: methcodes.append(pars["method_codes"]) PmagSpecRec["specimen_dec"] = "%7.1f" % (pars["specimen_dec"]) PmagSpecRec["specimen_inc"] = "%7.1f" % (pars["specimen_inc"]) PmagSpecRec["specimen_tilt_correction"] = "-1" PmagSpecRec["specimen_direction_type"] = "l" PmagSpecRec["direction_type"] = "l" # this is redudant, but helpful - won't be imported PmagSpecRec["specimen_dang"] = "%7.1f " % (pars["specimen_dang"]) PmagSpecRec["specimen_drats"] = "%7.1f " % (pars["specimen_drats"]) PmagSpecRec["specimen_drat"] = "%7.1f " % (pars["specimen_drat"]) PmagSpecRec["specimen_int_ptrm_n"] = "%i " % (pars["specimen_int_ptrm_n"]) PmagSpecRec["specimen_rsc"] = "%6.4f " % (pars["specimen_rsc"]) PmagSpecRec["specimen_md"] = "%i " % (int(pars["specimen_md"])) if PmagSpecRec["specimen_md"] == "-1": PmagSpecRec["specimen_md"] = "" PmagSpecRec["specimen_b_sigma"] = "%5.3f " % (pars["specimen_b_sigma"]) if "IE-TT" not in methcodes: methcodes.append("IE-TT") methods = "" for meth in methcodes: methods = methods + meth + ":" PmagSpecRec["magic_method_codes"] = methods.strip(":") PmagSpecRec["magic_software_packages"] = version_num PmagSpecRec["specimen_description"] = comment if critout != "": kill = pmag.grade(PmagSpecRec, accept, "specimen_int") if len(kill) > 0: Grade = "F" # fails else: Grade = "A" # passes PmagSpecRec["specimen_grade"] = Grade else: PmagSpecRec["specimen_grade"] = "" # not graded if nltrm == 0 and anis == 0 and cool != 0: # apply cooling rate correction SCR = pmag.get_dictitem( SampCRs, "er_sample_name", PmagSpecRec["er_sample_name"], "T" ) # get this samples, cooling rate correction CrSpecRec = pmag.cooling_rate(PmagSpecRec, SCR, crfrac, crtype) if CrSpecRec["er_specimen_name"] != "none": CrSpecs.append(CrSpecRec) PmagSpecs.append(PmagSpecRec) NltSpecRec = "" # # check on non-linear TRM correction # if nltrm == 1: # # find the data from the nlt_data list for this specimen # TRMs, Bs = [], [] NltSpecRec = "" NltRecs = pmag.get_dictitem( nlt_data, "er_specimen_name", PmagSpecRec["er_specimen_name"], "has" ) # fish out all the NLT data for this specimen if len(NltRecs) > 2: for NltRec in NltRecs: Bs.append(float(NltRec["treatment_dc_field"])) TRMs.append(float(NltRec["measurement_magn_moment"])) NLTpars = nlt.NLtrm( Bs, TRMs, float(PmagSpecRec["specimen_int"]), float(PmagSpecRec["specimen_lab_field_dc"]), 0, ) if NLTpars["banc"] > 0: NltSpecRec = {} for key in PmagSpecRec.keys(): NltSpecRec[key] = PmagSpecRec[key] NltSpecRec["specimen_int"] = "%9.4e" % (NLTpars["banc"]) NltSpecRec["magic_method_codes"] = PmagSpecRec["magic_method_codes"] + ":DA-NL" NltSpecRec["specimen_correction"] = "c" NltSpecRec["specimen_grade"] = PmagSpecRec["specimen_grade"] NltSpecRec["magic_software_packages"] = version_num print NltSpecRec["er_specimen_name"], " Banc= ", float(NLTpars["banc"]) * 1e6 if anis == 0 and cool != 0: SCR = pmag.get_dictitem( SampCRs, "er_sample_name", NltSpecRec["er_sample_name"], "T" ) # get this samples, cooling rate correction CrSpecRec = pmag.cooling_rate(NltSpecRec, SCR, crfrac, crtype) if CrSpecRec["er_specimen_name"] != "none": CrSpecs.append(CrSpecRec) NltSpecRecs.append(NltSpecRec) # # check on anisotropy correction if anis == 1: if NltSpecRec != "": Spc = NltSpecRec else: # find uncorrected data Spc = PmagSpecRec AniSpecs = pmag.get_dictitem( anis_data, "er_specimen_name", PmagSpecRec["er_specimen_name"], "T" ) if len(AniSpecs) > 0: AniSpec = AniSpecs[0] AniSpecRec = pmag.doaniscorr(Spc, AniSpec) AniSpecRec["specimen_grade"] = PmagSpecRec["specimen_grade"] AniSpecRec["magic_instrument_codes"] = PmagSpecRec["magic_instrument_codes"] AniSpecRec["specimen_correction"] = "c" AniSpecRec["magic_software_packages"] = version_num if cool != 0: SCR = pmag.get_dictitem( SampCRs, "er_sample_name", AniSpecRec["er_sample_name"], "T" ) # get this samples, cooling rate correction CrSpecRec = pmag.cooling_rate(AniSpecRec, SCR, crfrac, crtype) if CrSpecRec["er_specimen_name"] != "none": CrSpecs.append(CrSpecRec) AniSpecRecs.append(AniSpecRec) elif anis == 1: AniSpecs = pmag.get_dictitem( anis_data, "er_specimen_name", PmagSpecRec["er_specimen_name"], "T" ) if len(AniSpecs) > 0: AniSpec = AniSpecs[0] AniSpecRec = pmag.doaniscorr(PmagSpecRec, AniSpec) AniSpecRec["specimen_grade"] = PmagSpecRec["specimen_grade"] AniSpecRec["magic_instrument_codes"] = PmagSpecRec["magic_instrument_codes"] AniSpecRec["specimen_correction"] = "c" AniSpecRec["magic_software_packages"] = version_num if crfrac != 0: CrSpecRec = {} for key in AniSpecRec.keys(): CrSpecRec[key] = AniSpecRec[key] inten = frac * float(CrSpecRec["specimen_int"]) CrSpecRec["specimen_int"] = "%9.4e " % ( inten ) # adjust specimen intensity by cooling rate correction CrSpecRec["magic_method_codes"] = CrSpecRec["magic_method_codes"] + ":DA-CR-" + crtype CRSpecs.append(CrSpecRec) AniSpecRecs.append(AniSpecRec) spec += 1 else: print "skipping ", s spec += 1 pmag_file = dir_path + "/" + pmag_file pmag.magic_write(pmag_file, PmagSpecs, "pmag_specimens") print "uncorrected thellier data saved in: ", pmag_file if anis == 1 and len(AniSpecRecs) > 0: anisout = dir_path + "/" + anisout pmag.magic_write(anisout, AniSpecRecs, "pmag_specimens") print "anisotropy corrected data saved in: ", anisout if nltrm == 1 and len(NltSpecRecs) > 0: nltout = dir_path + "/" + nltout pmag.magic_write(nltout, NltSpecRecs, "pmag_specimens") print "non-linear TRM corrected data saved in: ", nltout if crfrac != 0: crout = dir_path + "/" + crout pmag.magic_write(crout, CRSpecs, "pmag_specimens") print "cooling rate corrected data saved in: ", crout
def main(): """ NAME zeq_magic_redo.py DESCRIPTION Calculate principal components through demagnetization data using bounds and calculation type stored in "redo" file SYNTAX zeq_magic_redo.py [command line options] OPTIONS -h prints help message -usr USER: identify user, default is "" -f: specify input file, default is magic_measurements.txt -F: specify output file, default is zeq_specimens.txt -fre REDO: specify redo file, default is "zeq_redo" -fsa SAMPFILE: specify er_samples format file, default is "er_samples.txt" -A : don't average replicate measurements, default is yes -crd [s,g,t] : specify coordinate system [s,g,t] [default is specimen coordinates] are specimen, geographic, and tilt corrected respectively NB: you must have a SAMPFILE in this directory to rotate from specimen coordinates -leg: attaches "Recalculated from original measurements; supercedes published results. " to comment field INPUTS zeq_redo format file is: specimen_name calculation_type[DE-BFL,DE-BFL-A,DE-BFL-O,DE-BFP,DE-FM] step_min step_max component_name[A,B,C] """ dir_path='.' INCL=["LT-NO","LT-AF-Z","LT-T-Z","LT-M-Z"] # looking for demag data beg,end,pole,geo,tilt,askave,save=0,0,[],0,0,0,0 user,doave,comment= "",1,"" geo,tilt=0,0 version_num=pmag.get_version() args=sys.argv if '-WD' in args: ind=args.index('-WD') dir_path=args[ind+1] meas_file,pmag_file,mk_file= dir_path+"/"+"magic_measurements.txt",dir_path+"/"+"zeq_specimens.txt",dir_path+"/"+"zeq_redo" samp_file,coord=dir_path+"/"+"er_samples.txt","" if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind=args.index("-usr") user=sys.argv[ind+1] if "-A" in args:doave=0 if "-leg" in args: comment="Recalculated from original measurements; supercedes published results. " if "-f" in args: ind=args.index("-f") meas_file=dir_path+'/'+sys.argv[ind+1] if "-F" in args: ind=args.index("-F") pmag_file=dir_path+'/'+sys.argv[ind+1] if "-fre" in args: ind=args.index("-fre") mk_file=dir_path+"/"+args[ind+1] try: mk_f=open(mk_file,'rU') except: print "Bad redo file" sys.exit() mkspec,skipped=[],[] speclist=[] for line in mk_f.readlines(): tmp=line.split() mkspec.append(tmp) speclist.append(tmp[0]) if "-fsa" in args: ind=args.index("-fsa") samp_file=dir_path+'/'+sys.argv[ind+1] if "-crd" in args: ind=args.index("-crd") coord=sys.argv[ind+1] if coord=="g":geo,tilt=1,0 if coord=="t":geo,tilt=1,1 # # now get down to bidness if geo==1: samp_data,file_type=pmag.magic_read(samp_file) if file_type != 'er_samples': print file_type print "This is not a valid er_samples file " sys.exit() # set orientation priorities SO_methods=[] for rec in samp_data: if "magic_method_codes" in rec: methlist=rec["magic_method_codes"] for meth in methlist.split(":"): if "SO" in meth and "SO-POM" not in meth.strip(): if meth.strip() not in SO_methods: SO_methods.append(meth.strip()) SO_priorities=pmag.set_priorities(SO_methods,0) # # # meas_data,file_type=pmag.magic_read(meas_file) if file_type != 'magic_measurements': print file_type print file_type,"This is not a valid magic_measurements file " sys.exit() # # sort the specimen names # k = 0 print 'Processing ',len(speclist), ' specimens - please wait' PmagSpecs=[] while k < len(speclist): s=speclist[k] recnum=0 PmagSpecRec={} method_codes,inst_codes=[],[] # find the data from the meas_data file for this sample # # collect info for the PmagSpecRec dictionary # meas_meth=[] for rec in meas_data: # copy of vital stats to PmagSpecRec from first spec record in demag block skip=1 if rec["er_specimen_name"]==s: methods=rec["magic_method_codes"].split(":") if len(set(methods) & set(INCL))>0: PmagSpecRec["er_analyst_mail_names"]=user PmagSpecRec["magic_software_packages"]=version_num PmagSpecRec["er_specimen_name"]=s PmagSpecRec["er_sample_name"]=rec["er_sample_name"] PmagSpecRec["er_site_name"]=rec["er_site_name"] PmagSpecRec["er_location_name"]=rec["er_location_name"] PmagSpecRec["er_citation_names"]="This study" if "magic_experiment_name" not in rec.keys(): rec["magic_experiment_name"]="" PmagSpecRec["magic_experiment_names"]=rec["magic_experiment_name"] if "magic_instrument_codes" not in rec.keys(): rec["magic_instrument_codes"]="" inst=rec['magic_instrument_codes'].split(":") for I in inst: if I not in inst_codes: # copy over instruments inst_codes.append(I) meths=rec["magic_method_codes"].split(":") for meth in meths: if meth.strip() not in meas_meth:meas_meth.append(meth) if "LP-DIR-AF" in meas_meth or "LT-AF-Z" in meas_meth: PmagSpecRec["measurement_step_unit"]="T" if "LP-DIR-AF" not in method_codes:method_codes.append("LP-DIR-AF") if "LP-DIR-T" in meas_meth or "LT-T-Z" in meas_meth: PmagSpecRec["measurement_step_unit"]="K" if "LP-DIR-T" not in method_codes:method_codes.append("LP-DIR-T") if "LP-DIR-M" in meas_meth or "LT-M-Z" in meas_meth: PmagSpecRec["measurement_step_unit"]="J" if "LP-DIR-M" not in method_codes:method_codes.append("LP-DIR-M") if PmagSpecRec=={}: print 'no data found for specimen: ',s print 'delete from zeq_redo input file...., then try again' sys.exit() # # data,units=pmag.find_dmag_rec(s,meas_data) # datablock=data noskip=1 if len(datablock) <2 or s not in speclist : noskip=0 k+=1 # print 'skipping ', s,len(datablock) if noskip: # # find replicate measurements at given treatment step and average them # # step_meth,avedata=pmag.vspec(data) # # if len(avedata) != len(datablock): # if doave==1: # method_codes.append("DE-VM") # datablock=avedata # # do geo or stratigraphic correction now # if geo==1: # find top priority orientation method redo,p=1,0 if len(SO_methods)<=1: az_type=SO_methods[0] orient=pmag.find_samp_rec(PmagSpecRec["er_sample_name"],samp_data,az_type) if orient["sample_azimuth"] !="": method_codes.append(az_type) redo=0 while redo==1: if p>=len(SO_priorities): print "no orientation data for ",s orient["sample_azimuth"]="" orient["sample_dip"]="" method_codes.append("SO-NO") redo=0 else: az_type=SO_methods[SO_methods.index(SO_priorities[p])] orient=pmag.find_samp_rec(PmagSpecRec["er_sample_name"],samp_data,az_type) if orient["sample_azimuth"] !="": method_codes.append(az_type) redo=0 p+=1 # # if tilt selected, get stratigraphic correction # tiltblock,geoblock=[],[] for rec in datablock: if "sample_azimuth" in orient.keys() and orient["sample_azimuth"]!="": d_geo,i_geo=pmag.dogeo(rec[1],rec[2],orient["sample_azimuth"],orient["sample_dip"]) geoblock.append([rec[0],d_geo,i_geo,rec[3],rec[4],rec[5]]) if tilt==1 and "sample_bed_dip_direction" in orient.keys(): d_tilt,i_tilt=pmag.dotilt(d_geo,i_geo,orient["sample_bed_dip_direction"],orient["sample_bed_dip"]) tiltblock.append([rec[0],d_tilt,i_tilt,rec[3],rec[4],rec[5]]) elif tilt==1: if PmagSpecRec["er_sample_name"] not in skipped: print 'no tilt correction for ', PmagSpecRec["er_sample_name"],' skipping....' skipped.append(PmagSpecRec["er_sample_name"]) else: if PmagSpecRec["er_sample_name"] not in skipped: print 'no geographic correction for ', PmagSpecRec["er_sample_name"],' skipping....' skipped.append(PmagSpecRec["er_sample_name"]) # # get beg_pca, end_pca, pca if PmagSpecRec['er_sample_name'] not in skipped: compnum=-1 for spec in mkspec: if spec[0]==s: CompRec={} for key in PmagSpecRec.keys():CompRec[key]=PmagSpecRec[key] compnum+=1 calculation_type=spec[1] beg=float(spec[2]) end=float(spec[3]) if len(spec)>4: comp_name=spec[4] else: comp_name=string.uppercase[compnum] CompRec['specimen_comp_name']=comp_name if beg < float(datablock[0][0]):beg=float(datablock[0][0]) if end > float(datablock[-1][0]):end=float(datablock[-1][0]) for l in range(len(datablock)): if datablock[l][0]==beg:beg_pca=l if datablock[l][0]==end:end_pca=l if geo==1 and tilt==0: mpars=pmag.domean(geoblock,beg_pca,end_pca,calculation_type) if mpars["specimen_direction_type"]!="Error": CompRec["specimen_dec"]='%7.1f ' %(mpars["specimen_dec"]) CompRec["specimen_inc"]='%7.1f ' %(mpars["specimen_inc"]) CompRec["specimen_tilt_correction"]='0' if geo==1 and tilt==1: mpars=pmag.domean(tiltblock,beg_pca,end_pca,calculation_type) if mpars["specimen_direction_type"]!="Error": CompRec["specimen_dec"]='%7.1f ' %(mpars["specimen_dec"]) CompRec["specimen_inc"]='%7.1f ' %(mpars["specimen_inc"]) CompRec["specimen_tilt_correction"]='100' if geo==0 and tilt==0: mpars=pmag.domean(datablock,beg_pca,end_pca,calculation_type) if mpars["specimen_direction_type"]!="Error": CompRec["specimen_dec"]='%7.1f ' %(mpars["specimen_dec"]) CompRec["specimen_inc"]='%7.1f ' %(mpars["specimen_inc"]) CompRec["specimen_tilt_correction"]='-1' if mpars["specimen_direction_type"]=="Error": pass else: CompRec["measurement_step_min"]='%8.3e '%(datablock[beg_pca][0]) try: CompRec["measurement_step_max"]='%8.3e '%(datablock[end_pca][0] ) except: print 'error in end_pca ',PmagSpecRec['er_specimen_name'] CompRec["specimen_correction"]='u' if calculation_type!='DE-FM': CompRec["specimen_mad"]='%7.1f '%(mpars["specimen_mad"]) CompRec["specimen_alpha95"]="" else: CompRec["specimen_mad"]="" CompRec["specimen_alpha95"]='%7.1f '%(mpars["specimen_alpha95"]) CompRec["specimen_n"]='%i '%(mpars["specimen_n"]) CompMeths=[] for meth in method_codes: if meth not in CompMeths:CompMeths.append(meth) if calculation_type not in CompMeths:CompMeths.append(calculation_type) if geo==1: CompMeths.append("DA-DIR-GEO") if tilt==1: CompMeths.append("DA-DIR-TILT") if "DE-BFP" not in calculation_type: CompRec["specimen_direction_type"]='l' else: CompRec["specimen_direction_type"]='p' CompRec["magic_method_codes"]="" if len(CompMeths) != 0: methstring="" for meth in CompMeths: methstring=methstring+ ":" +meth CompRec["magic_method_codes"]=methstring.strip(':') CompRec["specimen_description"]=comment if len(inst_codes) != 0: inststring="" for inst in inst_codes: inststring=inststring+ ":" +inst CompRec["magic_instrument_codes"]=inststring.strip(':') PmagSpecs.append(CompRec) k+=1 pmag.magic_write(pmag_file,PmagSpecs,'pmag_specimens') print "Recalculated specimen data stored in ",pmag_file
def main(): """ NAME sort_specimens.py DESCRIPTION Reads in a pmag_specimen formatted file and separates it into different components (A,B...etc.) SYNTAX sort_specimens.py [-h] [command line options] INPUT takes pmag_specimens.txt formatted input file OPTIONS -h: prints help message and quits -f FILE: specify input file, default is 'pmag_specimens.txt' OUTPUT makes pmag_specimen formatted files with input filename plus _X_Y where X is the component name and Y is s,g,t for coordinate system """ dir_path='.' inspec="pmag_specimens.txt" 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') inspec=sys.argv[ind+1] basename=inspec.split('.')[:-1] inspec=dir_path+"/"+inspec ofile_base=dir_path+"/"+basename[0] # # read in data # prior_spec_data,file_type=pmag.magic_read(inspec) if file_type != 'pmag_specimens': print file_type, " this is not a valid pmag_specimens file" sys.exit() # get list of specimens in file, components, coordinate systems available specs,comps,coords=[],[],[] for spec in prior_spec_data: if spec['er_specimen_name'] not in specs:specs.append(spec['er_specimen_name']) if 'specimen_comp_name' not in spec.keys():spec['specimen_comp_name']='A' if 'specimen_tilt_correction' not in spec.keys():spec['tilt_correction']='-1' # assume specimen coordinates if spec['specimen_comp_name'] not in comps:comps.append(spec['specimen_comp_name']) if spec['specimen_tilt_correction'] not in coords:coords.append(spec['specimen_tilt_correction']) # work on separating out components, coordinate systems by specimen for coord in coords: print coord for comp in comps: print comp speclist=[] for spec in prior_spec_data: if spec['specimen_tilt_correction']==coord and spec['specimen_comp_name']==comp:speclist.append(spec) ofile=ofile_base+'_'+coord+'_'+comp+'.txt' pmag.magic_write(ofile,speclist,'pmag_specimens') print 'coordinate system: ',coord,' component name: ',comp,' saved in ',ofile
def main(): """ NAME magic_select.py DESCRIPTION picks out records and dictitem options saves to magic_special file SYNTAX magic_select.py [command line optins] OPTIONS -h prints help message and quits -f FILE: specify input magic format file -F FILE: specify output magic format file -key KEY string [T,F,has, not, eval,min,max] returns records where the value of the key either: matches exactly the string (T) does not match the string (F) contains the string (has) does not contain the string (not) the value equals the numerical value of the string (eval) the value is greater than the numerical value of the string (min) the value is less than the numerical value of the string (max) NOTES for age range: use KEY: age (converts to Ma, takes mid point of low, high if no value for age. for paleolat: use KEY: model_lat (uses lat, if age<5 Ma, else, model_lat, or attempts calculation from average_inc if no model_lat.) returns estimate in model_lat key """ dir_path="." flag='' if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] if '-h' in sys.argv: print main.__doc__ sys.exit() if '-f' in sys.argv: ind=sys.argv.index('-f') magic_file=dir_path+'/'+sys.argv[ind+1] else: print main.__doc__ sys.exit() if '-F' in sys.argv: ind=sys.argv.index('-F') outfile=dir_path+'/'+sys.argv[ind+1] else: print main.__doc__ sys.exit() if '-key' in sys.argv: ind=sys.argv.index('-key') grab_key=sys.argv[ind+1] v=sys.argv[ind+2] flag=sys.argv[ind+3] else: print main.__doc__ print '-key is required' sys.exit() # # get data read in Data,file_type=pmag.magic_read(magic_file) if grab_key =='age': grab_key='average_age' Data=pmag.convert_ages(Data) if grab_key =='model_lat': Data=pmag.convert_lat(Data) Data=pmag.convert_ages(Data) Selection=pmag.get_dictitem(Data,grab_key,v,flag) if len(Selection)>0: pmag.magic_write(outfile,Selection,file_type) print len(Selection),' records written to ',outfile else: print 'no data matched your criteria'
def main(): """ NAME kly4s_magic.py DESCRIPTION converts files generated by SIO kly4S labview program to MagIC formated files for use with PmagPy plotting software SYNTAX kly4s_magic.py -h [command line options] OPTIONS -h: prints the help message and quits -i: allows interactive input of input/output filenames -f FILE: specify .ams input file name -fad AZDIP: specify AZDIP file with orientations, will create er_samples.txt file -fsa SFILE: specify existing er_samples.txt file with orientation information -fsp SPFILE: specify existing er_specimens.txt file for appending -F MFILE: specify magic_measurements output file -Fa AFILE: specify rmag_anisotropy output file -ocn ORCON: specify orientation convention: default is #3 below -only with AZDIP file -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 #1 below DEFAULTS MFILE: magic_measurements.txt AFILE: rmag_anisotropy.txt SPFILE: create new er_specimen.txt file USER: "" LOC: "unknown" INST: "SIO-KLY4S" SPEC: 1 specimen name is same as sample (if SPEC is 1, sample is all but last character) NOTES: 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] XXXXYYY: YYY is sample designation with Z characters from site XXX [5] all others you will have to either customize your self or e-mail [email protected] for help. Orientation convention: [1] Lab arrow azimuth= azimuth; Lab arrow dip=-dip i.e., dip is degrees from vertical down - the hade [default] [2] Lab arrow azimuth = azimuth-90; Lab arrow dip = -dip i.e., azimuth is strike and dip is hade [3] Lab arrow azimuth = azimuth; Lab arrow dip = dip-90 e.g. dip is degrees from horizontal of drill direction [4] Lab arrow azimuth = azimuth; Lab arrow dip = dip [5] Lab arrow azimuth = azimuth; Lab arrow dip = 90-dip [6] all others you will have to either customize your self or e-mail [email protected] for help. """ citation='This study' cont=0 ask=0 samp_con,Z="1",1 or_con="3" # see orientation_magic.py help message inst,specnum="SIO-KLY4S",0 AniRecs,SpecRecs,SampRecs,MeasRecs=[],[],[],[] user,locname,specfile="","unknown","er_specimens.txt" AppSpec=0 sampfile,measfile='','magic_measurements.txt' anisfile='rmag_anisotropy.txt' azdipfile="" 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 '-usr' in sys.argv: ind=sys.argv.index('-usr') user=sys.argv[ind+1] if '-ocn' in sys.argv: ind=sys.argv.index('-ocn') or_con=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 3-Z where Z is an integer" sys.exit() else: Z=samp_con.split("-")[1] samp_con="4" if '-f' in sys.argv: ind=sys.argv.index('-f') amsfile=sys.argv[ind+1] else: print main.__doc__ print 'must specify ascii input file ' sys.exit() if '-F' in sys.argv: ind=sys.argv.index('-F') measfile=sys.argv[ind+1] if '-Fa' in sys.argv: ind=sys.argv.index('-Fa') anisfile=sys.argv[ind+1] if '-Fr' in sys.argv: ind=sys.argv.index('-Fr') routput=sys.argv[ind+1] if '-fsa' in sys.argv: ind=sys.argv.index('-fsa') sampfile=sys.argv[ind+1] if '-fsp' in sys.argv: ind=sys.argv.index('-fsp') specfile=sys.argv[ind+1] AppSpec=1 if '-fad' in sys.argv: ind=sys.argv.index('-fad') azdipfile=dir_path+"/"+sys.argv[ind+1] azfile=open(azdipfile,'rU') AzDipDat=azfile.readlines() if '-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 specfile=dir_path+'/'+specfile sampfile=dir_path+'/'+sampfile measfile=dir_path+'/'+measfile anisfile=dir_path+'/'+anisfile amsfile=dir_path+'/'+amsfile try: input=open(amsfile,'rU') except: print 'Error opening file: ', amsfile sys.exit() SpecRecs,speclist=[],[] if AppSpec==1: try: SpecRecs,filetype=pmag.magic_read(specfile) # append new records to existing if len(SpecRecs)>0: for spec in SpecRecs: if spec['er_specimen_name'] not in speclist:speclist.append(spec['er_specimen_name']) except IOError: print 'trouble opening ',specfile Data=input.readlines() samps=[] if sampfile!=dir_path+'/': samps,file_type=pmag.magic_read(sampfile) SO_methods=[] for rec in samps: if "magic_method_codes" in rec.keys(): methlist=rec["magic_method_codes"].replace(" ","").split(":") for meth in methlist: if "SO" in meth and "SO-POM" not in meth and "SO-GT5" not in meth and "SO-ASC" not in meth and "SO-BAD" not in meth: if meth not in SO_methods: SO_methods.append(meth) # SO_priorities=pmag.set_priorities(SO_methods,ask) for line in Data: rec=line.split() if len(rec)>0: AniRec,SpecRec,SampRec,SiteRec,MeasRec={},{},{},{},{} specname=rec[0] if specnum!=0: sampname=specname[:specnum] else: sampname=specname site=pmag.parse_site(sampname,samp_con,Z) AniRec['er_location_name']=locname AniRec['er_citation_names']="This study" AniRec['magic_instrument_codes']=inst method_codes=['LP-X','AE-H','LP-AN-MS'] AniRec['magic_experiment_name']=specname+":"+"LP-AN-MS" AniRec['er_analyst_mail_names']=user AniRec['er_site_name']=site AniRec['er_sample_name']=sampname AniRec['er_specimen_name']=specname labaz,labdip,bed_dip_direction,bed_dip="","","","" if azdipfile!="": for key in AniRec.keys():SampRec[key]=AniRec[key] for oline in AzDipDat: # look for exact match first orec=oline.replace('\n','').split() if orec[0].upper() in specname.upper(): # we have a match labaz,labdip=pmag.orient(float(orec[1]),float(orec[2]),or_con) bed_dip_direction=float(orec[3])-90. # assume dip to right of strike bed_dip=float(orec[4]) break if labaz=="": # found no exact match - now look at sample level for oline in AzDipDat: orec=oline.split() if orec[0].upper() == sampname.upper(): # we have a match labaz,labdip=pmag.orient(float(orec[1]),float(orec[2]),or_con) bed_dip_direction=float(orec[3])-90. # assume dip to right of strike bed_dip=float(orec[4]) break if labaz=="": # found no exact match - now look at sample level print 'found no orientation data - will use specimen coordinates' raw_input("<return> to continue") else: for key in AniRec.keys():SampRec[key]=AniRec[key] SampRec['sample_azimuth']='%7.1f'%(labaz) SampRec['sample_dip']='%7.1f'%(labdip) SampRec['sample_bed_dip_direction']='%7.1f'%(bed_dip_direction) SampRec['sample_bed_dip']='%7.1f'%(bed_dip) SampRecs.append(SampRec) elif sampfile!=dir_path+'/': redo,p=1,0 orient={} if len(SO_methods)==1: az_type=SO_methods[0] orient=pmag.find_samp_rec(AniRec["er_sample_name"],samps,az_type) if orient['sample_azimuth']!="": method_codes.append(az_type) else: print "no orientation data for ",AniRec["er_sample_name"],labaz orient["sample_azimuth"]="" orient["sample_dip"]="" orient["sample_bed_dip_direction"]="" orient["sample_bed_dip"]="" noorient=1 method_codes.append("SO-NO") redo=0 redo=0 while redo==1: if p>=len(SO_priorities): print "no orientation data for ",AniRec["er_sample_name"],labaz orient["sample_azimuth"]="" orient["sample_dip"]="" orient["sample_bed_dip_direction"]="" orient["sample_bed_dip"]="" noorient=1 method_codes.append("SO-NO") redo=0 else: az_type=SO_methods[SO_methods.index(SO_priorities[p])] orient=pmag.find_samp_rec(AniRec["er_sample_name"],samps,az_type) if orient["sample_azimuth"] !="": method_codes.append(az_type) redo=0 noorient=0 p+=1 if orient['sample_azimuth']!="":labaz=float(orient['sample_azimuth']) if orient['sample_dip']!="":labdip=float(orient['sample_dip']) if "sample_bed_dip_direction" in orient.keys() and orient['sample_bed_dip_direction']!="": bed_dip_direction=float(orient['sample_bed_dip_direction']) if "sample_bed_dip" in orient.keys() and orient['sample_bed_dip']!="": sample_bed_dip=float(orient['sample_bed_dip']) for key in AniRec.keys():SpecRec[key]=AniRec[key] for key in AniRec.keys():MeasRec[key]=AniRec[key] AniRec['anisotropy_type']="AMS" AniRec['anisotropy_n']="192" AniRec['anisotropy_s1']=rec[1] AniRec['anisotropy_s2']=rec[2] AniRec['anisotropy_s3']=rec[3] AniRec['anisotropy_s4']=rec[4] AniRec['anisotropy_s5']=rec[5] AniRec['anisotropy_s6']=rec[6] AniRec['anisotropy_sigma']=rec[7] AniRec['anisotropy_tilt_correction']='-1' AniRec['anisotropy_unit']='Normalized by trace' SpecRec['specimen_volume']='%8.3e'%(1e-6*float(rec[12])) # volume from cc to m^3 MeasRec['measurement_flag']='g' # good MeasRec['measurement_standard']='u' # unknown date=rec[14].split('/') if int(date[2])>80: date[2]='19'+date[2] else: date[2]='20'+date[2] datetime=date[2]+':'+date[0]+':'+date[1]+":" datetime=datetime+rec[15] MeasRec['measurement_number']='1' MeasRec['measurement_date']=datetime MeasRec['measurement_lab_field_ac']='%8.3e'%(4*math.pi*1e-7*float(rec[11])) # convert from A/m to T MeasRec['measurement_temp']="300" # assumed room T in kelvin MeasRec['measurement_chi_volume']=rec[8] MeasRec['measurement_description']='Bulk measurement' MeasRec['magic_method_codes']='LP-X' if SpecRec['er_specimen_name'] not in speclist: # add to list speclist.append(SpecRec['er_specimen_name']) SpecRecs.append(SpecRec) MeasRecs.append(MeasRec) methods="" for meth in method_codes: methods=methods+meth+":" AniRec["magic_method_codes"]=methods[:-1] # get rid of annoying spaces in Anthony's export files AniRecs.append(AniRec) if labaz!="": # have orientation info 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,bed_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) pmag.magic_write(anisfile,AniRecs,'rmag_anisotropy') pmag.magic_write(measfile,MeasRecs,'magic_measurements') pmag.magic_write(specfile,SpecRecs,'er_specimens') print 'anisotropy data saved in ',anisfile print 'measurement data saved in ',measfile if AppSpec==1: print 'new specimen information added to ',specfile else: print 'specimen information saved in new ',specfile if azdipfile!="": sampfile='er_samples.txt' pmag.magic_write(sampfile,SampRecs,'er_samples') print 'sample data saved in ',sampfile
def main(): """ NAME UCSC_magic.py DESCRIPTION converts UCSC format files to MagIC formatted files SYNTAX UCSC_magic.py [command line options] OPTIONS -h: prints the help message and quits. -f FILE: specify UCSC format input file, required -F FILE: specify output file, default is magic_measurements.txt -A: don't average replicate measurements """ global k,Data k,Data,measNum=0,[],0 ErLocs,ErSites,ErSamps,ErSpecs,MagRecs=[],[],[],[],[] # MagIC formatted info # initialize some stuff noave=0 args=sys.argv ErLocs,ErSites,ErSamps,ErSpecs,MagicMeas=[],[],[],[],[] # MagIC formatted info dir_path='.' # # get command line arguments # if '-WD' in args: # set working directory (only for within MagIC.py GUI) ind=args.index("-WD") dir_path=args[ind+1] loc_file,site_file,samp_file,spec_file,meas_file=dir_path+"/er_locations.txt",dir_path+"/er_sites.txt",dir_path+"/er_samples.txt",dir_path+"/er_specimens.txt",dir_path+"/magic_measurements.txt" if "-h" in args: print main.__doc__ sys.exit() if '-F' in args: ind=args.index("-F") meas_file=dir_path+'/'+args[ind+1] if '-f' in args: ind=args.index("-f") magfile=dir_path+'/'+args[ind+1] try: input=open(magfile,'rU') except: print "bad mag file name" sys.exit() else: print "mag_file field is required option" print main.__doc__ sys.exit() if "-A" in args: noave=1 InData=input.readlines() Data=[] for line in InData: if line!="\n" and line!="": Data.append(line) # strip out annoying blank lines LocRec=parseloc() # peel off the location info ErLoc={} ErLoc['er_location_name']=LocRec['name'] ErLoc['er_citation_name']="This study" ErLoc['location_type']="outcrop" ErLoc['location_begin_lat']=LocRec['northLatitude'] ErLoc['location_begin_lon']=LocRec['eastLongitude'] ErLoc['location_begin_elevation']=convert2meters(LocRec['altitude'],LocRec['altitudeUnits']) ErLoc['location_description']=LocRec['comments'] ErLocs.append(ErLoc) while "</locality>" not in Data[k]: ErSite={} SiteRec=parsesite() if SiteRec=='done': break print SiteRec['name'] ErSite['er_citation_name']="This study" ErSite['er_location_name']=ErLoc['er_location_name'] ErSite['site_definition']='s' # this means a single site as opposed to composite site ErSite['er_site_name']=SiteRec['name'] ErSite['site_type']="" ErSite['site_class']="" ErSite['site_lithology']="" ErSite['site_lat']=SiteRec['northLatitude'] ErSite['site_lon']=SiteRec['eastLongitude'] ErSite['site_elevation']=convert2meters(SiteRec['altitude'],SiteRec['altitudeUnits']) ErSite['site_description']=SiteRec['comments'] ErSites.append(ErSite) samples=[] # this is a list for unique sample names while '</site>' not in Data[k] and k<len(Data): ErSpec={} SpecRec=parsespec() print SpecRec['name'] ErSpec['er_specimen_name']=SpecRec['name'] ErSpec['er_citation_name']="This study" ErSpec['er_location_name']=ErLoc['er_location_name'] ErSpec['er_citation_names']="This study" ErSpec['er_site_name']=ErSite['er_site_name'] er_sample_name=ErSpec['er_specimen_name'][:-1] ErSpec['er_sample_name']=er_sample_name ErSpec['specimen_volume']=SpecRec['volume'] # volume in m^3 ErSpecs.append(ErSpec) MeasRecs=parsesteps() print len(MeasRecs),' measurements' if er_sample_name not in samples: # new sample name samples.append(er_sample_name) ErSamp={} ErSamp['er_sample_name']=er_sample_name ErSamp['er_citation_name']="This study" ErSamp['er_location_name']=ErLoc['er_location_name'] ErSamp['er_site_name']=ErSite['er_site_name'] ErSamp['sample_lat']=ErSite['site_lat'] ErSamp['sample_lon']=ErSite['site_lon'] ErSamp['sample_elevation']=ErSite['site_elevation'] ErSamp['sample_date']=parsedate(SpecRec['dateCollected']) # ErSamp['sample_time_zone']=LocRec['gmtOffset']+"+GMT" ErSamp['sample_bed_dip_direction']=str(float(SpecRec['strike'])+90.) ErSamp['sample_bed_dip']=SpecRec['dip'] ErSamp['sample_height']=SpecRec['stratigraphicLevel'] ErSamp['sample_description']=SpecRec['comments'] ErSamp['sample_declination_correction']=LocRec['regionalDeclination'] if 'calculatedSunAz' in SpecRec.keys(): ErSamp['sample_azimuth']=SpecRec['calculatedSunAz'] ErSamp['magic_method_codes']='SO-SUN' az,pl=pmag.get_azpl(float(MeasRecs[0]['coreDec']),float(MeasRecs[0]['coreInc']),float(MeasRecs[0]['geoDec']),float(MeasRecs[0]['geoInc'])) ErSamp['sample_azimuth']=str(az) ErSamp['sample_dip']=str(pl) ErSamps.append(ErSamp) for MeasRec in MeasRecs: MagRec={} measNum+=1 MagRec['er_citation_names']="This study" MagRec['measurement_number']='%i'%(measNum) MagRec['er_location_name']=ErSpec['er_location_name'] MagRec['er_site_name']=ErSpec['er_site_name'] MagRec['er_sample_name']=ErSpec['er_sample_name'] MagRec['er_specimen_name']=ErSpec['er_specimen_name'] MagRec['measurement_date']=parsedate(MeasRec['date']) 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' step=MeasRec['stepType'] if step=='AF': MagRec["magic_method_codes"]="LT-AF-Z" # lab treatment, af in zero field MagRec['magic_experiment_name']=MagRec['er_specimen_name']+":LT-AF-Z" elif step=="TH": # I'm guessing here MagRec["magic_method_codes"]="LT-T-Z" # this is "lab treatment, thermal in zero field MagRec['magic_experiment_name']=MagRec['er_specimen_name']+":LT-T-Z" else: MagRec["magic_method_codes"]="LT-NO" # no lab treatment - NRM MagRec['magic_experiment_name']=MagRec['er_specimen_name']+":LT-NO" MagRec['measurement_dec']=MeasRec['coreDec'] MagRec['measurement_inc']=MeasRec['coreInc'] MagRec['measurement_magn_volume']=MeasRec['J'] # intensity in A/m MagRec['measurement_magn_moment']=str(float(MeasRec['J'])*float(ErSpec['specimen_volume'])) # intensity in Am^2 MagRec['measurement_chi_volume']=MeasRec['susceptibility'] # assuming dimensionless SI CHECK THIS MagRec['magic_software_packages']=MeasRec['measuringRoutine'] # if step=="AF": MagRec["treatment_ac_field"]=str(1e-3*float(MeasRec['stepLevel'])) # stepLevel in tesla if step=="TH": stepLevel=float(MeasRec['stepLevel']) +273 MagRec["treatment_temp"]='%8.3e' % (stepLevel) # treatment step in kelvin MagRec["measurement_csd"]=MeasRec['Q_95'] # I think this is the csd MagRec["magic_instrument_codes"]='UCSC-'+MeasRec['instrument'] MagRec["er_analyst_mail_names"]=MeasRec['operator'] MagRec["measurement_flag"]='g' # good measurement flag MagRec["measurement_standard"]='u' # # unknown - as opposed to standard MagRecs.append(MagRec) pmag.magic_write(loc_file,ErLocs,'er_locations') print "results put in ",loc_file pmag.magic_write(site_file,ErSites,'er_sites') print "results put in ",site_file pmag.magic_write(samp_file,ErSamps,'er_samples') print "results put in ",samp_file pmag.magic_write(spec_file,ErSpecs,'er_specimens') print "results put in ",spec_file pmag.magic_write(meas_file,MagRecs,'magic_measurements') print "results put in ",meas_file
def main(command_line=True, **kwargs): """ NAME IODP_jr6_magic.py DESCRIPTION converts shipboard .jr6 format files to magic_measurements format files SYNTAX IODP_jr6_magic.py [command line options] OPTIONS -h: prints the help message and quits. -f FILE: specify input file, or -F FILE: specify output file, default is magic_measurements.txt -fsa FILE: specify er_samples.txt file for sample name lookup , default is 'er_samples.txt' -loc HOLE : specify hole name (U1456A) -A: don't average replicate measurements INPUT JR6 .jr6 format file """ def fix_separation(filename, new_filename): old_file = open(filename, 'rU') data = old_file.readlines() new_data = [] for line in data: new_line = line.replace('-', ' -') new_line = new_line.replace(' ', ' ') new_data.append(new_line) new_file = open(new_filename, 'w') for s in new_data: new_file.write(s) old_file.close() new_file.close() return new_filename def old_fix_separation(filename, new_filename): old_file = open(filename, 'rU') data = old_file.readlines() new_data = [] for line in data: new_line = [] for i in line.split(): if '-' in i[1:]: lead_char = '-' if i[0] == '-' else '' if lead_char: v = i[1:].split('-') else: v = i.split('-') new_line.append(lead_char + v[0]) new_line.append('-' + v[1]) else: new_line.append(i) new_line = (' '.join(new_line)) + '\n' new_data.append(new_line) new_file = open(new_filename, 'w') for s in new_data: new_file.write(s) new_file.close() old_file.close() return new_filename # initialize some stuff noave=0 volume=2.5**3 #default volume is a 2.5cm cube inst="" samp_con,Z='5',"" missing=1 demag="N" er_location_name="unknown" citation='This study' args=sys.argv meth_code="LP-NO" version_num=pmag.get_version() dir_path='.' MagRecs=[] samp_file = 'er_samples.txt' meas_file = 'magic_measurements.txt' mag_file = '' # # get command line arguments # if command_line: if '-WD' in sys.argv: ind = sys.argv.index('-WD') dir_path=sys.argv[ind+1] if '-ID' in sys.argv: ind = sys.argv.index('-ID') input_dir_path = sys.argv[ind+1] else: input_dir_path = dir_path output_dir_path = dir_path if "-h" in args: print main.__doc__ return False if '-F' in args: ind=args.index("-F") meas_file = args[ind+1] if '-fsa' in args: ind = args.index("-fsa") samp_file = args[ind+1] if samp_file[0]!='/': samp_file = os.path.join(input_dir_path, samp_file) try: open(samp_file,'rU') ErSamps,file_type=pmag.magic_read(samp_file) except: print samp_file,' not found: ' print ' download csv file and import to MagIC with IODP_samples_magic.py' if '-f' in args: ind = args.index("-f") mag_file= args[ind+1] if "-loc" in args: ind=args.index("-loc") er_location_name=args[ind+1] if "-A" in args: noave=1 if not command_line: dir_path = kwargs.get('dir_path', '.') input_dir_path = kwargs.get('input_dir_path', dir_path) output_dir_path = dir_path meas_file = kwargs.get('meas_file', 'magic_measurements.txt') mag_file = kwargs.get('mag_file', '') samp_file = kwargs.get('samp_file', 'er_samples.txt') specnum = kwargs.get('specnum', 1) samp_con = kwargs.get('samp_con', '1') if len(str(samp_con)) > 1: samp_con, Z = samp_con.split('-') else: Z = '' er_location_name = kwargs.get('er_location_name', '') noave = kwargs.get('noave', 0) # default (0) means DO average meth_code = kwargs.get('meth_code', "LP-NO") # format variables meth_code=meth_code+":FS-C-DRILL-IODP:SP-SS-C:SO-V" meth_code=meth_code.strip(":") if mag_file: mag_file = os.path.join(input_dir_path, mag_file) samp_file = os.path.join(input_dir_path, samp_file) meas_file = os.path.join(output_dir_path, meas_file) # validate variables if not mag_file: print "You must provide an IODP_jr6 format file" return False, "You must provide an IODP_jr6 format file" if not os.path.exists(mag_file): print 'The input file you provided: {} does not exist.\nMake sure you have specified the correct filename AND correct input directory name.'.format(os.path.join(input_dir_path, mag_file)) return False, 'The input file you provided: {} does not exist.\nMake sure you have specified the correct filename AND correct input directory name.'.format(magfile) if not os.path.exists(samp_file): print 'samp_file', samp_file print "Your input directory:\n{}\nmust contain an er_samples.txt file, or you must explicitly provide one".format(input_dir_path) return False, "Your input directory:\n{}\nmust contain an er_samples.txt file, or you must explicitly provide one".format(input_dir_path) # parse data temp = os.path.join(output_dir_path, 'temp.txt') fix_separation(mag_file, temp) #os.rename('temp.txt', mag_file) #data = open(mag_file, 'rU').readlines() data=pd.read_csv(temp, delim_whitespace=True,header=None) os.remove(temp) samples,filetype = pmag.magic_read(samp_file) data.columns=['specname','step','negz','y','x','expon','sample_azimuth','sample_dip','sample_bed_dip_direction','sample_bed_dip','bed_dip_dir2','bed_dip2','param1','param2','param3','param4','measurement_csd'] cart=np.array([data['x'],data['y'],-data['negz']]).transpose() dir= pmag.cart2dir(cart).transpose() data['measurement_dec']=dir[0] data['measurement_inc']=dir[1] data['measurement_magn_volume']=dir[2]*(10.0**data['expon']) # A/m - data in A/m data['measurement_flag']='g' data['measurement_standard']='u' data['measurement_number']='1' data['measurement_temp']='273' data['er_location_name']=er_location_name for rowNum, row in data.iterrows(): MagRec={} spec_text_id=row['specname'].split('_')[1] SampRecs=pmag.get_dictitem(samples,'er_sample_alternatives',spec_text_id,'has') # retrieve sample record for this specimen if len(SampRecs)>0: # found one MagRec['er_specimen_name']=SampRecs[0]['er_sample_name'] MagRec['er_sample_name']=MagRec['er_specimen_name'] MagRec['er_site_name']=MagRec['er_specimen_name'] MagRec["er_citation_names"]="This study" MagRec['er_location_name']=er_location_name MagRec['magic_software_packages']=version_num MagRec["treatment_temp"]='%8.3e' % (273) # room temp in kelvin MagRec["measurement_temp"]='%8.3e' % (273) # room temp in kelvin MagRec["measurement_flag"]='g' MagRec["measurement_standard"]='u' MagRec["measurement_number"]='1' MagRec["treatment_ac_field"]='0' volume=float(SampRecs[0]['sample_volume']) moment=row['measurement_magn_volume'] * volume MagRec["measurement_magn_moment"]=str(moment) MagRec["measurement_magn_volume"]=str(row['measurement_magn_volume']) MagRec["measurement_dec"]='%7.1f'%(row['measurement_dec']) MagRec["measurement_inc"]='%7.1f'%(row['measurement_inc']) if row['step'] == 'NRM': meas_type="LT-NO" elif row['step'][0:2] == 'AD': meas_type="LT-AF-Z" treat=float(row['step'][2:]) MagRec["treatment_ac_field"]='%8.3e' %(treat*1e-3) # convert from mT to tesla elif row['step'][0] == 'TD': meas_type="LT-T-Z" treat=float(row['step'][2:]) MagRec["treatment_temp"]='%8.3e' % (treat+273.) # temp in kelvin elif row['step'][0:3]=='ARM': # meas_type="LT-AF-I" treat=float(row['step'][3:]) MagRec["treatment_ac_field"]='%8.3e' %(treat*1e-3) # convert from mT to tesla MagRec["treatment_dc_field"]='%8.3e' %(50e-6) # assume 50uT DC field MagRec["measurement_description"]='Assumed DC field - actual unknown' elif row['step'][0:3]=='IRM': # meas_type="LT-IRM" treat=float(row['step'][3:]) MagRec["treatment_dc_field"]='%8.3e' %(treat*1e-3) # convert from mT to tesla else: print 'unknown treatment type for ',row return False, 'unknown treatment type for ',row MagRec['magic_method_codes']=meas_type MagRecs.append(MagRec.copy()) else: print 'sample name not found: ',row['specname'] MagOuts=pmag.measurements_methods(MagRecs,noave) file_created, error_message = pmag.magic_write(meas_file,MagOuts,'magic_measurements') if file_created: return True, meas_file else: return False, 'Results not written to file'
def main(): """ NAME LIVMW_magic.py DESCRIPTION converts Liverpool microwave format files to magic_measurements format files SYNTAX LIVMW_magic.py [command line options] OPTIONS -h: prints the help message and quits. -f FILE: specify liverpool format input file, required -usr USER: identify user, default is "" -ins INST: identify instrument, e.g., LIV-TRISTAN, LIV-OLD14GHZ, default is "" -loc LOCNAME : specify location/study name, required -F FILE: specify output file, default is magic_measurements.txt -Fsa FILE: specify er_samples formatted file for appending, default is new er_samples.txt -spc NUM : specify number of characters to designate a specimen, default = 1 -sit Site_name : specify site name for this specimen -unc measurement units are uncalibrated (default is uAm^2) -B PHI THETA: dc lab field phi, theta, default is 0, 90 -ncn NCON: specify naming convention - required if -sit not specified Sample naming convention: do not use if -sit option used! [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. """ # initialize some stuff version_num = pmag.get_version() noave = 0 methcode, instcode = "", "" phi, theta, peakfield, labfield = 0, 0, 0, 0 pMRM, MD, samp_con, Z, site = 0, 0, "6", "", "" er_location_name = "" citation = "This study" args = sys.argv methcode = "LP-NO" # NRM specnum, measnum = 1, 1 powt_max = 0 ErSamps, Samps = [], [] # # get command line arguments # dirpath = "." meas_file, samp_file = dirpath + "/magic_measurements.txt", dirpath + "/er_samples.txt" user = "" unc = 0 if "-WD" in args: ind = args.index("-WD") dirpath = args[ind + 1] if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind = args.index("-usr") user = args[ind + 1] if "-ins" in args: ind = args.index("-ins") instcode = args[ind + 1] if "-F" in args: ind = args.index("-F") meas_file = dirpath + "/" + args[ind + 1] if "-Fsa" in args: ind = args.index("-Fsa") samp_file = args[ind + 1] samp_file = dirpath + "/" + samp_file try: open(samp_file, "rU") ErSamps, file_type = pmag.magic_read(samp_file) print "sample information will be appended to new er_samples.txt file" except: print "er_samples.txt file does not exist" print "sample information will be stored in new er_samples.txt file" if "-f" in args: ind = args.index("-f") magfile = args[ind + 1] magfile = dirpath + "/" + magfile try: input = open(magfile, "rU") except: print "bad mag file name" sys.exit() else: print "mag_file field is required option" print main.__doc__ sys.exit() if "-B" in args: ind = args.index("-B") phi = args[ind + 1] theta = args[ind + 2] else: phi, theta = "0.", "90." if "-spc" in args: ind = args.index("-spc") specnum = int(args[ind + 1]) if specnum != 0: specnum = -specnum if "-loc" in args: ind = args.index("-loc") er_location_name = args[ind + 1] if "-unc" in args: unc = 1 if "-sit" in args: ind = args.index("-sit") site = args[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 samp_con == "6" and site == "": print "you must either specify a naming convention, or a site name" print main.__doc__ sys.exit() MagRecs = [] if len(ErSamps) > 1: for samp in ErSamps: if samp["er_sample_name"] not in Samps: Samps.append(samp["er_sample_name"]) Data = input.readlines() if 1: # never mind for line in Data: if len(line) > 1: rec = line.split(",") MagRec = {} MagRec["er_citation_names"] = "This study" MagRec["er_location_name"] = er_location_name MagRec["magic_software_packages"] = version_num MagRec["treatment_temp"] = "%8.3e" % (273) # room temp in kelvin MagRec["measurement_temp"] = "%8.3e" % (273) # room temp in kelvin MagRec["treatment_ac_field"] = "0" MagRec["treatment_dc_field"] = "0" MagRec["treatment_dc_field_phi"] = "" MagRec["treatment_dc_field_theta"] = "" MagRec["treatment_mw_integral"] = "" meas_type = "LT-NO" MagRec["er_specimen_name"] = rec[0][1:-1] MagRec["er_location_name"] = er_location_name if specnum != 0: MagRec["er_sample_name"] = rec[0][1:-1][:specnum] else: MagRec["er_sample_name"] = rec[0][1:-1] if site == "": site = pmag.parse_site(MagRec["er_sample_name"], samp_con, Z) MagRec["er_site_name"] = site MagRec["treatment_mw_power"] = rec[2] MagRec["treatment_mw_time"] = rec[3] powt = int(float(MagRec["treatment_mw_power"]) * (float(MagRec["treatment_mw_time"]))) MagRec["treatment_mw_energy"] = "%7.1f" % (powt) if powt > powt_max: powt_max = powt treat = rec[1].strip('"').upper() if treat == "Z": # in zero field meas_type = "LT-M-Z" # as opposed to LT-MV-Z if powt < powt_max: meas_type = "LT-PMRM-Z" elif treat == "A": # in zero field meas_type = "LT-M-I" # as opposed to LT-MV-I labfield = float(rec[10]) * 1e-6 # assuming uT, convert to T MagRec["treatment_dc_field"] = "%8.3e" % (labfield) # labfield in tesla (convert from microT) MagRec["treatment_dc_field_phi"] = phi # labfield phi MagRec["treatment_dc_field_theta"] = theta # labfield theta if powt < powt_max: meas_type = "LT-PMRM-I" if len(rec) > 10: MagRec["treatment_mw_integral"] = rec[10] if unc == 0: MagRec["measurement_magn_moment"] = "%10.3e" % (float(rec[4]) * 1e-6) # moment in Am^2 (from uAm^2) if unc == 1: MagRec["measurement_magnitude"] = rec[4] # uncalibrated moment cart = [] cart.append(float(rec[7])) cart.append(float(rec[8])) cart.append(float(rec[9])) dir = pmag.cart2dir(cart) MagRec["measurement_dec"] = "%9.3f" % (dir[0]) MagRec["measurement_inc"] = "%9.3f" % (dir[1]) MagRec["magic_instrument_codes"] = instcode MagRec["magic_method_codes"] = meas_type MagRec["measurement_flag"] = "g" MagRec["measurement_standard"] = "u" MagRec["measurement_number"] = "%i" % (measnum) MagRec["magic_experiment_name"] = MagRec["er_specimen_name"] + ":" + methcode measnum += 1 MagRecs.append(MagRec) if MagRec["er_sample_name"] not in Samps: # add this puppy to the list in er_samples.txt Samps.append(MagRec["er_sample_name"]) ErSamp = {} ErSamp["er_sample_name"] = Samps[-1] ErSamp["er_location_name"] = MagRec["er_location_name"] ErSamp["er_site_name"] = site ErSamp["er_citation_names"] = "This study" gdec = float(rec[5]) ginc = float(rec[6]) az, pl = pmag.get_azpl(dir[0], dir[1], gdec, ginc) ErSamp["sample_azimuth"] = "%7.1f" % az ErSamp["sample_dip"] = "%7.1f" % pl ErSamps.append(ErSamp) MagOuts = pmag.mw_measurements_methods(MagRecs) pmag.magic_write(meas_file, MagOuts, "magic_measurements") print "measurements put in ", meas_file pmag.magic_write(samp_file, ErSamps, "er_samples") print "sample names put in ", samp_file
def main(): """ NAME site_edit_magic.py DESCRIPTION makes equal area projections site by site from pmag_specimens.txt file with Fisher confidence ellipse using McFadden and McElhinny (1988) technique for combining lines and planes allows testing and reject specimens for bad orientations SYNTAX site_edit_magic.py [command line options] OPTIONS -h: prints help and quits -f: specify pmag_specimen format file, default is pmag_specimens.txt -fsa: specify er_samples.txt file -exc: use existing pmag_criteria.txt file -N: reset all sample flags to good OUPUT edited er_samples.txt file """ dir_path='.' FIG={} # plot dictionary FIG['eqarea']=1 # eqarea is figure 1 in_file='pmag_specimens.txt' sampfile='er_samples.txt' out_file="" fmt,plot='svg',1 Crits="" M,N=180.,1 repeat='' renew=0 if '-h' in sys.argv: print main.__doc__ sys.exit() if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] if '-f' in sys.argv: ind=sys.argv.index("-f") in_file=sys.argv[ind+1] if '-fsa' in sys.argv: ind=sys.argv.index("-fsa") sampfile=sys.argv[ind+1] if '-exc' in sys.argv: Crits,file_type=pmag.magic_read(dir_path+'/pmag_criteria.txt') for crit in Crits: if crit['pmag_criteria_code']=='DE-SPEC': M=float(crit['specimen_mad']) N=float(crit['specimen_n']) if '-fmt' in sys.argv: ind=sys.argv.index("-fmt") fmt=sys.argv[ind+1] if '-N' in sys.argv: renew=1 # if in_file[0]!="/":in_file=dir_path+'/'+in_file if sampfile[0]!="/":sampfile=dir_path+'/'+sampfile crd='s' Specs,file_type=pmag.magic_read(in_file) if file_type!='pmag_specimens': print ' bad pmag_specimen input file' sys.exit() Samps,file_type=pmag.magic_read(sampfile) if file_type!='er_samples': print ' bad er_samples input file' sys.exit() SO_methods=[] for rec in Samps: if 'sample_orientation_flag' not in rec.keys(): rec['sample_orientation_flag']='g' if 'sample_description' not in rec.keys(): rec['sample_description']='' if renew==1: rec['sample_orientation_flag']='g' description=rec['sample_description'] if '#' in description: newdesc="" c=0 while description[c]!='#' and c<len(description)-1: # look for first pound sign newdesc=newdesc+description[c] c+=1 while description[c]=='#': c+=1# skip first set of pound signs while description[c]!='#':c+=1 # find second set of pound signs while description[c]=='#' and c<len(description)-1:c+=1 # skip second set of pound signs while c<len(description)-1: # look for first pound sign newdesc=newdesc+description[c] c+=1 rec['sample_description']=newdesc # edit out old comment about orientations if "magic_method_codes" in rec: methlist=rec["magic_method_codes"] for meth in methlist.split(":"): if "SO" in meth.strip() and "SO-POM" not in meth.strip(): if meth.strip() not in SO_methods: SO_methods.append(meth.strip()) pmag.magic_write(sampfile,Samps,'er_samples') SO_priorities=pmag.set_priorities(SO_methods,0) sitelist=[] for rec in Specs: if rec['er_site_name'] not in sitelist: sitelist.append(rec['er_site_name']) sitelist.sort() EQ={} EQ['eqarea']=1 pmagplotlib.plot_init(EQ['eqarea'],5,5) k=0 while k<len(sitelist): site=sitelist[k] print site data=[] ThisSiteSpecs=pmag.get_dictitem(Specs,'er_site_name',site,'T') ThisSiteSpecs=pmag.get_dictitem(ThisSiteSpecs,'specimen_tilt_correction','-1','T') # get all the unoriented data for spec in ThisSiteSpecs: if spec['specimen_mad']!="" and spec['specimen_n']!="" and float(spec['specimen_mad'])<=M and float(spec['specimen_n'])>=N: # good spec, now get orientation.... redo,p=1,0 if len(SO_methods)<=1: az_type=SO_methods[0] orient=pmag.find_samp_rec(spec["er_sample_name"],Samps,az_type) redo=0 while redo==1: if p>=len(SO_priorities): print "no orientation data for ",spec['er_sample_name'] orient["sample_azimuth"]="" orient["sample_dip"]="" redo=0 else: az_type=SO_methods[SO_methods.index(SO_priorities[p])] orient=pmag.find_samp_rec(spec["er_sample_name"],Samps,az_type) if orient["sample_azimuth"] !="": redo=0 p+=1 if orient['sample_azimuth']!="": rec={} for key in spec.keys():rec[key]=spec[key] rec['dec'],rec['inc']=pmag.dogeo(float(spec['specimen_dec']),float(spec['specimen_inc']),float(orient['sample_azimuth']),float(orient['sample_dip'])) rec["tilt_correction"]='1' crd='g' rec['sample_azimuth']=orient['sample_azimuth'] rec['sample_dip']=orient['sample_dip'] data.append(rec) if len(data)>2: print 'specimen, dec, inc, n_meas/MAD,| method codes ' for i in range(len(data)): print '%s: %7.1f %7.1f %s / %s | %s' % (data[i]['er_specimen_name'], data[i]['dec'], data[i]['inc'], data[i]['specimen_n'], data[i]['specimen_mad'], data[i]['magic_method_codes']) fpars=pmag.dolnp(data,'specimen_direction_type') print "\n Site lines planes kappa a95 dec inc" print site, fpars["n_lines"], fpars["n_planes"], fpars["K"], fpars["alpha95"], fpars["dec"], fpars["inc"], fpars["R"] if out_file!="": if float(fpars["alpha95"])<=acutoff and float(fpars["K"])>=kcutoff: out.write('%s %s %s\n'%(fpars["dec"],fpars['inc'],fpars['alpha95'])) pmagplotlib.plotLNP(EQ['eqarea'],site,data,fpars,'specimen_direction_type') pmagplotlib.drawFIGS(EQ) if k!=0 and repeat!='y': ans=raw_input("s[a]ve plot, [q]uit, [e]dit specimens, [p]revious site, <return> to continue:\n ") elif k==0 and repeat!='y': ans=raw_input("s[a]ve plot, [q]uit, [e]dit specimens, <return> to continue:\n ") if ans=="p": k-=2 if ans=="a": files={} files['eqarea']=site+'_'+crd+'_eqarea'+'.'+fmt pmagplotlib.saveP(EQ,files) if ans=="q": sys.exit() if ans=="e" and Samps==[]: print "can't edit samples without orientation file, sorry" elif ans=="e": # k-=1 testspec=raw_input("Enter name of specimen to check: ") for spec in data: if spec['er_specimen_name']==testspec: # first test wrong direction of drill arrows (flip drill direction in opposite direction and re-calculate d,i d,i=pmag.dogeo(float(spec['specimen_dec']),float(spec['specimen_inc']),float(spec['sample_azimuth'])-180.,-float(spec['sample_dip'])) XY=pmag.dimap(d,i) pmagplotlib.plotXY(EQ['eqarea'],[XY[0]],[XY[1]],sym='g^') # first test wrong end of compass (take az-180.) d,i=pmag.dogeo(float(spec['specimen_dec']),float(spec['specimen_inc']),float(spec['sample_azimuth'])-180.,float(spec['sample_dip'])) XY=pmag.dimap(d,i) pmagplotlib.plotXY(EQ['eqarea'],[XY[0]],[XY[1]],sym='kv') # did the sample spin in the hole? # now spin around specimen's z X_up,Y_up,X_d,Y_d=[],[],[],[] for incr in range(0,360,5): d,i=pmag.dogeo(float(spec['specimen_dec'])+incr,float(spec['specimen_inc']),float(spec['sample_azimuth']),float(spec['sample_dip'])) XY=pmag.dimap(d,i) if i>=0: X_d.append(XY[0]) Y_d.append(XY[1]) else: X_up.append(XY[0]) Y_up.append(XY[1]) pmagplotlib.plotXY(EQ['eqarea'],X_d,Y_d,sym='b.') pmagplotlib.plotXY(EQ['eqarea'],X_up,Y_up,sym='c.') pmagplotlib.drawFIGS(EQ) break print "Triangle: wrong arrow for drill direction." print "Delta: wrong end of compass." print "Small circle: wrong mark on sample. [cyan upper hemisphere]" deleteme=raw_input("Mark this sample as bad? y/[n] ") if deleteme=='y': reason=raw_input("Reason: [1] broke, [2] wrong drill direction, [3] wrong compass direction, [4] bad mark, [5] displaced block [6] other ") if reason=='1': description=' sample broke while drilling' if reason=='2': description=' wrong drill direction ' if reason=='3': description=' wrong compass direction ' if reason=='4': description=' bad mark in field' if reason=='5': description=' displaced block' if reason=='6': description=raw_input('Enter brief reason for deletion: ') for samp in Samps: if samp['er_sample_name']==spec['er_sample_name']: samp['sample_orientation_flag']='b' samp['sample_description']=samp['sample_description']+' ## direction deleted because: '+description+'##' # mark description pmag.magic_write(sampfile,Samps,'er_samples') repeat=raw_input("Mark another sample, this site? y/[n] ") if repeat=='y': k-=1 else: print 'skipping site - not enough data with specified coordinate system' k+=1 print "sample flags stored in ",sampfile
def main(command_line=True, **kwargs): """ NAME CIT_magic.py DESCRIPTION converts CIT and .sam format files to magic_measurements format files SYNTAX CIT_magic.py [command line options] OPTIONS -h: prints the help message and quits. -usr USER: identify user, default is "" -f FILE: specify .sam format input file, required -fsi SITEFILE : specify file with site names and locations [tab delimited magic file] -F FILE: specify output measurements file, default is magic_measurements.txt -Fsp FILE: specify output er_specimens.txt file, default is er_specimens.txt -Fsi FILE: specify output er_sites.txt file, default is er_sites.txt -Fsa FILE: specify output er_samples.txt file, default is er_samples.txt # LORI -n [gm,kg,cc,m3]: specify normalization -A: don't average replicate measurements -spc NUM : specify number of characters to designate a specimen, default = 0 -ncn NCON: specify naming convention -loc LOCNAME : specify location/study name, must have either LOCNAME or SITEFILE or be a synthetic -mcd [FS-FD:SO-MAG,.....] colon delimited list for method codes applied to all specimens in .sam file -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 INPUT Best to put separate experiments (all AF, thermal, thellier, trm aquisition, Shaw, etc.) NOTES: 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) [default] [4-Z] XXXXYYY: YYY is sample designation with Z characters from site XXX [5] all others you will have to either customize your self or e-mail [email protected] for help. """ # #initialize variables norm='cc' samp_con,Z='3',1 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=[],[],[],[],[] MeasRecs=[] specnum,units,locname=0,"1","unknown" citation="This study" dir_path='.' args=sys.argv if command_line: if '-WD' in args: ind=args.index("-WD") dir_path=args[ind+1] if "-h" in args: print main.__doc__ return False if "-usr" in args: ind=args.index("-usr") user=args[ind+1] if '-F' in args: ind=args.index("-F") meas_file=args[ind+1] if '-Fsp' in args: ind=args.index("-Fsp") spec_file=args[ind+1] if '-Fsa' in args: ind=args.index("-Fsa") samp_file=args[ind+1] if '-Fsi' in args: # LORI addition ind=args.index("-Fsi") site_file=args[ind+1] if '-loc' in args: ind=args.index("-loc") locname=args[ind+1] if '-mcd' in args: ind=args.index("-mcd") methods=args[ind+1] else: methods='SO-MAG' if '-spc' in args: ind=args.index("-spc") specnum=-int(args[ind+1]) if '-n' in args: ind=args.index("-n") norm=args[ind+1] if "-A" in args: avg=1 else: avg=0 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" return False, "naming convention option [4] must be in form 4-Z where Z is an integer" else: Z=samp_con.split("-")[1] samp_con="4" if '-f' in args: ind=args.index("-f") magfile=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 # LJ # if you are running as a module: elif not command_line: dir_path = kwargs.get('dir_path', '.') user = kwargs.get('user', '') meas_file = kwargs.get('meas_file', 'magic_measurements.txt') # outfile spec_file = kwargs.get('spec_file', 'er_specimens.txt') # specimen outfile samp_file = kwargs.get('samp_file', 'er_samples.txt') # sample outfile site_file = kwargs.get('site_file', 'er_sites.txt') # site outfile locname = kwargs.get('locname', '') methods = kwargs.get('methods', ['SO-MAG']) specnum = -int(kwargs.get('specnum', 0)) norm = kwargs.get('norm', 'cc') avg = kwargs.get('avg', 0) # 0 means do average, 1 means don't samp_con = kwargs.get('samp_con', '3') magfile = kwargs.get('magfile', '') input_dir_path = kwargs.get('input_dir_path', dir_path) output_dir_path = dir_path # done with module-specific stuff # formatting and checking variables 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, "naming convention option [4] must be in form 4-Z where Z is an integer" else: Z=samp_con.split("-")[1] samp_con="4" magfile = os.path.join(input_dir_path, magfile) spec_file = os.path.join(output_dir_path, spec_file) samp_file = os.path.join(output_dir_path, samp_file) site_file = os.path.join(output_dir_path, site_file) meas_file= os.path.join(output_dir_path, meas_file) try: file_input=open(magfile,'r') except Exception as ex: print "bad sam file name: ", magfile return False, "bad sam file name" File = file_input.readlines() sids,ln,format=[],0,'CIT' formats=['CIT','2G','APP','JRA'] ErLocRec={} ErLocRec["er_location_name"]=locname ErLocRec["er_citation_names"]=citation comment=File[ln] if comment=='CIT': format=comment ln+=1 comment=File[ln] print comment ln+=1 specimens,samples,sites=[],[],[] if format=='CIT': line=File[ln].split() site_lat=line[0] site_lon=line[1] ErLocRec["location_begin_lat"]=site_lat ErLocRec["location_begin_lon"]=site_lon ErLocRec["location_end_lat"]=site_lat ErLocRec["location_end_lon"]=site_lon ErLocs.append(ErLocRec) Cdec=float(line[2]) for k in range(ln+1,len(File)): line=File[k] rec=line.split() specimen=rec[0] specimens.append(specimen) for specimen in specimens: ErSpecRec,ErSampRec,ErSiteRec={},{},{} if specnum!=0: sample=specimen[:specnum] else: sample=specimen site=pmag.parse_site(sample,samp_con,Z) ErSpecRec['er_specimen_name']=specimen ErSpecRec['er_sample_name']=sample ErSpecRec['er_site_name']=site ErSpecRec['er_location_name']=locname ErSpecRec['er_citation_names']=citation ErSampRec['er_sample_name']=sample ErSampRec['er_site_name']=site ErSampRec['er_location_name']=locname ErSampRec['er_citation_names']=citation ErSampRec['magic_method_codes']=methods ErSampRec['sample_declination_correction']='%7.1f'%(Cdec) ErSiteRec['er_site_name']=site ErSiteRec['er_location_name']=locname ErSiteRec['er_citation_names']=citation ErSiteRec['site_lat']=site_lat ErSiteRec['site_lon']=site_lon f=open(input_dir_path+'/'+specimen,'rU') Lines=f.readlines() comment="" line=Lines[0].split() if len(line)>2: comment=line[2] info=Lines[1].split() vol=float(info[-1]) if vol!=1.0: if norm=='cc':units="1" if norm=='m3':units="2" ErSpecRec['specimen_weight']="" if units=="1" or "": ErSpecRec['specimen_volume']='%10.3e'%(vol*1e-6) else: ErSpecRec['specimen_volume']='%10.3e'%(vol) else: if norm=='cc':units="1" if norm=='m3':units="2" ErSpecRec['specimen_volume']="" if units=="1" or "": ErSpecRec['specimen_weight']='%10.3e'%(vol*1e-3) else: ErSpecRec['specimen_weight']='%10.3e'%(vol) dip=float(info[-2]) dip_direction=float(info[-3])+Cdec+90. sample_dip=-float(info[-4]) sample_azimuth=float(info[-5])+Cdec-90. if len(info)>5: ErSampRec['sample_height']=info[-6] else: ErSampRec['sample_height']='0' ErSampRec['sample_azimuth']='%7.1f'%(sample_azimuth) ErSampRec['sample_dip']='%7.1f'%(sample_dip) ErSampRec['sample_bed_dip']='%7.1f'%(dip) ErSampRec['sample_bed_dip_direction']='%7.1f'%(dip_direction) ErSampRec['sample_class']='' ErSampRec['sample_type']='' ErSampRec['sample_lithology']='' if Cdec!=0 or Cdec!="": ErSampRec['magic_method_codes']='SO-CMD-NORTH' else: ErSampRec['magic_method_codes']='SO-MAG' for line in Lines[2:len(Lines)]: #print 'line:', line MeasRec=ErSpecRec.copy() # Remove specimen_volume and specimen_weight as they do not exits in the magic_measurement table del MeasRec["specimen_volume"] del MeasRec["specimen_weight"] treat_type=line[0:3] treat=line[3:6] #print 'treat:', treat if treat_type.strip()=='NRM': MeasRec['magic_method_codes']='LT-NO' MeasRec['measurement_temp']='273' MeasRec['treatment_temp']='273' MeasRec['treatment_dc_field']='0' MeasRec['treatment_ac_field']='0' elif treat_type.strip()=='AF': MeasRec['magic_method_codes']='LT-AF-Z' MeasRec['measurement_temp']='273' MeasRec['treatment_temp']='273' MeasRec['treatment_dc_field']='0' if treat == ' ': MeasRec['treatment_ac_field']='0' else: MeasRec['treatment_ac_field']='%10.3e'%(float(treat)*1e-3) elif treat_type.strip()=='TT': MeasRec['magic_method_codes']='LT-T-Z' MeasRec['measurement_temp']='273' if treat == ' ': MeasRec['treatment_temp']='273' else: MeasRec['treatment_temp']='%7.1f'%(float(treat)+273) MeasRec['treatment_dc_field']='0' MeasRec['treatment_ac_field']='0' elif treat_type.strip()=='LT' or treat_type.strip()=='LN2': MeasRec['magic_method_codes']='LT-LT-Z' MeasRec['measurement_temp']='273' MeasRec['treatment_temp']='77' MeasRec['treatment_dc_field']='0' MeasRec['treatment_ac_field']='0' else: print "trouble with your treatment steps" MeasRec['measurement_dec']=line[46:51] MeasRec['measurement_inc']=line[52:58] M='%8.2e'%(float(line[31:39])*vol*1e-3) # convert to Am2 MeasRec['measurement_magn_moment']=M MeasRec['measurement_sd_x']='%8.2e'%(float(line[58:67])*1e-8) #(convert e-5emu to Am2) MeasRec['measurement_sd_y']='%8.2e'%(float(line[67:76])*1e-8) MeasRec['measurement_sd_z']='%8.2e'%(float(line[76:85])*1e-8) MeasRec['measurement_csd']='%7.1f'%(eval(line[41:46])) MeasRec['magic_instrument_codes']=line[85:] MeasRec["measurement_positions"]='1' MeasRec['measurement_standard']='u' MeasRecs.append(MeasRec) ErSpecs.append(ErSpecRec) if sample not in samples: samples.append(sample) ErSamps.append(ErSampRec) site=pmag.parse_site(sample,samp_con,Z) if site not in sites: sites.append(site) ErSites.append(ErSiteRec) pmag.magic_write(spec_file,ErSpecs,'er_specimens') print 'specimens stored in ',spec_file pmag.magic_write(samp_file,ErSamps,'er_samples') print 'samples stored in ',samp_file pmag.magic_write(site_file,ErSites,'er_sites') print 'sites stored in ', site_file Fixed=pmag.measurements_methods(MeasRecs,avg) pmag.magic_write(meas_file,Fixed,'magic_measurements') print 'data stored in ',meas_file 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 CIT_magic.py DESCRIPTION converts CalTech (CIT) .sam format files to magic_measurements format files SYNTAX CIT_magic.py [command line options] OPTIONS -h: prints the help message and quits. -usr USER: identify user, default is "" -f FILE: specify .sam format input file, required -fsi SITEFILE : specify file with site names and locations [tab delimited magic file] -F FILE: specify output measurements file, default is magic_measurements.txt -Fsp FILE: specify output er_specimens.txt file, default is er_specimens.txt -Fsi FILE: specify output er_sites.txt file, default is er_sites.txt -n [gm,kg,cc,m3]: specify normalization -spc NUM : specify number of characters to designate a specimen, default = 0 -ncn NCON: specify naming convention -loc LOCNAME : specify location/study name, must have either LOCNAME or SITEFILE or be a synthetic -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 INPUT Best to put separate experiments (all AF, thermal, thellier, trm aquisition, Shaw, etc.) NOTES: 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. """ # # norm='cc' samp_con,Z='3',1 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=[],[],[],[],[] MeasRecs=[] specnum,units,locname=0,"1","unknown" citation="This study" dir_path='.' args=sys.argv if '-WD' in args: ind=args.index("-WD") dir_path=args[ind+1] if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind=args.index("-usr") user=args[ind+1] if '-F' in args: ind=args.index("-F") meas_file=args[ind+1] if '-Fsp' in args: ind=args.index("-Fsp") spec_file=args[ind+1] if '-Fsa' in args: ind=args.index("-Fsa") samp_file=args[ind+1] if '-loc' in args: ind=args.index("-loc") locname=args[ind+1] if '-spc' in args: ind=args.index("-spc") specnum=-int(args[ind+1]) if '-n' in args: ind=args.index("-n") norm=args[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 '-f' in args: ind=args.index("-f") magfile=args[ind+1] magfile=dir_path+'/'+magfile spec_file=dir_path+'/'+spec_file samp_file=dir_path+'/'+samp_file site_file=dir_path+'/'+site_file meas_file=dir_path+'/'+meas_file try: input=open(magfile,'r') except: print "bad sam file name" sys.exit() File=input.readlines() sids,ln,format=[],0,'CIT' formats=['CIT','2G','APP','JRA'] ErLocRec={} ErLocRec["er_location_name"]=locname ErLocRec["er_citation_name"]=citation comment=File[ln] if comment=='CIT': format=comment ln+=1 comment=File[ln] print comment ln+=1 specimens,samples,sites=[],[],[] if format=='CIT': line=File[ln].split() site_lat=line[0] site_lon=line[1] ErLocRec["location_begin_lat"]=site_lat ErLocRec["location_begin_lon"]=site_lon ErLocRec["location_end_lat"]=site_lat ErLocRec["location_end_lon"]=site_lon ErLocs.append(ErLocRec) Cdec=float(line[2]) if len(line)>4: fa_az=line[3] fa_pl=line[4] if len(line)>6: bed_dip_dir='%7.1f'%(float(line[5]+90.)) bed_dip=line[6] for k in range(ln+1,len(File)): line=File[k] rec=line.split() specimen=rec[0] specimens.append(specimen) else: print 'file type not yet supported' sys.exit() for specimen in specimens: ErSpecRec,ErSampRec,ErSiteRec={},{},{} if specnum!=0: sample=specimen[:specnum] else: sample=specimen site=pmag.parse_site(sample,samp_con,Z) ErSpecRec['er_specimen_name']=specimen ErSpecRec['er_sample_name']=sample ErSpecRec['er_site_name']=site ErSpecRec['er_location_name']=locname ErSpecRec['er_citation_name']=citation ErSampRec['er_sample_name']=sample ErSampRec['er_site_name']=site ErSampRec['er_location_name']=locname ErSampRec['er_citation_name']=citation for k in range(ln+1,len(File)): line=File[k] rec=line.split() specimen=rec[0] specimens.append(specimen) for specimen in specimens: ErSpecRec,ErSampRec,ErSiteRec={},{},{} if specnum!=0: sample=specimen[:specnum] else: sample=specimen site=pmag.parse_site(sample,samp_con,Z) ErSpecRec['er_specimen_name']=specimen ErSpecRec['er_sample_name']=sample ErSpecRec['er_site_name']=site ErSpecRec['er_location_name']=locname ErSpecRec['er_citation_name']=citation ErSampRec['er_sample_name']=sample ErSampRec['er_site_name']=site ErSampRec['er_location_name']=locname ErSampRec['er_citation_name']=citation ErSiteRec['er_site_name']=site ErSiteRec['er_location_name']=locname ErSiteRec['er_citation_name']=citation ErSiteRec['site_lat']=site_lat ErSiteRec['site_lon']=site_lon f=open(dir_path+'/'+specimen,'rU') Lines=f.readlines() comment=Lines[0][10:] if len(line)>2:comment=line[2] info=Lines[1].split() vol=float(info[-1]) if vol!=1.0: if norm=='cc':units="1" if norm=='m3':units="2" ErSampRec['specimen_weight']="" if units=="1" or "": ErSampRec['specimen_volume']='%10.3e'%(vol*1e-6) else: ErSampRec['specimen_volume']='%10.3e'%(vol) else: if norm=='cc':units="1" if norm=='m3':units="2" ErSampRec['specimen_volume']="" if units=="1" or "": ErSampRec['specimen_weight']='%10.3e'%(vol*1e-3) else: ErSampRec['specimen_weight']='%10.3e'%(vol) dip=float(info[-2]) dip_direction=float(info[-3])+Cdec+90. sample_dip=-float(info[-4]) sample_azimuth=float(info[-5])+Cdec-90. if len(info)>5: ErSampRec['sample_height']=info[-6] else: ErSampRec['sample_height']='0' ErSampRec['sample_azimuth']='%7.1f'%(sample_azimuth) ErSampRec['sample_dip']='%7.1f'%(sample_dip) ErSampRec['sample_bed_dip']='%7.1f'%(dip) ErSampRec['sample_bed_dip_direction']='%7.1f'%(dip_direction) ErSampRec['sample_class']='' ErSampRec['sample_type']='' ErSampRec['sample_lithology']='' if Cdec!=0 or Cdec!="": ErSampRec['magic_method_codes']='SO-CMD-NORTH' else: ErSampRec['magic_method_codes']='SO-MAG' for line in Lines[2:len(Lines)-1]: MeasRec=ErSpecRec.copy() treat_type=line[0:3] treat=line[3:6] if treat_type.strip()=='NRM' or treat==" ": MeasRec['magic_method_codes']='LT-NO' MeasRec['measurement_temp']='273' MeasRec['treatment_temp']='273' MeasRec['treatment_dc_field']='0' MeasRec['treatment_ac_field']='0' elif treat_type.strip()=='AF': MeasRec['magic_method_codes']='LT-AF-Z' MeasRec['measurement_temp']='273' MeasRec['treatment_temp']='273' MeasRec['treatment_dc_field']='0' MeasRec['treatment_ac_field']='%10.3e'%(float(treat)*1e-3) elif treat_type.strip()=='TT': MeasRec['magic_method_codes']='LT-T-Z' MeasRec['measurement_temp']='273' MeasRec['treatment_temp']='%7.1f'%(float(treat)+273) MeasRec['treatment_dc_field']='0' MeasRec['treatment_ac_field']='0' else: print "trouble with your treatment steps" MeasRec['measurement_dec']=line[46:51] MeasRec['measurement_inc']=line[52:58] int='%8.2e'%(float(line[31:39])*vol*1e-3) # convert to Am2 MeasRec['measurement_magn_moment']=int MeasRec['measurement_x_sd']='%8.2e'%(float(line[58:67])*1e-8) #(convert e-5emu to Am2) MeasRec['measurement_y_sd']='%8.2e'%(float(line[67:76])*1e-8) MeasRec['measurement_z_sd']='%8.2e'%(float(line[76:85])*1e-8) MeasRec['measurement_csd']='%7.1f'%(eval(line[41:46])) MeasRec['magic_instrument_codes']=line[85:] MeasRecs.append(MeasRec) ErSpecs.append(ErSpecRec) if sample not in samples: samples.append(sample) ErSamps.append(ErSampRec) site=pmag.parse_site(sample,samp_con,Z) if site not in sites: sites.append(site) ErSites.append(ErSiteRec) pmag.magic_write(spec_file,ErSpecs,'er_specimens') print 'specimens stored in ',spec_file pmag.magic_write(samp_file,ErSamps,'er_samples') print 'samples stored in ',samp_file pmag.magic_write(site_file,ErSites,'er_sites') Fixed=pmag.measurements_methods(MeasRecs,0) pmag.magic_write(meas_file,Fixed,'magic_measurements') print 'data stored in ',meas_file
def main(): """ NAME MsT_magic.py DESCRIPTION converts MsT data (T,M) to magic_measurements format files SYNTAX MsT_magic.py [command line options] OPTIONS -h: prints the help message and quits. -usr USER: identify user, default is "" -f FILE: specify T,M format input file, required -fsa SFILE: name with sample, site, location information -F FILE: specify output file, default is MsT_measurements.txt -dc H: specify applied field during measurement, default is 0.5 T -syn : This is a synthetic specimen and has no sample/site/location information -spn SPEC: specimen name -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 -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. INPUT files: T M: T is in Centigrade and M is uncalibrated magnitude """ # initialize some stuff samp_con,Z="1","0" dir_path='.' citation='This study' args=sys.argv specnum,measnum=0,1 # # get command line arguments # user="" if '-WD' in args: ind=args.index("-WD") dir_path=args[ind+1] meas_file=dir_path+"/MsT_measurements.txt" if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind=args.index("-usr") user=args[ind+1] labfield='0.5' if "-dc" in args: ind=args.index("-dc") labfield=args[ind+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] Samps,file_type=pmag.magic_read(samp_file) if '-f' in args: ind=args.index("-f") infile=dir_path+'/'+args[ind+1] try: input=open(infile,'rU') except: print "bad mag file name" sys.exit() else: print main.__doc__ print "-f is required option" sys.exit() if "-spc" in args: ind=args.index("-spc") specnum=int(args[ind+1]) if specnum!=0:specnum=-specnum er_location_name,syn,specimen_name='unknown',0,'unknown' if "-loc" in args: ind=args.index("-loc") er_location_name=args[ind+1] if "-spn" in args: ind=args.index("-spn") specimen_name=args[ind+1] else: print main.__doc__ print "-spn is required option" sys.exit() if "-syn" in args: syn=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" samp_con=sys.argv[ind+1] 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" MagRecs,specs=[],[] version_num=pmag.get_version() data=input.readlines() T0=float(data[0].split()[0]) for line in data: instcode="" if len(line)>1: MagRec={} if syn==0: MagRec['er_location_name']=er_location_name MagRec['magic_software_packages']=version_num MagRec["treatment_dc_field"]=labfield rec=line.split() T=float(rec[0]) MagRec["measurment_temp"]='%8.3e' % (float(rec[0])+273.) # temp in kelvin if T>T0: MagRec["magic_method_codes"]='LP-MW-I' elif T<T0: MagRec["magic_method_codes"]='LP-MC-I' T0=T else: print 'skipping repeated temperature step' MagRec["magic_method_codes"]='' T0=T MagRec["measurement_magnitude"]='%10.3e'% (float(rec[1])) # uncalibrated magnitude if syn==0: MagRec["er_specimen_name"]=specimen_name MagRec["er_site_name"]="" if specnum!=0: MagRec["er_sample_name"]=specimen_name[:specnum] else: MagRec["er_sample_name"]=specimen_name if "-fsa" in args: for samp in Samps: if samp["er_sample_name"] == MagRec["er_sample_name"]: MagRec["er_location_name"]=samp["er_location_name"] MagRec["er_site_name"]=samp["er_site_name"] break elif int(samp_con)!=6: site=pmag.parse_site(MagRec['er_sample_name'],samp_con,Z) MagRec["er_site_name"]=site if MagRec['er_site_name']=="": print 'No site name found for: ',MagRec['er_specimen_name'],MagRec['er_sample_name'] if MagRec["er_location_name"]=="": print 'no location name for: ',MagRec["er_specimen_name"] else: MagRec["er_synthetic_name"]=specimen_name MagRec["er_location_name"]="" MagRec["er_sample_name"]="" MagRec["er_site_name"]="" MagRec["er_specimen_name"]="" MagRec["magic_instrument_codes"]=instcode MagRec["er_analyst_mail_names"]=user MagRec["er_citation_names"]=citation MagRec["measurement_flag"]='g' MagRec["measurement_number"]=str(measnum) measnum+=1 MagRecs.append(MagRec) for rec in MagRecs: # sort out the measurements by experiment type rec['magic_experiment_name']=specimen_name if rec['magic_method_codes']=='LP-MW-I': rec["magic_experiment_name"]=specimen_name+':LP-MW-I:Curie' elif rec['magic_method_codes']=='LP-MC-I': rec["magic_experiment_name"]=specimen_name+':LP-MC-I' pmag.magic_write(meas_file,MagRecs,'magic_measurements') print "results put in ",meas_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 save_redo(SpecRecs,inspec): SpecRecs,keys=pmag.fillkeys(SpecRecs) pmag.magic_write(inspec,SpecRecs,'pmag_specimens')
def main(): """ NAME FLA_magic.py DESCRIPTION import data files from the Univ. Florida, Gainesvile format to magic SYNTAX FLA_magic.py """ if '-h' in sys.argv: print main.__doc__ sys.exit() meas_type,methcode,instcode,experiment_name,izzi="LT-NO","","","",0 phi,theta,peakfield,labfield=0,0,0,0 pTRM,MD,ispec=0,0,0 dec=[315,225,180,135,45,90,270,270,270,90,180,180,0,0,0] inc=[0,0,0,0,0,-45,-45,0,45,45,45,-45,-90,-45,45] er_location_name=raw_input("Enter the location name for this study, or <return> for none ") if er_location_name=="": er_sites_file=raw_input("Enter site location file name, or <return> for none ") if er_sites_file=="": er_location_name="none" else: site_locations,file_type=pmag.magic_read(er_sites_file) magfile=raw_input("Enter florida measurement filename for processing ") print "Enter whether [A]F or [T]hermal de-(re)magnetization " ans=raw_input(" <return> for NRMs only ") inst="" methcode="LT-NO" if ans=="A": inst="UFG-AF" methcode="LT-AF-Z" if ans=="T": inst="UFG-thermal" methcode="LT-T-Z" if ans=="":methcode="LT-NO" input=open(magfile,'r') MagRecs=[] for line in input.readlines(): print line 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"]='%8.3e' %(peakfield) # peak field in tesla MagRec["treatment_dc_field"]='%8.3e' %(labfield) # lab field in tesla MagRec["treatment_dc_field_phi"]='%7.1f' %(phi) MagRec["treatment_dc_field_theta"]='%7.1f'% (theta) rec=line.split() MagRec["er_specimen_name"]=rec[0] MagRec["er_sample_name"]=rec[0] sitetmp=rec[0].split('.') # Florida naming convention splits on '.' between site and sample MagRec["er_site_name"]=sitetmp[0] MagRec["er_location_name"]="none" if er_location_name!="": MagRec["er_location_name"]=er_location_name else: for site in site_locations: if site["er_site_name"] == MagRec["er_site_name"]: MagRec["er_location_name"]=site["er_location_name"] if inst=="UFG-AF": MagRec["treatment_ac_field"]='%8.3e' % ( float(rec[1])*1e-4) # AF field in tesla from Oersted in Florida convention meas_type="LT-AF-Z" MagRec["treatment_dc_field"]='0' else: MagRec["treatment_temp"]='%8.3e' % (float(rec[1])+273.) # temp in kelvin meas_type="LT-T-Z" MagRec["measurement_magn_moment"]='%10.3e'% ((float(rec[4])/100)*1e-5) # moment in Am^2 (from 50xA/m and assuming 5cc sample in Florida convention) MagRec["measurement_dec"]=rec[7] MagRec["measurement_inc"]=rec[8] MagRec["magic_method_codes"]=meas_type MagRecs.append(MagRec) output=raw_input("Filename for output [magic_measurements.txt] ") if output=="":output="magic_measurements.txt" MagOuts=pmag.measurements_methods(MagRecs,0) pmag.magic_write(output,MagOuts,'magic_measurements') print "results put in ",output
def main(): """ NAME UCSC_leg_magic.py DESCRIPTION converts UCSC legacy format files to magic_measurements format files SYNTAX UCSC_leg_magic.py [command line options] OPTIONS -h: prints the help message and quits. -usr USER: identify user, default is "" -f FILE: specify input file, or -fin INDEX: specify index file for reading whole directory: default is index.txt -F FILE: specify output file, default is magic_measurements.txt -Fsa: specify er_samples format file for appending, default is new er_samples.txt -spc NUM : specify number of characters to designate a specimen, default = 1 -loc LOCNAME : specify location/study name -A: don't average replicate measurements Sample naming convention: [1] XXXXY: where XXXX is an arbitrary length site designation and Y is the single character sample designation. e.g., TG001a is the first sample from site TG001. [default] [2] XXXX-YY: YY sample from site XXXX (XXX, YY of arbitary length) [3] XXXX.YY: YY sample from site XXXX (XXX, YY of arbitary length) [4-Z] XXXXYYY: YYY is sample designation with Z characters from site XXX [5] sample = site [6] all others you will have to either customize your self or e-mail [email protected] for help. INPUT Format of UCSC legacy files: Spec Treat CDec CInc GDec GInc SDec SInc Int [optional A95] Treat is HX where X is AF field in Oe, TX where X is T in C, or NRM Intensity assumed to be total moment in (emu/cc) with a 10cc specimen volume CDec: Declination in specimen coordinate system CInc: Declination in specimen coordinate system GDec: Declination in geographic coordinate system GInc: Declination in geographic coordinate system SDec: Declination in stratigraphic coordinate system SInc: Declination in stratigraphic coordinate system index file: must be formatted: FILENAME SITE """ # initialize some stuff noave=0 methcode,inst="","" samp_con,Z='4',3 missing=1 demag="N" er_location_name="" citation='This study' args=sys.argv methcode="LP-NO" specnum=-1 MagRecs=[] version_num=pmag.get_version() Samps=[] # keeps track of sample orientations DIspec=[] MagFiles=[] # # get command line arguments # user="" mag_file="" ind_file="" dir_path='.' ErSamps,ErSites=[],[] if '-WD' in sys.argv: ind = sys.argv.index('-WD') dir_path=sys.argv[ind+1] samp_file=dir_path+'/er_samples.txt' site_file=dir_path+'/er_sites.txt' meas_file=dir_path+"/magic_measurements.txt" if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind=args.index("-usr") user=args[ind+1] if '-F' in args: ind=args.index("-F") meas_file=dir_path+'/'+args[ind+1] if '-Fsi' in args: ind=args.index("-Fsi") site_file=dirpath+'.'+args[ind+1] try: open(site_file,'rU') ErSites,file_type=pmag.magic_read(site_file) print 'site information will be appended to ', site_file except: print site_file,' not found: site information will be stored in new er_sites.txt file' site_file=dir_path+'/er_sites.txt' if '-Fsa' in args: ind=args.index("-Fsa") samp_file=dirpath+'/'+args[ind+1] try: open(samp_file,'rU') ErSamps,file_type=pmag.magic_read(samp_file) print 'sample information will be appended to ', samp_file except: print samp_file,' not found: sample information will be stored in new er_samples.txt file' samp_file=dir_path+'/er_samples.txt' if '-f' in args: ind=args.index("-f") mag_file=args[ind+1] site=mag_file.split('.')[0] magfile=dir_path+'/'+mag_file try: input=open(magfile,'rU') MagFiles.append([magfile,site]) except: print "bad input file name" sys.exit() elif '-fin' in args: ind=args.index("-fin") ind_file=args[ind+1] ind_file=dir_path+'/'+ind_file try: index_file=open(ind_file,'rU') except: print "bad index file name" sys.exit() elif '-fin' not in args: ind_file=dir_path+'/index.txt' try: index_file=open(ind_file,'rU') except: print "bad index file name" sys.exit() if ind_file!="": Files=index_file.readlines() for file in Files: rec=file.split() MagFiles.append(rec) if "-spc" in args: ind=args.index("-spc") specnum=int(args[ind+1]) if specnum!=0:specnum=-specnum if "-loc" in args: ind=args.index("-loc") er_location_name=args[ind+1] else: print "-loc is required option" print main.__doc__ sys.exit() if "-A" in args: noave=1 Sites=[] for file in MagFiles: site=file[1] # attach site name either from file name or from index file if site not in Sites: Sites.append(site) ErSiteRec={'er_location_name': er_location_name,'er_site_name':site,'er_citation_names':citation,'site_definition':'s','site_lat':'','site_lon':"",'site_class':"",'site_lithology':"",'site_type':""} ErSites.append(ErSiteRec) print 'processing file: ',file[0],' for site: ',site data=open(dir_path+'/'+file[0],'rU').readlines() # read in data from file firstrec=data[0].split() if firstrec[0]=='FILE': # this file has a header, must look for start of data for k in range(len(data)): if data[k][0]=='-': break else: k=-1 while k<len(data)-1: k+=1 line=data[k] if len(line)>2: # skip stupid terminal lines line=line.replace(' T ',' T') # make columns consistent line=line.replace(' H ',' H') # make columns consistent line=line.replace(' T ',' T') # make columns consistent line=line.replace(' H ',' H') # make columns consistent rec=line.split() if len(rec)<2: break # skip junk MagRec={} MagRec['er_location_name']=er_location_name MagRec['magic_software_packages']=version_num MagRec["treatment_temp"]='%8.3e' % (273) # room temp in kelvin MagRec["measurement_temp"]='%8.3e' % (273) # room temp in kelvin MagRec["treatment_ac_field"]='0' meas_type="LT-NO" MagRec["measurement_flag"]='g' MagRec["measurement_standard"]='u' MagRec["measurement_number"]='1' MagRec["er_specimen_name"]=rec[0] if specnum!=0: MagRec["er_sample_name"]=rec[0][:specnum] else: MagRec["er_sample_name"]=rec[0] # site=pmag.parse_site(MagRec['er_sample_name'],samp_con,Z) MagRec["er_site_name"]=site MagRec["measurement_magn_moment"]='%10.3e'% (float(rec[8])*1e-4) # # int is in emu/cc; assuming 10cc, this converts to Am^2 # if samp_file!="" and MagRec["er_sample_name"] not in Samps: # create er_samples.txt file with these data cdec,cinc=float(rec[2]),float(rec[3]) gdec,ginc=float(rec[4]),float(rec[5]) az,pl=pmag.get_azpl(cdec,cinc,gdec,ginc) bdec,binc=float(rec[6]),float(rec[7]) if rec[4]!=rec[6] and rec[5]!=rec[7]: dipdir,dip=pmag.get_tilt(gdec,ginc,bdec,binc) else: dipdir,dip=0,0 ErSampRec={} ErSampRec['er_citation_names']='This study' ErSampRec['er_location_name']=MagRec['er_location_name'] ErSampRec['er_site_name']=MagRec['er_site_name'] ErSampRec['er_sample_name']=MagRec['er_sample_name'] ErSampRec['sample_azimuth']='%7.1f'%(az) ErSampRec['sample_dip']='%7.1f'%(pl) ErSampRec['sample_bed_dip_direction']='%7.1f'%(dipdir) ErSampRec['sample_bed_dip']='%7.1f'%(dip) ErSampRec['sample_description']='az,pl,dip_dir and dip recalculated from [c,g,b][dec,inc] in UCSC legacy file' ErSampRec['magic_method_codes']='SO-NO' ErSamps.append(ErSampRec) Samps.append(ErSampRec['er_sample_name']) MagRec["measurement_dec"]=rec[2] MagRec["measurement_inc"]=rec[3] MagRec["er_analyst_mail_names"]="" MagRec["er_citation_names"]="This study" demag=rec[1][0] if demag!='N': treat=float(rec[1][1:]) else: treat=0 if demag=="H": MagRec["treatment_ac_field"]='%8.3e' %(treat*1e-4) # convert from oe to tesla meas_type="LT-AF-Z" elif demag=="T": MagRec["treatment_temp"]='%8.3e' % (treat+273.) # 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 "results put in ",meas_file pmag.magic_write(samp_file,ErSamps,'er_samples') print "sample orientations put in ",samp_file pmag.magic_write(site_file,ErSites,'er_sites') print "site names put in ",site_file
def main(): """ NAME generic_magic.py DESCRIPTION converts magnetometer files in generic format to magic_measurements format SYNTAX generic_magic.py [command line options] OPTIONS -h prints the help message and quits. -usr USER identify user, default is "" -f FILE: specify path to input file, required -fsa SAMPFILE: specify er_samples.txt file for sample orientation data. default is er_samples.txt -F FILE specify output file, default is magic_measurements.txt ???-Fsy: specify er_synthetics file, default is er_sythetics.txt #-Fsa: # specify output er_samples file, default is NONE -exp EXPERIMENT-TYPE Demag: AF and/or Thermal PI: paleointenisty thermal experiment (ZI/IZ/IZZI) ATRM n: ATRM in n positions AARM n: AARM in n positions CR: cooling rate experiment The treatment coding of the measurement file should be: XXX.00,XXX.10, XXX.20 ...XX.70 etc. (XXX.00 is optional) where XXX in the temperature and .10,.20... are running numbers of the cooling rates steps. XXX.00 is optional zerofield baseline. XXX.70 is alteration check. syntax in sio_magic is: -LP CR xxx,yyy,zzz,.....xx -A where xx, yyy,zzz...xxx are cooling rates in [K/minutes], seperated by comma, ordered at the same order as XXX.10,XXX.20 ...XX.70 No need to specify the cooling rate for the zerofield It is important to add to the command line the -A option so the measurements will not be evraged. But users need to make sure that there are no duplicate meaurements in the file NLT: non-linear-TRM experiment -samp X Y specimen-sample naming convention. X=0 Y=n: specimen is distiguished from sample by n initial characters. (example: if n=4 then and specimen = mgf13a then sample = mgf13) X=1 Y=n: specimen is distiguished from sample by n terminate characters. (example: if n=1 then and specimen = mgf13a then sample = mgf13) X=2 Y=c: specimen is distiguishing from sample by a delimiter. (example: if c=- then annd specimen = mgf13-a then sample = mgf13) -site X Y sample-site naming convention. X=0 Y=n: sample is distiguished from site by n initial characters. (example: if n=3 then and sample = mgf13 then sample = mgf) X=1 Y=n: sample is distiguished from site by n terminate characters. (example: if n=2 and sample = mgf13 then site = mgf) X=2 Y=c: specimen is distiguishing from sample by a delimiter. (example: if c='-' and sample = 'mgf-13' then site = mgf) -loc LOCNAM specify location/study name. -dc B PHI THETA: B: dc lab field (in micro tesla) PHI (declination). takes numbers from 0 to 360 THETA (inclination). takes numbers from -90 to 90 NB: use PHI, THETA = -1 -1 to signal that it changes, i.e. in anisotropy experiment. -A: don't average replicate measurements. Take the last measurement from replicate measurements. -WD working directory INPUT A generic file is a tab-delimited file. Each columns should have a header. The file must include the follwing headers. The order of the columns is not important. specimen: string specifying specimen name treatment: a number with one or two decimal point (X.Y) coding for thermal demagnetization: 0.0 or 0 is NRM. X is temperature in celcsius Y is always 0 coding for AF demagnetization: 0.0 or 0 is NRM. X is AF peak field in mT Y is always 0 coding for Thellier-type experiment: 0.0 or 0 is NRM X is temperature in celcsius Y=0: zerofield Y=1: infield Y=2: pTRM check Y=3: pTRM tail check Y=4: Additivity check # Ron, Add also 5 for Thellier protocol treatment_type: N: NRM A: AF T: Thermal moment: magnetic moment in emu !! In addition. at least one of the following headers are requiered: dec_s: declination in specimen coordinate system (0 to 360) inc_s: inclination in specimen coordinate system (-90 to 90) Testing: 1) make a genetric file with AF 2) make a genetric file with Thermal 3) make a genetric file with Thermal + AF 4) make a genetric file with IZZI 5) check duplicates option """ #-------------------------------------- # functions #-------------------------------------- def sort_magic_file(path,ignore_lines_n,sort_by_this_name): ''' reads a file with headers. Each line is stored as a dictionary following the headers. Lines are sorted in DATA by the sort_by_this_name header DATA[sort_by_this_name]=[dictionary1,dictionary2,...] ''' DATA={} fin=open(path,'rU') #ignore first lines for i in range(ignore_lines_n): fin.readline() #header line=fin.readline() header=line.strip('\n').split('\t') #print header for line in fin.readlines(): if line[0]=="#": continue tmp_data={} tmp_line=line.strip('\n').split('\t') #print tmp_line for i in range(len(tmp_line)): if i>= len(header): continue tmp_data[header[i]]=tmp_line[i] DATA[tmp_data[sort_by_this_name]]=tmp_data fin.close() return(DATA) def read_generic_file(path,average_replicates): ''' reads a generic file format. If average_replicates==True average replicate measurements. Rrturns a Data dictionary with measurements line sorted by specimen Data[specimen_name][dict1,dict2,...] ''' Data={} Fin=open(path,'rU') header=Fin.readline().strip('\n').split('\t') duplicates=[] for line in Fin.readlines(): tmp_data={} #found_duplicate=False l=line.strip('\n').split('\t') for i in range(min(len(header),len(l))): tmp_data[header[i]]=l[i] specimen=tmp_data['specimen'] if specimen not in Data.keys(): Data[specimen]=[] Data[specimen].append(tmp_data) # search fro duplicates for specimen in Data.keys(): x=len(Data[specimen])-1 new_data=[] duplicates=[] for i in range(1,x): while i< len(Data[specimen]) and Data[specimen][i]['treatment']==Data[specimen][i-1]['treatment'] and Data[specimen][i]['treatment_type']==Data[specimen][i-1]['treatment_type']: duplicates.append(Data[specimen][i]) del(Data[specimen][i]) if len(duplicates)>0: if average_replicates: duplicates.append(Data[specimen][i-1]) Data[specimen][i-1]=average_duplicates(duplicates) print "-W- WARNING: averaging %i duplicates for specimen %s treatmant %s"%(len(duplicates),specimen,duplicates[-1]['treatment']) duplicates=[] else: Data[specimen][i-1]=duplicates[-1] print "-W- WARNING: found %i duplicates for specimen %s treatmant %s. Taking the last measurement only"%(len(duplicates),specimen,duplicates[-1]['treatment']) duplicates=[] if i==len(Data[specimen])-1: break # if tmp_data['treatment']==Data[specimen][-1]['treatment'] and tmp_data['treatment_type']==Data[specimen][-1]['treatment_type']: # ## check replicates #if tmp_data['treatment']==Data[specimen][-1]['treatment'] and tmp_data['treatment_type']==Data[specimen][-1]['treatment_type']: # #found_duplicate=True # duplicates.append(Data[specimen][-1]) # duplicates.append(tmp_data) # del(Data[specimen][-1]) # continue #else: # if len(duplicates)>0: # if average_replicates: # Data[specimen].append(average_duplicates(duplicates)) # print "-W- WARNING: averaging %i duplicates for specimen %s treatmant %s"%(len(duplicates),specimen,duplicates[-1]['treatment']) # else: # Data[specimen].append(duplicates[-1]) # print "-W- WARNING: found %i duplicates for specimen %s treatmant %s. Taking the last measurement only"%(len(duplicates),specimen,duplicates[-1]['treatment']) # duplicates=[] # Data[specimen].append(tmp_data) return(Data) def average_duplicates(duplicates): ''' avarage replicate measurements. ''' carts_s,carts_g,carts_t=[],[],[] for rec in duplicates: moment=float(rec['moment']) if 'dec_s' in rec.keys() and 'inc_s' in rec.keys(): if rec['dec_s']!="" and rec['inc_s']!="": dec_s=float(rec['dec_s']) inc_s=float(rec['inc_s']) cart_s=pmag.dir2cart([dec_s,inc_s,moment]) carts_s.append(cart_s) if 'dec_g' in rec.keys() and 'inc_g' in rec.keys(): if rec['dec_g']!="" and rec['inc_g']!="": dec_g=float(rec['dec_g']) inc_g=float(rec['inc_g']) cart_g=pmag.dir2cart([dec_g,inc_g,moment]) carts_g.append(cart_g) if 'dec_t' in rec.keys() and 'inc_t' in rec.keys(): if rec['dec_t']!="" and rec['inc_t']!="": dec_t=float(rec['dec_t']) inc_t=float(rec['inc_t']) cart_t=pmag.dir2cart([dec_t,inc_t,moment]) carts_t.append(cart_t) if len(carts_s)>0: carts=scipy.array(carts_s) x_mean=scipy.mean(carts[:,0]) y_mean=scipy.mean(carts[:,1]) z_mean=scipy.mean(carts[:,2]) mean_dir=pmag.cart2dir([x_mean,y_mean,z_mean]) mean_dec_s="%.2f"%mean_dir[0] mean_inc_s="%.2f"%mean_dir[1] mean_moment="%10.3e"%mean_dir[2] else: mean_dec_s,mean_inc_s="","" if len(carts_g)>0: carts=scipy.array(carts_g) x_mean=scipy.mean(carts[:,0]) y_mean=scipy.mean(carts[:,1]) z_mean=scipy.mean(carts[:,2]) mean_dir=pmag.cart2dir([x_mean,y_mean,z_mean]) mean_dec_g="%.2f"%mean_dir[0] mean_inc_g="%.2f"%mean_dir[1] mean_moment="%10.3e"%mean_dir[2] else: mean_dec_g,mean_inc_g="","" if len(carts_t)>0: carts=scipy.array(carts_t) x_mean=scipy.mean(carts[:,0]) y_mean=scipy.mean(carts[:,1]) z_mean=scipy.mean(carts[:,2]) mean_dir=pmag.cart2dir([x_mean,y_mean,z_mean]) mean_dec_t="%.2f"%mean_dir[0] mean_inc_t="%.2f"%mean_dir[1] mean_moment="%10.3e"%mean_dir[2] else: mean_dec_t,mean_inc_t="","" meanrec={} for key in duplicates[0].keys(): if key in ['dec_s','inc_s','dec_g','inc_g','dec_t','inc_t','moment']: continue else: meanrec[key]=duplicates[0][key] meanrec['dec_s']=mean_dec_s meanrec['dec_g']=mean_dec_g meanrec['dec_t']=mean_dec_t meanrec['inc_s']=mean_inc_s meanrec['inc_g']=mean_inc_g meanrec['inc_t']=mean_inc_t meanrec['moment']=mean_moment return meanrec def get_upper_level_name(name,nc): ''' get sample/site name from specimen/sample using naming convention ''' if float(nc[0])==0: if float(nc[1])!=0: number_of_char=int(nc[1]) high_name=name[:number_of_char] else: high_name=name elif float(nc[0])==1: if float(nc[1])!=0: number_of_char=int(nc[1])*-1 high_name=name[:number_of_char] else: high_name=name elif float(nc[0])==2: d=str(nc[1]) name_splitted=name.split(d) if len(name_splitted)==1: high_name=name_splitted[0] else: high_name=d.join(name_splitted[:-1]) else: high_name=name return high_name def merge_pmag_recs(old_recs): recs={} recs=copy.deepcopy(old_recs) headers=[] for rec in recs: for key in rec.keys(): if key not in headers: headers.append(key) for rec in recs: for header in headers: if header not in rec.keys(): rec[header]="" return recs #-------------------------------------- # get command line arguments #-------------------------------------- args=sys.argv user="" if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind=args.index("-usr") user=args[ind+1] else: user="" if '-F' in args: ind=args.index("-F") meas_file=args[ind+1] if '-Fsa' in args: ind=args.index("-Fsa") samp_file=args[ind+1] else: samp_file="er_samples.txt" if '-f' in args: ind=args.index("-f") magfile=args[ind+1] try: input=open(magfile,'rU') except: print "bad mag file:",magfile sys.exit() else: print "mag_file field is required option" print main.__doc__ sys.exit() if "-dc" in args: ind=args.index("-dc") labfield=float(args[ind+1])*1e-6 labfield_phi=float(args[ind+2]) labfield_theta=float(args[ind+3]) if '-exp' in args: ind=args.index("-exp") experiment=args[ind+1] else: print "-LP is required option" print main.__doc__ sys.exit() if experiment=='ATRM': ind=args.index("ATRM") atrm_n_pos=int(args[ind+1]) if experiment=='AARM': ind=args.index("AARM") aarm_n_pos=int(args[ind+1]) if experiment=='CR': ind=args.index("CR") coolling_times=args[ind+1] coolling_times_list=coolling_times.split(',') if "-samp" in args: ind=args.index("-samp") sample_nc=[] sample_nc.append(args[ind+1]) sample_nc.append(args[ind+2]) if "-site" in args: ind=args.index("-site") site_nc=[] site_nc.append(args[ind+1]) site_nc.append(args[ind+2]) if "-loc" in args: ind=args.index("-loc") er_location_name=args[ind+1] else: er_location_name="" if "-A" in args: noave=1 else: noave=0 if "-WD" in args: ind=args.index("-WD") WD=args[ind+1] os.chdir(WD) #-------------------------------------- # read data from er_samples.txt #-------------------------------------- #if "-fsa" in args: # ind=args.index("-fsa") # er_sample_file=args[ind+1] #else: # er_sample_file="er_samples.txt" er_sample_data={} #er_sample_data=sort_magic_file(samp_file,1,'er_sample_name') try: er_sample_data=sort_magic_file(samp_file,1,'er_sample_name') print "-I- Found er_samples.txt" print '-I- sample information will be appended to existing er_samples.txt file' except: print "-I- Cant find file er_samples.txt" print '-I- sample information will be stored in new er_samples.txt file' #-------------------------------------- # read data from generic file #-------------------------------------- if noave: mag_data=read_generic_file(magfile,False) else: mag_data=read_generic_file(magfile,True) #-------------------------------------- # for each specimen get the data, and translate it to MagIC format #-------------------------------------- ErSamplesRecs=[] MagRecs=[] specimens_list=mag_data.keys() specimens_list.sort() for specimen in specimens_list: measurement_running_number=0 this_specimen_treatments=[] # a list of all treatments MagRecs_this_specimen=[] LP_this_specimen=[] # a list of all lab protocols IZ,ZI=0,0 # counter for IZ and ZI steps for meas_line in mag_data[specimen]: #------------------ # trivial MagRec data #------------------ MagRec={} MagRec['er_citation_names']="This study" MagRec["er_specimen_name"]=meas_line['specimen'] MagRec["er_sample_name"]=get_upper_level_name(MagRec["er_specimen_name"],sample_nc) MagRec["er_site_name"]=get_upper_level_name(MagRec["er_sample_name"],site_nc) MagRec['er_location_name']=er_location_name MagRec['er_analyst_mail_names']=user MagRec["magic_instrument_codes"]="" MagRec["measurement_flag"]='g' MagRec["measurement_number"]="%i"%measurement_running_number MagRec["measurement_magn_moment"]='%10.3e'%(float(meas_line["moment"])*1e-3) # in Am^2 MagRec["measurement_temp"]='273.' # room temp in kelvin #------------------ # decode treatments from treatment column in the generic file #------------------ treatment=[] treatment_code=str(meas_line['treatment']).split(".") treatment.append(float(treatment_code[0])) if len(treatment_code)==1: treatment.append(0) else: treatment.append(float(treatment_code[1])) #------------------ # lab field direction #------------------ if experiment in ['PI','NLT','CR']: if float(treatment[1])==0: MagRec["treatment_dc_field"]="0" MagRec["treatment_dc_field_phi"]="0" MagRec["treatment_dc_field_theta"]="0" else: MagRec["treatment_dc_field"]='%8.3e'%(float(labfield)) MagRec["treatment_dc_field_phi"]="%.2f"%(float(labfield_phi)) MagRec["treatment_dc_field_theta"]="%.2f"%(float(labfield_theta)) else: MagRec["treatment_dc_field"]="" MagRec["treatment_dc_field_phi"]="" MagRec["treatment_dc_field_theta"]="" #------------------ # treatment temperature/peak field #------------------ if experiment == 'Demag': if meas_line['treatment_type']=='A': MagRec['treatment_temp']="273." MagRec["treatment_ac_field"]="%.3e"%(treatment[0]*1e-3) elif meas_line['treatment_type']=='N': MagRec['treatment_temp']="273." MagRec["treatment_ac_field"]="" else: MagRec['treatment_temp']="%.2f"%(treatment[0]+273.) MagRec["treatment_ac_field"]="" else: MagRec['treatment_temp']="%.2f"%(treatment[0]+273.) MagRec["treatment_ac_field"]="" #--------------------- # Lab treatment # Lab protocol #--------------------- #--------------------- # Lab treatment and lab protocoal for NRM: #--------------------- if float(meas_line['treatment'])==0: LT="LT-NO" LP="" # will be filled later after finishing reading all measurements line #--------------------- # Lab treatment and lab protocoal for paleointensity experiment #--------------------- elif experiment =='PI': LP="LP-PI-TRM" if treatment[1]==0: LT="LT-T-Z" elif treatment[1]==1 or treatment[1]==10: # infield LT="LT-T-I" elif treatment[1]==2 or treatment[1]==20: # pTRM check LT="LT-PTRM-I" LP=LP+":"+"LP-PI-ALT-PTRM" elif treatment[1]==3 or treatment[1]==30: # Tail check LT="LT-PTRM-MD" LP=LP+":"+"LP-PI-BT-MD" elif treatment[1]==4 or treatment[1]==40: # Additivity check LT="LT-PTRM-AC" LP=LP+":"+"LP-PI-BT-MD" else: print "-E- unknown measurement code specimen %s treatmemt %s"%(meas_line['specimen'],meas_line['treatment']) MagRec={} continue # save all treatment in a list # we will use this later to distinguidh between ZI / IZ / and IZZI this_specimen_treatments.append(float(meas_line['treatment'])) if LT=="LT-T-Z": if float(treatment[0]+0.1) in this_specimen_treatments: LP=LP+":"+"LP-PI-IZ" if LT=="LT-T-I": if float(treatment[0]+0.0) in this_specimen_treatments: LP=LP+":"+"LP-PI-ZI" #--------------------- # Lab treatment and lab protocoal for demag experiment #--------------------- elif "Demag" in experiment: if meas_line['treatment_type']=='A': LT="LT-AF-Z" LP="LP-DIR-AF" else: LT="LT-T-Z" LP="LP-DIR-T" #--------------------- # Lab treatment and lab protocoal for ATRM experiment #--------------------- elif experiment in ['ATRM','AARM']: if experiment=='ATRM': LP="LP-AN-TRM" n_pos=atrm_n_pos if n_pos!=6: print "the program does not support ATRM in %i position."%n_pos continue if experiment=='AARM': #MagRec['treatment_temp']="273." #MagRec["treatment_ac_field"]="" LP="LP-AN-ARM" n_pos=aarm_n_pos if n_pos!=6: print "the program does not support AARM in %i position."%n_pos continue if treatment[1]==0: if experiment=='ATRM': LT="LT-T-Z" MagRec['treatment_temp']="%.2f"%(treatment[0]+273.) MagRec["treatment_ac_field"]="" else: LT="LT-AF-Z" MagRec['treatment_temp']="273." MagRec["treatment_ac_field"]="%.3e"%(treatment[0]*1e-3) MagRec["treatment_dc_field"]='0' MagRec["treatment_dc_field_phi"]='0' MagRec["treatment_dc_field_theta"]='0' else: if experiment=='ATRM': if float(treatment[1])==70 or float(treatment[1])==7: # alteration check as final measurement LT="LT-PTRM-I" else: LT="LT-T-I" else: LT="LT-AF-I" MagRec["treatment_dc_field"]='%8.3e'%(float(labfield)) # find the direction of the lab field in two ways: # (1) using the treatment coding (XX.1=+x, XX.2=+y, XX.3=+z, XX.4=-x, XX.5=-y, XX.6=-z) tdec=[0,90,0,180,270,0,0,90,0] tinc=[0,0,90,0,0,-90,0,0,90] if treatment[1] < 10: ipos_code=int(treatment[1])-1 else: ipos_code=int(treatment[1]/10)-1 # (2) using the magnetization if meas_line["dec_s"]!="": DEC=float(meas_line["dec_s"]) INC=float(meas_line["inc_s"]) elif meas_line["dec_g"]!="": DEC=float(meas_line["dec_g"]) INC=float(meas_line["inc_g"]) elif meas_line["dec_t"]!="": DEC=float(meas_line["dec_t"]) INC=float(meas_line["inc_t"]) if DEC<0 and DEC>-359: DEC=360.+DEC if INC < 45 and INC > -45: if DEC>315 or DEC<45: ipos_guess=0 if DEC>45 and DEC<135: ipos_guess=1 if DEC>135 and DEC<225: ipos_guess=3 if DEC>225 and DEC<315: ipos_guess=4 else: if INC >45: ipos_guess=2 if INC <-45: ipos_guess=5 # prefer the guess over the code ipos=ipos_guess # check it if treatment[1]!= 7 and treatment[1]!= 70: if ipos_guess!=ipos_code: print "-W- WARNING: check specimen %s step %s, anistropy measurements, coding does not match the direction of the lab field"%(specimen,meas_line['treatment']) MagRec["treatment_dc_field_phi"]='%7.1f' %(tdec[ipos]) MagRec["treatment_dc_field_theta"]='%7.1f'% (tinc[ipos]) #--------------------- # Lab treatment and lab protocoal for cooling rate experiment #--------------------- elif experiment == "CR": coolling_times_list LP="LP-CR-TRM" MagRec["treatment_temp"]='%8.3e' % (float(treatment[0])+273.) # temp in kelvin if treatment[1]==0: LT="LT-T-Z" MagRec["treatment_dc_field"]="0" MagRec["treatment_dc_field_phi"]='0' MagRec["treatment_dc_field_theta"]='0' else: if treatment[1]==7: # alteration check as final measurement LT="LT-PTRM-I" else: LT="LT-T-I" MagRec["treatment_dc_field"]='%8.3e'%(labfield) MagRec["treatment_dc_field_phi"]='%7.1f' % (labfield_phi) # labfield phi MagRec["treatment_dc_field_theta"]='%7.1f' % (labfield_theta) # labfield theta indx=int(treatment[1])-1 # alteration check matjed as 0.7 in the measurement file if indx==6: cooling_time= coolling_times_list[-1] else: cooling_time=coolling_times_list[indx] MagRec["measurement_description"]="cooling_rate"+":"+cooling_time+":"+"K/min" #--------------------- # Lab treatment and lab protocoal for NLT experiment #--------------------- elif 'NLT' in experiment : print "Dont support yet NLT rate experiment file. Contact [email protected]" #--------------------- # magic_method_codes for this measurement only # LP will be fixed after all measurement lines are read #--------------------- MagRec["magic_method_codes"]=LT+":"+LP #--------------------- # Demag experiments only: # search if orientation data exists in er_samples.txt # if not: create one and save #--------------------- # see if core azimuth and tilt-corrected data are in er_samples.txt sample=MagRec["er_sample_name"] found_sample_azimuth,found_sample_dip,found_sample_bed_dip_direction,found_sample_bed_dip=False,False,False,False if sample in er_sample_data.keys(): if "sample_azimuth" in er_sample_data[sample].keys() and er_sample_data[sample]['sample_azimuth'] !="": sample_azimuth=float(er_sample_data[sample]['sample_azimuth']) found_sample_azimuth=True if "sample_dip" in er_sample_data[sample].keys() and er_sample_data[sample]['sample_dip']!="": sample_dip=float(er_sample_data[sample]['sample_dip']) found_sample_dip=True if "sample_bed_dip_direction" in er_sample_data[sample].keys() and er_sample_data[sample]['sample_bed_dip_direction']!="": sample_bed_dip_direction=float(er_sample_data[sample]['sample_bed_dip_direction']) found_sample_bed_dip_direction=True if "sample_bed_dip" in er_sample_data[sample].keys() and er_sample_data[sample]['sample_bed_dip']!="": sample_bed_dip=float(er_sample_data[sample]['sample_bed_dip']) found_sample_bed_dip=True else: er_sample_data[sample]={} #-------------------- # deal with specimen orientation and different coordinate system #-------------------- found_s,found_geo,found_tilt=False,False,False if "dec_s" in meas_line.keys() and "inc_s" in meas_line.keys(): if meas_line["dec_s"]!="" and meas_line["inc_s"]!="": found_s=True MagRec["measurement_dec"]=meas_line["dec_s"] MagRec["measurement_inc"]=meas_line["inc_s"] if "dec_g" in meas_line.keys() and "inc_g" in meas_line.keys(): if meas_line["dec_g"]!="" and meas_line["inc_g"]!="": found_geo=True if "dec_t" in meas_line.keys() and "inc_t" in meas_line.keys(): if meas_line["dec_t"]!="" and meas_line["inc_t"]!="": found_tilt=True #----------------------------- # specimen coordinates: no # geographic coordinates: yes #----------------------------- if found_geo and not found_s: MagRec["measurement_dec"]=meas_line["dec_g"] MagRec["measurement_inc"]=meas_line["inc_g"] # core azimuth/plunge is not in er_samples.txt if not found_sample_dip or not found_sample_azimuth: er_sample_data[sample]['sample_azimuth']="0" er_sample_data[sample]['sample_dip']="0" # core azimuth/plunge is in er_samples.txt else: sample_azimuth=float(er_sample_data[sample]['sample_azimuth']) sample_dip=float(er_sample_data[sample]['sample_dip']) if sample_azimuth!=0 and sample_dip!=0: print "-W- WARNING: delete core azimuth/plunge in er_samples.txt\n\ becasue dec_s and inc_s are unavaialable" #----------------------------- # specimen coordinates: no # geographic coordinates: no #----------------------------- if not found_geo and not found_s: print "-E- ERROR: sample %s does not have dec_s/inc_s or dec_g/inc_g. Ignore specimen %s "%(sample,specimen) break #----------------------------- # specimen coordinates: yes # geographic coordinates: yes # # commant: Ron, this need to be tested !! #----------------------------- if found_geo and found_s: cdec,cinc=float(meas_line["dec_s"]),float(meas_line["inc_s"]) gdec,ginc=float(meas_line["dec_g"]),float(meas_line["inc_g"]) az,pl=pmag.get_azpl(cdec,cinc,gdec,ginc) # core azimuth/plunge is not in er_samples.txt: # calculate core az/pl and add it to er_samples.txt if not found_sample_dip or not found_sample_azimuth: er_sample_data[sample]['sample_azimuth']="%.1f"%az er_sample_data[sample]['sample_dip']="%.1f"%pl # core azimuth/plunge is in er_samples.txt else: if float(er_sample_data[sample]['sample_azimuth'])!= az: print "-E- ERROR in sample_azimuth sample %s. Check it! using the value in er_samples.txt"%sample if float(er_sample_data[sample]['sample_dip'])!= pl: print "-E- ERROR in sample_dip sample %s. Check it! using the value in er_samples.txt"%sample #----------------------------- # specimen coordinates: yes # geographic coordinates: no #----------------------------- if not found_geo and found_s: if found_sample_dip and found_sample_azimuth: pass # (nothing to do) else: if "Demag" in experiment: print "-W- WARNING: missing sample_dip or sample_azimuth for sample %s"%sample #----------------------------- # tilt-corrected coordinates: yes # geographic coordinates: no #----------------------------- if found_tilt and not found_geo: print "-E- ERROR: missing geographic data for sample %s. Ignoring tilt-corrected data "%sample if found_tilt and found_geo: dec_geo,inc_geo=float(meas_line["dec_g"]),float(meas_line["inc_g"]) dec_tilt,inc_tilt=float(meas_line["dec_t"]),float(meas_line["inc_t"]) if dec_geo==dec_tilt and inc_geo==inc_tilt: DipDir,Dip=0.,0. else: DipDir,Dip=pmag.get_tilt(dec_geo,inc_geo,dec_tilt,inc_tilt) if not found_sample_bed_dip_direction or not found_sample_bed_dip: print "-I- calculating dip and dip direction used for tilt correction sample %s. results are put in er_samples.txt"%sample er_sample_data[sample]['sample_bed_dip_direction']="%.1f"%DipDir er_sample_data[sample]['sample_bed_dip']="%.1f"%Dip #----------------------------- # er_samples method codes # geographic coordinates: no #----------------------------- if found_tilt or found_geo: er_sample_data[sample]['magic_method_codes']="SO-NO" #----------------- # er_samples_data #----------------- if sample in er_sample_data.keys(): er_sample_data[sample]['er_sample_name']=sample er_sample_data[sample]['er_site_name']=MagRec["er_site_name"] er_sample_data[sample]['er_location_name']=MagRec["er_location_name"] #MagRec["magic_method_codes"]=LT MagRecs_this_specimen.append(MagRec) #if LP!="" and LP not in LP_this_specimen: # LP_this_specimen.append(LP) measurement_running_number+=1 #------- #------- # after reading all the measurements lines for this specimen # 1) add magic_experiment_name # 2) fix magic_method_codes with the correct lab protocol #------- LP_this_specimen=[] for MagRec in MagRecs_this_specimen: magic_method_codes=MagRec["magic_method_codes"].split(":") for code in magic_method_codes: if "LP" in code and code not in LP_this_specimen: LP_this_specimen.append(code) # check IZ/ZI/IZZI if "LP-PI-ZI" in LP_this_specimen and "LP-PI-IZ" in LP_this_specimen: LP_this_specimen.remove("LP-PI-ZI") LP_this_specimen.remove("LP-PI-IZ") LP_this_specimen.append("LP-PI-BT-IZZI") # add the right LP codes and fix experiment name for MagRec in MagRecs_this_specimen: MagRec["magic_experiment_name"]=MagRec["er_specimen_name"]+":"+":".join(LP_this_specimen) magic_method_codes=MagRec["magic_method_codes"].split(":") LT="" for code in magic_method_codes: if code[:3]=="LT-": LT=code; break MagRec["magic_method_codes"]=LT+":"+":".join(LP_this_specimen) MagRecs.append(MagRec) #-- # write magic_measurements.txt #-- MagRecs_fixed=merge_pmag_recs(MagRecs) pmag.magic_write(meas_file,MagRecs_fixed,'magic_measurements') print "-I- MagIC file is saved in %s"%meas_file #-- # write er_samples.txt #-- ErSamplesRecs=[] samples=er_sample_data.keys() samples.sort() for sample in samples: ErSamplesRecs.append(er_sample_data[sample]) ErSamplesRecs_fixed=merge_pmag_recs(ErSamplesRecs) pmag.magic_write("er_samples.txt",ErSamplesRecs_fixed,'er_samples')
def main(): """ NAME CIT_magic.py DESCRIPTION converts CIT and .sam format files to magic_measurements format files SYNTAX CIT_magic.py [command line options] OPTIONS -h: prints the help message and quits. -usr USER: identify user, default is "" -f FILE: specify .sam format input file, required -fsi SITEFILE : specify file with site names and locations [tab delimited magic file] -F FILE: specify output measurements file, default is magic_measurements.txt -Fsp FILE: specify output er_specimens.txt file, default is er_specimens.txt -Fsi FILE: specify output er_sites.txt file, default is er_sites.txt -Fsa FILE: specify output er_samples.txt file, default is er_samples.txt # LORI -n [gm,kg,cc,m3]: specify normalization -A: don't average replicate measurements -spc NUM : specify number of characters to designate a specimen, default = 0 -ncn NCON: specify naming convention -loc LOCNAME : specify location/study name, must have either LOCNAME or SITEFILE or be a synthetic -mcd [FS-FD:SO-MAG,.....] colon delimited list for method codes applied to all specimens in .sam file -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 INPUT Best to put separate experiments (all AF, thermal, thellier, trm aquisition, Shaw, etc.) NOTES: 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) [default] [4-Z] XXXXYYY: YYY is sample designation with Z characters from site XXX [5] all others you will have to either customize your self or e-mail [email protected] for help. """ # # norm = 'cc' samp_con, Z = '3', 1 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 = [], [], [], [], [] MeasRecs = [] specnum, units, locname = 0, "1", "unknown" citation = "This study" dir_path = '.' args = sys.argv if '-WD' in args: ind = args.index("-WD") dir_path = args[ind + 1] if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind = args.index("-usr") user = args[ind + 1] if '-F' in args: ind = args.index("-F") meas_file = args[ind + 1] if '-Fsp' in args: ind = args.index("-Fsp") spec_file = args[ind + 1] if '-Fsa' in args: ind = args.index("-Fsa") samp_file = args[ind + 1] if '-Fsi' in args: # LORI addition ind = args.index("-Fsi") site_file = args[ind + 1] if '-loc' in args: ind = args.index("-loc") locname = args[ind + 1] if '-mcd' in args: ind = args.index("-mcd") methods = args[ind + 1] else: methods = 'SO-MAG' if '-spc' in args: ind = args.index("-spc") specnum = -int(args[ind + 1]) if '-n' in args: ind = args.index("-n") norm = args[ind + 1] if "-A" in args: avg = 1 else: avg = 0 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 3-Z where Z is an integer" sys.exit() else: Z = samp_con.split("-")[1] samp_con = "4" if '-f' in args: ind = args.index("-f") magfile = args[ind + 1] # LJ 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 # LJ magfile = input_dir_path + '/' + magfile spec_file = output_dir_path + '/' + spec_file samp_file = output_dir_path + '/' + samp_file site_file = output_dir_path + '/' + site_file meas_file = output_dir_path + '/' + meas_file try: input = open(magfile, 'r') except Exception as ex: print "bad sam file name" sys.exit() File = input.readlines() sids, ln, format = [], 0, 'CIT' formats = ['CIT', '2G', 'APP', 'JRA'] ErLocRec = {} ErLocRec["er_location_name"] = locname ErLocRec["er_citation_name"] = citation comment = File[ln] if comment == 'CIT': format = comment ln += 1 comment = File[ln] print comment ln += 1 specimens, samples, sites = [], [], [] if format == 'CIT': line = File[ln].split() site_lat = line[0] site_lon = line[1] ErLocRec["location_begin_lat"] = site_lat ErLocRec["location_begin_lon"] = site_lon ErLocRec["location_end_lat"] = site_lat ErLocRec["location_end_lon"] = site_lon ErLocs.append(ErLocRec) Cdec = float(line[2]) for k in range(ln + 1, len(File)): line = File[k] rec = line.split() specimen = rec[0] specimens.append(specimen) for specimen in specimens: ErSpecRec, ErSampRec, ErSiteRec = {}, {}, {} if specnum != 0: sample = specimen[:specnum] else: sample = specimen site = pmag.parse_site(sample, samp_con, Z) ErSpecRec['er_specimen_name'] = specimen ErSpecRec['er_sample_name'] = sample ErSpecRec['er_site_name'] = site ErSpecRec['er_location_name'] = locname ErSpecRec['er_citation_name'] = citation ErSampRec['er_sample_name'] = sample ErSampRec['er_site_name'] = site ErSampRec['er_location_name'] = locname ErSampRec['er_citation_name'] = citation ErSampRec['magic_method_codes'] = methods ErSampRec['sample_declination_correction'] = '%7.1f' % (Cdec) ErSiteRec['er_site_name'] = site ErSiteRec['er_location_name'] = locname ErSiteRec['er_citation_name'] = citation ErSiteRec['site_lat'] = site_lat ErSiteRec['site_lon'] = site_lon f = open(input_dir_path + '/' + specimen, 'rU') Lines = f.readlines() comment = "" line = Lines[0].split() if len(line) > 2: comment = line[2] info = Lines[1].split() vol = float(info[-1]) if vol != 1.0: if norm == 'cc': units = "1" if norm == 'm3': units = "2" ErSampRec['specimen_weight'] = "" if units == "1" or "": ErSampRec['specimen_volume'] = '%10.3e' % (vol * 1e-6) else: ErSampRec['specimen_volume'] = '%10.3e' % (vol) else: if norm == 'cc': units = "1" if norm == 'm3': units = "2" ErSampRec['specimen_volume'] = "" if units == "1" or "": ErSampRec['specimen_weight'] = '%10.3e' % (vol * 1e-3) else: ErSampRec['specimen_weight'] = '%10.3e' % (vol) dip = float(info[-2]) dip_direction = float(info[-3]) + Cdec + 90. sample_dip = -float(info[-4]) sample_azimuth = float(info[-5]) + Cdec - 90. if len(info) > 5: ErSampRec['sample_height'] = info[-6] else: ErSampRec['sample_height'] = '0' ErSampRec['sample_azimuth'] = '%7.1f' % (sample_azimuth) ErSampRec['sample_dip'] = '%7.1f' % (sample_dip) ErSampRec['sample_bed_dip'] = '%7.1f' % (dip) ErSampRec['sample_bed_dip_direction'] = '%7.1f' % (dip_direction) ErSampRec['sample_class'] = '' ErSampRec['sample_type'] = '' ErSampRec['sample_lithology'] = '' if Cdec != 0 or Cdec != "": ErSampRec['magic_method_codes'] = 'SO-CMD-NORTH' else: ErSampRec['magic_method_codes'] = 'SO-MAG' for line in Lines[2:len(Lines) - 1]: MeasRec = ErSpecRec.copy() treat_type = line[0:3] treat = line[3:6] if treat_type.strip( ) == 'NRM' or treat == ' ': # reverting back. otherwise breaks examples. MeasRec['magic_method_codes'] = 'LT-NO' MeasRec['measurement_temp'] = '273' MeasRec['treatment_temp'] = '273' MeasRec['treatment_dc_field'] = '0' MeasRec['treatment_ac_field'] = '0' elif treat_type.strip() == 'AF': MeasRec['magic_method_codes'] = 'LT-AF-Z' MeasRec['measurement_temp'] = '273' MeasRec['treatment_temp'] = '273' MeasRec['treatment_dc_field'] = '0' MeasRec['treatment_ac_field'] = '%10.3e' % (float(treat) * 1e-3) elif treat_type.strip() == 'TT': MeasRec['magic_method_codes'] = 'LT-T-Z' MeasRec['measurement_temp'] = '273' MeasRec['treatment_temp'] = '%7.1f' % (float(treat) + 273) MeasRec['treatment_dc_field'] = '0' MeasRec['treatment_ac_field'] = '0' elif treat_type.strip() == 'LT' or treat_type.strip() == 'LN2': MeasRec['magic_method_codes'] = 'LT-LT-Z' MeasRec['measurement_temp'] = '273' MeasRec['treatment_temp'] = '77' MeasRec['treatment_dc_field'] = '0' MeasRec['treatment_ac_field'] = '0' else: print "trouble with your treatment steps" MeasRec['measurement_dec'] = line[46:51] MeasRec['measurement_inc'] = line[52:58] M = '%8.2e' % (float(line[31:39]) * vol * 1e-3) # convert to Am2 MeasRec['measurement_magn_moment'] = M MeasRec['measurement_x_sd'] = '%8.2e' % ( float(line[58:67]) * 1e-8) #(convert e-5emu to Am2) MeasRec['measurement_y_sd'] = '%8.2e' % (float(line[67:76]) * 1e-8) MeasRec['measurement_z_sd'] = '%8.2e' % (float(line[76:85]) * 1e-8) MeasRec['measurement_csd'] = '%7.1f' % (eval(line[41:46])) MeasRec['magic_instrument_codes'] = line[85:] MeasRec["measurement_positions"] = '1' MeasRecs.append(MeasRec) ErSpecs.append(ErSpecRec) if sample not in samples: samples.append(sample) ErSamps.append(ErSampRec) site = pmag.parse_site(sample, samp_con, Z) if site not in sites: sites.append(site) ErSites.append(ErSiteRec) pmag.magic_write(spec_file, ErSpecs, 'er_specimens') print 'specimens stored in ', spec_file pmag.magic_write(samp_file, ErSamps, 'er_samples') print 'samples stored in ', samp_file pmag.magic_write(site_file, ErSites, 'er_sites') print 'sites stored in ', site_file Fixed = pmag.measurements_methods(MeasRecs, avg) pmag.magic_write(meas_file, Fixed, 'magic_measurements') print 'data stored in ', meas_file
def main(): """ NAME thellier_magic_redo.py DESCRIPTION Calculates paleointensity parameters for thellier-thellier type data using bounds stored in the "redo" file SYNTAX thellier_magic_redo [command line options] OPTIONS -h prints help message -usr USER: identify user, default is "" -fcr CRIT, set criteria for grading -f IN: specify input file, default is magic_measurements.txt -fre REDO: specify redo file, default is "thellier_redo" -F OUT: specify output file, default is thellier_specimens.txt -leg: attaches "Recalculated from original measurements; supercedes published results. " to comment field -CR PERC TYPE: apply a cooling rate correction. PERC should be a percentage of original (say reduce to 90%) TYPE should be one of the following: EG (for educated guess); PS (based on pilots); TRM (based on comparison of two TRMs) -Fcr CRout: specify pmag_specimen format file for cooling rate corrected data -ANI: there are anisotropy data to correct thellier results -fan ANIFILE: specify rmag_anisotropy format file, default is rmag_anisotropy.txt -Fac ACout: specify pmag_specimen format file for anisotropy corrected data default is AC_specimens.txt -NLT: there are non-linear trm data in the measurements file to correct thellier results -fnl NLTFILE: specify magic_measurments format file, default is magic_measurements.txt -Fnl NLTout: specify pmag_specimen format file for non-linear trm corrected data default is NLT_specimens.txt -z use z component differenences for pTRM calculation """ dir_path='.' critout="" version_num=pmag.get_version() field,first_save=-1,1 spec,recnum,start,end=0,0,0,0 frac=0 NltRecs,PmagSpecs,AniSpecRecs,NltSpecRecs,CRSpecs=[],[],[],[],[] meas_file,pmag_file,mk_file="magic_measurements.txt","thellier_specimens.txt","thellier_redo" anis_file="rmag_anisotropy.txt" anisout,nltout="AC_specimens.txt","NLT_specimens.txt" crout="CR_specimens.txt" nlt_file="" comment,user="","unknown" anis,nltrm=0,0 jackknife=0 # maybe in future can do jackknife args=sys.argv Zdiff=0 if '-WD' in args: ind=args.index('-WD') dir_path=args[ind+1] if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind=args.index("-usr") user=sys.argv[ind+1] if "-leg" in args: comment="Recalculated from original measurements; supercedes published results. " if "-CR" in args: ind=args.index("-CR") frac=.01*float(sys.argv[ind+1]) crtype=sys.argv[ind+2] if "-Fcr" in args: ind=args.index("-Fcr") crout=sys.argv[ind+1] if "-f" in args: ind=args.index("-f") meas_file=sys.argv[ind+1] if "-F" in args: ind=args.index("-F") pmag_file=sys.argv[ind+1] if "-fre" in args: ind=args.index("-fre") mk_file=args[ind+1] # # if "-ANI" in args: anis=1 ind=args.index("-ANI") if "-Fac" in args: ind=args.index("-Fac") anisout=args[ind+1] if "-fan" in args: ind=args.index("-fan") anis_file=args[ind+1] # if "-NLT" in args: nltrm=1 if "-Fnl" in args: ind=args.index("-Fnl") nltout=args[ind+1] if "-fnl" in args: ind=args.index("-fnl") nlt_file=args[ind+1] if "-z" in args: Zdiff=1 if '-fcr' in sys.argv: ind=args.index("-fcr") critout=sys.argv[ind+1] # # start reading in data: # meas_file=dir_path+"/"+meas_file mk_file=dir_path+"/"+mk_file critout=dir_path+"/"+critout try: open(critout,'rU') accept_keys=['specimen_int_ptrm_n','specimen_md','specimen_fvds','specimen_b_beta','specimen_dang','specimen_drats','specimen_Z'] crit_data,file_type=pmag.magic_read(critout) 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]) except: critout="" # no acceptance criteria specified meas_data,file_type=pmag.magic_read(meas_file) if file_type != 'magic_measurements': print file_type print file_type,"This is not a valid magic_measurements file " sys.exit() try: mk_f=open(mk_file,'rU') except: print "Bad redo file" sys.exit() mkspec=[] speclist=[] for line in mk_f.readlines(): tmp=line.split() mkspec.append(tmp) speclist.append(tmp[0]) if anis==1: anis_file=dir_path+"/"+anis_file anis_data,file_type=pmag.magic_read(anis_file) if file_type != 'rmag_anisotropy': print file_type print file_type,"This is not a valid rmag_anisotropy file " sys.exit() if nlt_file=="": nlt_data=meas_data # look for trm acquisition data in the meas_data file else: nlt_file=dir_path+"/"+nlt_file nlt_data,file_type=pmag.magic_read(nlt_file) # # sort the specimen names and step through one by one # sids=pmag.get_specs(meas_data) # print 'Processing ',len(speclist),' specimens - please wait ' while spec < len(speclist): s=speclist[spec] recnum=0 datablock=[] PmagSpecRec={} PmagSpecRec["er_analyst_mail_names"]=user PmagSpecRec["er_citation_names"]="This study" PmagSpecRec["magic_software_packages"]=version_num methcodes,inst_code=[],"" # # find the data from the meas_data file for this specimen # for rec in meas_data: if rec["er_specimen_name"].lower()==s.lower(): if "magic_instrument_codes" not in rec.keys(): rec["magic_instrument_codes"]="unknown" meths=rec["magic_method_codes"] for meth in meths:meth.strip() # get rid of annoying spaces in method codes if "LP-PI-TRM" in meths: datablock.append(rec) # # collect info for the PmagSpecRec dictionary # if len(datablock)>0: rec=datablock[0] PmagSpecRec["er_specimen_name"]=s PmagSpecRec["er_sample_name"]=rec["er_sample_name"] PmagSpecRec["er_site_name"]=rec["er_site_name"] PmagSpecRec["er_location_name"]=rec["er_location_name"] PmagSpecRec["measurement_step_unit"]="K" PmagSpecRec["specimen_correction"]='u' if "magic_instrument_codes" not in rec.keys(): PmagSpecRec["magic_instrument_codes"]="unknown" else: PmagSpecRec["magic_instrument_codes"]=rec["magic_instrument_codes"] if "magic_experiment_name" not in rec.keys(): rec["magic_experiment_name"]="" else: PmagSpecRec["magic_experiment_names"]=rec["magic_experiment_name"] meths=rec["magic_experiment_name"].split(":") for meth in meths: if meth.strip() not in methcodes and "LP-" in meth:methcodes.append(meth.strip()) # # sort out the data into first_Z, first_I, ptrm_check, ptrm_tail # araiblock,field=pmag.sortarai(datablock,s,Zdiff) first_Z=araiblock[0] first_I=araiblock[1] ptrm_check=araiblock[2] ptrm_tail=araiblock[3] if len(first_I)<3 or len(first_Z)<4: spec+=1 print 'skipping specimen ', s else: # # get start, end # for redospec in mkspec: if redospec[0]==s: b,e=float(redospec[1]),float(redospec[2]) break if e > float(first_Z[-1][0]):e=float(first_Z[-1][0]) for recnum in range(len(first_Z)): if first_Z[recnum][0]==b:start=recnum if first_Z[recnum][0]==e:end=recnum nsteps=end-start if nsteps>2: zijdblock,units=pmag.find_dmag_rec(s,meas_data) pars,errcode=pmag.PintPars(araiblock,zijdblock,start,end) pars['measurement_step_unit']=units pars["specimen_lab_field_dc"]=field pars["specimen_int"]=-1*field*pars["specimen_b"] PmagSpecRec["measurement_step_min"]='%8.3e' % (pars["measurement_step_min"]) PmagSpecRec["measurement_step_max"]='%8.3e' % (pars["measurement_step_max"]) PmagSpecRec["specimen_int_n"]='%i'%(pars["specimen_int_n"]) PmagSpecRec["specimen_lab_field_dc"]='%8.3e'%(pars["specimen_lab_field_dc"]) PmagSpecRec["specimen_int"]='%9.4e '%(pars["specimen_int"]) PmagSpecRec["specimen_b"]='%5.3f '%(pars["specimen_b"]) PmagSpecRec["specimen_q"]='%5.1f '%(pars["specimen_q"]) PmagSpecRec["specimen_f"]='%5.3f '%(pars["specimen_f"]) PmagSpecRec["specimen_fvds"]='%5.3f'%(pars["specimen_fvds"]) PmagSpecRec["specimen_b_beta"]='%5.3f'%(pars["specimen_b_beta"]) PmagSpecRec["specimen_int_mad"]='%7.1f'%(pars["specimen_int_mad"]) PmagSpecRec["specimen_Z"]='%7.1f'%(pars["specimen_Z"]) PmagSpecRec["specimen_gamma"]='%7.1f'%(pars["specimen_gamma"]) if pars["method_codes"]!="" and pars["method_codes"] not in methcodes: methcodes.append(pars["method_codes"]) PmagSpecRec["specimen_dec"]='%7.1f'%(pars["specimen_dec"]) PmagSpecRec["specimen_inc"]='%7.1f'%(pars["specimen_inc"]) PmagSpecRec["specimen_tilt_correction"]='-1' PmagSpecRec["specimen_direction_type"]='l' PmagSpecRec["direction_type"]='l' # this is redudant, but helpful - won't be imported PmagSpecRec["specimen_dang"]='%7.1f '%(pars["specimen_dang"]) PmagSpecRec["specimen_drats"]='%7.1f '%(pars["specimen_drats"]) PmagSpecRec["specimen_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["magic_software_packages"]=version_num PmagSpecRec["specimen_description"]=comment if critout!="": score,kill=pmag.grade(PmagSpecRec,accept) Grade="" if score==len(accept.keys()):Grade='A' if score==len(accept.keys())-1:Grade='B' if score==len(accept.keys())-2:Grade='C' if score==len(accept.keys())-3:Grade='D' if score<=len(accept.keys())-4:Grade='F' PmagSpecRec["specimen_grade"]=Grade else: PmagSpecRec["specimen_grade"]="" if nltrm==0 and anis==0 and frac!=0: # apply cooling rate correction CrSpecRec={} for key in PmagSpecRec.keys():CrSpecRec[key]=PmagSpecRec[key] inten=frac*float(CrSpecRec['specimen_int']) CrSpecRec["specimen_int"]='%9.4e '%(inten) # adjust specimen intensity by cooling rate correction CrSpecRec['magic_method_codes'] = CrSpecRec['magic_method_codes']+':DA-CR-'+crtype CrSpecRec["specimen_correction"]='c' CRSpecs.append(CrSpecRec) PmagSpecs.append(PmagSpecRec) NltSpecRec="" # # check on non-linear TRM correction # if nltrm==1: # # find the data from the nlt_data list for this specimen # TRMs,Bs=[],[] NltSpecRec="" NltRecs=[] for NltRec in nlt_data: if NltRec['er_specimen_name']==PmagSpecRec["er_specimen_name"]: meths=NltRec["magic_method_codes"].split(":") for meth in meths:meth.strip() if "LP-TRM" in meths: NltRecs.append(NltRec) if len(NltRecs) > 2: for NltRec in NltRecs: Bs.append(float(NltRec['treatment_dc_field'])) TRMs.append(float(NltRec['measurement_magn_moment'])) NLTpars=nlt.NLtrm(Bs,TRMs,float(PmagSpecRec['specimen_int']),float(PmagSpecRec['specimen_lab_field_dc']),0) if NLTpars['banc']>0: NltSpecRec={} for key in PmagSpecRec.keys(): NltSpecRec[key]=PmagSpecRec[key] NltSpecRec['specimen_int']='%9.4e'%(NLTpars['banc']) NltSpecRec['magic_method_codes']=PmagSpecRec["magic_method_codes"]+":DA-NL" NltSpecRec["specimen_correction"]='c' NltSpecRec['specimen_grade']=PmagSpecRec['specimen_grade'] NltSpecRec["magic_software_packages"]=version_num print NltSpecRec['er_specimen_name'], ' Banc= ',float(NLTpars['banc'])*1e6 if anis==0 and frac!=0: CrSpecRec={} for key in NltSpecRec.keys():CrSpecRec[key]=NltSpecRec[key] inten=frac*float(CrSpecRec['specimen_int']) CrSpecRec["specimen_int"]='%9.4e '%(inten) # adjust specimen intensity by cooling rate correction CrSpecRec['magic_method_codes'] = CrSpecRec['magic_method_codes']+':DA-CR-'+crtype CRSpecs.append(CrSpecRec) NltSpecRecs.append(NltSpecRec) # # check on anisotropy correction if anis==1: if NltSpecRec!="": Spc=NltSpecRec else: # find uncorrected data Spc=PmagSpecRec for AniSpec in anis_data: if AniSpec["er_specimen_name"]==PmagSpecRec["er_specimen_name"]: AniSpecRec=pmag.thellier_anis_corr(Spc,AniSpec) AniSpecRec['specimen_grade']=PmagSpecRec['specimen_grade'] inst_codes=Spc["magic_instrument_codes"] if "magic_instrument_codes" in AniSpec.keys(): if inst_codes=="unknown": inst_codes=AniSpec["magic_instrument_codes"] else: inst_codes=inst_codes+":"+AniSpec["magic_instrument_codes"] AniSpecRec["magic_instrument_codes"]=inst_codes AniSpecRec["specimen_correction"]='c' AniSpecRec["magic_software_packages"]=version_num if frac!=0: CrSpecRec={} for key in AniSpecRec.keys():CrSpecRec[key]=AniSpecRec[key] inten=frac*float(CrSpecRec['specimen_int']) CrSpecRec["specimen_int"]='%9.4e '%(inten) # adjust specimen intensity by cooling rate correction CrSpecRec['magic_method_codes'] = CrSpecRec['magic_method_codes']+':DA-CR-'+crtype CRSpecs.append(CrSpecRec) AniSpecRecs.append(AniSpecRec) break elif anis==1: for AniSpec in anis_data: if AniSpec["er_specimen_name"]==PmagSpecRec["er_specimen_name"]: AniSpecRec=pmag.thellier_anis_corr(PmagSpecRec,AniSpec) AniSpecRec['specimen_grade']=PmagSpecRec['specimen_grade'] inst_codes=PmagSpecRec["magic_instrument_codes"] if "magic_instrument_codes" in AniSpec.keys(): if inst_codes=="unknown": inst_codes=AniSpec["magic_instrument_codes"] else: inst_codes=inst_codes+":"+AniSpec["magic_instrument_codes"] AniSpecRec["magic_instrument_codes"]=inst_codes AniSpecRec["specimen_correction"]='c' AniSpecRec["magic_software_packages"]=version_num if frac!=0: CrSpecRec={} for key in AniSpecRec.keys():CrSpecRec[key]=AniSpecRec[key] inten=frac*float(CrSpecRec['specimen_int']) CrSpecRec["specimen_int"]='%9.4e '%(inten) # adjust specimen intensity by cooling rate correction CrSpecRec['magic_method_codes'] = CrSpecRec['magic_method_codes']+':DA-CR-'+crtype CRSpecs.append(CrSpecRec) AniSpecRecs.append(AniSpecRec) break spec +=1 else: print "skipping ",s spec+=1 pmag_file=dir_path+'/'+pmag_file pmag.magic_write(pmag_file,PmagSpecs,'pmag_specimens') if anis==1: anisout=dir_path+'/'+anisout pmag.magic_write(anisout,AniSpecRecs,'pmag_specimens') if nltrm==1: nltout=dir_path+'/'+nltout pmag.magic_write(nltout,NltSpecRecs,'pmag_specimens') if frac!=0: crout=dir_path+'/'+crout pmag.magic_write(crout,CRSpecs,'pmag_specimens')
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(): """ NAME pt_rot.py DESCRIPTION rotates pt according to specified age and plate SYNTAX pt_rot.py [command line options] OPTIONS -h prints help and quits -f file with lon lat plate age Dplate as space delimited input Dplate is the destination plate coordinates desires - default is "fixed south africa" Dplate should be one of: [nwaf, neaf,saf,aus, eur, ind, sam, ant, grn, nam] -ff file Efile, file has lat lon data file and Efile has sequential rotation poles: Elat Elon Omega -F OFILE, output pmag_results formatted file with rotated points stored in vgp_lon, vgp_lat default is to print out rotated lon, lat to standard output """ dir_path='.' PTS=[] ResRecs=[] ofile="" Dplates=['nwaf', 'neaf','saf','aus', 'eur', 'ind', 'sam', 'ant', 'grn', 'nam'] 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') ofile=dir_path+'/'+sys.argv[ind+1] if '-f' in sys.argv: ind = sys.argv.index('-f') file=dir_path+'/'+sys.argv[ind+1] f=open(file,'rU') data=f.readlines() elif '-ff' in sys.argv: ind = sys.argv.index('-ff') file=dir_path+'/'+sys.argv[ind+1] f=open(file,'rU') data=f.readlines() Efile=dir_path+'/'+sys.argv[ind+2] f=open(Efile,'rU') edata=f.readlines() Poles=[] for p in edata: rec=p.split() pole=[float(rec[0]),float(rec[1]),float(rec[2])] Poles.append(pole) else: data=sys.stdin.readlines() for line in data: PtRec={} rec=line.split() PtRec['site_lat']=rec[0] PtRec['site_lon']=rec[1] if '-ff' in sys.argv: pt_lat,pt_lon=float(rec[0]),float(rec[1]) for pole in Poles: ptrot= pmag.PTrot(pole,[pt_lat],[pt_lon]) pt_lat=ptrot[0][0] pt_lon=ptrot[1][0] if ofile=="": print ptrot[1][0], ptrot[0][0] else: ResRec={'vgp_lat': '%7.1f'%(ptrot[0][0]),'vgp_lon':'%7.1f'%( ptrot[1][0])} ResRecs.append(ResRec) else: PtRec['cont']=rec[2] if PtRec['cont']=='af':PtRec['cont']='saf' # use fixed south africa PtRec['age']=rec[3] if len(rec)>4: PtRec['dcont']=rec[4] PTS.append(PtRec) if '-ff' not in sys.argv: for pt in PTS: pole='not specified' pt_lat=float(pt['site_lat']) pt_lon=float(pt['site_lon']) age=float(pt['age']) ptrot=[[pt_lat],[pt_lon]] if pt['cont']=='ib': pole=frp.get_pole(pt['cont'],age) ptrot= pmag.PTrot(pole,[pt_lat],[pt_lon]) pt_lat=ptrot[0][0] pt_lon=ptrot[1][0] pt['cont']='eur' if pt['cont']!='saf': pole1=frp.get_pole(pt['cont'],age) ptrot= pmag.PTrot(pole1,[pt_lat],[pt_lon]) if 'dcont' in pt.keys(): pt_lat=ptrot[0][0] pt_lon=ptrot[1][0] pole=frp.get_pole(pt['dcont'],age) pole[2]=-pole[2] ptrot= pmag.PTrot(pole,[pt_lat],[pt_lon]) if ofile=="": print ptrot[1][0], ptrot[0][0] else: ResRec={'vgp_lat': '%7.1f'%(ptrot[0][0]),'vgp_lon':'%7.1f'%( ptrot[1][0])} ResRecs.append(ResRec) else: if 'dcont' in pt.keys(): pole=frp.get_pole(pt['dcont'],age) pole[2]=-pole[2] ptrot= pmag.PTrot(pole,[pt_lat],[pt_lon]) if ofile=="": print ptrot[1][0], ptrot[0][0] else: ResRec={'vgp_lat': '%7.1f'%(ptrot[0][0]),'vgp_lon':'%7.1f'%( ptrot[1][0])} ResRecs.append(ResRec) else: if ofile=="": print ptrot[1][0], ptrot[0][0] else: ResRec={'vgp_lat': '%7.1f'%(ptrot[0][0]),'vgp_lon':'%7.1f'%( ptrot[1][0])} ResRecs.append(ResRec) if len(ResRecs)>0: pmag.magic_write(ofile,ResRecs,'pmag_results')
def main(): """ NAME download_magic.py DESCRIPTION unpacks a magic formatted smartbook .txt file from the MagIC database into the tab delimited MagIC format txt files for use with the MagIC-Py programs. SYNTAX download_magic.py command line options] INPUT takes either the upload.txt file created by upload_magic.py or the file exported by the MagIC v2.2 console software (downloaded from the MagIC database or output by the Console on your PC). OPTIONS -h prints help message and quits -i allows interactive entry of filename -f FILE specifies input file name """ dir_path='.' if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] if '-i' in sys.argv: file=raw_input("Magic txt file for unpacking? ") elif '-f' in sys.argv: ind=sys.argv.index("-f") file=sys.argv[ind+1] else: print main.__doc__ sys.exit() f=open(dir_path+'/'+file,'rU') File=f.readlines() LN=0 type_list=[] filenum=0 while LN<len(File)-1: line=File[LN] file_type=line.split('\t')[1] file_type=file_type.lower() if file_type=='delimited':file_type=Input[skip].split('\t')[2] if file_type[-1]=="\n":file_type=file_type[:-1] print 'working on: ',repr(file_type) if file_type not in type_list: type_list.append(file_type) else: filenum+=1 LN+=1 line=File[LN] keys=line.replace('\n','').split('\t') LN+=1 Recs=[] while LN<len(File): line=File[LN] if line[:4]==">>>>" and len(Recs)>0: if filenum==0: outfile=dir_path+"/"+file_type.strip()+'.txt' else: outfile=dir_path+"/"+file_type.strip()+'_'+str(filenum)+'.txt' NewRecs=[] for rec in Recs: if 'magic_method_codes' in rec.keys(): meths=rec['magic_method_codes'].split(":") if len(meths)>0: methods="" for meth in meths: methods=methods+meth.strip()+":" # get rid of nasty spaces!!!!!! rec['magic_method_codes']=methods[:-1] NewRecs.append(rec) pmag.magic_write(outfile,Recs,file_type) print file_type," data put in ",outfile if file_type =='pmag_specimens' and 'magic_measurements.txt' in File and 'measurement_step_min' in File and 'measurement_step_max' in File: # sort out zeq_specimens and thellier_specimens os.system('mk_redo.py') os.system('zeq_magic_redo.py') os.system('thellier_magic_redo.py') type_list.append('zeq_specimens') type_list.append('thellier_specimens') Recs=[] LN+=1 break else: rec=line.split('\t') Rec={} if len(rec)==len(keys): for k in range(len(rec)): Rec[keys[k]]=rec[k] Recs.append(Rec) else: print 'WARNING: problem in file with line: ' print line print 'skipping....' LN+=1 if len(Recs)>0: if filenum==0: outfile=dir_path+"/"+file_type.strip()+'.txt' else: outfile=dir_path+"/"+file_type.strip()+'_'+str(filenum)+'.txt' NewRecs=[] for rec in Recs: if 'magic_method_codes' in rec.keys(): meths=rec['magic_method_codes'].split(":") if len(meths)>0: methods="" for meth in meths: methods=methods+meth.strip()+":" # get rid of nasty spaces!!!!!! rec['magic_method_codes']=methods[:-1] NewRecs.append(rec) pmag.magic_write(outfile,Recs,file_type) print file_type," data put in ",outfile # look through locations table and create separate directories for each location locs,locnum=[],1 if 'er_locations' in type_list: locs,file_type=pmag.magic_read(dir_path+'/er_locations.txt') if len(locs)>0: # at least one location for loc in locs: print 'location_'+str(locnum)+": ",loc['er_location_name'] lpath=dir_path+'/Location_'+str(locnum) locnum+=1 try: os.mkdir(lpath) except: print 'directory ',lpath,' already exists - overwrite everything [y/n]?' ans=raw_input() if ans=='n':sys.exit() for f in type_list: print 'unpacking: ',dir_path+'/'+f+'.txt' recs,file_type=pmag.magic_read(dir_path+'/'+f+'.txt') print len(recs),' read in' if 'results' not in f: lrecs=pmag.get_dictitem(recs,'er_location_name',loc['er_location_name'],'T') if len(lrecs)>0: pmag.magic_write(lpath+'/'+f+'.txt',lrecs,file_type) print len(lrecs),' stored in ',lpath+'/'+f+'.txt' else: lrecs=pmag.get_dictitem(recs,'er_location_names',loc['er_location_name'],'T') if len(lrecs)>0: pmag.magic_write(lpath+'/'+f+'.txt',lrecs,file_type) print len(lrecs),' stored in ',lpath+'/'+f+'.txt'
def main(): """ NAME ODP_srm_magic.py DESCRIPTION converts ODP measurement format files to magic_measurements format files SYNTAX ODP_srm_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_sample.txt file, default is er_sample.txt -A : don't average replicate measurements INPUT put data from a single core into a directory. depths will be below core top """ # # version_num=pmag.get_version() meas_file='magic_measurements.txt' samp_file='er_samples.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 '-Fsa' in args: ind=args.index("-Fsa") samp_file=args[ind+1] 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 samp_file=dir_path+'/'+samp_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 file in filelist: # parse each file if file[-3:].lower()=='srm': print 'processing: ',file Nfo=file.split('_')[0].split('-') try: sect=int(Nfo[3][:-1]) except: sect=1 input=open(file,'rU').readlines() MagRec,SpecRec,SampRec={},{},{} alt_spec,treatment_type,treatment_value,user="","","","" inst="ODP-SRM" SampRec['sample_azimuth']='0' SampRec['sample_dip']='0' SampRec['magic_method_code']='FS-C-DRILL-IODP:SP-SS-C' 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 treatment_value,inst="","ODP-SRM" k=0 while 1: fields= input[k].replace('\n','').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 if "treatment_value" in fields[0]: value=fields[1] if value!=" ": treatment_value=float(value)*1e-3 MagRec["treatment_ac_field"]='%8.3e'%(treatment_value) # AF demag in treat mT => T if 'user' in fields[0]: user=fields[-1] MagRec["er_analyst_mail_names"]=user 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' k+=1 if input[k][0:7]=='<MULTI>': break while 1: k+=1 line = input[k] if line[0:5]=='<RAW>': break treatment_value="" rec=line.replace('\n','').split(',') # list of data if len(rec)>2: MeasRec,SampRec={},{'core_depth':'0','er_sample_name':'0','er_site_name':'0','er_location_name':'location'} for key in MagRec.keys():MeasRec[key]=MagRec[key] for item in rec: items=item.split('=') if 'demag_level' in items[0]: treat= float(items[1]) if treat!=0: MeasRec['magic_method_codes']='LT-AF-Z' inst=inst+':ODP-SRM-AF' MeasRec["treatment_ac_field"]='%8.3e'%(treat*1e-3) # AF demag in treat mT => T if 'inclination_w_tray_w_bkgrd' in items[0]: MeasRec['measurement_inc']=items[1] if 'declination_w_tray_w_bkgrd' in items[0]: MeasRec['measurement_dec']=items[1] if 'intensity_w_tray_w_bkgrd' in items[0]: MeasRec['measurement_magn_moment']='%8.3e'%(float(items[1])*vol) # convert intensity from A/m to Am^2 using vol MeasRec['magic_instrument_codes']=inst if 'offset' in items[0]: depth='%7.3f'%(float(sect-1)*1.5+float(items[1])) SampRec['core_depth']=depth MeasRec['er_specimen_name']=depth MeasRec['er_sample_name']=depth MeasRec['er_site_name']=depth MeasRec['er_location_name']='location' SampRec['er_sample_name']=depth SampRec['er_site_name']=depth SampRec['er_location_name']='location' MeasRec['measurement_number']='1' SampRecs.append(SampRec) MagRecs.append(MeasRec) pmag.magic_write(samp_file,SampRecs,'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(): """ NAME TDT_magic.py DESCRIPTION converts ThellierTool format files to magic_measurements format files SYNTAX TDT_magic.py [command line options] OPTIONS -h: prints the help message and quits. -usr USER: identify user, default is "" -f FILE: specify .tdt format input file, required -F FILE: specify output file, default is magic_measurements.txt -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 -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. INPUT Format of ThellierTool files: 2 line header: Thellier-tdt XX.0 (field in microtesla) Data: Spec Treat Intensity Declination Inclination Spec: specimen name Treat: treatment step XXX.00 first zero field step XXX.11 (or .1) first in field step [XXX.0 and XXX.1 can be done in any order] XXX.12 (or .2)second in-field step at lower temperature (pTRM check) XXX.13 (or .3) second zero-field step after infield (pTRM check step) XXX.13 MUST be done in this order [XXX.00, XXX.11 [optional XXX.12] XXX.13] Intensity assumed to be total moment in 10^3 Am^2 (emu) Declination: Declination in specimen coordinate system Inclination: Declination in specimen coordinate system """ # initialize some stuff noave=0 methcode,inst="","" phi,theta,labfield=0,90,0 pTRM,MD,samp_con,Z=0,0,'1',1 demag="N" er_location_name="" citation='This study' args=sys.argv methcode="LP-NO" specnum=0 # # get command line arguments # dir_path='.' meas_file,samp_file="magic_measurements.txt","er_samples.txt" user="" if "-WD" in args: ind=args.index("-WD") dir_path=args[ind+1] if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind=args.index("-usr") user=args[ind+1] if '-F' in args: ind=args.index("-F") meas_file=dir_path+'/'+args[ind+1] if '-f' in args: ind=args.index("-f") magfile=dir_path+'/'+args[ind+1] try: input=open(magfile,'rU') except: print "bad mag file name" sys.exit() else: print "mag_file field is required option" print main.__doc__ sys.exit() if "-spc" in args: ind=args.index("-spc") specnum=int(args[ind+1]) if specnum!=0:specnum=-specnum if "-loc" in args: ind=args.index("-loc") er_location_name=args[ind+1] if "-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" MagRecs=[] demag="T" version_num=pmag.get_version() data=input.readlines() rec=data[1].split() labfield=float(rec[0])*1e-6 for line in data[2:]: rec=line.split() if len(rec)>2: MagRec={} MagRec['er_location_name']=er_location_name MagRec['magic_software_packages']=version_num MagRec["treatment_temp"]='%8.3e' % (273) # room temp in kelvin MagRec["measurement_temp"]='%8.3e' % (273) # room temp in kelvin MagRec["treatment_ac_field"]='0' MagRec["treatment_dc_field"]='0' MagRec["treatment_dc_field_phi"]='0' MagRec["treatment_dc_field_theta"]='0' meas_type="LT-NO" MagRec["er_specimen_name"]=rec[0] MagRec["er_synthetic_name"]="" MagRec["er_site_name"]="" if specnum!=0: MagRec["er_sample_name"]=rec[0][:specnum] else: MagRec["er_sample_name"]=rec[0] if "-fsa" in args: for samp in Samps: if samp["er_sample_name"] == MagRec["er_sample_name"]: MagRec["er_location_name"]=samp["er_location_name"] MagRec["er_site_name"]=samp["er_site_name"] break elif int(samp_con)!=6: site=pmag.parse_site(MagRec['er_sample_name'],samp_con,Z) MagRec["er_site_name"]=site if MagRec['er_site_name']=="": print 'No site name found for: ',MagRec['er_specimen_name'],MagRec['er_sample_name'] if MagRec["er_location_name"]=="": print 'no location name for: ',MagRec["er_specimen_name"] if rec[1]==".00":rec[1]="0.00" treat=rec[1].split('.') if float(rec[1])==0: pass if len(treat)==1:treat.append('0') MagRec["treatment_temp"]='%8.3e' % (float(treat[0])+273.) # temp in kelvin if treat[1][0]=='0': meas_type="LT-T-Z" else: MagRec["treatment_dc_field"]='%8.3e' % (labfield) # labfield in tesla (convert from microT) MagRec["treatment_dc_field_phi"]='%7.1f' % (phi) # labfield phi MagRec["treatment_dc_field_theta"]='%7.1f' % (theta) # labfield theta if treat[1][-1]=='1':meas_type="LT-T-I" # in-field thermal step if treat[1][-1]=='2': meas_type="LT-PTRM-I" # pTRM check pTRM=1 if treat[1][-1]=='3': MagRec["treatment_dc_field"]='0' # this is a zero field step meas_type="LT-PTRM-MD" # pTRM tail check MagRec["measurement_magn_moment"]='%10.3e'% (float(rec[2])*1e-3) # moment in Am^2 (from emu) MagRec["measurement_dec"]=rec[3] MagRec["measurement_inc"]=rec[4] MagRec["er_analyst_mail_names"]=user MagRec["er_citation_names"]=citation MagRec["magic_method_codes"]=meas_type MagRec["measurement_flag"]='g' MagRec["er_specimen_name"]=rec[0] MagRec["measurement_standard"]='u' MagRec["measurement_number"]='1' MagRecs.append(MagRec) MagOuts=pmag.measurements_methods(MagRecs,noave) pmag.magic_write(meas_file,MagOuts,'magic_measurements') print "results put in ",meas_file