forked from PmagPy/PmagPy
/
goprinc.py
executable file
·65 lines (59 loc) · 1.99 KB
/
goprinc.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
#!/usr/bin/env python
#!/usr/bin/env python
import pmag,sys
def main():
"""
NAME
goprinc.py
DESCRIPTION
calculates Principal components from dec/iinc data
INPUT FORMAT
takes dec/inc as first two columns in space delimited file
SYNTAX
goprinc.py [options] [< filename]
OPTIONS
-h prints help message and quits
-i for interactive filename entry
-f FILE, specify input file
-F FILE, specifies output file name
< filename for reading from standard input
OUTPUT
tau_1 V1_Dec, V1_Inc, tau_2 V2_Dec V2_Inc, tau_3 V3_Dec V3_Inc, N
"""
if len(sys.argv) > 0:
if '-h' in sys.argv: # check if help is needed
print main.__doc__
sys.exit() # graceful quit
if '-f' in sys.argv:
ind=sys.argv.index('-f')
file=sys.argv[ind+1]
f=open(file,'rU')
data=f.readlines()
elif '-i' in sys.argv: # ask for filename
file=raw_input("Enter file name with dec, inc data: ")
f=open(file,'rU')
data=f.readlines()
else:
#
data=sys.stdin.readlines() # read in data from standard input
ofile = ""
if '-F' in sys.argv:
ind = sys.argv.index('-F')
ofile= sys.argv[ind+1]
out = open(ofile, 'w + a')
DIs= [] # set up list for dec inc data
for line in data: # read in the data from standard input
if '\t' in line:
rec=line.split('\t') # split each line on space to get records
else:
rec=line.split() # split each line on space to get records
DIs.append((float(rec[0]),float(rec[1])))
#
ppars=pmag.doprinc(DIs)
output = '%7.5f %7.1f %7.1f %7.5f %7.1f %7.1f %7.5f %7.1f %7.1f %i' % (ppars["tau1"],ppars["dec"],ppars["inc"],ppars["tau2"],ppars["V2dec"],ppars["V2inc"],ppars["tau3"],ppars["V3dec"],ppars["V3inc"],ppars["N"])
if ofile == "":
print output
else:
out.write(output+'\n')
#
main()