IIINSTRUMENT Pipeline Reference Manual  1.3.10
detmon_lg.h
1 /* $Id: detmon_lg.h,v 1.4 2013-06-18 13:34:19 jtaylor Exp $
2  *
3  * This file is part of the irplib package
4  * Copyright (C) 2002, 2003 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: jtaylor $
23  * $Date: 2013-06-18 13:34:19 $
24  * $Revision: 1.4 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifndef IRPLIB_DETMON_LG_H
29 #define IRPLIB_DETMON_LG_H
30 
31 /*----------------------------------------------------------------------------
32  Includes
33  ----------------------------------------------------------------------------*/
34 
35 #include <cpl.h>
36 
37 /*----------------------------------------------------------------------------
38  Defines
39  ----------------------------------------------------------------------------*/
40 /* Define here the DO.CATG keywords */
41 #define DETMON_LG_ON_RAW_OLD "ON_RAW"
42 #define DETMON_LG_OFF_RAW_OLD "OFF_RAW"
43 #define DETMON_LG_ON_RAW_NEW "DETMON_LAMP_ON"
44 #define DETMON_LG_OFF_RAW_NEW "DETMON_LAMP_OFF"
45 
46 
47 #define NIR TRUE
48 #define OPT FALSE
49 
50 #define DETMON_QC_COUNTS_MIN "ESO QC COUNTS MIN"
51 #define DETMON_QC_COUNTS_MIN_C "Minimum median value used in linearity test (in a user defined region) [ADU]"
52 
53 #define DETMON_QC_COUNTS_MAX "ESO QC COUNTS MAX"
54 #define DETMON_QC_COUNTS_MAX_C "Maximum median value used in linearity test (in a user defined region) [ADU]"
55 
56 #define DETMON_QC_CONAD "ESO QC CONAD"
57 #define DETMON_QC_CONAD_C "Conversion from e- to ADUs [ADU/e-]"
58 
59 #define DETMON_QC_CONAD_CORR "ESO QC CONAD CORR"
60 #define DETMON_QC_CONAD_CORR_C "CONAD value taken QC.AUTOCORR into account [ADU/e-]"
61 
62 #define DETMON_QC_GAIN "ESO QC GAIN"
63 #define DETMON_QC_GAIN_C "GAIN (see QC.METHOD) [e-/ADU]"
64 
65 #define DETMON_QC_GAIN_MSE "ESO QC GAIN MSE"
66 #define DETMON_QC_GAIN_MSE_C "Measured Squared error in GAIN computation"
67 
68 #define DETMON_QC_RON "ESO QC RON"
69 #define DETMON_QC_RON_C "RON obtained as independent term (PTC method)"
70 
71 #define DETMON_QC_AUTOCORR "ESO QC AUTOCORR"
72 #define DETMON_QC_AUTOCORR_C "Autocorrelation factor computed as sum of " \
73  "all pixels in autocorrelation image"
74 #define DETMON_QC_GAIN_CORR "ESO QC GAIN CORR"
75 #define DETMON_QC_GAIN_CORR_C "GAIN taken QC.AUTOCORR into account [e-/ADU]"
76 
77 #define DETMON_QC_LAMP_FLUX "ESO QC LAMP FLUX"
78 #define DETMON_QC_LAMP_FLUX_C "Lamp flux"
79 
80 #define DETMON_QC_NUM_BPM "ESO QC NUM BPM"
81 #define DETMON_QC_NUM_BPM_C "Number of bad pixels detected according to "\
82  "polynomial information"
83 
84 #define DETMON_QC_LAMP_STAB "ESO QC LAMP STAB"
85 #define DETMON_QC_LAMP_STAB_C "Lamp stability"
86 
87 #define DETMON_QC_METHOD "ESO QC METHOD"
88 #define DETMON_QC_METHOD_C "Method applied to compute GAIN"
89 
90 #define DETMON_QC_LIN_EFF "ESO QC LIN EFF"
91 #define DETMON_QC_LIN_EFF_C "Effective non-linearity correction"
92 
93 #define DETMON_QC_LIN_EFF_FLUX "ESO QC LIN EFF FLUX"
94 #define DETMON_QC_LIN_EFF_FLUX_C "FLux level at which effective non-linearity correction is computed"
95 
96 #define DETMON_QC_LIN_COEF "ESO QC LIN COEF"
97 #define DETMON_QC_LIN_COEF_C "Linearity coefficient value"
98 
99 
100 #define DETMON_QC_LIN_COEF_ERR "ESO QC LIN EFF ERR"
101 #define DETMON_QC_LIN_COEF_ERR_C "Linearity coefficient error value"
102 #define DETMON_QC_LIN_COEF_MSE_ERR_C "Linearity coefficient measured square error value"
103 
104 
105 #define DETMON_QC_ERRFIT "ESO QC ERRFIT"
106 #define DETMON_QC_ERRFIT_C "Error of fit"
107 #define DETMON_QC_ERRFIT_MSE_C "Measured square error of fit"
108 
109 
110 #define DETMON_QC_CONTAM "ESO QC CONTAM"
111 #define DETMON_QC_CONTAM_C "Detector contamination in a region"
112 
113 #define DETMON_QC_FPN "ESO QC FPN"
114 #define DETMON_QC_FPN_C "Flat pattern noise"
115 
116 /* Macros to generate the recipe(s) description(s) */
117 #define detmon_lg_get_description(RECIPE_NAME, PIPE_NAME, \
118  DETMON_LG_ON_RAW_NEW, \
119  DETMON_LG_OFF_RAW_NEW, \
120  DETMON_LG_ON_RAW_OLD, \
121  DETMON_LG_OFF_RAW_OLD) \
122  RECIPE_NAME " -- " PIPE_NAME " linearity/gain recipe for OPT/IR.\n" \
123  "The files listed in the Set Of Frames must be tagged:\n" \
124  "the raw-on-file.fits "DETMON_LG_ON_RAW_NEW" and\n" \
125  "the raw-off-file.fits "DETMON_LG_OFF_RAW_NEW"\n" \
126  "For backward compatibility are alternatively still supported the following tags:\n" \
127  "the raw-on-file.fits "DETMON_LG_ON_RAW_OLD" and\n" \
128  "the raw-off-file.fits "DETMON_LG_OFF_RAW_OLD"\n" \
129  "The recipe requires at least order+1 valid pairs of ON frames\n" \
130  "and order+1 valid pairs of OFF frames, \n" \
131  "where order is the value of the 'order' parameter.\n" \
132  "There is no requirement for pairs of OFF frames if collapse parameter " \
133  "is set to true.\n" \
134  "Frames with median flux over --filter will be excluded from the " \
135  "computation.\n" \
136  "To perform a stability check you need frames with at least 2 DIT " \
137  "values\n" \
138  "NOTE for multiextension cases: it is mandatory to modify the --exts " \
139  "parameter, either to -1 (all extensions) or to any valid extension nb.\n" \
140  "\n" \
141  "The output PRO.CATG are:\n" \
142  "GAIN_INFO - the gain table\n" \
143  "DET_LIN_INFO - the linearity table\n" \
144  "BP_MAP_NL - the bad pixel map (only produced with --pix2pix=TRUE)\n" \
145  "COEFFS_CUBE - the fit coefficient cube (only produced with --pix2pix=TRUE)\n"
146 
147 #define REGEXP "ARCFILE|MJD-OBS|ESO TPL ID|DATE-OBS|ESO DET DIT|ESO DET NDIT"
148 
149 typedef unsigned long irplib_gain_flag;
150 
151 #define IRPLIB_GAIN_PTC ((irplib_gain_flag) 1 << 1)
152 #define IRPLIB_GAIN_MEDIAN ((irplib_gain_flag) 1 << 2)
153 #define IRPLIB_GAIN_NO_COLLAPSE ((irplib_gain_flag) 1 << 3)
154 #define IRPLIB_GAIN_COLLAPSE ((irplib_gain_flag) 1 << 4)
155 #define IRPLIB_GAIN_WITH_AUTOCORR ((irplib_gain_flag) 1 << 5)
156 #define IRPLIB_GAIN_WITH_RESCALE ((irplib_gain_flag) 1 << 6)
157 #define IRPLIB_GAIN_OPT ((irplib_gain_flag) 1 << 7)
158 #define IRPLIB_GAIN_NIR ((irplib_gain_flag) 1 << 8)
159 
160 typedef unsigned long irplib_lin_flag;
161 
162 #define IRPLIB_LIN_NO_COLLAPSE ((irplib_lin_flag) 1 << 10)
163 #define IRPLIB_LIN_COLLAPSE ((irplib_lin_flag) 1 << 11)
164 #define IRPLIB_LIN_PIX2PIX ((irplib_lin_flag) 1 << 12)
165 #define IRPLIB_LIN_WITH_RESCALE ((irplib_lin_flag) 1 << 13)
166 #define IRPLIB_LIN_OPT ((irplib_lin_flag) 1 << 14)
167 #define IRPLIB_LIN_NIR ((irplib_lin_flag) 1 << 15)
168 
169 /*----------------------------------------------------------------------------
170  Prototypes
171  ----------------------------------------------------------------------------*/
172 
173 cpl_error_code
174 detmon_lg(cpl_frameset * frameset,
175  const cpl_parameterlist * parlist,
176  const char * tag_on,
177  const char * tag_off,
178  const char * recipe_name,
179  const char * pipeline_name,
180  const char * pafregexp,
181  const cpl_propertylist * pro_lintbl,
182  const cpl_propertylist * pro_gaintbl,
183  const cpl_propertylist * pro_coeffscube,
184  const cpl_propertylist * pro_bpm,
185  const cpl_propertylist * pro_corr,
186  const cpl_propertylist * pro_diff,
187  const char * package,
188  int (* compare) (const cpl_frame *,
189  const cpl_frame *),
190  int (* load_fset) (const cpl_frameset *,
191  cpl_type,
192  cpl_imagelist *),
193  const cpl_boolean opt_nir);
194 
195 
196 cpl_image * detmon_image_correlate(const cpl_image *,
197  const cpl_image *,
198  const int ,
199  const int );
200 
201 cpl_error_code
202 detmon_lg_fill_parlist_nir_default(cpl_parameterlist *,
203  const char *,
204  const char *);
205 
206 cpl_error_code
207 detmon_lg_fill_parlist_nir_default_mr(cpl_parameterlist * parlist,
208  const char *recipe_name,
209  const char *pipeline_name);
210 
211 cpl_error_code
212 detmon_lg_fill_parlist_opt_default(cpl_parameterlist *,
213  const char *,
214  const char *);
215 
216 cpl_error_code
217 detmon_lg_fill_parlist_opt_default_mr(cpl_parameterlist * parlist,
218  const char *recipe_name,
219  const char *pipeline_name);
220 
221 cpl_error_code
222 detmon_lg_fill_parlist(cpl_parameterlist * parlist,
223  const char *recipe_name, const char *pipeline_name,
224  const char *method,
225  int order,
226  double kappa,
227  int niter,
228  int llx,
229  int lly,
230  int urx,
231  int ury,
232  int ref_level,
233  const char * intermediate,
234  const char * autocorr,
235  const char * collapse,
236  const char * rescale,
237  const char * pix2pix,
238  const char * bpmbin,
239  int filter,
240  int m,
241  int n,
242  double tolerance,
243  const char * pafgen,
244  const char * pafname,
245  int llx1,
246  int lly1,
247  int urx1,
248  int ury1,
249  int llx2,
250  int lly2,
251  int urx2,
252  int ury2,
253  int llx3,
254  int lly3,
255  int urx3,
256  int ury3,
257  int llx4,
258  int lly4,
259  int urx4,
260  int ury4,
261  int llx5,
262  int lly5,
263  int urx5,
264  int ury5,
265  int exts,
266  cpl_boolean opt_nir);
267 
268 cpl_image *
269 detmon_autocorrelate(const cpl_image *,
270  const int, const int);
271 
272 cpl_table *
273 detmon_gain(const cpl_imagelist *,
274  const cpl_imagelist *,
275  const cpl_vector *,
276  const cpl_vector *,
277  double ,
278  int ,
279  int ,
280  int ,
281  int ,
282  double ,
283  int ,
284  int ,
285  int ,
286  cpl_propertylist *,
287  unsigned ,
288  cpl_imagelist **,
289  cpl_imagelist **);
290 
291 cpl_table *
292 detmon_lin(const cpl_imagelist *,
293  const cpl_imagelist *,
294  const cpl_vector *,
295  double ,
296  int ,
297  int ,
298  int ,
299  int ,
300  int ,
301  int ,
302  double,
303  cpl_boolean,
304  cpl_propertylist *,
305  unsigned ,
306  cpl_imagelist **,
307  cpl_image **);
308 
309 cpl_error_code
310 detmon_lg_set_tag(cpl_frameset* set, const char** tag_on, const char** tag_off);
311 
312 #endif