forked from PmagPy/PmagPy
/
dmag_magic.py
executable file
·119 lines (115 loc) · 4.8 KB
/
dmag_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
#!/usr/bin/env python
import sys,pmag,pmagplotlib
def main():
"""
NAME
dmag_magic.py
DESCRIPTION
plots intensity decay curves for demagnetization experiments
SYNTAX
dmag_magic -h [command line options]
INPUT
takes magic formatted magic_measurements.txt files
OPTIONS
-h prints help message and quits
-f FILE: specify input file, default is: magic_measurements.txt
-obj OBJ: specify object [loc, sit, sam, spc] for plot, default is by location
-LT [AF,T,M]: specify lab treatment type, default AF
-XLP [PI]: exclude specific lab protocols (for example, method codes like LP-PI)
-N do not normalize by NRM magnetization
NOTE
loc: location (study); sit: site; sam: sample; spc: specimen
"""
FIG={} # plot dictionary
FIG['demag']=1 # demag is figure 1
in_file,plot_key,LT='magic_measurements.txt','er_location_name',"LT-AF-Z"
XLP=""
norm=1
LT='LT-AF-Z'
units,dmag_key='T','treatment_ac_field'
plot_key='er_location_name'
if len(sys.argv)>1:
if '-h' in sys.argv:
print main.__doc__
sys.exit()
if '-N' in sys.argv: norm=0
if '-f' in sys.argv:
ind=sys.argv.index("-f")
in_file=sys.argv[ind+1]
if '-obj' in sys.argv:
ind=sys.argv.index('-obj')
plot_by=sys.argv[ind+1]
if plot_by=='sit':plot_key='er_site_name'
if plot_by=='sam':plot_key='er_sample_name'
if plot_by=='spc':plot_key='er_specimen_name'
if '-XLP' in sys.argv:
ind=sys.argv.index("-XLP")
XLP=sys.argv[ind+1] # get lab protocol for excluding
if '-LT' in sys.argv:
ind=sys.argv.index("-LT")
LT='LT-'+sys.argv[ind+1]+'-Z' # get lab treatment for plotting
if LT=='LT-T-Z':
units,dmag_key='K','treatment_temp'
elif LT=='LT-AF-Z':
units,dmag_key='T','treatment_ac_field'
elif LT=='LT-M-Z':
units,dmag_key='J','treatment_mw_energy'
else:
units='U'
data,file_type=pmag.magic_read(in_file)
sids=pmag.get_specs(data)
pmagplotlib.plot_init(FIG['demag'],5,5)
print len(data),' records read from ',in_file
#
#
# find desired intensity data
#
# get plotlist
#
plotlist,intlist=[],['measurement_magnitude','measurement_magn_moment','measurement_magn_volume','measurement_magn_mass']
IntMeths=[]
FixData=[]
for rec in data:
meths=[]
methcodes=rec['magic_method_codes'].split(':')
for meth in methcodes:meths.append(meth.strip())
for key in rec.keys():
if key in intlist and rec[key]!="":
if key not in IntMeths:IntMeths.append(key)
if rec[plot_key] not in plotlist and LT in meths: plotlist.append(rec[plot_key])
if 'measurement_flag' not in rec.keys():rec['measurement_flag']='g'
FixData.append(rec)
plotlist.sort()
if len(IntMeths)==0:
print 'No intensity information found'
sys.exit()
data=FixData
int_key=IntMeths[0] # plot first intensity method found - normalized to initial value anyway - doesn't matter which used
for plot in plotlist:
print plot,'plotting by: ',plot_key
PLTblock=pmag.get_dictitem(data,plot_key,plot,'T') # fish out all the data for this type of plot
PLTblock=pmag.get_dictitem(PLTblock,'magic_method_codes',LT,'has') # fish out all the dmag for this experiment type
PLTblock=pmag.get_dictitem(PLTblock,int_key,'','F') # get all with this intensity key non-blank
if XLP!="":PLTblock=pmag.get_dictitem(PLTblock,'magic_method_codes',XLP,'not') # reject data with XLP in method_code
if len(PLTblock)>2:
title=PLTblock[0][plot_key]
spcs=[]
for rec in PLTblock:
if rec['er_specimen_name'] not in spcs:spcs.append(rec['er_specimen_name'])
for spc in spcs:
SPCblock=pmag.get_dictitem(PLTblock,'er_specimen_name',spc,'T') # plot specimen by specimen
INTblock=[]
for rec in SPCblock:
INTblock.append([float(rec[dmag_key]),0,0,float(rec[int_key]),1,rec['measurement_flag']])
if len(INTblock)>2:
pmagplotlib.plotMT(FIG['demag'],INTblock,title,0,units,norm)
pmagplotlib.drawFIGS(FIG)
ans=raw_input(" S[a]ve to save plot, [q]uit, Return to continue: ")
if ans=='q':sys.exit()
if ans=="a":
files={}
for key in FIG.keys():
files[key]=title+'_'+LT+'.svg'
pmagplotlib.saveP(FIG,files)
pmagplotlib.clearFIG(FIG['demag'])
main()