-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcr.py
More file actions
74 lines (56 loc) · 1.91 KB
/
cr.py
File metadata and controls
74 lines (56 loc) · 1.91 KB
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
import getopt, sys
import numpy as np
from lincr import removeContinuumInplace
def main(argv=None):
class usage(Exception):
def __init__(self, msg):
self.msg = msg
if argv is None:
argv = sys.argv
try:
try:
longopts = ['verbose','plot',]
longoptsp = ['infile','outfile']
shortopts = ''.join([o[0] for o in longopts])
shortopts += ''.join([o[0]+':' for o in longoptsp])
opts, args = getopt.getopt(argv[1:], shortopts, longopts)
except getopt.error, msg:
raise usage(msg)
infile,outfile = '','crdat.txt'
verbose,doplot = False,False
for opt, val in opts:
if opt in ('--verbose','-v'):
verbose=True
elif opt in ('--plot','-p'):
doplot=True
if opt in ('--infile','-i'):
infile=val
if opt in ('--outfile','-o'):
outfile=val
except usage, err:
print >>sys.stderr, err.msg
return 2
[wvl,cidat] = np.loadtxt(infile,skiprows=1).T
crdat,ccdat = cidat.copy(),cidat.copy()
removeContinuumInplace(wvl,crdat,0,verbose)
removeContinuumInplace(wvl,ccdat,1,verbose)
np.savetxt(outfile,np.c_[wvl,cidat,crdat,ccdat])
print "CR complete, %s written"%outfile
if doplot:
import pylab as pl
pl.figure()
pl.suptitle('Input file: '+infile)
pl.subplot(211)
pl.plot(wvl,cidat,label='Continuum Intact Spectrum')
pl.plot(wvl,ccdat,label='Continuum Curve')
pl.legend(loc='best')
pl.subplot(212)
pl.axhline(1.0,color='k')
pl.axhline(0.0,color='k')
pl.plot(wvl,crdat,label='Continuum Removed Spectrum')
pl.ylim(-0.1,1.1)
pl.xlabel('wavelength')
pl.legend(loc='best')
pl.show()
if __name__ == '__main__':
sys.exit(main())