forked from PmagPy/PmagPy
/
ODP_srm_magic.py
executable file
·188 lines (184 loc) · 8.18 KB
/
ODP_srm_magic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env python
import pmag,sys,os,exceptions
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
main()