forked from PmagPy/PmagPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
irmaq_magic.py
executable file
·97 lines (93 loc) · 3.41 KB
/
irmaq_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
#!/usr/bin/env python
import sys,pmag,pmagplotlib
def main():
"""
NAME
irmaq_magic.py
DESCRIPTION
plots IRM acquisition curves from magic_measurements file
SYNTAX
irmaq_magic [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
-N ; do not normalize by last point - use original units
NOTE
loc: location (study); sit: site; sam: sample; spc: specimen
"""
FIG={} # plot dictionary
FIG['exp']=1 # exp is figure 1
dir_path='./'
units,dmag_key='T','treatment_dc_field'
XLP=[]
norm=1
in_file,plot_key,LP='magic_measurements.txt','er_location_name',"LP-IRM"
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 '-WD' in sys.argv:
ind=sys.argv.index('-WD')
dir_path=sys.argv[ind+1]
in_file=dir_path+'/'+in_file
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'
data,file_type=pmag.magic_read(in_file)
sids=pmag.get_specs(data)
pmagplotlib.plot_init(FIG['exp'],6,6)
#
#
# find desired intensity data
#
# get plotlist
#
plotlist,intlist=[],['measurement_magnitude','measurement_magn_moment','measurement_magn_volume','measurement_magn_mass']
IntMeths=[]
data=pmag.get_dictitem(data,'magic_method_codes',LP,'has') # get all the records with this lab protocol
Ints={}
NoInts,int_key=1,""
for key in intlist:
Ints[key]=pmag.get_dictitem(data,key,'','F') # get all non-blank data for intensity type
if len(Ints[key])>0:
NoInts=0
if int_key=="":int_key=key
if NoInts==1:
print 'No intensity information found'
sys.exit()
for rec in Ints[int_key]:
if rec[plot_key] not in plotlist: plotlist.append(rec[plot_key])
plotlist.sort()
for plot in plotlist:
print plot
INTblock=[]
data=pmag.get_dictitem(Ints[int_key],plot_key,plot,'T') # get data with right intensity info whose plot_key matches plot
sids=pmag.get_specs(data) # get a list of specimens with appropriate data
if len(sids)>0:
title=data[0][plot_key]
for s in sids:
INTblock=[]
sdata=pmag.get_dictitem(data,'er_specimen_name',s,'T') # get data for each specimen
for rec in sdata:
INTblock.append([float(rec[dmag_key]),0,0,float(rec[int_key]),1,'g'])
pmagplotlib.plotMT(FIG['exp'],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+'_'+LP+'.svg'
pmagplotlib.saveP(FIG,files)
pmagplotlib.clearFIG(FIG['exp'])
main()