-
Notifications
You must be signed in to change notification settings - Fork 1
/
aries_measure_arc.py
117 lines (89 loc) · 2.91 KB
/
aries_measure_arc.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
import os, sys
import numpy as np
import argparse
from ccdproc import CCDData
from pyhrs import red_process
import specutils
from astropy import units as u
from astropy import modeling as mod
from astropy.io import fits
import pylab as pl
import specreduce
from specreduce.models import ISISModel
from specreduce.interidentify import InterIdentify
from specreduce import spectools as st
from specreduce import WavelengthSolution
#Xe_spec = specutils.io.read_ascii.read_ascii_spectrum1d('Xe.salt', dispersion_unit=u.angstrom)
parser = argparse.ArgumentParser(description='Reduce arc data from SALT Engineering Aries Observations')
parser.add_argument('arcfile', help='an arcfile to wavelength calibrate')
parser.add_argument('--list', dest='arc_ref', default='CuArNe.txt',
help='File with list of known arc lines')
parser.add_argument('--yc', dest='yc', default=121, type=int,
help='Row to extract')
args = parser.parse_args()
arcfile=args.arcfile
arc = fits.open(arcfile)
#read in arc lines
arc_ref=args.arc_ref
slines, sfluxes = np.loadtxt(arc_ref, usecols=(0,1), unpack=True)
function='poly'
order=3
rstep=1
nrows=1
mdiff=20
wdiff=3
thresh=3
niter=5
dc=3
ndstep=50
dsigma=5
method='Zeropoint'
res=6.0
dres=0.1
filename=None
smooth=0
inter=True
subback=0
textcolor='black'
log = None
data = arc[0].data
xarr = np.arange(data.shape[1])
warr = 4000 *u.angstrom + 4 * xarr * u.angstrom
#warr = rss.get_wavelength(xarr) * u.mm
#warr = warr.to(u.angstrom)
yc = args.yc
lmax = data[yc].max()
swarr, sfarr = st.makeartificial(slines, sfluxes, lmax, res, dres)
pl.plot(warr, data[yc])
mask = (swarr > warr.value.min()) * ( swarr < warr.value.max())
pl.plot(swarr[mask], sfarr[mask])
#pmel.show()
#nws = fit_ws(ws_init, xarr, warr)
ws_init = mod.models.Legendre1D(3)
ws_init.domain = [xarr.min(), xarr.max()]
ws = WavelengthSolution.WavelengthSolution(xarr, warr.value, ws_init)
ws.fit()
istart = yc
smask = (slines > warr.value.min()-20) * (slines < warr.value.max()+20)
iws = InterIdentify(xarr, data, slines[smask], sfluxes[smask], ws, mdiff=mdiff, rstep=rstep,
function=function, order=order, sigma=thresh, niter=niter, wdiff=wdiff,
res=res, dres=dres, dc=dc, ndstep=ndstep, istart=istart,
method=method, smooth=smooth, filename=filename,
subback=subback, textcolor=textcolor, log=log, verbose=True)
import pickle
name = os.path.basename(arcfile).replace('fit', 'pkl')
pickle.dump(iws, open(name, 'w'))
exit()
ws_init = mod.models.Legendre1D(3)
ws_init.domain = [xarr.min(), xarr.max()]
ws = WavelengthSolution.WavelengthSolution(xarr, xarr, ws_init)
ws.fit()
istart = arg.yc
aws = st.arc_straighten(data, istart, ws, rstep=1)
data = st.wave_map(data, aws)
k = iws.keys()[0]
for i in range(data.shape[0]):
data[i,:] = iws[k](data[i,:])
arc.append(fits.ImageHDU(data=data, name='WAV'))
arc.writeto('w_' + os.path.basename(arcfile), clobber=True)
exit()