-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplot.py
75 lines (55 loc) · 1.83 KB
/
splot.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
#!/usr/bin/env python
#
# Look at VSOP spectra
#
# Import core Python modules
import optparse, os.path, os, re
# Import PyRAF and IRAF, the IRAF packages
import pyraf, iraf
from pyraf.iraf import onedspec
VERSION = '0.9'
matchfits = re.compile(r".*0_s1d\.fits$")
def getTargets (targets, targetList):
if targetList != None:
f = open (targetList, mode='r')
for target in f:
targets.append(target.strip('\n'))
f.close()
validTargets = []
invalidTargets = []
for target in targets:
if os.path.isdir (target):
validTargets.append(target)
else:
invalidTargets.append(target)
return validTargets, invalidTargets
def getSpectra (targets):
specdict = {}
for target in targets:
files = os.listdir(target+'/wiki/')
sp =[]
for f in files:
if matchfits.match(f): sp.append(target+'/wiki/'+f)
specdict[target] = sp
return specdict
def main():
# Parse input arguments
usage = 'usage: %prog [options] targets'
p = optparse.OptionParser(usage=usage, version='v'+VERSION)
p.add_option('--debug', action='store_true', help='toggle debug messages')
p.add_option('--verbose', '-v', action='store_true', help='toggle on verbose mode')
p.add_option('--tlist', '-l', action='store', type='string', dest='tlist', help='Target list')
(options, args) = p.parse_args()
if options.debug:
options.verbose = True
print 'options: ', options
print 'args: ', args
(validTargets, invalidTarget) = getTargets(args, options.tlist)
specdict = getSpectra(validTargets)
onedspec()
for target in validTargets:
print target
for spectrum in specdict[target]:
onedspec.splot(spectrum)
if __name__ == '__main__':
main()