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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
include <imhdr.h>
include "ccdred.h"
.help proc Feb87 noao.imred.ccdred
.nf ----------------------------------------------------------------------------
proc -- Process CCD images
These are the main CCD reduction procedures. There is one for each
readout axis (lines or columns) and one for short and real image data.
They apply corrections for bad pixels, overscan levels, zero levels,
dark counts, flat field response, illumination response, and fringe
effects. The image is also trimmed if it was mapped with an image
section. The mean value for the output image is computed when the flat
field or illumination image is processed to form the scale factor for
these calibrations in order to avoid reading through these image a
second time.
The processing information and parameters are specified in the CCD
structure. The processing operations to be performed are specified by
the correction array CORS in the ccd structure. There is one array
element for each operation with indices defined symbolically by macro
definitions (see ccdred.h); i.e. FLATCOR. The value of the array
element is an integer bit field in which the bit set is the same as the
array index; i.e element 3 will have the third bit set for an operation
with array value 2**(3-1)=4. If an operation is not to be performed
the bit is not set and the array element has the numeric value zero.
Note that the addition of several correction elements gives a unique
bit field describing a combination of operations. For efficiency the
most common combinations are implemented as separate units.
The CCD structure also contains the correction or calibration data
consisting either pointers to data, IMIO pointers for the calibration
images, and scale factors.
The processing is performed line-by-line. The procedure CORINPUT is
called to get an input line. This procedure trims and fixes bad pixels by
interpolation. The output line and lines from the various calibration
images are read. The image vectors as well as the overscan vector and
the scale factors are passed to the procedure COR (which also
dereferences the pointer data into simple arrays and variables). That
procedure does the actual corrections apart from bad pixel
corrections.
The final optional step is to add each corrected output line to form a
mean. This adds efficiency since the operation is done only if desired
and the output image data is already in memory so there is no I/O
penalty.
SEE ALSO
ccdred.h, cor, fixpix, setfixpix, setoverscan, settrim,
setzero, setdark, setflat, setillum, setfringe
.endhelp ----------------------------------------------------------------------
$for (sr)
# PROC1 -- Process CCD images with readout axis 1 (lines).
procedure proc1$t (ccd)
pointer ccd # CCD structure
int line, ncols, nlines, findmean, rep
int overscan_type, overscan_c1, noverscan
real overscan, darkscale, flatscale, illumscale, frgscale, mean
PIXEL minrep
pointer in, out, zeroim, darkim, flatim, illumim, fringeim, overscan_vec
pointer inbuf, outbuf, zerobuf, darkbuf, flatbuf, illumbuf, fringebuf
$if (datatype == csir)
real asum$t()
$else $if (datatype == ld)
double asum$t()
$else
PIXEL asum$t()
$endif $endif
real find_overscan$t()
pointer imgl2$t(), impl2$t(), ccd_gl$t(), xt_fps$t()
begin
# Initialize. If the correction image is 1D then just get the
# data once.
in = IN_IM(ccd)
out = OUT_IM(ccd)
ncols = OUT_C2(ccd) - OUT_C1(ccd) + 1
nlines = OUT_L2(ccd) - OUT_L1(ccd) + 1
findmean = CORS(ccd, FINDMEAN)
if (findmean == YES)
mean = 0.
rep = CORS(ccd, MINREP)
if (rep == YES)
minrep = MINREPLACE(ccd)
if (CORS(ccd, OVERSCAN) == 0)
overscan_type = 0
else {
overscan_type = OVERSCAN_TYPE(ccd)
overscan_vec = OVERSCAN_VEC(ccd)
overscan_c1 = BIAS_C1(ccd) - 1
noverscan = BIAS_C2(ccd) - overscan_c1
}
if (CORS(ccd, ZEROCOR) == 0) {
zeroim = NULL
zerobuf = 1
} else if (IM_LEN(ZERO_IM(ccd),2) == 1) {
zeroim = NULL
zerobuf = ccd_gl$t (ZERO_IM(ccd), ZERO_C1(ccd), ZERO_C2(ccd), 1)
} else
zeroim = ZERO_IM(ccd)
if (CORS(ccd, DARKCOR) == 0) {
darkim = NULL
darkbuf = 1
} else if (IM_LEN(DARK_IM(ccd),2) == 1) {
darkim = NULL
darkbuf = ccd_gl$t (DARK_IM(ccd), DARK_C1(ccd), DARK_C2(ccd), 1)
darkscale = FLATSCALE(ccd)
} else {
darkim = DARK_IM(ccd)
darkscale = DARKSCALE(ccd)
}
if (CORS(ccd, FLATCOR) == 0) {
flatim = NULL
flatbuf = 1
} else if (IM_LEN(FLAT_IM(ccd),2) == 1) {
flatim = NULL
flatbuf = ccd_gl$t (FLAT_IM(ccd), FLAT_C1(ccd), FLAT_C2(ccd), 1)
flatscale = FLATSCALE(ccd)
} else {
flatim = FLAT_IM(ccd)
flatscale = FLATSCALE(ccd)
}
if (CORS(ccd, ILLUMCOR) == 0) {
illumim = NULL
illumbuf = 1
} else {
illumim = ILLUM_IM(ccd)
illumscale = ILLUMSCALE(ccd)
}
if (CORS(ccd, FRINGECOR) == 0) {
fringeim = NULL
fringebuf = 1
} else {
fringeim = FRINGE_IM(ccd)
frgscale = FRINGESCALE(ccd)
}
# For each line read lines from the input. Procedure XT_FPS replaces
# bad pixels by interpolation. The trimmed region is copied to the
# output. Get lines from the output image and from the zero level,
# dark count, flat field, illumination, and fringe images. Call COR1
# to do the actual pixel corrections. Finally, add the output pixels
# to a sum for computing the mean. We must copy data outside of the
# output data section.
do line = 2 - OUT_L1(ccd), 0
call amov$t (
Mem$t[imgl2$t(in,IN_L1(ccd)+line-1)+IN_C1(ccd)-OUT_C1(ccd)],
Mem$t[impl2$t(out,OUT_L1(ccd)+line-1)], IM_LEN(out,1))
do line = 1, nlines {
outbuf = impl2$t (out, OUT_L1(ccd)+line-1)
inbuf = xt_fps$t (MASK_FP(ccd), in, IN_L1(ccd)+line-1, IN_C1(ccd),
IN_C2(ccd), IN_L1(ccd), IN_L2(ccd), NULL)
call amov$t (Mem$t[inbuf+IN_C1(ccd)-OUT_C1(ccd)], Mem$t[outbuf],
IM_LEN(out,1))
outbuf = outbuf + OUT_C1(ccd) - 1
if (overscan_type != 0) {
if (overscan_type < OVERSCAN_FIT)
overscan = find_overscan$t (Mem$t[inbuf+overscan_c1],
noverscan, overscan_type)
else
overscan = Memr[overscan_vec+line-1]
}
if (zeroim != NULL)
zerobuf = ccd_gl$t (zeroim, ZERO_C1(ccd), ZERO_C2(ccd),
ZERO_L1(ccd)+line-1)
if (darkim != NULL)
darkbuf = ccd_gl$t (darkim, DARK_C1(ccd), DARK_C2(ccd),
DARK_L1(ccd)+line-1)
if (flatim != NULL)
flatbuf = ccd_gl$t (flatim, FLAT_C1(ccd), FLAT_C2(ccd),
FLAT_L1(ccd)+line-1)
if (illumim != NULL)
illumbuf = ccd_gl$t (illumim, ILLUM_C1(ccd), ILLUM_C2(ccd),
ILLUM_L1(ccd)+line-1)
if (fringeim != NULL)
fringebuf = ccd_gl$t (fringeim, FRINGE_C1(ccd), FRINGE_C2(ccd),
FRINGE_L1(ccd)+line-1)
call cor1$t (CORS(ccd,1), Mem$t[outbuf],
overscan, Mem$t[zerobuf], Mem$t[darkbuf],
Mem$t[flatbuf], Mem$t[illumbuf], Mem$t[fringebuf], ncols,
darkscale, flatscale, illumscale, frgscale)
if (rep == YES)
call amaxk$t (Mem$t[outbuf], minrep, Mem$t[outbuf], ncols)
if (findmean == YES)
mean = mean + asum$t (Mem$t[outbuf], ncols)
}
do line = nlines+1, IM_LEN(out,2)-OUT_L1(ccd)+1
call amov$t (
Mem$t[imgl2$t(in,IN_L1(ccd)+line-1)+IN_C1(ccd)-OUT_C1(ccd)],
Mem$t[impl2$t(out,OUT_L1(ccd)+line-1)], IM_LEN(out,1))
# Compute the mean from the sum of the output pixels.
if (findmean == YES)
MEAN(ccd) = mean / ncols / nlines
end
# PROC2 -- Process CCD images with readout axis 2 (columns).
procedure proc2$t (ccd)
pointer ccd # CCD structure
int line, ncols, nlines, findmean, rep
real darkscale, flatscale, illumscale, frgscale, mean
PIXEL minrep
pointer in, out, zeroim, darkim, flatim, illumim, fringeim, overscan_vec
pointer inbuf, outbuf, zerobuf, darkbuf, flatbuf, illumbuf, fringebuf
$if (datatype == csir)
real asum$t()
$else $if (datatype == ld)
double asum$t()
$else
PIXEL asum$t()
$endif $endif
pointer imgl2$t(), impl2$t(), imgs2$t(), ccd_gl$t(), xt_fps$t()
begin
# Initialize. If the correction image is 1D then just get the
# data once.
in = IN_IM(ccd)
out = OUT_IM(ccd)
ncols = OUT_C2(ccd) - OUT_C1(ccd) + 1
nlines = OUT_L2(ccd) - OUT_L1(ccd) + 1
findmean = CORS(ccd, FINDMEAN)
if (findmean == YES)
mean = 0.
rep = CORS(ccd, MINREP)
if (rep == YES)
minrep = MINREPLACE(ccd)
overscan_vec = OVERSCAN_VEC(ccd)
if (CORS(ccd, ZEROCOR) == 0) {
zeroim = NULL
zerobuf = 1
} else if (IM_LEN(ZERO_IM(ccd),1) == 1) {
zeroim = NULL
zerobuf = imgs2$t (ZERO_IM(ccd), 1, 1, ZERO_L1(ccd), ZERO_L2(ccd))
} else
zeroim = ZERO_IM(ccd)
if (CORS(ccd, DARKCOR) == 0) {
darkim = NULL
darkbuf = 1
} else if (IM_LEN(DARK_IM(ccd),1) == 1) {
darkim = NULL
darkbuf = imgs2$t (DARK_IM(ccd), 1, 1, DARK_L1(ccd), DARK_L2(ccd))
darkscale = DARKSCALE(ccd)
} else {
darkim = DARK_IM(ccd)
darkscale = DARKSCALE(ccd)
}
if (CORS(ccd, FLATCOR) == 0) {
flatim = NULL
flatbuf = 1
} else if (IM_LEN(FLAT_IM(ccd),1) == 1) {
flatim = NULL
flatbuf = imgs2$t (FLAT_IM(ccd), 1, 1, FLAT_L1(ccd), FLAT_L2(ccd))
flatscale = FLATSCALE(ccd)
} else {
flatim = FLAT_IM(ccd)
flatscale = FLATSCALE(ccd)
}
if (CORS(ccd, ILLUMCOR) == 0) {
illumim = NULL
illumbuf = 1
} else {
illumim = ILLUM_IM(ccd)
illumscale = ILLUMSCALE(ccd)
}
if (CORS(ccd, FRINGECOR) == 0) {
fringeim = NULL
fringebuf = 1
} else {
fringeim = FRINGE_IM(ccd)
frgscale = FRINGESCALE(ccd)
}
# For each line read lines from the input. Procedure CORINPUT
# replaces bad pixels by interpolation and applies a trim to the
# input. Get lines from the output image and from the zero level,
# dark count, flat field, illumination, and fringe images.
# Call COR2 to do the actual pixel corrections. Finally, add the
# output pixels to a sum for computing the mean.
# We must copy data outside of the output data section.
do line = 2 - OUT_L1(ccd), 0
call amov$t (
Mem$t[imgl2$t(in,IN_L1(ccd)+line-1)+IN_C1(ccd)-OUT_C1(ccd)],
Mem$t[impl2$t(out,OUT_L1(ccd)+line-1)], IM_LEN(out,1))
do line = 1, nlines {
outbuf = impl2$t (out, OUT_L1(ccd)+line-1)
inbuf = xt_fps$t (MASK_FP(ccd), in, IN_L1(ccd)+line-1, IN_C1(ccd),
IN_C2(ccd), IN_L1(ccd), IN_L2(ccd), NULL)
call amov$t (Mem$t[inbuf+IN_C1(ccd)-OUT_C1(ccd)], Mem$t[outbuf],
IM_LEN(out,1))
outbuf = outbuf + OUT_C1(ccd) - 1
if (zeroim != NULL)
zerobuf = ccd_gl$t (zeroim, ZERO_C1(ccd), ZERO_C2(ccd),
ZERO_L1(ccd)+line-1)
if (darkim != NULL)
darkbuf = ccd_gl$t (darkim, DARK_C1(ccd), DARK_C2(ccd),
DARK_L1(ccd)+line-1)
if (flatim != NULL)
flatbuf = ccd_gl$t (flatim, FLAT_C1(ccd), FLAT_C2(ccd),
FLAT_L1(ccd)+line-1)
if (illumim != NULL)
illumbuf = ccd_gl$t (illumim, ILLUM_C1(ccd), ILLUM_C2(ccd),
ILLUM_L1(ccd)+line-1)
if (fringeim != NULL)
fringebuf = ccd_gl$t (fringeim, FRINGE_C1(ccd), FRINGE_C2(ccd),
FRINGE_L1(ccd)+line-1)
call cor2$t (line, CORS(ccd,1), Mem$t[outbuf],
Memr[overscan_vec], Mem$t[zerobuf], Mem$t[darkbuf],
Mem$t[flatbuf], Mem$t[illumbuf], Mem$t[fringebuf], ncols,
zeroim, flatim, darkscale, flatscale, illumscale, frgscale)
if (rep == YES)
call amaxk$t (Mem$t[outbuf], minrep, Mem$t[outbuf], ncols)
if (findmean == YES)
mean = mean + asum$t (Mem$t[outbuf], ncols)
}
do line = nlines+1, IM_LEN(out,2)-OUT_L1(ccd)+1
call amov$t (
Mem$t[imgl2$t(in,IN_L1(ccd)+line-1)+IN_C1(ccd)-OUT_C1(ccd)],
Mem$t[impl2$t(out,OUT_L1(ccd)+line-1)], IM_LEN(out,1))
# Compute the mean from the sum of the output pixels.
if (findmean == YES)
MEAN(ccd) = mean / ncols / nlines
end
# FIND_OVERSCAN -- Find the overscan value for a line.
# No check is made on the number of pixels.
# The median is the (npix+1)/2 element.
real procedure find_overscan$t (data, npix, type)
PIXEL data[npix] #I Overscan data
int npix #I Number of overscan points
int type #I Type of overscan calculation
int i
real overscan, d, dmin, dmax
PIXEL asok$t()
begin
if (type == OVERSCAN_MINMAX) {
overscan = data[1]
dmin = data[1]
dmax = data[1]
do i = 2, npix {
d = data[i]
overscan = overscan + d
if (d < dmin)
dmin = d
else if (d > dmax)
dmax = d
}
overscan = (overscan - dmin - dmax) / (npix - 2)
} else if (type == OVERSCAN_MEDIAN)
overscan = asok$t (data, npix, (npix + 1) / 2)
else {
overscan = data[1]
do i = 2, npix
overscan = overscan + data[i]
overscan = overscan / npix
}
return (overscan)
end
$endfor
|