-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.py
179 lines (152 loc) · 5.64 KB
/
debug.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
"""
debug.py
Debugging module for spectrograph simulation. This is to be used to check the
footprint diagram of the spectrographs, not for the optimization purposes
(but that could be implemented).
"""
import numpy as np
#import matplotlib.pyplot as plt
from printer import Printer
from physics import *
from slitfunctions import *
import cfunctions
def fmtcols(mylist, cols):
lines = ("\t".join(mylist[i:i+cols]) for i in xrange(0,len(mylist),cols))
return '\n'.join(lines)
def print_wave_table(arm):
dvline1 = ":::::::::::::::::::::::::::::::::::::::::::::::::"
header = "FSR Wavelengths"
columns = "Order\tWmin [A]\tWblaze [A]\tWmax [A]"
dvline2 = "-------------------------------------------------"
print dvline1
print header
print columns
print dvline2
for m,wmin,wblaze,wmax in zip(arm.ORDERS, arm.fsr_waves_min, arm.bl_ech, arm.fsr_waves_max):
print "%i:\t%.3f\t%.3f\t%.3f" % (m, wmin*1.e7, wblaze*1.e7, wmax*1.e7)
dvline1 = ":::::::::::::::::::::::::::::::::::::::::::::::::"
header = "CCD Wavelengths"
columns = "Order\tWmin [A]\tWblaze [A]\tWmax [A]"
dvline2 = "-------------------------------------------------"
print dvline1
print header
print columns
print dvline2
for m,wmin,wblaze,wmax in zip(arm.ORDERS, arm.ccd_waves_min, arm.bl_ech, arm.ccd_waves_max):
print "%i:\t%.3f\t%.3f\t%.3f" % (m, wmin*1.e7, wblaze*1.e7, wmax*1.e7)
print ""
def compute(arm, orders, wavelengths, slit=0):
"""Compute wrapper for debug."""
norders = orders.size
nw = wavelengths.shape[0]
if slit is 0:
slitfunc = point_source
else:
slitfunc = half_moon_even
slitx, slity = slitfunc(arm, offset=0.0)
print "xd_0 = %.2f mm" % arm.XD_0
print "yd_0 = %.2f mm" % arm.YD_0
xd = np.empty(wavelengths.shape)
yd = np.empty(wavelengths.shape)
ng = np.empty(wavelengths.shape)
returnx = np.empty(wavelengths[0].size)
returny = np.empty(wavelengths[0].size)
for i in xrange(norders):
lamb = wavelengths[i]
ng = n_sell(arm.ARM, lamb)
print "n_sell = ", ng
cfunctions.compute(arm.ARM_FLAG,
0, # blaze flag
1, # location flag
nw,
slitx.size,
orders[i],
arm.XD_0,
arm.YD_0,
np.ascontiguousarray(ng, dtype=np.float64),
np.ascontiguousarray(slitx, dtype=np.float64),
np.ascontiguousarray(slity, dtype=np.float64),
np.ascontiguousarray(lamb, dtype=np.float64),
np.empty(0), # weights
np.empty((0,0)), # ccd
np.empty((0,0), dtype=np.uint), # counts
np.empty((0,0), dtype=np.uint), # order list
np.ascontiguousarray(returnx, dtype=np.float64),
np.ascontiguousarray(returny, dtype=np.float64))
xd[i] = returnx # mm
yd[i] = returny # mm
xd = xd.flatten()/ arm.DPIX
yd = yd.flatten()/arm.DPIX
xdmin = xd.min()
xdmax = xd.max()
xdrange = np.absolute(xdmax - xdmin)
ydmin = yd.min()
ydmax = yd.max()
ydrange = np.absolute(ydmax - ydmin)
return wavelengths.flatten(), xd, yd, xdrange, ydrange
def plot_corners(arm, slit=0):
orders = arm.corner_orders
wavelengths = arm.corner_wavelengths
wavelengths, xd, yd, xdrange, ydrange = compute(arm, orders, wavelengths)
print "::::: FSR WAVELENGTHS :::::"
print "xdrange = %.2f pix" % xdrange
print "ydrange = %.2f pix" % ydrange
xdmin = xd.min()
xdmax = xd.max()
ydmin = yd.min()
ydmax = yd.max()
fig = plt.figure()
ax = fig.add_subplot(111, aspect="auto")
ax.set_title("%s post-xy offset correction" % arm.ARM)
ax.scatter(xd, yd, label="FSR")
#ax.grid()
for i,wave in enumerate(wavelengths):
ax.annotate("%.2f" % (wave*1.e7), xy=(xd[i], yd[i]))
ax.vlines(-arm.NXPIX/2, ydmin, ydmax)
ax.vlines(arm.NXPIX/2, ydmin, ydmax)
ax.fill([-arm.NXPIX/2, arm.NXPIX/2, arm.NXPIX/2, -arm.NXPIX/2],
[-arm.NYPIX/2, -arm.NYPIX/2, arm.NYPIX/2, arm.NYPIX/2],
'r',
alpha=0.1,
edgecolor='g')
plt.legend()
plt.show()
def plot_zemax(arm):
orders = arm.zemax_orders
wavelengths = arm.zemax_wavelengths
wavelengths, xd, yd, xdrange, ydrange = compute(arm, orders, wavelengths)
print "::::: ZEMAX WAVELENGTHS :::::"
print "xdrange = %.2f pix" % xdrange
print "ydrange = %.2f pix" % ydrange
print "xd_0 = %.2f mm" % arm.XD_0
print "yd_0 = %.2f mm" % arm.YD_0
xdmin = xd.min()
xdmax = xd.max()
ydmin = yd.min()
ydmax = yd.max()
fig = plt.figure()
ax = fig.add_subplot(111, aspect="auto")
ax.set_title("%s post-xy offset correction" % arm.ARM)
ax.scatter(xd, yd, label="ZEMAX")
#ax.grid()
for i,wave in enumerate(wavelengths):
ax.annotate("%.2f" % (wave*1.e7), xy=(xd[i], yd[i]))
ax.vlines(-arm.NXPIX/2, ydmin, ydmax)
ax.vlines(arm.NXPIX/2, ydmin, ydmax)
ax.fill([-arm.NXPIX/2, arm.NXPIX/2, arm.NXPIX/2, -arm.NXPIX/2],
[-arm.NYPIX/2, -arm.NYPIX/2, arm.NYPIX/2, arm.NYPIX/2],
'r',
alpha=0.1,
edgecolor='g')
plt.legend()
plt.show()
# :::::::::::::::::::::::::: MAIN ::::::::::::::::::::::::::::::::::
def debug(arm):
#print_wave_table(arm)
#plot_corners(arm)
plot_zemax(arm)
#import_zemax_table(arm)
#plot_slit()
#plot_offset()
#plot_fsr()
return 0