Debian Codegraph @

stdred/ccdred/proc/prep_scan.prg

raw
1 ! @(#)prep_scan.prg 19.1 (ES0-DMD) 02/25/03 14:16:06
2 !++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 !.COPYRIGHT (C) 1993 European Southern Observatory
4 !.IDENT prep_scan.prg
5 !.AUTHOR Rein H. Warmels, ESO-Garching
6 !.KEYWORDS Direct imaging, CCD package
7 !.PURPOSE BIAS overscan correction of input frame
8 !.USE @s prepscan p1 p2
9 !. p1 = input frame
10 !. p2 = correction lable string
11 !.METHOD - Return if overscan is not requested or has been corrected
12 !. previously
13 !. - Determine scan direction and area.
14 !. - Average overscan area in columns or rows
15 !. - Convert the overscan row/column into table and fit a function
16 !. with the MIDAS fit commands.
17 !. - Do the overscan correction of the input frame
18 !. - Set the processing flags.
19 !. The mean and s.d. of a defined area of overclocked columns is
20 !. calculated by STATISTICS/IMAGE and the resulting values are put
21 !. into the descriptor CCDBIAS. The mean is subtracted from the
22 !. image. All coordinates are in (integer) pixels.
23 !.PARAMETERS P1: input frame
24 ! P2: correction label string which will be checked by
25 ! ccdcorrect.prg to do the desired actions.
26 !.NOTE The procedure checks if the operation was already done
27 !. by checking the descriptor CCDSTAT
28 !. CCDSTAT(1) for overscan correction
29 !. CCDSTAT(2) for trimming the frame
30 !. CCDSTAT(3) for bad pixel correction
31 !. CCDSTAT(4) for bias subtraction
32 !. CCDSTAT(5) for dark current subtraction
33 !. CCDSTAT(6) for flat fielding
34 !. CCDSTAT(7) for bad pixel correction
35 !. CCDSTAT(8) for fringing correction
36 !.VERSION 930105 RHW Creation
37 !.VERSION 971117 SW correction labels have to be local -> new param.
38 !.VERSION 980128 SW additional return param = name of scan-table
39 ! bug: START, STEP have to be adjusted to INPUT-frame
40 ! bug: DIRECT==y: use the right STA, STE, IPIX
41 !-------------------------------------------------------
42 DEFINE/PARAM P1 ? I "Input frame for overscan correction:"
43 DEFINE/PARAM P2 {CCDCORS(1:20)}
44 !The correction label string CCDCORS which will be checked by CCDCORRECT.PRG
45 !has to be local, in order to always get the right link to the actual frame.
46 !In a global definition the correction labels may overwritten by other pre-
47 !pared frames which leads to unwished actions to previous frames (SW,97.11.17).
48 !
49 ! *** Check if overscan has already been applied
50 IF SC_SCAN .NE. "yes" .OR. {{P1},CCDSTAT(1)} .EQ. 1 THEN
51 WRITE/OUT "{P1}: Overscan correction not requested or was applied"
52 RETURN {P2}
53 ENDIF
54 !
55 ! *** return if only listing is wanted
56 IF SC_PROC .EQ. "yes" THEN
57 WRITE/OUT "{P1}: *** TO BE DONE: Overscan section is {OV_SEC}"
58 RETURN {P2}
59 ENDIF
60 !
61 ! *** more locals
62 DEFINE/LOCAL KAPPA/R/1/1 {OV_REJEC}
63 DEFINE/LOCAL PRERMS/R/1/1 0.
64 DEFINE/LOCAL RMS/R/1/1 0.
65 DEFINE/LOCAL RATIO/R/1/1 0.
66 DEFINE/LOCAL ITER/I/1/1 0
67 DEFINE/LOCAL IDOT/I/1/1 0
68 DEFINE/LOCAL IPIX/I/1/2 0 ALL
69 DEFINE/LOCAL STA/D/1/2 0 ALL
70 DEFINE/LOCAL STE/D/1/2 0 ALL
71 DEFINE/LOCAL CCDIN/C/1/60 " " ALL
72 DEFINE/LOCAL CCDOUT/C/1/60 " " ALL
73 DEFINE/LOCAL SCANTBL/C/1/60 " " ALL
74 DEFINE/LOCAL SCANMEAN/R/1/1 0
75 !
76 ! *** write the keywords
77 WRITE/KEYW INPUTC/C/1/1 {OV_IMODE} ! manual of auto fitting
78 COPY/DK {P1} NPIX/I/1/2 IPIX
79 COPY/DK {P1} START/D/1/2 STA
80 COPY/DK {P1} STEP/D/1/2 STE
81 !
82 STATIS/IMAGE {P1} {OV_SEC} ? ? SN ! do statistics of the overscan
83 SCANMEAN = {{P1},STATISTIC(3)}
84 !
85 ! *** setting for interactive use
86 IF INPUTC(1:1) .EQ. "y" THEN
87 CREATE/GRAPH 0
88 WRITE/OUT "{P1}: Overscan area interactively fitted"
89 SET/GRAP pmode=1 ltype=1 stype=0
90 ENDIF
91 !
92 ! *** label for interactive use
93 INTER:
94 IDOT = M$INDEX(P1,".bdf")-1
95 IF IDOT .GT. 0 THEN
96 CCDIN = "{P1(1:{IDOT})}"
97 ELSE
98 CCDIN = "{P1}"
99 ENDIF
100 CCDOUT = "{CCDIN}_scan"
101 WRITE/KEYW INPUTI/I/1/1 {OV_AVER} ! smoothing parameter
102 RUN STD_EXE:ccdscan.exe ! create smooth overscan table
103 SELECT/TABLE {CCDOUT} {SCANSEL}
104 !
105 ! here do the fitting
106 DO ITER = 1 {OV_ITER}
107 WRITE/OUT "{CCDOUT}: Interation {ITER} out of {OV_ITER} started"
108 IF OV_FUNCT(1:1) .EQ. "l" THEN ! do the linear fit
109 REGRESSION/LINEAR {CCDOUT} :FLUX :X
110 RMS = OUTPUTR(3)*KAPPA
111 ELSEIF OV_FUNCT(1:1) .EQ. "p" THEN ! do polynomial fit
112 REGRESSION/POLYNOMIAL {CCDOUT} :FLUX :X {OV_ORDER}
113 RMS = OUTPUTR(5)*KAPPA
114 ENDIF
115 !
116 IF ITER .EQ. 1 THEN ! iteration step
117 PRERMS = RMS
118 ELSE
119 RATIO = RMS/PRERMS-1.
120 PRERMS = RMS
121 IF M$ABS(RATIO) .LT. 0.01 THEN
122 IF OV_IMODE(1:1) .EQ. "y" THEN
123 GOTO INQUIR
124 ENDIF
125 ENDIF
126 ENDIF
127 SAVE/REGRESSION {CCDOUT} COEF
128 COMPUTE/REGRESSION {CCDOUT} :FIT = COEF
129 COMPUTE/TABLE {CCDOUT} :RESIDUAL = :FIT - :FLUX ! select for next iter
130 SELECT/TABLE {CCDOUT} {SCANSEL}.AND.(ABS(:RESIDUAL).LT.{RMS})
131 ENDDO
132 !
133 INQUIR:
134 IF OV_IMODE(1:1) .EQ. "y" THEN ! overplot in interactive mode
135 SELECT/TABLE {CCDOUT} ALL
136 SET/GRAP COLOUR=2
137 OVERPLOT/TABLE {CCDOUT} :X :FIT
138 SET/GRAP COLOUR=1
139 INQUIRE/KEYW INPUTC/C/1/1 "***> Do you want to try another fit [no]?: "
140 IF AUX_MODE(7) .EQ. 0 INPUTC(1:1) = "N"
141 IF INPUTC(1:1) .EQ. "Y" THEN
142 INQUIRE/KEYW OV_FUNCT/C/1/20 "***> Enter type of function [{OV_FUNCT}]: "
143 IF OV_FUNCT(1:3) .EQ. "pol" THEN ! do the fit
144 OV_FUNCT = "polynomial"
145 INQUIRE/KEYW OV_ORDER/I/1/1 -
146 "***> Enter degree of the polynomial [3]: "
147 IF AUX_MODE(7) .EQ. 0 OV_ORDER = 3
148 ELSE
149 OV_FUNCT = "linear"
150 ENDIF
151 INQUIRE/KEYW OV_AVER/I/1/1 "***> Enter number of points to combine [1]: "
152 IF AUX_MODE(7) .EQ. 0 OV_AVER = 1
153 INQUIRE/KEYW OV_ITER/I/1/1 "***> Enter number of iterations [1]: "
154 IF AUX_MODE(7) .EQ. 0 OV_ITER = 1
155 INQUIRE/KEYW OV_REJEC/R/1/1 "***> Enter sigma rejection factor [3.]: "
156 IF AUX_MODE(7) .EQ. 0 OV_REJEC = 3.
157 GOTO INTER
158 ELSE
159 IF CCDCMD(1:3) .EQ. "RED" THEN ! only for reduce/ccd
160 INQUIRE/KEYW INPUTC/C/1/1 -
161 "***> Continue the interactive fitting [yes]: "
162 IF AUX_MODE(7) .EQ. 0 OV_IMODE = "yes"
163 IF INPUTC(1:1) .EQ. "y" THEN
164 OV_IMODE = "yes"
165 ELSE
166 OV_IMODE = "no"
167 ENDIF
168 ENDIF
169 ENDIF
170 ENDIF
171 !
172 ! *** write the output overscan frame
173 COMPUTE/KEYW SCANTBL = "{CCDOUT}" ! save name of scan-table
174 IF OV_ORDER .GE. 1 THEN ! vector
175 SELECT/TABLE {CCDOUT} all
176 COPY/TABLE {CCDOUT} &t
177 DELETE/COLUMN &t :X :FLUX :RESIDUAL
178 COPY/TI &t &o
179 IF DIRECT .EQ. "X" THEN
180 GROW/IMAGE {CCDOUT} = &o {STA(1)},{STE(1)},{IPIX(1)} <,line C
181 !adjust world coordinates to the ones of the input frame as CCDOUT will later
182 !be used for bias correction [the x are already ok (SW)]
183 {CCDOUT},START(2) = {STA(2)}
184 {CCDOUT},STEP(2) = {STE(2)}
185 ELSE
186 ! GROW/IMAGE {CCDOUT} = &o {STA(1)},{STE(1)},{IPIX(1)} <,line L
187 GROW/IMAGE {CCDOUT} = &o {STA(2)},{STE(2)},{IPIX(2)} <,line L
188 !adjust world coordinates to the ones of the input frame as CCDOUT will later
189 !be used for bias correction [the y are already ok (SW)]
190 {CCDOUT},START(1) = {STA(1)}
191 {CCDOUT},STEP(1) = {STE(1)}
192 ENDIF
193 DELETE/TABLE &t NO
194 DELETE/IMAGE &o NO
195 CCDSCAN = "{CCDOUT}" ! store overscan image
196
197 ELSE ! scalar
198 STATIS/TABLE {CCDOUT} :FLUX
199 SCANMEAN = {OUTPUTR(3)}
200 CCDSCAN = "{SCANMEAN}"
201 ENDIF
202 !
203 WRITE/OUT "{CCDIN}.bdf: Overscan area is {OV_SEC}; mean={SCANMEAN}"
204 P2(1:1) = "O"
205 P2(11:11) = "Y"
206 RETURN {P2} {SCANTBL}