| 1 |
! @(#)ccdflatcor.prg 19.1 (ESO-DMD) 02/25/03 14:16:00 |
| 2 |
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 3 |
!.COPYRIGHT (C) 1993 European Southern Observatory |
| 4 |
!.IDENT ccdflatcor.prg |
| 5 |
!.AUTHOR Rein H. Warmels, ESO-Garching |
| 6 |
!.KEYWORDS Direct imaging, CCD package, SKYCOR/CCD |
| 7 |
!.PURPOSE Make illumination illumination correction frame(s) |
| 8 |
!.USE ILLCOR/CCD p1 p2 p3 p4 p5 p6 |
| 9 |
!. ILLFLAT/CCD p1 p2 p3 p4 p5 p6 |
| 10 |
!. where p1 = reduction table or single flat field |
| 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 flat frame is 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 flat the illumation frame are created by a box |
| 21 |
!. smoothing algorithm. |
| 22 |
!. The illumination correction frame will be indicated as a FF- |
| 23 |
!. correction frame -- in contrast to an sky-correction frame -- |
| 24 |
!. by the descriptor ILLCOR. 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 ILLCOR/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. ILLCOR to identify dome-ff-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 SELECT/C/1/80 " " |
| 54 |
! |
| 55 |
DEFINE/LOCAL NCA/I/1/1 0 |
| 56 |
DEFINE/LOCAL NRA/I/1/1 0 |
| 57 |
DEFINE/LOCAL IRA/I/1/1 0 |
| 58 |
DEFINE/LOCAL IDOT/I/1/1 0 |
| 59 |
DEFINE/LOCAL TBL/I/1/1 0 |
| 60 |
DEFINE/LOCAL MCMND/C/1/20 "{MID$CMND}" |
| 61 |
|
| 62 |
DEFINE/PARAM P3 {IL_XBOX(1)},{IL_XBOX(2)} N |
| 63 |
DEFINE/PARAM P4 {IL_YBOX(1)},{IL_YBOX(2)} N |
| 64 |
DEFINE/PARAM P5 {IL_CLIP} C |
| 65 |
! |
| 66 |
IF P5(1:1) .EQ. "Y" THEN |
| 67 |
DEFINE/PARAM P6 {IL_SIGMA(1)},{IL_SIGMA(2)} |
| 68 |
ENDIF |
| 69 |
! |
| 70 |
! *** first check for single frame of input table |
| 71 |
TBL = M$INDEX(P1,".tbl") ! search for .tbl |
| 72 |
IF TBL .EQ. 0 THEN ! frame input |
| 73 |
IF M$EXIST("{P1}.bdf") .EQ. 0 THEN ! check existence |
| 74 |
WRITE/OUT "*** FATAL: Missing input flat frame {P1}" |
| 75 |
RETURN |
| 76 |
ELSE |
| 77 |
CCDIN = "{P1}" |
| 78 |
ENDIF |
| 79 |
! |
| 80 |
ELSE ! reduction table input |
| 81 |
CCD_IN = "{P1}" |
| 82 |
SET/MIDAS OUTPUT=LOGONLY |
| 83 |
SELECT = "{{CCD_IN},TSELTABL(1:60)}" ! read the selection |
| 84 |
SET/MIDAS OUTPUT=YE |
| 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 MCMND(1:6) .EQ. "ILLCOR" .AND. - |
| 98 |
M$EXISTC(CCD_IN,IL_COL) .EQ. -1 THEN |
| 99 |
CREATE/COLUMN {CCD_IN} {IL_COL} C*60 ? A20 ! create illum column |
| 100 |
ENDIF |
| 101 |
|
| 102 |
SET/FORMAT I3 |
| 103 |
NCA = {{CCD_IN},TBLCONTR(3)} |
| 104 |
NRA = {{CCD_IN},TBLCONTR(4)} ! check number of rows |
| 105 |
IF NRA .EQ. 0 THEN |
| 106 |
WRITE/OUT - |
| 107 |
"*** INFO: No (selected) entries in input table; REDUCTION STOPPED" |
| 108 |
GOTO FINISH |
| 109 |
ENDIF |
| 110 |
! |
| 111 |
! *** collect the input flat frame and calibration frames |
| 112 |
WRITE/OUT "Start processing flat frames frames in table {CCD_IN} |
| 113 |
IRA = 0 |
| 114 |
NXTFRM: |
| 115 |
IRA = IRA + 1 |
| 116 |
SELECT/TABL {CCD_IN} {SELECT} |
| 117 |
IF {{CCD_IN},SEL,@{IRA}} .EQ. 0 THEN |
| 118 |
GOTO DONE |
| 119 |
ENDIF |
| 120 |
! |
| 121 |
CCDIN = "{{CCD_IN},:{FF_COL},@{IRA}}" ! get input image name |
| 122 |
IDOT = M$INDEX(CCDIN,".bdf") - 1 ! remove bdf extension |
| 123 |
IF IDOT .GT. 0 THEN |
| 124 |
CCDIN = "{CCDIN(1:{IDOT})}" |
| 125 |
ELSE |
| 126 |
CCDIN = "{CCDIN}" |
| 127 |
ENDIF |
| 128 |
SET/MIDAS OUTPUT=LOGONLY |
| 129 |
SELECT/TABL {CCD_IN} :{FF_COL}.EQ."{CCDIN}.bdf" .OR. :{FF_COL}.EQ."{CCDIN}" |
| 130 |
SET/MIDAS OUTPUT=YES |
| 131 |
WRITE/OUT " " |
| 132 |
! |
| 133 |
IF M$EXIST("{CCDIN}.bdf") .EQ. 0 THEN ! checking flat frame |
| 134 |
WRITE/OUT "*** INFO Combined flat frame {CCDIN} to be created" |
| 135 |
COMBINE/CCD FF {CCD_IN} ! combine |
| 136 |
ENDIF |
| 137 |
IF M$EXIST("{CCDIN}.bdf") .EQ. 0 THEN ! checking flat frame |
| 138 |
WRITE/OUT "*** ERROR: Failed to make combined flat frame {CCDIN}" |
| 139 |
GOTO FINISH |
| 140 |
ENDIF |
| 141 |
! |
| 142 |
IF SC_BSCOR(1:1) .EQ. "y" THEN ! bias correc. wanted? |
| 143 |
SET/MIDAS OUTPUT=LOGONLY |
| 144 |
SC_BSFRM = "{{CCD_IN},:{BS_COL},@{IRA}}" |
| 145 |
SET/MIDAS OUTPUT=YES |
| 146 |
IF SC_BSFRM(1:1) .EQ. " " THEN |
| 147 |
WRITE/OUT "{CCDIN}: No master BIAS defined; ** NO REDUCTION ***" |
| 148 |
GOTO DONE |
| 149 |
ENDIF |
| 150 |
ENDIF |
| 151 |
! |
| 152 |
IF SC_DKCOR(1:1) .EQ. "y" THEN ! dark correc. wanted? |
| 153 |
SET/MIDAS OUTPUT=LOGONLY |
| 154 |
SC_DKFRM = "{{CCD_IN},:{DK_COL},@{IRA}}" |
| 155 |
SET/MIDAS OUTPUT=YES |
| 156 |
IF SC_DKFRM(1:1) .EQ. " " THEN |
| 157 |
WRITE/OUT "{CCDIN}: No master DARK defined; *** NO REDUCTION ***" |
| 158 |
GOTO DONE |
| 159 |
ENDIF |
| 160 |
ENDIF |
| 161 |
ENDIF |
| 162 |
! |
| 163 |
IF M$EXIST("{CCDIN}.bdf") .EQ. 0 THEN ! check exsistence |
| 164 |
WRITE/OUT "*** WARNING: Missing input frame {CCDIN}; *** NO REDUCTION" |
| 165 |
GOTO DONE |
| 166 |
ENDIF |
| 167 |
! |
| 168 |
IF MCMND(1:6) .EQ. "ILLCOR" THEN ! illumination correction (ILLCOR/CCD) |
| 169 |
IF TBL .EQ. 0 THEN ! determine the output frame |
| 170 |
DEFINE/PARAM P2 {CCDIN}_ill IMA "Enter the output frame:" |
| 171 |
CCDOUT = "{P2}" |
| 172 |
ELSE |
| 173 |
CCDOUT = "{CCDIN}_ill" ! reduce output image name |
| 174 |
ENDIF |
| 175 |
@s ccdredfrm {CCDIN} {CCDIN} ! reduction of the frame |
| 176 |
@s make_illum {CCDIN} {CCDOUT} {P3} {P4} {P5} {P6} ! create illum frame |
| 177 |
! |
| 178 |
IF M$EXIST("{CCDOUT}.bdf") .EQ. 0 THEN ! is it there? |
| 179 |
WRITE/OUT "*** ERROR: Failed to make illum. correction from {CCDIN}" |
| 180 |
GOTO FINISH |
| 181 |
ELSE |
| 182 |
WRITE/OUT "{CCDIN}: Illumination correction frame {CCDOUT} created" |
| 183 |
WRITE/DESCR {CCDOUT} ILLCOR/C/1/10 screen ! ill corr.descriptor |
| 184 |
WRITE/DESCR {CCDOUT} HISTORY/C/-1/80 "ILLCOR/CCD {CCDIN} {CCDOUT}" |
| 185 |
IF TBL .GT. 0 THEN ! stored output in table |
| 186 |
{CCD_IN},:{IL_COL},@{IRA} = "{CCDOUT}" |
| 187 |
ENDIF |
| 188 |
ENDIF |
| 189 |
|
| 190 |
ELSE ! here illumination flat (ILLFLAT/CCD) |
| 191 |
IF TBL .EQ. 0 THEN ! determine the output frame |
| 192 |
DEFINE/PARAM P2 {CCDIN} IMA "Enter the output illumination flat frame:" |
| 193 |
CCDOUT = "{P2}" |
| 194 |
ELSE |
| 195 |
CCDOUT = "{CCDIN}" ! reduce output image name |
| 196 |
ENDIF |
| 197 |
@s ccdredfrm {CCDIN} {CCDIN} ! reduction of the frame |
| 198 |
@s make_illum {CCDIN} &d {P3} {P4} {P5} {P6} ! create illum frame |
| 199 |
! |
| 200 |
IF M$EXIST("&d") .EQ. 0 THEN ! is it there? |
| 201 |
WRITE/OUT "*** ERROR: Failed to make illum. correction from {CCDIN}" |
| 202 |
GOTO FINISH |
| 203 |
ELSE |
| 204 |
@s make_illflat {CCDIN} &d {CCDOUT} |
| 205 |
WRITE/OUT "{CCDIN}: Illumination corrected flat field {CCDOUT} created" |
| 206 |
WRITE/DESCR {CCDOUT} HISTORY/C/-1/80 "ILLFLAT/CCD {CCDIN} {CCDOUT}" |
| 207 |
ENDIF |
| 208 |
ENDIF |
| 209 |
! |
| 210 |
! *** finish up |
| 211 |
DONE: |
| 212 |
IF TBL .GE. 1 THEN ! single frame input |
| 213 |
IF IRA .LT. {NRA} THEN |
| 214 |
GOTO NXTFRM |
| 215 |
ELSE |
| 216 |
WRITE/OUT " " |
| 217 |
IF NRA .EQ. 0 THEN |
| 218 |
WRITE/OUT "{P1}: *** WARNING: Input table {P1} selection is empty" |
| 219 |
ELSE |
| 220 |
IF MCMND(1:6) .EQ. "ILLCOR" THEN ! illumination correction |
| 221 |
WRITE/OUT "{P1}: *** ALL DONE: Illumination correction frames ready" |
| 222 |
ELSE |
| 223 |
WRITE/OUT "{P1}: *** ALL DONE: Illumination flat frames ready" |
| 224 |
ENDIF |
| 225 |
ENDIF |
| 226 |
SET/MIDAS OUTPUT=LOGONLY |
| 227 |
SELECT/TABL {P1} {SELECT} |
| 228 |
SET/MIDAS OUTPUT=YES |
| 229 |
DELETE/IMAG &d NO |
| 230 |
ENDIF |
| 231 |
ENDIF |
| 232 |
! |
| 233 |
! *** restore keywords settings |
| 234 |
FINISH: |
| 235 |
CCD_IN = "{CCDSAV}" |
| 236 |
SC_BSFRM = "{BSFRM}" ! restore keyword setting |
| 237 |
SC_DKFRM = "{DKFRM}" |
| 238 |
RETURN |