28#ifndef IRPLIB_DETMON_LG_H
29#define IRPLIB_DETMON_LG_H
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"
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]"
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]"
56#define DETMON_QC_CONAD "ESO QC CONAD"
57#define DETMON_QC_CONAD_C "Conversion from e- to ADUs [ADU/e-]"
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-]"
62#define DETMON_QC_GAIN "ESO QC GAIN"
63#define DETMON_QC_GAIN_C "GAIN (see QC.METHOD) [e-/ADU]"
65#define DETMON_QC_GAIN_MSE "ESO QC GAIN MSE"
66#define DETMON_QC_GAIN_MSE_C "Measured Squared error in GAIN computation"
68#define DETMON_QC_RON "ESO QC RON"
69#define DETMON_QC_RON_C "RON obtained as independent term (PTC method)"
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]"
77#define DETMON_QC_LAMP_FLUX "ESO QC LAMP FLUX"
78#define DETMON_QC_LAMP_FLUX_C "Lamp flux"
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"
84#define DETMON_QC_NUM_BPM_AVG "ESO QC NUM BPM AVG"
85#define DETMON_QC_NUM_BPM_AVG_C "Avg of ESO QC NUM BPM"
87#define DETMON_QC_LAMP_STAB "ESO QC LAMP STAB"
88#define DETMON_QC_LAMP_STAB_C "Lamp stability"
90#define DETMON_QC_METHOD "ESO QC METHOD"
91#define DETMON_QC_METHOD_C "Method applied to compute GAIN"
93#define DETMON_QC_LIN_EFF "ESO QC LIN EFF"
94#define DETMON_QC_LIN_EFF_C "Effective non-linearity correction"
96#define DETMON_QC_LIN_EFF_FLUX "ESO QC LIN EFF FLUX"
97#define DETMON_QC_LIN_EFF_FLUX_C "FLux level at which effective non-linearity correction is computed"
99#define DETMON_QC_LIN_COEF "ESO QC LIN COEF"
100#define DETMON_QC_LIN_COEF_C "Linearity coefficient value"
103#define DETMON_QC_LIN_COEF_ERR "ESO QC LIN EFF ERR"
104#define DETMON_QC_LIN_COEF_ERR_C "Linearity coefficient error value"
105#define DETMON_QC_LIN_COEF_MSE_ERR_C "Linearity coefficient measured square error value"
108#define DETMON_QC_ERRFIT "ESO QC ERRFIT"
109#define DETMON_QC_ERRFIT_C "Error of fit"
110#define DETMON_QC_ERRFIT_MSE_C "Measured square error of fit"
112#define DETMON_QC_CONTAM "ESO QC CONTAM"
113#define DETMON_QC_CONTAM_C "Detector contamination in a region"
115#define DETMON_QC_FPN "ESO QC FPN"
116#define DETMON_QC_FPN_C "Flat pattern noise"
118#define DETMON_QC_FPN_FRAC "ESO QC FPN FRAC"
119#define DETMON_QC_FPN_FRAC_C "QC.FPN / QC.SIGNAL.MEAN"
121#define DETMON_QC_SIGMA_PH "ESO QC SIGMA PH"
122#define DETMON_QC_SIGMA_PH_C "RMS of raw frame photon noise (SIG_ON_DIF)"
124#define DETMON_QC_SIGNAL_MEAN "ESO QC SIGNAL MEAN"
125#define DETMON_QC_SIGNAL_MEAN_C "Mean signal (from MEAN_ON1)"
128#define DETMON_QC_CONAD_AVG "ESO QC CONAD AVG"
129#define DETMON_QC_CONAD_AVG_C "Avg measured e- -> ADU (from GAIN)"
131#define DETMON_QC_CONAD_RMS "ESO QC CONAD RMS"
132#define DETMON_QC_CONAD_RMS_C "RMS of measured e- -> ADU (from GAIN)"
134#define DETMON_QC_GAIN_AVG "ESO QC GAIN AVG"
135#define DETMON_QC_GAIN_AVG_C "Avg gain across detectors"
137#define DETMON_QC_GAIN_RMS "ESO QC GAIN RMS"
138#define DETMON_QC_GAIN_RMS_C "RMS of gain across detectors"
140#define DETMON_QC_CONTAMi_NORM "ESO QC CONTAM%zd NORM"
141#define DETMON_QC_CONTAMi_NORM_C "QC.CONTAM%01d / (gain)QC.SIGNAL.MEAN"
143#define DETMON_QC_GAIN_ERR_AVG "ESO QC GAIN ERR AVG"
144#define DETMON_QC_GAIN_ERR_AVG_C "Avg QC GAIN ERR"
146#define DETMON_QC_GAIN_ERR_RMS "ESO QC GAIN ERR RMS"
147#define DETMON_QC_GAIN_ERR_RMS_C "RMS of QC GAIN ERR"
149#define DETMON_QC_COUNTS_MIN_AVG "ESO QC COUNTS MIN AVG"
150#define DETMON_QC_COUNTS_MIN_AVG_C "Avg of QC COUNTS MIN"
152#define DETMON_QC_COUNTS_MIN_RMS "ESO QC COUNTS MIN RMS"
153#define DETMON_QC_COUNTS_MIN_RMS_C "RMS of QC COUNTS MIN"
155#define DETMON_QC_COUNTS_MAX_AVG "ESO QC COUNTS MAX AVG"
156#define DETMON_QC_COUNTS_MAX_AVG_C "Avg of QC COUNTS MAX"
158#define DETMON_QC_COUNTS_MAX_RMS "ESO QC COUNTS MAX RMS"
159#define DETMON_QC_COUNTS_MAX_RMS_C "RMS of QC COUNTS MAX"
161#define DETMON_QC_LIN_EFF_AVG "ESO QC LIN EFF AVG"
162#define DETMON_QC_LIN_EFF_AVG_C "Avg of QC LIN EFF"
164#define DETMON_QC_LIN_EFF_RMS "ESO QC LIN EFF RMS"
165#define DETMON_QC_LIN_EFF_RMS_C "RMS of QC LIN EFF"
167#define DETMON_QC_LIN_EFF_FLUX_AVG "ESO QC LIN EFF FLUX AVG"
168#define DETMON_QC_LIN_EFF_FLUX_AVG_C "Avg of QC LIN EFF"
170#define DETMON_QC_LIN_EFF_FLUX_RMS "ESO QC LIN EFF FLUX RMS"
171#define DETMON_QC_LIN_EFF_FLUX_RMS_C "RMS of QC LIN EFF FLUX"
173#define DETMON_QC_CONTAMi_AVG "ESO QC CONTAM%zd AVG"
174#define DETMON_QC_CONTAMi_AVG_C "Avg of ESO QC CONTAM%zd"
176#define DETMON_QC_CONTAMi_RMS "ESO QC CONTAM%zd RMS"
177#define DETMON_QC_CONTAMi_RMS_C "RMS of ESO QC CONTAM%zd"
182#define DETMON_QC_LIN_COEFF_AVG "ESO QC COEFF%s AVG"
183#define DETMON_QC_LIN_COEFF_AVG_C "Avg of ESO QC COEF%s"
185#define DETMON_QC_LIN_COEFF_RMS "ESO QC COEFF%s RMS"
186#define DETMON_QC_LIN_COEFF_RMS_C "RMS of ESO QC COEF%s"
188#define DETMON_QC_LIN_COEFF_ERR_AVG "ESO QC COEFF%s ERR AVG"
189#define DETMON_QC_LIN_COEFF_ERR_AVG_C "Avg of ESO QC COEF%s ERR"
191#define DETMON_QC_LIN_COEFF_ERR_RMS "ESO QC COEFF%s ERR RMS"
192#define DETMON_QC_LIN_COEFF_ERR_RMS_C "RMS of ESO QC COEF%s ERR"
195#define detmon_lg_get_description(RECIPE_NAME, PIPE_NAME, \
196 DETMON_LG_ON_RAW_NEW, \
197 DETMON_LG_OFF_RAW_NEW, \
198 DETMON_LG_ON_RAW_OLD, \
199 DETMON_LG_OFF_RAW_OLD) \
200 RECIPE_NAME " -- " PIPE_NAME " linearity/gain recipe for OPT/IR.\n" \
201 "The files listed in the Set Of Frames must be tagged:\n" \
202 "the raw-on-file.fits "DETMON_LG_ON_RAW_NEW" and\n" \
203 "the raw-off-file.fits "DETMON_LG_OFF_RAW_NEW"\n" \
204 "For backward compatibility are alternatively still supported the following tags:\n" \
205 "the raw-on-file.fits "DETMON_LG_ON_RAW_OLD" and\n" \
206 "the raw-off-file.fits "DETMON_LG_OFF_RAW_OLD"\n" \
207 "The recipe requires at least order+1 valid pairs of ON frames\n" \
208 "and order+1 valid pairs of OFF frames, \n" \
209 "where order is the value of the 'order' parameter.\n" \
210 "There is no requirement for pairs of OFF frames if collapse parameter " \
211 "is set to true.\n" \
212 "Frames with median flux over --filter will be excluded from the " \
214 "To perform a stability check you need frames with at least 2 DIT " \
216 "NOTE for multiextension cases: it is mandatory to modify the --exts " \
217 "parameter, either to -1 (all extensions) or to any valid extension nb.\n" \
219 "The output PRO.CATG are:\n" \
220 "GAIN_INFO - the gain table\n" \
221 "DET_LIN_INFO - the linearity table\n" \
222 "BP_MAP_NL - the bad pixel map (only produced with --pix2pix=TRUE)\n" \
223 "COEFFS_CUBE - the fit coefficient cube (only produced with --pix2pix=TRUE)\n"
225#define REGEXP "ARCFILE|MJD-OBS|ESO TPL ID|DATE-OBS|ESO DET DIT|ESO DET NDIT"
227typedef unsigned long irplib_gain_flag;
229#define IRPLIB_GAIN_PTC ((irplib_gain_flag) 1 << 1)
230#define IRPLIB_GAIN_MEDIAN ((irplib_gain_flag) 1 << 2)
231#define IRPLIB_GAIN_NO_COLLAPSE ((irplib_gain_flag) 1 << 3)
232#define IRPLIB_GAIN_COLLAPSE ((irplib_gain_flag) 1 << 4)
233#define IRPLIB_GAIN_WITH_AUTOCORR ((irplib_gain_flag) 1 << 5)
234#define IRPLIB_GAIN_WITH_RESCALE ((irplib_gain_flag) 1 << 6)
235#define IRPLIB_GAIN_OPT ((irplib_gain_flag) 1 << 7)
236#define IRPLIB_GAIN_NIR ((irplib_gain_flag) 1 << 8)
238typedef unsigned long irplib_lin_flag;
240#define IRPLIB_LIN_NO_COLLAPSE ((irplib_lin_flag) 1 << 10)
241#define IRPLIB_LIN_COLLAPSE ((irplib_lin_flag) 1 << 11)
242#define IRPLIB_LIN_PIX2PIX ((irplib_lin_flag) 1 << 12)
243#define IRPLIB_LIN_WITH_RESCALE ((irplib_lin_flag) 1 << 13)
244#define IRPLIB_LIN_OPT ((irplib_lin_flag) 1 << 14)
245#define IRPLIB_LIN_NIR ((irplib_lin_flag) 1 << 15)
252detmon_lg(cpl_frameset * frameset,
253 const cpl_parameterlist * parlist,
255 const char * tag_off,
256 const char * recipe_name,
257 const char * pipeline_name,
258 const char * pafregexp,
259 const cpl_propertylist * pro_lintbl,
260 const cpl_propertylist * pro_gaintbl,
261 const cpl_propertylist * pro_coeffscube,
262 const cpl_propertylist * pro_bpm,
263 const cpl_propertylist * pro_corr,
264 const cpl_propertylist * pro_diff,
265 const char * package,
266 int (* compare) (
const cpl_frame *,
268 int (* load_fset) (
const cpl_frameset *,
271 const cpl_boolean opt_nir);
274cpl_image * detmon_image_correlate(
const cpl_image *,
280detmon_lg_fill_parlist_nir_default(cpl_parameterlist *,
285detmon_lg_fill_parlist_nir_default_mr(cpl_parameterlist * parlist,
286 const char *recipe_name,
287 const char *pipeline_name);
290detmon_lg_fill_parlist_opt_default(cpl_parameterlist *,
295detmon_lg_fill_parlist_opt_default_mr(cpl_parameterlist * parlist,
296 const char *recipe_name,
297 const char *pipeline_name);
300detmon_lg_fill_parlist(cpl_parameterlist * parlist,
301 const char *recipe_name,
const char *pipeline_name,
311 const char * intermediate,
312 const char * autocorr,
313 const char * collapse,
314 const char * rescale,
315 const char * pix2pix,
322 const char * pafname,
344 cpl_boolean opt_nir);
347detmon_autocorrelate(
const cpl_image *,
348 const int,
const int);
351detmon_gain(
const cpl_imagelist *,
352 const cpl_imagelist *,
370detmon_lin(
const cpl_imagelist *,
371 const cpl_imagelist *,
388detmon_lg_set_tag(cpl_frameset* set,
const char** tag_on,
const char** tag_off);
391detmon_lg_qc_params(cpl_table* linear_table, cpl_propertylist* lint_qclist,
392 cpl_table* gain_table, cpl_propertylist* gaint_qclist,
393 cpl_imagelist* coeffs, cpl_propertylist* linc_qclist,
394 cpl_image* bpm, cpl_propertylist* bpm_qclist,
395 const char * recipe_name);
398detmon_lg_qc_params_global_gain(
const char * recipe_name,
int nsets);
401detmon_lg_qc_params_global_gain_update(
const char * fn,
402 const char * recipe_name);
405detmon_lg_qc_params_global_lin(
const char * recipe_name,
int nsets);
408detmon_lg_qc_params_global_lin_update(
const char * fn,
409 const char * recipe_name);
412detmon_lg_qc_params_global_bpm(
const char * recipe_name,
int nsets);
415detmon_lg_qc_params_global_bpm_update(
const char * fn,
416 const char * recipe_name);
419detmon_lg_qc_params_global_coeffs(
const char * recipe_name,
int nsets);
422detmon_lg_qc_params_global_coeffs_update(
const char * fn,
423 const char * recipe_name);
426detmon_lg_qc_set_kw_from_table_column(cpl_table* table,
429 cpl_propertylist* header,
431 const char * kw_comment);