Debian Codegraph @

stdred/ccdred/proc/ccdskycor.prg

raw
1 ! @(#)ccdskycor.prg 19.1 (ESO-DMD) 02/25/03 14:16:02
2 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 !.COPYRIGHT (C) 1993 European Southern Observatory
4 !.IDENT ccdskycor.prg
5 !.AUTHOR Rein H. Warmels, ESO-Garching
6 !.KEYWORDS Direct imaging, CCD package, SKYCOR/CCD
7 !.PURPOSE Make sky illumination correction frame(s)
8 !.USE SKYCOR/CCD p1 p2 p3 p4 p5 p6
9 !. SKYFLAT/CCD p1 p2 p3 p4 p5 p6
10 !. where p1 = input table with sky column frames or single frame
11 !. p2 = output frame (only in case of single frame input)
12 !. p3 = xboxmin, xboxmax smoothing box
13 !. p4 = yboxmin, yboxmax smoothing box
14 !. p5 = clipping option
15 !. p6 = low and high clipping factor
16 !.ALGORITHM: In case the input is the association table the procedure first
17 !. checks if the sky frame are available. If not available the
18 !. frame will be created and reduced. For single frame input all
19 !. frames have to be available and stored in the CCD keywords.
20 !. Using the reduced sky the illumation frame are created by a box
21 !. smoothing algorithm.
22 !. The illumination correction frame will be indicated as a sky-
23 !. correction frame -- in contrast to an FF-correction frame --
24 !. by the descriptor SKYCOR. It later helps to identify the illumi-
25 !. nation correction frame during processing the science frame by
26 !. means of the REDUCE/CCD command.
27 !. In the case the association table is used as input, the output
28 !. illumination correction (command SKYCOR/CCD) is stored in the
29 !. table.
30 !.NOTE The individual procedures check if one operation was already done
31 !. by checking the descriptor CCDSTAT. The CCDSTAT descriptor values
32 !. represent the following status:
33 !. CCDSTAT(1) for overscan correction
34 !. CCDSTAT(2) for trimming the frame
35 !. CCDSTAT(3) for bad pixel correction
36 !. CCDSTAT(4) for bias subtraction
37 !. CCDSTAT(5) for dark current subtraction
38 !. CCDSTAT(6) for flat fielding
39 !. CCDSTAT(7) for illumination correction
40 !. CCDSTAT(8) for fringing correction
41 !.VERSION: 920731 RHW Creation
42 !.VERSION: 930728 RHW Improve layout and structure
43 !.VERSION: 971201 SW Add descr. SKYCOR to identify sky-correc. frame
44 !-------------------------------------------------------
45 DEFINE/PARAM P1 {CCD_IN} C "Enter input specification [no default]:"
46 !
47 ! *** keyword saving
48 DEFINE/LOCAL CCDIN/C/1/60 " "
49 DEFINE/LOCAL CCDOUT/C/1/60 " "
50 DEFINE/LOCAL CCDSAV/C/1/60 "{CCD_IN}"
51 DEFINE/LOCAL BSFRM/C/1/60 "{SC_BSFRM}"
52 DEFINE/LOCAL DKFRM/C/1/60 "{SC_DKFRM}"
53 DEFINE/LOCAL FFFRM/C/1/60 "{SC_FFFRM}"
54 DEFINE/LOCAL FLATCOR/I/1/1 0
55 DEFINE/LOCAL SELECT/C/1/80 " "
56 !
57 DEFINE/LOCAL NCA/I/1/1 0
58 DEFINE/LOCAL NRA/I/1/1 0
59 DEFINE/LOCAL IRA/I/1/1 0
60 DEFINE/LOCAL IDOT/I/1/1 0
61 DEFINE/LOCAL TBL/I/1/1 0
62 DEFINE/LOCAL MCMND/C/1/20 "{MID$CMND}"
63 !
64 DEFINE/PARAM P3 {IL_XBOX(1)},{IL_XBOX(2)} N
65 DEFINE/PARAM P4 {IL_YBOX(1)},{IL_YBOX(2)} N
66 DEFINE/PARAM P5 {IL_CLIP} C
67 !
68 IF P5(1:1) .EQ. "Y" THEN
69 DEFINE/PARAM P6 {IL_SIGMA(1)},{IL_SIGMA(2)}
70 ENDIF
71 !
72 ! *** first check for single frame of input table
73 TBL = M$INDEX(P1,".tbl") ! search for .tbl
74 IF TBL .EQ. 0 THEN ! frame input
75 IF M$EXIST("{P1}.bdf") .EQ. 0 THEN ! check existence
76 WRITE/OUT "*** FATAL: Missing input sky frame {P1}"
77 RETURN
78 ELSE
79 CCDIN = "{P1}"
80 ENDIF
81
82 ELSE ! reduction table input
83 CCD_IN = "{P1}"
84 SELECT = "{{CCD_IN},TSELTABL(1:60)}" ! read the selection
85 IF M$EXIST(CCD_IN) .EQ. 0 THEN ! check exsistence
86 WRITE/OUT "*** FATAL: Missing CCD input table {CCD_IN}"
87 RETURN
88 ENDIF
89 IF SC_BSCOR(1:1) .EQ. "y" .AND. M$EXISTC(CCD_IN,BS_COL) .EQ. -1 THEN
90 WRITE/OUT "*** FATAL: No BIAS column defined; *** REDUCTION STOPPED"
91 RETURN
92 ENDIF
93 IF SC_DKCOR(1:1) .EQ. "y" .AND. M$EXISTC(CCD_IN,DK_COL) .EQ. -1 THEN
94 WRITE/OUT "*** FATAL: No DARK column defined; *** REDUCTION STOPPED"
95 RETURN
96 ENDIF
97 IF SC_FFCOR(1:1) .EQ. "y" .AND. M$EXISTC(CCD_IN,FF_COL) .EQ. -1 THEN
98 WRITE/OUT "*** FATAL: No FLAT column defined; *** REDUCTION STOPPED"
99 RETURN
100 ENDIF
101 IF MCMND(1:6) .EQ. "SKYCOR" .AND. -
102 M$EXISTC(CCD_IN,IL_COL) .EQ. -1 THEN
103 CREATE/COLUMN {CCD_IN} {IL_COL} C*60 ? A20 ! create illum column
104 ENDIF
105
106 SET/FORMAT I3
107 NCA = {{CCD_IN},TBLCONTR(3)}
108 NRA = {{CCD_IN},TBLCONTR(4)} ! check number of rows
109 IF NRA .EQ. 0 THEN
110 WRITE/OUT -
111 "*** INFO: No (selected) entries in input table; REDUCTION STOPPED"
112 GOTO FINISH
113 ENDIF
114 !
115 ! *** collect the input sky frame and calibration frames
116 WRITE/OUT "Start processing sky frames in table {CCD_IN}"
117 IRA = 0
118 NXTFRM:
119 IRA = IRA + 1
120 SET/MIDAS OUTPUT=LOGONLY
121 SELECT/TABL {CCD_IN} {SELECT}
122 SET/MIDAS OUTPUT=YES
123 IF {{CCD_IN},SEL,@{IRA}} .EQ. 0 THEN
124 GOTO DONE
125 ENDIF
126
127 CCDIN = "{{CCD_IN},:{SK_COL},@{IRA}}" ! get input image name
128 IDOT = M$INDEX(CCDIN,".bdf") - 1
129 IF IDOT .GT. 0 THEN
130 CCDIN = "{CCDIN(1:{IDOT})}"
131 ELSE
132 CCDIN = "{CCDIN}"
133 ENDIF
134
135 SET/MIDAS OUTPUT=LOGONLY
136 SELECT/TABL {CCD_IN} :{SK_COL}.EQ."{CCDIN}.bdf" .OR. :{SK_COL}.EQ."{CCDIN}"
137 SET/MIDAS OUTPUT=YES
138 WRITE/OUT " "
139 !
140 IF M$EXIST("{CCDIN}.bdf") .EQ. 0 THEN ! checking the sky frame
141 WRITE/OUT "*** INFO Combined sky frame {CCDIN} to be created"
142 COMBINE/CCD SK {CCD_IN} ! combine
143 ENDIF
144 IF M$EXIST("{CCDIN}.bdf") .EQ. 0 THEN ! checking the sky frame
145 WRITE/OUT "*** ERROR: Failed to make combined sky frame {CCDIN}"
146 GOTO FINISH
147 ENDIF
148 !
149 IF SC_BSCOR(1:1) .EQ. "y" THEN ! bias correc. wanted?
150 SET/MIDAS OUTPUT=LOGONLY
151 SC_BSFRM = "{{CCD_IN},:{BS_COL},@{IRA}}"
152 SET/MIDAS OUTPUT=YES
153 IF SC_BSFRM(1:1) .EQ. " " THEN
154 WRITE/OUT "{CCDIN}: No master BIAS defined; ** NO REDUCTION ***"
155 GOTO DONE
156 ENDIF
157 ENDIF
158 !
159 IF SC_DKCOR(1:1) .EQ. "y" THEN ! dark correc. wanted?
160 SET/MIDAS OUTPUT=LOGONLY
161 SC_DKFRM = "{{CCD_IN},:{DK_COL},@{IRA}}"
162 SET/MIDAS OUTPUT=YES
163 IF SC_DKFRM(1:1) .EQ. " " THEN
164 WRITE/OUT "{CCDIN}: No master DARK defined; *** NO REDUCTION ***"
165 GOTO DONE
166 ENDIF
167 ENDIF
168 !
169 IF SC_FFCOR(1:1) .EQ. "y" THEN ! flat correc. wanted?
170 SET/MIDAS OUTPUT=LOGONLY
171 SC_FFFRM = "{{CCD_IN},:{FF_COL},@{IRA}}"
172 SET/MIDAS OUTPUT=YES
173 IF SC_FFFRM(1:1) .EQ. " " THEN
174 WRITE/OUT "{CCDIN}: No master FLAT defined; NO REDUCTION ***"
175 GOTO DONE
176 ENDIF
177 ENDIF
178 ENDIF
179 !
180 IF M$EXIST("{CCDIN}.bdf") .EQ. 0 THEN ! check exsistence
181 WRITE/OUT "*** WARNING: Missing input frame {CCDIN}; *** NO REDUCTION"
182 GOTO DONE
183 ENDIF
184 !
185 IF MCMND(1:6) .EQ. "SKYCOR" THEN ! illumination correction (SKYCOR/CCD)
186 IF TBL .EQ. 0 THEN ! determine the output frame
187 DEFINE/PARAM P2 {CCDIN}_ill IMA "Enter the output illumnation frame:"
188 CCDOUT = "{P2}"
189 ELSE
190 CCDOUT = "{CCDIN}_ill" ! reduce output image name
191 ENDIF
192 !
193 {CCDIN},{EXP_DESC} = "ILLUM"
194 @s ccdredfrm {CCDIN} {CCDIN} ! do the reduction of the frame
195 FLATCOR = {{CCDIN},CCDSTAT(6)}
196 IF FLATCOR .NE. 1 THEN
197 WRITE/OUT "{CCDIN}: *** WARNING: Frame should be flat fielded first"
198 RETURN
199 ELSE
200 @s make_illum {CCDIN} {CCDOUT} {P3} {P4} {P5} {P6} ! create illum frame
201 ENDIF
202
203 IF M$EXIST("{CCDOUT}.bdf") .EQ. 0 THEN ! is it there?
204 WRITE/OUT "*** ERROR: Failed to make illum. correction from {CCDIN}"
205 GOTO FINISH
206 ELSE
207 WRITE/OUT "{CCDIN}: Sky illumination correction {CCDOUT} ready"
208 WRITE/DESCR {CCDOUT} SKYCOR/C/1/10 blank sky ! ill.corr.descriptor
209 WRITE/DESCR {CCDOUT} HISTORY/C/-1/80 "SKYCOR/CCD {CCDIN} {CCDOUT}"
210 IF TBL .GT. 0 THEN ! stored output in table
211 {CCD_IN},:{IL_COL},@{IRA} = "{CCDOUT}"
212 ENDIF
213 ENDIF
214
215 ELSE
216 IF TBL .EQ. 0 THEN ! determine the output frame
217 DEFINE/PARAM P2 {SC_FFFRM} IMA "Enter the sky flat frame:"
218 CCDOUT = "{P2}"
219 ELSE
220 CCDOUT = "{SC_FFFRM}"
221 ENDIF
222 {CCDIN},{EXP_DESC} = "ILLUM"
223 @s ccdredfrm {CCDIN} {CCDIN} ! do the reduction of the frame
224 FLATCOR = {{CCDIN},CCDSTAT(6)}
225 IF FLATCOR .NE. 1 THEN
226 WRITE/OUT "{CCDIN}: *** WARNING: Frame should be flat fielded first"
227 RETURN
228 ELSE
229 @s make_illum {CCDIN} {CCDIN} {P3} {P4} {P5} {P6} ! create illum frame
230 ENDIF
231
232 IF M$EXIST("{CCDIN}.bdf") .EQ. 0 THEN ! is it there?
233 WRITE/OUT "*** ERROR: Failed to make illum. correction {CCDIN}"
234 GOTO FINISH
235 ELSE
236 @s make_skyflat {SC_FFFRM} {CCDIN} {CCDOUT}
237 WRITE/OUT "{SC_FFFRM}: Sky flat field {CCDOUT} created"
238 WRITE/DESCR {CCDOUT} HISTORY/C/-1/80 "SKYFLAT/CCD {CCDIN} {CCDOUT}"
239 ENDIF
240 ENDIF
241 !
242 ! *** finish up
243 DONE:
244 IF TBL .GE. 1 THEN ! single frame input
245 IF IRA .LT. {NRA} THEN
246 GOTO NXTFRM
247 ELSE
248 WRITE/OUT " "
249 IF NRA .EQ. 0 THEN
250 WRITE/OUT "{P1}: *** WARNING: Input table {P1} selection is empty"
251 ELSE
252 IF MCMND(1:6) .EQ. "SKYCOR" THEN
253 WRITE/OUT "{P1}: *** ALL DONE: Sky correction frames ready"
254 ELSE
255 WRITE/OUT "{P1}: *** ALL DONE: Sky flat field frames ready"
256 ENDIF
257 ENDIF
258 SET/MIDAS OUTPUT=LOGONLY
259 SELECT/TABL {P1} {SELECT}
260 SET/MIDAS OUTPUT=YES
261 ENDIF
262 ENDIF
263 !
264 ! *** restore keywords settings
265 FINISH:
266 CCD_IN = "{CCDSAV}"
267 SC_BSFRM = "{BSFRM}" ! restore keyword setting
268 SC_DKFRM = "{DKFRM}"
269 SC_FFFRM = "{FFFRM}"
270 RETURN