def main(): """ NAME s_geo.py DESCRIPTION rotates .s data into geographic coordinates using azimuth and plunge SYNTAX s_geo.py [-h][options] OPTIONS -h prints help message and quits -i allows interactive entry of file name -f file specifies filename on command line -F FILE specifies output file on command line < filename, reads from standard input (Unix like operating systems only) INPUT x11 x22 x33 x12 x23 x13 az pl OUTPUT x11 x22 x33 x12 x23 x13 """ if "-h" in sys.argv: print main.__doc__ sys.exit() # read in the data elif "-i" in sys.argv: file = raw_input("Enter filename for processing: ") f = open(file, "rU") data = f.readlines() f.close() elif "-f" in sys.argv: ind = sys.argv.index("-f") file = sys.argv[ind + 1] f = open(file, "rU") data = f.readlines() f.close() else: data = sys.stdin.readlines() ofile = "" if "-F" in sys.argv: ind = sys.argv.index("-F") ofile = sys.argv[ind + 1] out = open(ofile, "w + a") for line in data: s = [] rec = line.split() for i in range(6): s.append(float(rec[i])) az, pl = float(rec[6]), float(rec[7]) s_rot = pmag.dosgeo(s, az, pl) outstring = "" for s in s_rot: outstring += "%10.8f " % (s) if ofile == "": print outstring else: out.write(outstring + "\n")
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 k15_magic.py DESCRIPTION converts .k15 format data to magic_measurements format. assums Jelinek Kappabridge measurement scheme SYNTAX k15_magic.py [-h] [command line options] OPTIONS -h prints help message and quits -f KFILE: specify .k15 format input file -F MFILE: specify magic_measurements format output file -Fsa SFILE, specify er_samples format file for output -Fa AFILE, specify rmag_anisotropy format file for output -loc LOC: specify location name for study -ins INST: specify instrument that measurements were made on -spc NUM: specify number of digets for specimen ID, default is 0 -ncn NCOM: specify naming convention (default is #1) 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] sample, site, location info in er_samples.txt [7] all others you will have to either customize your DEFAULTS MFILE: k15_measurements.txt SFILE: er_samples.txt AFILE: rmag_anisotropy.txt LOC: unknown INST: unknown INPUT name [az,pl,strike,dip], followed by 3 rows of 5 measurements for each specimen """ # # initialize some variables # version_num=pmag.get_version() specnum=0 sampfile, measfile="er_samples.txt","k15_measurements.txt" anisfile='rmag_anisotropy.txt' resfile='rmag_results.txt' syn=0 er_location_name="unknown" inst="unknown" itilt,igeo,linecnt,key=0,0,0,"" first_save=1 k15,specnum=[],0 citation='This study' dir_path='.' if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] # pick off stuff from command line if '-h' in sys.argv: print main.__doc__ sys.exit() if '-f' in sys.argv: ind=sys.argv.index('-f') k15file=sys.argv[ind+1] if '-F' in sys.argv: ind=sys.argv.index('-F') measfile=sys.argv[ind+1] if '-Fsa' in sys.argv: ind=sys.argv.index('-Fsa') sampfile=sys.argv[ind+1] if '-Fa' in sys.argv: ind=sys.argv.index('-Fa') anisfile=sys.argv[ind+1] if '-loc' in sys.argv: ind=sys.argv.index('-loc') er_location_name=sys.argv[ind+1] if '-spc' in sys.argv: ind=sys.argv.index('-spc') specnum=-int(sys.argv[ind+1]) samp_con,Z="1","" if "-ncn" in sys.argv: ind=sys.argv.index("-ncn") samp_con=sys.argv[ind+1] if "4" in samp_con: if "-" not in samp_con: print "option [4] must be in form 4-Z where Z is an integer" sys.exit() else: Z=samp_con.split("-")[1] samp_con="4" if samp_con=='6': Samps,filetype=pmag.magic_read(dirpath+'/er_samples.txt') sampfile, measfile=dir_path+'/'+sampfile,dir_path+'/'+measfile anisfile=dir_path+'/'+anisfile resfile=dir_path+'/'+resfile k15file=dir_path+'/'+k15file try: SampRecs,filetype=pmag.magic_read(sampfile) # append new records to existing samplist=[] for samp in SampRecs: if samp['er_sample_name'] not in samplist:samplist.append(samp['er_sample_name']) except IOError: SampRecs=[] # measurement directions for Jelinek 1977 protocol: Decs=[315,225,180,135,45,90,270,270,270,90,180,180,0,0,0] Incs=[0,0,0,0,0,-45,-45,0,45,45,45,-45,-90,-45,45] # some defaults to read in .k15 file format # list of measurements and default number of characters for specimen ID # some magic default definitions # # read in data input=open(k15file,'rU') MeasRecs,SpecRecs,AnisRecs,ResRecs=[],[],[],[] # read in data MeasRec,SpecRec,SampRec,SiteRec,AnisRec,ResRec={},{},{},{},{},{} for line in input.readlines(): linecnt+=1 rec=line.split() if linecnt==1: MeasRec["magic_method_codes"]="" SpecRec["magic_method_codes"]="" SampRec["magic_method_codes"]="" AnisRec["magic_method_codes"]="" SiteRec["magic_method_codes"]="" ResRec["magic_smethod_codes"]="" MeasRec["magic_software_packages"]=version_num SpecRec["magic_software_packages"]=version_num SampRec["magic_software_packages"]=version_num AnisRec["magic_software_packages"]=version_num SiteRec["magic_software_packages"]=version_num ResRec["magic_software_packages"]=version_num MeasRec["magic_method_codes"]="LP-X" MeasRec["measurement_flag"]="g" MeasRec["measurement_standard"]="u" MeasRec["er_citation_names"]="This study" SpecRec["er_citation_names"]="This study" SampRec["er_citation_names"]="This study" AnisRec["er_citation_names"]="This study" ResRec["er_citation_names"]="This study" MeasRec["er_specimen_name"]=rec[0] MeasRec["magic_experiment_name"]=rec[0]+":LP-AN-MS" AnisRec["magic_experiment_names"]=rec[0]+":AMS" ResRec["magic_experiment_names"]=rec[0]+":AMS" SpecRec["er_specimen_name"]=rec[0] AnisRec["er_specimen_name"]=rec[0] SampRec["er_specimen_name"]=rec[0] ResRec["rmag_result_name"]=rec[0] if specnum!=0: MeasRec["er_sample_name"]=rec[0][:specnum] if specnum==0: MeasRec["er_sample_name"]=rec[0] SampRec["er_sample_name"]=MeasRec["er_sample_name"] SpecRec["er_sample_name"]=MeasRec["er_sample_name"] AnisRec["er_sample_name"]=MeasRec["er_sample_name"] ResRec["er_sample_names"]=MeasRec["er_sample_name"] if samp_con=="6": for samp in Samps: if samp['er_sample_name']==AnisRec["er_sample_name"]: sitename=samp['er_site_name'] er_location_name=samp['er_location_name'] elif samp_con!="": sitename=pmag.parse_site(AnisRec['er_sample_name'],samp_con,Z) MeasRec["er_site_name"]=sitename MeasRec["er_location_name"]=er_location_name SampRec["er_site_name"]=MeasRec["er_site_name"] SpecRec["er_site_name"]=MeasRec["er_site_name"] AnisRec["er_site_name"]=MeasRec["er_site_name"] ResRec["er_site_names"]=MeasRec["er_site_name"] SampRec["er_location_name"]=MeasRec["er_location_name"] SpecRec["er_location_name"]=MeasRec["er_location_name"] AnisRec["er_location_name"]=MeasRec["er_location_name"] ResRec["er_location_names"]=MeasRec["er_location_name"] if len(rec)>=3: SampRec["sample_azimuth"],SampRec["sample_dip"]=rec[1],rec[2] az,pl,igeo=float(rec[1]),float(rec[2]),1 if len(rec)==5: SampRec["sample_bed_dip_direction"],SampRec["sample_bed_dip"]= '(%7.1f)'%(90.+float(rec[3])),(rec[4]) bed_az,bed_dip,itilt,igeo=90.+float(rec[3]),float(rec[4]),1,1 else: for i in range(5): k15.append(1e-6*float(rec[i])) # assume measurements in micro SI if linecnt==4: sbar,sigma,bulk=pmag.dok15_s(k15) hpars=pmag.dohext(9,sigma,sbar) MeasRec["treatment_temp"]='%8.3e' % (273) # room temp in kelvin MeasRec["measurement_temp"]='%8.3e' % (273) # room temp in kelvin for i in range(15): NewMeas=copy.deepcopy(MeasRec) NewMeas["measurement_orient_phi"]='%7.1f' %(Decs[i]) NewMeas["measurement_orient_theta"]='%7.1f'% (Incs[i]) NewMeas["measurement_chi_volume"]='%12.10f'% (k15[i]) NewMeas["measurement_number"]='%i'% (i+1) NewMeas["magic_experiment_name"]=rec[0]+":LP-AN-MS" MeasRecs.append(NewMeas) if SampRec['er_sample_name'] not in samplist: SampRecs.append(SampRec) samplist.append(SampRec['er_sample_name']) SpecRecs.append(SpecRec) AnisRec["anisotropy_type"]="AMS" ResRec["anisotropy_type"]="AMS" AnisRec["anisotropy_s1"]='%12.10f'%(sbar[0]) AnisRec["anisotropy_s2"]='%12.10f'%(sbar[1]) AnisRec["anisotropy_s3"]='%12.10f'%(sbar[2]) AnisRec["anisotropy_s4"]='%12.10f'%(sbar[3]) AnisRec["anisotropy_s5"]='%12.10f'%(sbar[4]) AnisRec["anisotropy_s6"]='%12.10f'%(sbar[5]) AnisRec["anisotropy_mean"]='%12.10f'%(bulk) AnisRec["anisotropy_sigma"]='%12.10f'%(sigma) AnisRec["anisotropy_unit"]='SI' AnisRec["anisotropy_n"]='15' AnisRec["anisotropy_tilt_correction"]='-1' AnisRec["magic_method_codes"]='LP-X:AE-H:LP-AN-MS' AnisRecs.append(AnisRec) ResRec["magic_method_codes"]='LP-X:AE-H:LP-AN-MS' ResRec["anisotropy_tilt_correction"]='-1' ResRec["anisotropy_t1"]='%12.10f'%(hpars['t1']) ResRec["anisotropy_t2"]='%12.10f'%(hpars['t2']) ResRec["anisotropy_t3"]='%12.10f'%(hpars['t3']) ResRec["anisotropy_fest"]='%12.10f'%(hpars['F']) ResRec["anisotropy_ftest12"]='%12.10f'%(hpars['F12']) ResRec["anisotropy_ftest23"]='%12.10f'%(hpars['F23']) ResRec["anisotropy_v1_dec"]='%7.1f'%(hpars['v1_dec']) ResRec["anisotropy_v2_dec"]='%7.1f'%(hpars['v2_dec']) ResRec["anisotropy_v3_dec"]='%7.1f'%(hpars['v3_dec']) ResRec["anisotropy_v1_inc"]='%7.1f'%(hpars['v1_inc']) ResRec["anisotropy_v2_inc"]='%7.1f'%(hpars['v2_inc']) ResRec["anisotropy_v3_inc"]='%7.1f'%(hpars['v3_inc']) ResRec['anisotropy_v1_eta_dec']=ResRec['anisotropy_v2_dec'] ResRec['anisotropy_v1_eta_inc']=ResRec['anisotropy_v2_inc'] ResRec['anisotropy_v1_zeta_dec']=ResRec['anisotropy_v3_dec'] ResRec['anisotropy_v1_zeta_inc']=ResRec['anisotropy_v3_inc'] ResRec['anisotropy_v2_eta_dec']=ResRec['anisotropy_v1_dec'] ResRec['anisotropy_v2_eta_inc']=ResRec['anisotropy_v1_inc'] ResRec['anisotropy_v2_zeta_dec']=ResRec['anisotropy_v3_dec'] ResRec['anisotropy_v2_zeta_inc']=ResRec['anisotropy_v3_inc'] ResRec['anisotropy_v3_eta_dec']=ResRec['anisotropy_v1_dec'] ResRec['anisotropy_v3_eta_inc']=ResRec['anisotropy_v1_inc'] ResRec['anisotropy_v3_zeta_dec']=ResRec['anisotropy_v2_dec'] ResRec['anisotropy_v3_zeta_inc']=ResRec['anisotropy_v2_inc'] ResRec["anisotropy_v1_eta_semi_angle"]='%7.1f'%(hpars['e12']) ResRec["anisotropy_v1_zeta_semi_angle"]='%7.1f'%(hpars['e13']) ResRec["anisotropy_v2_eta_semi_angle"]='%7.1f'%(hpars['e12']) ResRec["anisotropy_v2_zeta_semi_angle"]='%7.1f'%(hpars['e23']) ResRec["anisotropy_v3_eta_semi_angle"]='%7.1f'%(hpars['e13']) ResRec["anisotropy_v3_zeta_semi_angle"]='%7.1f'%(hpars['e23']) ResRec["result_description"]='Critical F: '+hpars["F_crit"]+';Critical F12/F13: '+hpars["F12_crit"] ResRecs.append(ResRec) if igeo==1: sbarg=pmag.dosgeo(sbar,az,pl) hparsg=pmag.dohext(9,sigma,sbarg) AnisRecG=copy.copy(AnisRec) ResRecG=copy.copy(ResRec) AnisRecG["anisotropy_s1"]='%12.10f'%(sbarg[0]) AnisRecG["anisotropy_s2"]='%12.10f'%(sbarg[1]) AnisRecG["anisotropy_s3"]='%12.10f'%(sbarg[2]) AnisRecG["anisotropy_s4"]='%12.10f'%(sbarg[3]) AnisRecG["anisotropy_s5"]='%12.10f'%(sbarg[4]) AnisRecG["anisotropy_s6"]='%12.10f'%(sbarg[5]) AnisRecG["anisotropy_tilt_correction"]='0' ResRecG["anisotropy_tilt_correction"]='0' ResRecG["anisotropy_v1_dec"]='%7.1f'%(hparsg['v1_dec']) ResRecG["anisotropy_v2_dec"]='%7.1f'%(hparsg['v2_dec']) ResRecG["anisotropy_v3_dec"]='%7.1f'%(hparsg['v3_dec']) ResRecG["anisotropy_v1_inc"]='%7.1f'%(hparsg['v1_inc']) ResRecG["anisotropy_v2_inc"]='%7.1f'%(hparsg['v2_inc']) ResRecG["anisotropy_v3_inc"]='%7.1f'%(hparsg['v3_inc']) ResRecG['anisotropy_v1_eta_dec']=ResRecG['anisotropy_v2_dec'] ResRecG['anisotropy_v1_eta_inc']=ResRecG['anisotropy_v2_inc'] ResRecG['anisotropy_v1_zeta_dec']=ResRecG['anisotropy_v3_dec'] ResRecG['anisotropy_v1_zeta_inc']=ResRecG['anisotropy_v3_inc'] ResRecG['anisotropy_v2_eta_dec']=ResRecG['anisotropy_v1_dec'] ResRecG['anisotropy_v2_eta_inc']=ResRecG['anisotropy_v1_inc'] ResRecG['anisotropy_v2_zeta_dec']=ResRecG['anisotropy_v3_dec'] ResRecG['anisotropy_v2_zeta_inc']=ResRecG['anisotropy_v3_inc'] ResRecG['anisotropy_v3_eta_dec']=ResRecG['anisotropy_v1_dec'] ResRecG['anisotropy_v3_eta_inc']=ResRecG['anisotropy_v1_inc'] ResRecG['anisotropy_v3_zeta_dec']=ResRecG['anisotropy_v2_dec'] ResRecG['anisotropy_v3_zeta_inc']=ResRecG['anisotropy_v2_inc'] ResRecG["result_description"]='Critical F: '+hpars["F_crit"]+';Critical F12/F13: '+hpars["F12_crit"] ResRecs.append(ResRecG) AnisRecs.append(AnisRecG) if itilt==1: sbart=pmag.dostilt(sbarg,bed_az,bed_dip) hparst=pmag.dohext(9,sigma,sbart) AnisRecT=copy.copy(AnisRec) ResRecT=copy.copy(ResRec) AnisRecT["anisotropy_s1"]='%12.10f'%(sbart[0]) AnisRecT["anisotropy_s2"]='%12.10f'%(sbart[1]) AnisRecT["anisotropy_s3"]='%12.10f'%(sbart[2]) AnisRecT["anisotropy_s4"]='%12.10f'%(sbart[3]) AnisRecT["anisotropy_s5"]='%12.10f'%(sbart[4]) AnisRecT["anisotropy_s6"]='%12.10f'%(sbart[5]) AnisRecT["anisotropy_tilt_correction"]='100' ResRecT["anisotropy_v1_dec"]='%7.1f'%(hparst['v1_dec']) ResRecT["anisotropy_v2_dec"]='%7.1f'%(hparst['v2_dec']) ResRecT["anisotropy_v3_dec"]='%7.1f'%(hparst['v3_dec']) ResRecT["anisotropy_v1_inc"]='%7.1f'%(hparst['v1_inc']) ResRecT["anisotropy_v2_inc"]='%7.1f'%(hparst['v2_inc']) ResRecT["anisotropy_v3_inc"]='%7.1f'%(hparst['v3_inc']) ResRecT['anisotropy_v1_eta_dec']=ResRecT['anisotropy_v2_dec'] ResRecT['anisotropy_v1_eta_inc']=ResRecT['anisotropy_v2_inc'] ResRecT['anisotropy_v1_zeta_dec']=ResRecT['anisotropy_v3_dec'] ResRecT['anisotropy_v1_zeta_inc']=ResRecT['anisotropy_v3_inc'] ResRecT['anisotropy_v2_eta_dec']=ResRecT['anisotropy_v1_dec'] ResRecT['anisotropy_v2_eta_inc']=ResRecT['anisotropy_v1_inc'] ResRecT['anisotropy_v2_zeta_dec']=ResRecT['anisotropy_v3_dec'] ResRecT['anisotropy_v2_zeta_inc']=ResRecT['anisotropy_v3_inc'] ResRecT['anisotropy_v3_eta_dec']=ResRecT['anisotropy_v1_dec'] ResRecT['anisotropy_v3_eta_inc']=ResRecT['anisotropy_v1_inc'] ResRecT['anisotropy_v3_zeta_dec']=ResRecT['anisotropy_v2_dec'] ResRecT['anisotropy_v3_zeta_inc']=ResRecT['anisotropy_v2_inc'] ResRecT["anisotropy_tilt_correction"]='100' ResRecT["result_description"]='Critical F: '+hpars["F_crit"]+';Critical F12/F13: '+hpars["F12_crit"] ResRecs.append(ResRecT) AnisRecs.append(AnisRecT) k15,linecnt=[],0 MeasRec,SpecRec,SampRec,SiteRec,AnisRec={},{},{},{},{} pmag.magic_write(sampfile,SampRecs,'er_samples') pmag.magic_write(anisfile,AnisRecs,'rmag_anisotropy') pmag.magic_write(resfile,ResRecs,'rmag_results') pmag.magic_write(measfile,MeasRecs,'magic_measurements') print "Data saved to: ",sampfile,anisfile,resfile,measfile
def main(): """ NAME k15_s.py DESCRIPTION converts .k15 format data to .s format. assumes Jelinek Kappabridge measurement scheme SYNTAX k15_s.py [-h][-i][command line options][<filename] OPTIONS -h prints help message and quits -i allows interactive entry of options -f FILE, specifies input file, default: standard input -F FILE, specifies output file, default: standard output -crd [g, t] specifies [g]eographic rotation, or geographic AND tectonic rotation INPUT name [az,pl,strike,dip], followed by 3 rows of 5 measurements for each specimen OUTPUT least squares matrix elements and sigma: x11,x22,x33,x12,x23,x13,sigma """ firstline,itilt,igeo,linecnt,key=1,0,0,0,"" out="" data,k15=[],[] if '-h' in sys.argv: print main.__doc__ sys.exit() if '-i' in sys.argv: file=raw_input("Input file name [.k15 format]: ") f=open(file,'rU') data=f.readlines() f.close() file=raw_input("Output file name [.s format]: ") out=open(file,'w') print (" [g]eographic, [t]ilt corrected, ") tg=raw_input(" [return for specimen coordinates]: ") if tg=='g': igeo=1 elif tg=='t': igeo,itilt=1,1 elif '-f' in sys.argv: ind=sys.argv.index('-f') file=sys.argv[ind+1] f=open(file,'rU') data=f.readlines() f.close() else: data= sys.stdin.readlines() if len(data)==0: print main.__doc__ sys.exit() if '-F' in sys.argv: ind=sys.argv.index('-F') file=sys.argv[ind+1] out=open(file,'w') if '-crd' in sys.argv: ind=sys.argv.index('-crd') tg=sys.argv[ind+1] if tg=='g':igeo=1 if tg=='t': igeo,itilt=1,1 for line in data: rec=line.split() if firstline==1: firstline=0 nam=rec[0] if igeo==1: az,pl=float(rec[1]),float(rec[2]) if itilt==1: bed_az,bed_dip=90.+float(rec[3]),float(rec[4]) else: linecnt+=1 for i in range(5): k15.append(float(rec[i])) if linecnt==3: sbar,sigma,bulk=pmag.dok15_s(k15) if igeo==1: sbar=pmag.dosgeo(sbar,az,pl) if itilt==1: sbar=pmag.dostilt(sbar,bed_az,bed_dip) outstring="" for s in sbar:outstring+='%10.8f '%(s) outstring+='%10.8f'%(sigma) if out=="": print outstring else: out.write(outstring+'\n') linecnt,firstline,k15=0,1,[]
def main(): """ NAME aarm_magic.py DESCRIPTION Converts AARM data to best-fit tensor (6 elements plus sigma) Original program ARMcrunch written to accomodate ARM anisotropy data collected from 6 axial directions (+X,+Y,+Z,-X,-Y,-Z) using the off-axis remanence terms to construct the tensor. A better way to do the anisotropy of ARMs is to use 9,12 or 15 measurements in the Hext rotational scheme. SYNTAX aarm_magic.py [-h][command line options] OPTIONS -h prints help message and quits -usr USER: identify user, default is "" -f FILE: specify input file, default is aarm_measurements.txt -crd [s,g,t] specify coordinate system, requires er_samples.txt file -fsa FILE: specify er_samples.txt file, default is er_samples.txt -Fa FILE: specify anisotropy output file, default is arm_anisotropy.txt -Fr FILE: specify results output file, default is aarm_results.txt INPUT Input for the present program is a series of baseline, ARM pairs. The baseline should be the AF demagnetized state (3 axis demag is preferable) for the following ARM acquisition. The order of the measurements is: positions 1,2,3, 6,7,8, 11,12,13 (for 9 positions) positions 1,2,3,4, 6,7,8,9, 11,12,13,14 (for 12 positions) positions 1-15 (for 15 positions) """ # initialize some parameters args=sys.argv user="" meas_file="aarm_measurements.txt" samp_file="er_samples.txt" rmag_anis="arm_anisotropy.txt" rmag_res="aarm_results.txt" dir_path='.' # # get name of file from command line # if '-WD' in args: ind=args.index('-WD') dir_path=args[ind+1] if "-h" in args: print main.__doc__ sys.exit() if "-usr" in args: ind=args.index("-usr") user=sys.argv[ind+1] if "-f" in args: ind=args.index("-f") meas_file=sys.argv[ind+1] coord='-1' if "-crd" in sys.argv: ind=sys.argv.index("-crd") coord=sys.argv[ind+1] if coord=='s':coord='-1' if coord=='g':coord='0' if coord=='t':coord='100' if "-fsa" in args: ind=args.index("-fsa") samp_file=sys.argv[ind+1] if "-Fa" in args: ind=args.index("-Fa") rmag_anis=args[ind+1] if "-Fr" in args: ind=args.index("-Fr") rmag_res=args[ind+1] meas_file=dir_path+'/'+meas_file samp_file=dir_path+'/'+samp_file rmag_anis=dir_path+'/'+rmag_anis rmag_res=dir_path+'/'+rmag_res # read in data meas_data,file_type=pmag.magic_read(meas_file) meas_data=pmag.get_dictitem(meas_data,'magic_method_codes','LP-AN-ARM','has') if file_type != 'magic_measurements': print file_type print file_type,"This is not a valid magic_measurements file " sys.exit() if coord!='-1': # need to read in sample data samp_data,file_type=pmag.magic_read(samp_file) if file_type != 'er_samples': print file_type print file_type,"This is not a valid er_samples file " print "Only specimen coordinates will be calculated" coord='-1' # # sort the specimen names # ssort=[] for rec in meas_data: spec=rec["er_specimen_name"] if spec not in ssort: ssort.append(spec) if len(ssort)>1: sids=sorted(ssort) else: sids=ssort # # work on each specimen # specimen=0 RmagSpecRecs,RmagResRecs=[],[] while specimen < len(sids): s=sids[specimen] data=[] RmagSpecRec={} RmagResRec={} method_codes=[] # # find the data from the meas_data file for this sample # data=pmag.get_dictitem(meas_data,'er_specimen_name',s,'T') # # find out the number of measurements (9, 12 or 15) # npos=len(data)/2 if npos==9: # # get dec, inc, int and convert to x,y,z # B,H,tmpH=pmag.designAARM(npos) # B matrix made from design matrix for positions X=[] for rec in data: Dir=[] Dir.append(float(rec["measurement_dec"])) Dir.append(float(rec["measurement_inc"])) Dir.append(float(rec["measurement_magn_moment"])) X.append(pmag.dir2cart(Dir)) # # subtract baseline and put in a work array # work=numpy.zeros((npos,3),'f') for i in range(npos): for j in range(3): work[i][j]=X[2*i+1][j]-X[2*i][j] # # calculate tensor elements # first put ARM components in w vector # w=numpy.zeros((npos*3),'f') index=0 for i in range(npos): for j in range(3): w[index]=work[i][j] index+=1 s=numpy.zeros((6),'f') # initialize the s matrix for i in range(6): for j in range(len(w)): s[i]+=B[i][j]*w[j] trace=s[0]+s[1]+s[2] # normalize by the trace for i in range(6): s[i]=s[i]/trace a=pmag.s2a(s) #------------------------------------------------------------ # Calculating dels is different than in the Kappabridge # routine. Use trace normalized tensor (a) and the applied # unit field directions (tmpH) to generate model X,Y,Z # components. Then compare these with the measured values. #------------------------------------------------------------ S=0. comp=numpy.zeros((npos*3),'f') for i in range(npos): for j in range(3): index=i*3+j compare=a[j][0]*tmpH[i][0]+a[j][1]*tmpH[i][1]+a[j][2]*tmpH[i][2] comp[index]=compare for i in range(npos*3): d=w[i]/trace - comp[i] # del values S+=d*d nf=float(npos*3-6) # number of degrees of freedom if S >0: sigma=numpy.sqrt(S/nf) else: sigma=0 RmagSpecRec["rmag_anisotropy_name"]=data[0]["er_specimen_name"] RmagSpecRec["er_location_name"]=data[0]["er_location_name"] RmagSpecRec["er_specimen_name"]=data[0]["er_specimen_name"] RmagSpecRec["er_sample_name"]=data[0]["er_sample_name"] RmagSpecRec["er_site_name"]=data[0]["er_site_name"] RmagSpecRec["magic_experiment_names"]=RmagSpecRec["rmag_anisotropy_name"]+":AARM" RmagSpecRec["er_citation_names"]="This study" RmagResRec["rmag_result_name"]=data[0]["er_specimen_name"]+":AARM" RmagResRec["er_location_names"]=data[0]["er_location_name"] RmagResRec["er_specimen_names"]=data[0]["er_specimen_name"] RmagResRec["er_sample_names"]=data[0]["er_sample_name"] RmagResRec["er_site_names"]=data[0]["er_site_name"] RmagResRec["magic_experiment_names"]=RmagSpecRec["rmag_anisotropy_name"]+":AARM" RmagResRec["er_citation_names"]="This study" if "magic_instrument_codes" in data[0].keys(): RmagSpecRec["magic_instrument_codes"]=data[0]["magic_instrument_codes"] else: RmagSpecRec["magic_instrument_codes"]="" RmagSpecRec["anisotropy_type"]="AARM" RmagSpecRec["anisotropy_description"]="Hext statistics adapted to AARM" if coord!='-1': # need to rotate s # set orientation priorities SO_methods=[] for rec in samp_data: if "magic_method_codes" not in rec: rec['magic_method_codes']='SO-NO' if "magic_method_codes" in rec: methlist=rec["magic_method_codes"] for meth in methlist.split(":"): if "SO" in meth and "SO-POM" not in meth.strip(): if meth.strip() not in SO_methods: SO_methods.append(meth.strip()) SO_priorities=pmag.set_priorities(SO_methods,0) # continue here redo,p=1,0 if len(SO_methods)<=1: az_type=SO_methods[0] orient=pmag.find_samp_rec(RmagSpecRec["er_sample_name"],samp_data,az_type) if orient["sample_azimuth"] !="": method_codes.append(az_type) redo=0 while redo==1: if p>=len(SO_priorities): print "no orientation data for ",s orient["sample_azimuth"]="" orient["sample_dip"]="" method_codes.append("SO-NO") redo=0 else: az_type=SO_methods[SO_methods.index(SO_priorities[p])] orient=pmag.find_samp_rec(PmagSpecRec["er_sample_name"],samp_data,az_type) if orient["sample_azimuth"] !="": method_codes.append(az_type) redo=0 p+=1 az,pl=orient['sample_azimuth'],orient['sample_dip'] s=pmag.dosgeo(s,az,pl) # rotate to geographic coordinates if coord=='100': sampe_bed_dir,sample_bed_dip=orient['sample_bed_dip_direction'],orient['sample_bed_dip'] s=pmag.dostilt(s,bed_dir,bed_dip) # rotate to geographic coordinates hpars=pmag.dohext(nf,sigma,s) # # prepare for output # RmagSpecRec["anisotropy_s1"]='%8.6f'%(s[0]) RmagSpecRec["anisotropy_s2"]='%8.6f'%(s[1]) RmagSpecRec["anisotropy_s3"]='%8.6f'%(s[2]) RmagSpecRec["anisotropy_s4"]='%8.6f'%(s[3]) RmagSpecRec["anisotropy_s5"]='%8.6f'%(s[4]) RmagSpecRec["anisotropy_s6"]='%8.6f'%(s[5]) RmagSpecRec["anisotropy_mean"]='%8.3e'%(trace/3) RmagSpecRec["anisotropy_sigma"]='%8.6f'%(sigma) RmagSpecRec["anisotropy_unit"]="Am^2" RmagSpecRec["anisotropy_n"]='%i'%(npos) RmagSpecRec["anisotropy_tilt_correction"]=coord RmagSpecRec["anisotropy_F"]='%7.1f '%(hpars["F"]) # used by thellier_gui - must be taken out for uploading RmagSpecRec["anisotropy_F_crit"]=hpars["F_crit"] # used by thellier_gui - must be taken out for uploading RmagResRec["anisotropy_t1"]='%8.6f '%(hpars["t1"]) RmagResRec["anisotropy_t2"]='%8.6f '%(hpars["t2"]) RmagResRec["anisotropy_t3"]='%8.6f '%(hpars["t3"]) RmagResRec["anisotropy_v1_dec"]='%7.1f '%(hpars["v1_dec"]) RmagResRec["anisotropy_v2_dec"]='%7.1f '%(hpars["v2_dec"]) RmagResRec["anisotropy_v3_dec"]='%7.1f '%(hpars["v3_dec"]) RmagResRec["anisotropy_v1_inc"]='%7.1f '%(hpars["v1_inc"]) RmagResRec["anisotropy_v2_inc"]='%7.1f '%(hpars["v2_inc"]) RmagResRec["anisotropy_v3_inc"]='%7.1f '%(hpars["v3_inc"]) RmagResRec["anisotropy_ftest"]='%7.1f '%(hpars["F"]) RmagResRec["anisotropy_ftest12"]='%7.1f '%(hpars["F12"]) RmagResRec["anisotropy_ftest23"]='%7.1f '%(hpars["F23"]) RmagResRec["result_description"]='Critical F: '+hpars["F_crit"]+';Critical F12/F13: '+hpars["F12_crit"] if hpars["e12"]>hpars["e13"]: RmagResRec["anisotropy_v1_zeta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v1_zeta_dec"]='%7.1f '%(hpars['v2_dec']) RmagResRec["anisotropy_v1_zeta_inc"]='%7.1f '%(hpars['v2_inc']) RmagResRec["anisotropy_v2_zeta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v2_zeta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v2_zeta_inc"]='%7.1f '%(hpars['v1_inc']) RmagResRec["anisotropy_v1_eta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v1_eta_dec"]='%7.1f '%(hpars['v3_dec']) RmagResRec["anisotropy_v1_eta_inc"]='%7.1f '%(hpars['v3_inc']) RmagResRec["anisotropy_v3_eta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v3_eta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v3_eta_inc"]='%7.1f '%(hpars['v1_inc']) else: RmagResRec["anisotropy_v1_zeta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v1_zeta_dec"]='%7.1f '%(hpars['v3_dec']) RmagResRec["anisotropy_v1_zeta_inc"]='%7.1f '%(hpars['v3_inc']) RmagResRec["anisotropy_v3_zeta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v3_zeta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v3_zeta_inc"]='%7.1f '%(hpars['v1_inc']) RmagResRec["anisotropy_v1_eta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v1_eta_dec"]='%7.1f '%(hpars['v2_dec']) RmagResRec["anisotropy_v1_eta_inc"]='%7.1f '%(hpars['v2_inc']) RmagResRec["anisotropy_v2_eta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v2_eta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v2_eta_inc"]='%7.1f '%(hpars['v1_inc']) if hpars["e23"]>hpars['e12']: RmagResRec["anisotropy_v2_zeta_semi_angle"]='%7.1f '%(hpars['e23']) RmagResRec["anisotropy_v2_zeta_dec"]='%7.1f '%(hpars['v3_dec']) RmagResRec["anisotropy_v2_zeta_inc"]='%7.1f '%(hpars['v3_inc']) RmagResRec["anisotropy_v3_zeta_semi_angle"]='%7.1f '%(hpars['e23']) RmagResRec["anisotropy_v3_zeta_dec"]='%7.1f '%(hpars['v2_dec']) RmagResRec["anisotropy_v3_zeta_inc"]='%7.1f '%(hpars['v2_inc']) RmagResRec["anisotropy_v3_eta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v3_eta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v3_eta_inc"]='%7.1f '%(hpars['v1_inc']) RmagResRec["anisotropy_v2_eta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v2_eta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v2_eta_inc"]='%7.1f '%(hpars['v1_inc']) else: RmagResRec["anisotropy_v2_zeta_semi_angle"]='%7.1f '%(hpars['e12']) RmagResRec["anisotropy_v2_zeta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v2_zeta_inc"]='%7.1f '%(hpars['v1_inc']) RmagResRec["anisotropy_v3_eta_semi_angle"]='%7.1f '%(hpars['e23']) RmagResRec["anisotropy_v3_eta_dec"]='%7.1f '%(hpars['v2_dec']) RmagResRec["anisotropy_v3_eta_inc"]='%7.1f '%(hpars['v2_inc']) RmagResRec["anisotropy_v3_zeta_semi_angle"]='%7.1f '%(hpars['e13']) RmagResRec["anisotropy_v3_zeta_dec"]='%7.1f '%(hpars['v1_dec']) RmagResRec["anisotropy_v3_zeta_inc"]='%7.1f '%(hpars['v1_inc']) RmagResRec["anisotropy_v2_eta_semi_angle"]='%7.1f '%(hpars['e23']) RmagResRec["anisotropy_v2_eta_dec"]='%7.1f '%(hpars['v3_dec']) RmagResRec["anisotropy_v2_eta_inc"]='%7.1f '%(hpars['v3_inc']) RmagResRec["tilt_correction"]='-1' RmagResRec["anisotropy_type"]='AARM' RmagResRec["magic_method_codes"]='LP-AN-ARM:AE-H' RmagSpecRec["magic_method_codes"]='LP-AN-ARM:AE-H' RmagResRec["magic_software_packages"]=pmag.get_version() RmagSpecRec["magic_software_packages"]=pmag.get_version() specimen+=1 RmagSpecRecs.append(RmagSpecRec) RmagResRecs.append(RmagResRec) else: print 'skipping specimen ',s,' only 9 positions supported','; this has ',npos specimen+=1 if rmag_anis=="":rmag_anis="rmag_anisotropy.txt" pmag.magic_write(rmag_anis,RmagSpecRecs,'rmag_anisotropy') print "specimen tensor elements stored in ",rmag_anis if rmag_res=="":rmag_res="rmag_results.txt" pmag.magic_write(rmag_res,RmagResRecs,'rmag_results') print "specimen statistics and eigenparameters stored in ",rmag_res
def main(): """ NAME sufar4-asc_magic.py DESCRIPTION converts ascii files generated by SUFAR ver.4.0 to MagIC formated files for use with PmagPy plotting software SYNTAX sufar4-asc_magic.py -h [command line options] OPTIONS -h: prints the help message and quits -f FILE: specify .asc input file name -F MFILE: specify magic_measurements output file -Fa AFILE: specify rmag_anisotropy output file -Fr RFILE: specify rmag_results output file -Fs SFILE: specify er_specimens output file with location, sample, site, etc. information -usr USER: specify who made the measurements -loc LOC: specify location name for study -ins INST: specify instrument used -spc SPEC: specify number of characters to specify specimen from sample -ncn NCON: specify naming convention: default is #2 below -k15 : specify static 15 position mode - default is spinning -new : replace all existing magic files DEFAULTS AFILE: rmag_anisotropy.txt RFILE: rmag_results.txt SFILE: default is to create new er_specimen.txt file USER: "" LOC: "unknown" INST: "" SPEC: 0 sample name is same as site (if SPEC is 1, sample is all but last character) appends to 'er_specimens.txt, er_samples.txt, er_sites.txt' files Sample naming convention: [1] XXXXY: where XXXX is an arbitrary length site designation and Y is the single character sample designation. e.g., TG001a is the first sample from site TG001. [default] [2] XXXX-YY: YY sample from site XXXX (XXX, YY of arbitary length) [3] XXXX.YY: YY sample from site XXXX (XXX, YY of arbitary length) [4-Z] XXXX[YYY]: YYY is sample designation with Z characters from site XXX [5] site name same as sample [6] site is entered under a separate column [7-Z] [XXXX]YYY: XXXX is site designation with Z characters with sample name XXXXYYYY NB: all others you will have to customize your self or e-mail [email protected] for help. [8] This is a synthetic [9] ODP naming convention """ citation = "This study" cont = 0 samp_con, Z = "1", 1 AniRecSs, AniRecs, SpecRecs, SampRecs, SiteRecs, MeasRecs = [], [], [], [], [], [] user, locname, specfile = "", "unknown", "er_specimens.txt" isspec, inst, specnum = "0", "", 0 spin, new = 1, 0 dir_path = "." if "-WD" in sys.argv: ind = sys.argv.index("-WD") dir_path = sys.argv[ind + 1] aoutput, routput, moutput = ( dir_path + "/rmag_anisotropy.txt", dir_path + "/rmag_results.txt", dir_path + "/magic_measurements.txt", ) if "-h" in sys.argv: print main.__doc__ sys.exit() if "-usr" in sys.argv: ind = sys.argv.index("-usr") user = sys.argv[ind + 1] if "-ncn" in sys.argv: ind = sys.argv.index("-ncn") samp_con = sys.argv[ind + 1] if "4" in samp_con: if "-" not in samp_con: print "option [4] must be in form 4-Z where Z is an integer" sys.exit() else: Z = samp_con.split("-")[1] samp_con = "4" if "7" in samp_con: if "-" not in samp_con: print "option [7] must be in form 7-Z where Z is an integer" sys.exit() else: Z = samp_con.split("-")[1] samp_con = "7" if "-k15" in sys.argv: spin = 0 if "-ins" in sys.argv: ind = sys.argv.index("-ins") inst = sys.argv[ind + 1] if "-f" in sys.argv: ind = sys.argv.index("-f") ascfile = dir_path + "/" + sys.argv[ind + 1] if "-F" in sys.argv: ind = sys.argv.index("-F") moutput = dir_path + "/" + sys.argv[ind + 1] if "-Fa" in sys.argv: ind = sys.argv.index("-Fa") aoutput = dir_path + "/" + sys.argv[ind + 1] if "-Fr" in sys.argv: ind = sys.argv.index("-Fr") routput = dir_path + "/" + sys.argv[ind + 1] if "-Fs" in sys.argv: ind = sys.argv.index("-Fs") specfile = dir_path + "/" + sys.argv[ind + 1] isspec = "1" elif "-loc" in sys.argv: ind = sys.argv.index("-loc") locname = sys.argv[ind + 1] if "-spc" in sys.argv: ind = sys.argv.index("-spc") specnum = -(int(sys.argv[ind + 1])) if specnum != 0: specnum = -specnum if isspec == "1": specs, file_type = pmag.magic_read(specfile) specnames, sampnames, sitenames = [], [], [] if "-new" not in sys.argv: # see if there are already specimen,sample, site files lying around try: SpecRecs, file_type = pmag.magic_read(dir_path + "/er_specimens.txt") for spec in SpecRecs: if spec["er_specimen_name"] not in specnames: specnames.append(samp["er_specimen_name"]) except: SpecRecs, specs = [], [] try: SampRecs, file_type = pmag.magic_read(dir_path + "/er_samples.txt") for samp in SampRecs: if samp["er_sample_name"] not in sampnames: sampnames.append(samp["er_sample_name"]) except: sampnames, SampRecs = [], [] try: SiteRecs, file_type = pmag.magic_read(dir_path + "/er_sites.txt") for site in SiteRecs: if site["er_site_names"] not in sitenames: sitenames.append(site["er_site_name"]) except: sitenames, SiteRecs = [], [] try: input = open(ascfile, "rU") except: print "Error opening file: ", ascfile Data = input.readlines() k = 0 while k < len(Data): line = Data[k] words = line.split() if "ANISOTROPY" in words: # first line of data for the spec MeasRec, AniRec, SpecRec, SampRec, SiteRec = {}, {}, {}, {}, {} specname = words[0] AniRec["er_specimen_name"] = specname if isspec == "1": for spec in specs: if spec["er_specimen_name"] == specname: AniRec["er_sample_name"] = spec["er_sample_name"] AniRec["er_site_name"] = spec["er_site_name"] AniRec["er_location_name"] = spec["er_location_name"] break elif isspec == "0": if specnum != 0: sampname = specname[:specnum] else: sampname = specname AniRec["er_sample_name"] = sampname SpecRec["er_specimen_name"] = specname SpecRec["er_sample_name"] = sampname SampRec["er_sample_name"] = sampname SiteRec["er_sample_name"] = sampname SiteRec["site_description"] = "s" if samp_con != "9": AniRec["er_site_name"] = pmag.parse_site(AniRec["er_sample_name"], samp_con, Z) SpecRec["er_site_name"] = pmag.parse_site(AniRec["er_sample_name"], samp_con, Z) SampRec["er_site_name"] = pmag.parse_site(AniRec["er_sample_name"], samp_con, Z) SiteRec["er_site_name"] = pmag.parse_site(AniRec["er_sample_name"], samp_con, Z) else: AniRec["er_site_name"] = specname SpecRec["er_site_name"] = specname SampRec["er_site_name"] = specname SiteRec["er_site_name"] = specname pieces = specname.split("-") AniRec["er_expedition_name"] = pieces[0] SpecRec["er_expedition_name"] = pieces[0] SampRec["er_expedition_name"] = pieces[0] SiteRec["er_expedition_name"] = pieces[0] location = pieces[1] AniRec["er_location_name"] = locname SpecRec["er_location_name"] = locname SampRec["er_location_name"] = locname SiteRec["er_location_name"] = locname AniRec["er_citation_names"] = "This study" SpecRec["er_citation_names"] = "This study" SampRec["er_citation_names"] = "This study" SiteRec["er_citation_names"] = "This study" AniRec["er_citation_names"] = "This study" AniRec["magic_instrument_codes"] = inst AniRec["magic_method_codes"] = "LP-X:AE-H:LP-AN-MS" AniRec["magic_experiment_names"] = specname + ":" + "LP-AN-MS" AniRec["er_analyst_mail_names"] = user for key in AniRec.keys(): MeasRec[key] = AniRec[key] MeasRec["measurement_flag"] = "g" AniRec["anisotropy_flag"] = "g" MeasRec["measurement_standard"] = "u" MeasRec["measurement_description"] = "Bulk sucsecptibility measurement" AniRec["anisotropy_type"] = "AMS" AniRec["anisotropy_unit"] = "Normalized by trace - bulk in measurements table" if spin == 1: AniRec["anisotropy_n"] = "192" else: AniRec["anisotropy_n"] = "15" if "Azi" in words and isspec == "0": SampRec["sample_azimuth"] = words[1] labaz = float(words[1]) if "Dip" in words: SampRec["sample_dip"] = "%7.1f" % (-float(words[1])) SpecRec["specimen_vol"] = "%8.3e" % (float(words[10]) * 1e-6) # convert actual volume to m^3 from cm^3 labdip = float(words[1]) if "T1" in words and "F1" in words: k += 2 # read in fourth line down line = Data[k] rec = line.split() dd = rec[1].split("/") dip_direction = int(dd[0]) + 90 SampRec["sample_bed_dip_direction"] = "%i" % (dip_direction) SampRec["sample_bed_dip"] = dd[1] bed_dip = float(dd[1]) if "Mean" in words: k += 4 # read in fourth line down line = Data[k] rec = line.split() MeasRec["measurement_chi_volume"] = rec[1] sigma = 0.01 * float(rec[2]) / 3.0 AniRec["anisotropy_sigma"] = "%7.4f" % (sigma) AniRec["anisotropy_unit"] = "SI" if "factors" in words: k += 4 # read in second line down line = Data[k] rec = line.split() if "Specimen" in words: # first part of specimen data AniRec["anisotropy_s1"] = "%7.4f" % (float(words[5]) / 3.0) # eigenvalues sum to unity - not 3 AniRec["anisotropy_s2"] = "%7.4f" % (float(words[6]) / 3.0) AniRec["anisotropy_s3"] = "%7.4f" % (float(words[7]) / 3.0) k += 1 line = Data[k] rec = line.split() AniRec["anisotropy_s4"] = "%7.4f" % (float(rec[5]) / 3.0) # eigenvalues sum to unity - not 3 AniRec["anisotropy_s5"] = "%7.4f" % (float(rec[6]) / 3.0) AniRec["anisotropy_s6"] = "%7.4f" % (float(rec[7]) / 3.0) AniRec["anisotropy_tilt_correction"] = "-1" AniRecs.append(AniRec) AniRecG, AniRecT = {}, {} for key in AniRec.keys(): AniRecG[key] = AniRec[key] for key in AniRec.keys(): AniRecT[key] = AniRec[key] sbar = [] sbar.append(float(AniRec["anisotropy_s1"])) sbar.append(float(AniRec["anisotropy_s2"])) sbar.append(float(AniRec["anisotropy_s3"])) sbar.append(float(AniRec["anisotropy_s4"])) sbar.append(float(AniRec["anisotropy_s5"])) sbar.append(float(AniRec["anisotropy_s6"])) sbarg = pmag.dosgeo(sbar, labaz, labdip) AniRecG["anisotropy_s1"] = "%12.10f" % (sbarg[0]) AniRecG["anisotropy_s2"] = "%12.10f" % (sbarg[1]) AniRecG["anisotropy_s3"] = "%12.10f" % (sbarg[2]) AniRecG["anisotropy_s4"] = "%12.10f" % (sbarg[3]) AniRecG["anisotropy_s5"] = "%12.10f" % (sbarg[4]) AniRecG["anisotropy_s6"] = "%12.10f" % (sbarg[5]) AniRecG["anisotropy_tilt_correction"] = "0" AniRecs.append(AniRecG) if bed_dip != "" and bed_dip != 0: # have tilt correction sbart = pmag.dostilt(sbarg, dip_direction, bed_dip) AniRecT["anisotropy_s1"] = "%12.10f" % (sbart[0]) AniRecT["anisotropy_s2"] = "%12.10f" % (sbart[1]) AniRecT["anisotropy_s3"] = "%12.10f" % (sbart[2]) AniRecT["anisotropy_s4"] = "%12.10f" % (sbart[3]) AniRecT["anisotropy_s5"] = "%12.10f" % (sbart[4]) AniRecT["anisotropy_s6"] = "%12.10f" % (sbart[5]) AniRecT["anisotropy_tilt_correction"] = "100" AniRecs.append(AniRecT) MeasRecs.append(MeasRec) if SpecRec["er_specimen_name"] not in specnames: SpecRecs.append(SpecRec) specnames.append(SpecRec["er_specimen_name"]) if SampRec["er_sample_name"] not in sampnames: SampRecs.append(SampRec) sampnames.append(SampRec["er_sample_name"]) if SiteRec["er_site_name"] not in sitenames: SiteRecs.append(SiteRec) sitenames.append(SiteRec["er_site_name"]) k += 1 # skip to next specimen pmag.magic_write(aoutput, AniRecs, "rmag_anisotropy") print "anisotropy tensors put in ", aoutput pmag.magic_write(moutput, MeasRecs, "magic_measurements") print "bulk measurements put in ", moutput if isspec == "0": SpecOut, keys = pmag.fillkeys(SpecRecs) output = dir_path + "/er_specimens.txt" pmag.magic_write(output, SpecOut, "er_specimens") print "specimen info put in ", output output = dir_path + "/er_samples.txt" SampOut, keys = pmag.fillkeys(SampRecs) pmag.magic_write(output, SampOut, "er_samples") print "sample info put in ", output output = dir_path + "/er_sites.txt" SiteOut, keys = pmag.fillkeys(SiteRecs) pmag.magic_write(output, SiteOut, "er_sites") print "site info put in ", output print """"