CR2RE Pipeline Reference Manual 1.7.0
cr2res_util_calib.c
1/*
2 * This file is part of the CR2RES Pipeline
3 * Copyright (C) 2002,2003 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27
28#include <locale.h>
29#include <string.h>
30
31#include <cpl.h>
32#include <hdrl.h>
33
34#include "cr2res_utils.h"
35#include "cr2res_calib.h"
36#include "cr2res_pfits.h"
37#include "cr2res_dfs.h"
38#include "cr2res_flat.h"
39#include "cr2res_trace.h"
40#include "cr2res_extract.h"
41#include "cr2res_io.h"
42
43/*-----------------------------------------------------------------------------
44 Define
45 -----------------------------------------------------------------------------*/
46
47#define RECIPE_STRING "cr2res_util_calib"
48
49/*-----------------------------------------------------------------------------
50 Plugin registration
51 -----------------------------------------------------------------------------*/
52
53int cpl_plugin_get_info(cpl_pluginlist * list);
54
55/*-----------------------------------------------------------------------------
56 Private function prototypes
57 -----------------------------------------------------------------------------*/
58
59static cpl_frameset * cr2res_util_calib_find_RAW(const cpl_frameset * in) ;
60static int cr2res_util_calib_create(cpl_plugin *);
61static int cr2res_util_calib_exec(cpl_plugin *);
62static int cr2res_util_calib_destroy(cpl_plugin *);
63static int cr2res_util_calib(cpl_frameset *, const cpl_parameterlist *);
64
65/*-----------------------------------------------------------------------------
66 Static variables
67 -----------------------------------------------------------------------------*/
68
69static char cr2res_util_calib_description[] = "\
70Frames Calibration \n\
71 Each input file is corrected with BPM / Dark / Flat / Det.Lin. / Cosmics\n\
72 \n\
73 Inputs \n\
74 raw.fits " CR2RES_FLAT_RAW" [1 to n] \n\
75 or " CR2RES_WAVE_UNE_RAW" \n\
76 or " CR2RES_WAVE_FPET_RAW" \n\
77 or " CR2RES_CAL_NODDING_OTHER_RAW " \n\
78 or " CR2RES_CAL_NODDING_JITTER_RAW" \n\
79 or " CR2RES_OBS_NODDING_OTHER_RAW" \n\
80 or " CR2RES_OBS_NODDING_JITTER_RAW" \n\
81 or " CR2RES_OBS_ASTROMETRY_OTHER_RAW" \n\
82 or " CR2RES_OBS_ASTROMETRY_JITTER_RAW" \n\
83 or " CR2RES_OBS_STARING_OTHER_RAW" \n\
84 or " CR2RES_OBS_STARING_JITTER_RAW" \n\
85 or " CR2RES_OBS_STARING_WAVE_SKY_RAW" \n\
86 or " CR2RES_OBS_POLARIMETRY_OTHER_RAW" \n\
87 or " CR2RES_OBS_2D_OBJECT_RAW" \n\
88 or " CR2RES_OBS_2D_SKY_RAW" \n\
89 detlin.fits " CR2RES_CAL_DETLIN_COEFFS_PROCATG " [0 to 1] \n\
90 bpm.fits " CR2RES_CAL_DARK_BPM_PROCATG " [0 to 1] \n\
91 or " CR2RES_CAL_FLAT_BPM_PROCATG " \n\
92 or " CR2RES_CAL_DETLIN_BPM_PROCATG " \n\
93 or " CR2RES_UTIL_BPM_MERGE_PROCATG " \n\
94 or " CR2RES_UTIL_BPM_SPLIT_PROCATG " \n\
95 master_dark.fits " CR2RES_CAL_DARK_MASTER_PROCATG " [0 to 1] \n\
96 master_flat.fits " CR2RES_CAL_FLAT_MASTER_PROCATG " [0 to 1] \n\
97 \n\
98 Outputs \n\
99 <input_name>_calibrated.fits " CR2RES_UTIL_CALIB_PROCATG " \n\
100 or \n\
101 <input_name>_calibrated_collapsed.fits " CR2RES_UTIL_CALIB_PROCATG "\n\
102 \n\
103 Algorithm \n\
104 loop on detectors d: \n\
105 Call cr2res_calib_imagelist()() to calibrate cosmics, \n\
106 detlin, bpm, dark, flat \n\
107 -> calibrated(d) \n\
108 Collapse the calibrated image list to collapsed(d) \n\
109 if (collapse) save collapsed \n\
110 else save every individual calibrated frame \n\
111 Library functions used: \n\
112 cr2res_io_load_image() \n\
113 cr2res_calib_imagelist() \n\
114 cr2res_io_save_CALIBRATED() \n\
115";
116
117/*-----------------------------------------------------------------------------
118 Function code
119 -----------------------------------------------------------------------------*/
120
121/*----------------------------------------------------------------------------*/
131/*----------------------------------------------------------------------------*/
132int cpl_plugin_get_info(cpl_pluginlist * list)
133{
134 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe );
135 cpl_plugin * plugin = &recipe->interface;
136
137 if (cpl_plugin_init(plugin,
138 CPL_PLUGIN_API,
139 CR2RES_BINARY_VERSION,
140 CPL_PLUGIN_TYPE_RECIPE,
141 RECIPE_STRING,
142 "Calibration utility",
143 cr2res_util_calib_description,
144 CR2RES_PIPELINE_AUTHORS,
145 PACKAGE_BUGREPORT,
147 cr2res_util_calib_create,
148 cr2res_util_calib_exec,
149 cr2res_util_calib_destroy)) {
150 cpl_msg_error(cpl_func, "Plugin initialization failed");
151 (void)cpl_error_set_where(cpl_func);
152 return 1;
153 }
154
155 if (cpl_pluginlist_append(list, plugin)) {
156 cpl_msg_error(cpl_func, "Error adding plugin to list");
157 (void)cpl_error_set_where(cpl_func);
158 return 1;
159 }
160
161 return 0;
162}
163
164/*----------------------------------------------------------------------------*/
172/*----------------------------------------------------------------------------*/
173static int cr2res_util_calib_create(cpl_plugin * plugin)
174{
175 cpl_recipe * recipe ;
176 cpl_parameter * p ;
177
178 /* Check that the plugin is part of a valid recipe */
179 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
180 recipe = (cpl_recipe *)plugin;
181 else
182 return -1;
183
184 /* Create the parameters list in the cpl_recipe object */
185 recipe->parameters = cpl_parameterlist_new();
186
187 /* Fill the parameters list */
188 p = cpl_parameter_new_value("cr2res.cr2res_util_calib.detector",
189 CPL_TYPE_INT, "Only reduce the specified detector",
190 "cr2res.cr2res_util_calib", 0);
191 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "detector");
192 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
193 cpl_parameterlist_append(recipe->parameters, p);
194
195 p = cpl_parameter_new_value("cr2res.cr2res_util_calib.clean_bad",
196 CPL_TYPE_BOOL, "Apply the cleaning to the bad pixels",
197 "cr2res.cr2res_util_calib", FALSE);
198 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "clean_bad");
199 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
200 cpl_parameterlist_append(recipe->parameters, p);
201
202 p = cpl_parameter_new_value(
203 "cr2res.cr2res_util_calib.subtract_nolight_rows",
204 CPL_TYPE_BOOL,
205 "Subtract median row from baffled region at detector bottom",
206 "cr2res.cr2res_util_calib", FALSE);
207 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "subtract_nolight_rows");
208 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
209 cpl_parameterlist_append(recipe->parameters, p);
210
211 p = cpl_parameter_new_value(
212 "cr2res.cr2res_util_calib.subtract_interorder_column",
213 CPL_TYPE_BOOL,
214 "Subtract column-by-column fit to the pixel values between"
215 " spectral orders",
216 "cr2res.cr2res_util_calib", TRUE);
217 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
218 "subtract_interorder_column");
219 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
220 cpl_parameterlist_append(recipe->parameters, p);
221
222 p = cpl_parameter_new_value("cr2res.cr2res_util_calib.cosmics",
223 CPL_TYPE_BOOL, "Find and mark cosmic rays hits as bad",
224 "cr2res.cr2res_util_calib", FALSE);
225 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "cosmics");
226 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
227 cpl_parameterlist_append(recipe->parameters, p);
228
229 p = cpl_parameter_new_value("cr2res.cr2res_util_calib.collapse",
230 CPL_TYPE_STRING, "Collapse the input (NONE, SUM, MEAN or MEDIAN)",
231 "cr2res.cr2res_util_calib", "NONE");
232 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "collapse");
233 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
234 cpl_parameterlist_append(recipe->parameters, p);
235
236 return 0;
237}
238
239/*----------------------------------------------------------------------------*/
245/*----------------------------------------------------------------------------*/
246static int cr2res_util_calib_exec(cpl_plugin * plugin)
247{
248 cpl_recipe *recipe;
249
250 /* Get the recipe out of the plugin */
251 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
252 recipe = (cpl_recipe *)plugin;
253 else return -1;
254
255 return cr2res_util_calib(recipe->frames, recipe->parameters);
256}
257
258/*----------------------------------------------------------------------------*/
264/*----------------------------------------------------------------------------*/
265static int cr2res_util_calib_destroy(cpl_plugin * plugin)
266{
267 cpl_recipe *recipe;
268
269 /* Get the recipe out of the plugin */
270 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
271 recipe = (cpl_recipe *)plugin;
272 else return -1 ;
273
274 cpl_parameterlist_delete(recipe->parameters);
275 return 0 ;
276}
277
278/*----------------------------------------------------------------------------*/
285/*----------------------------------------------------------------------------*/
286static int cr2res_util_calib(
287 cpl_frameset * frameset,
288 const cpl_parameterlist * parlist)
289{
290 const cpl_parameter * param ;
291 int clean_bad, cosmics, reduce_det,
292 subtract_nolight_rows, subtract_interorder_column ;
293 cr2res_collapse collapse ;
294 const char * sval ;
295 cpl_frameset * rawframes ;
296 const cpl_frame * detlin_frame ;
297 const cpl_frame * master_dark_frame ;
298 const cpl_frame * master_flat_frame ;
299 const cpl_frame * bpm_frame ;
300 cpl_vector * dits ;
301 cpl_vector * ndits ;
302 cpl_vector * ndsamples ;
303 hdrl_imagelist * in ;
304 cpl_image * contrib ;
305 const cpl_frame * cur_frame ;
306 const char * cur_fname ;
307 hdrl_image * collapsed_ima[CR2RES_NB_DETECTORS] ;
308 hdrl_image * calibrated_one[CR2RES_NB_DETECTORS] ;
309 hdrl_imagelist * calibrated[CR2RES_NB_DETECTORS] ;
310 cpl_propertylist * ext_plist[CR2RES_NB_DETECTORS] ;
311 hdrl_value mul_factor ;
312 char * out_file;
313 int det_nr ;
314
315 /* Needed for sscanf() */
316 setlocale(LC_NUMERIC, "C");
317
318 /* Initialise */
319 contrib = NULL ;
320 collapse = CR2RES_COLLAPSE_UNSPECIFIED ;
321
322 /* RETRIEVE INPUT PARAMETERS */
323 param = cpl_parameterlist_find_const(parlist,
324 "cr2res.cr2res_util_calib.detector");
325 reduce_det = cpl_parameter_get_int(param);
326 param = cpl_parameterlist_find_const(parlist,
327 "cr2res.cr2res_util_calib.clean_bad");
328 clean_bad = cpl_parameter_get_bool(param);
329 param = cpl_parameterlist_find_const(parlist,
330 "cr2res.cr2res_util_calib.subtract_nolight_rows");
331 subtract_nolight_rows = cpl_parameter_get_bool(param);
332 param = cpl_parameterlist_find_const(parlist,
333 "cr2res.cr2res_util_calib.subtract_interorder_column");
334 subtract_interorder_column = cpl_parameter_get_bool(param);
335 param = cpl_parameterlist_find_const(parlist,
336 "cr2res.cr2res_util_calib.cosmics");
337 cosmics = cpl_parameter_get_bool(param);
338 param = cpl_parameterlist_find_const(parlist,
339 "cr2res.cr2res_util_calib.collapse");
340 sval = cpl_parameter_get_string(param);
341 if (!strcmp(sval, "NONE")) collapse = CR2RES_COLLAPSE_NONE ;
342 else if (!strcmp(sval, "SUM")) collapse = CR2RES_COLLAPSE_SUM ;
343 else if (!strcmp(sval, "MEAN")) collapse = CR2RES_COLLAPSE_MEAN ;
344 else if (!strcmp(sval, "MEDIAN")) collapse = CR2RES_COLLAPSE_MEDIAN ;
345 if (collapse == CR2RES_COLLAPSE_UNSPECIFIED) {
346 cpl_msg_error(__func__, "Cannot understand the collapse method") ;
347 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
348 return -1 ;
349 }
350
351 /* Identify the RAW and CALIB frames in the input frameset */
352 if (cr2res_dfs_set_groups(frameset)) {
353 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
354 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
355 return -1 ;
356 }
357
358 /* Get Calibration frames */
359 detlin_frame = cpl_frameset_find_const(frameset,
360 CR2RES_CAL_DETLIN_COEFFS_PROCATG);
361 master_dark_frame = cpl_frameset_find_const(frameset,
362 CR2RES_CAL_DARK_MASTER_PROCATG) ;
363 master_flat_frame = cpl_frameset_find_const(frameset,
364 CR2RES_CAL_FLAT_MASTER_PROCATG) ;
365 bpm_frame = cr2res_io_find_BPM(frameset) ;
366
367 /* Get the rawframes */
368 rawframes = cr2res_util_calib_find_RAW(frameset) ;
369 if (rawframes==NULL || cpl_frameset_get_size(rawframes) <= 0) {
370 cpl_msg_error(__func__, "Cannot find any RAW file") ;
371 cpl_error_set(__func__, CPL_ERROR_DATA_NOT_FOUND) ;
372 if (rawframes!= NULL) cpl_frameset_delete(rawframes) ;
373 return -1 ;
374 }
375
376 /* Loop on the detectors */
377 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
378 /* Initialise */
379 collapsed_ima[det_nr-1] = NULL ;
380 calibrated[det_nr-1] = NULL ;
381
382 /* Compute only one detector */
383 if (reduce_det != 0 && det_nr != reduce_det) continue ;
384
385 cpl_msg_info(__func__, "Process Detector %d", det_nr) ;
386 cpl_msg_indent_more() ;
387
388 /* Load the DITs if necessary */
389 if (master_dark_frame != NULL) dits = cr2res_io_read_dits(rawframes) ;
390 else dits = NULL ;
391 if (cpl_msg_get_level() == CPL_MSG_DEBUG && dits != NULL)
392 cpl_vector_dump(dits, stdout) ;
393 ndits = cr2res_io_read_ndits(rawframes) ;
394
395 /* Load image list */
396 cpl_msg_info(__func__, "Load the input frames") ;
397 if ((in = cr2res_io_load_image_list_from_set(rawframes,
398 det_nr)) == NULL) {
399 cpl_msg_warning(__func__, "Cannot load images") ;
400 if (dits != NULL) cpl_vector_delete(dits) ;
401 if (ndits != NULL) cpl_vector_delete(ndits) ;
402 cpl_msg_indent_less() ;
403 continue ;
404 }
405 if (hdrl_imagelist_get_size(in) != cpl_frameset_get_size(rawframes)) {
406 cpl_msg_error(__func__, "Inconsistent number of loaded images") ;
407 if (dits != NULL) cpl_vector_delete(dits) ;
408 if (ndits != NULL) cpl_vector_delete(ndits) ;
410 cpl_msg_indent_less() ;
411 continue ;
412 }
413
414 /* Calibrate the images */
415 cpl_msg_info(__func__, "Calibrate the input images") ;
416 ndsamples = cr2res_io_read_ndsamples(rawframes) ;
417 calibrated[det_nr-1] = cr2res_calib_imagelist(in, det_nr,
418 clean_bad, subtract_nolight_rows,
419 subtract_interorder_column, cosmics,
420 master_flat_frame,
421 master_dark_frame, bpm_frame, detlin_frame,
422 dits, ndits, ndsamples) ;
423 cpl_vector_delete(ndsamples) ;
424 if (calibrated[det_nr-1] == NULL) {
425 cpl_msg_warning(__func__, "Failed to apply the calibrations") ;
426 cpl_error_reset() ;
427 if (dits != NULL) cpl_vector_delete(dits) ;
428 if (ndits != NULL) cpl_vector_delete(ndits) ;
430 cpl_msg_indent_less() ;
431 continue ;
432 }
434 if (dits != NULL) cpl_vector_delete(dits) ;
435 if (ndits != NULL) cpl_vector_delete(ndits) ;
436
437 /* Collapse */
438 if (collapse == CR2RES_COLLAPSE_MEAN) {
439 cpl_msg_info(__func__, "Collapse (Mean) the calibrated images") ;
440 cpl_msg_indent_more() ;
441 hdrl_imagelist_collapse_mean(calibrated[det_nr-1],
442 &(collapsed_ima[det_nr-1]), &contrib) ;
443 } else if (collapse == CR2RES_COLLAPSE_SUM) {
444 cpl_msg_info(__func__, "Collapse (Sum) the calibrated images") ;
445 cpl_msg_indent_more() ;
446 hdrl_imagelist_collapse_mean(calibrated[det_nr-1],
447 &(collapsed_ima[det_nr-1]), &contrib) ;
448 /* From mean to sum : multiply by the number of images */
449 mul_factor.data = hdrl_imagelist_get_size(calibrated[det_nr-1]) ;
450 mul_factor.error = hdrl_imagelist_get_size(calibrated[det_nr-1]) ;
451 hdrl_image_mul_scalar(collapsed_ima[det_nr-1], mul_factor) ;
452 } else if (collapse == CR2RES_COLLAPSE_MEDIAN) {
453 cpl_msg_info(__func__, "Collapse (Median) the calibrated images") ;
454 cpl_msg_indent_more() ;
455 hdrl_imagelist_collapse_median(calibrated[det_nr-1],
456 &(collapsed_ima[det_nr-1]), &contrib) ;
457 }
458 if (contrib != NULL) {
459 cpl_image_delete(contrib) ;
460 contrib = NULL ;
461 }
462 if (cpl_error_get_code() != CPL_ERROR_NONE) {
463 collapsed_ima[det_nr-1] = NULL ;
464 cpl_msg_warning(__func__, "Failed to Collapse") ;
465 cpl_msg_indent_less() ;
466 cpl_msg_indent_less() ;
467 cpl_error_reset() ;
468 continue ;
469 }
470 cpl_msg_indent_less() ;
471 cpl_msg_indent_less() ;
472 }
473
474 /* Save Products */
475 if (collapse == CR2RES_COLLAPSE_NONE) {
476 int i;
477 /* Save individual calibrated images */
478 /* Loop on the RAW frames */
479 for (i = 0; i < cpl_frameset_get_size(rawframes); i++) {
480 cpl_frameset *cur_fset;
481 /* Get the Current Frame */
482 cur_frame = cpl_frameset_get_position(rawframes, i) ;
483 cur_fname = cpl_frame_get_filename(cur_frame) ;
484
485 /* Save CALIBRATED */
486 out_file=cpl_sprintf("%s_calibrated.fits",
488 cur_fset = cpl_frameset_new() ;
489 cpl_frameset_insert(cur_fset, cpl_frame_duplicate(cur_frame)) ;
490
491 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
492 /* Initialise */
493 ext_plist[det_nr-1] = NULL ;
494 calibrated_one[det_nr-1] = NULL ;
495
496 /* Compute only one detector */
497 if (reduce_det != 0 && det_nr != reduce_det) continue ;
498
499 ext_plist[det_nr-1] = cpl_propertylist_load(cur_fname,
500 cr2res_io_get_ext_idx(cur_fname, det_nr, 1)) ;
501 calibrated_one[det_nr-1] = hdrl_image_duplicate(
502 hdrl_imagelist_get_const(calibrated[det_nr-1], i)) ;
503 }
504 cr2res_io_save_CALIBRATED(out_file, frameset, cur_fset, parlist,
505 calibrated_one, NULL, ext_plist, CR2RES_UTIL_CALIB_PROCATG,
506 RECIPE_STRING) ;
507 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
508 if (ext_plist[det_nr-1] != NULL)
509 cpl_propertylist_delete(ext_plist[det_nr-1]) ;
510 if (calibrated_one[det_nr-1] != NULL)
511 hdrl_image_delete(calibrated_one[det_nr-1]) ;
512 }
513 cpl_frameset_delete(cur_fset) ;
514 cpl_free(out_file);
515 }
516 }
517 else {
518 /* Save COLLAPSED calibrated image */
519 cur_frame = cpl_frameset_get_position(rawframes, 0) ;
520 cur_fname = cpl_frame_get_filename(cur_frame) ;
521 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
522 /* Initialise */
523 ext_plist[det_nr-1] = NULL ;
524
525 /* Compute only one detector */
526 if (reduce_det != 0 && det_nr != reduce_det) continue ;
527
528 ext_plist[det_nr-1] = cpl_propertylist_load(cur_fname,
529 cr2res_io_get_ext_idx(cur_fname, det_nr, 1)) ;
530 }
531 out_file=cpl_sprintf("%s_calibrated_collapsed.fits", RECIPE_STRING) ;
532 cr2res_io_save_CALIBRATED(out_file, frameset, rawframes, parlist,
533 collapsed_ima, NULL, ext_plist, CR2RES_UTIL_CALIB_PROCATG,
534 RECIPE_STRING) ;
535 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
536 if (ext_plist[det_nr-1] != NULL)
537 cpl_propertylist_delete(ext_plist[det_nr-1]) ;
538 }
539 cpl_free(out_file);
540 }
541
542 /* Free */
543 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
544 if (collapsed_ima[det_nr-1] != NULL)
545 hdrl_image_delete(collapsed_ima[det_nr-1]) ;
546 if (calibrated[det_nr-1] != NULL)
547 hdrl_imagelist_delete(calibrated[det_nr-1]) ;
548 }
549 cpl_frameset_delete(rawframes) ;
550 return (int)cpl_error_get_code();
551}
552
553/*----------------------------------------------------------------------------*/
574/*----------------------------------------------------------------------------*/
575static cpl_frameset * cr2res_util_calib_find_RAW(const cpl_frameset * in)
576{
577 cpl_frameset * out ;
578 char ** tags ;
579 int i, ntags ;
580
581 /* Check entries */
582 if (in == NULL) return NULL ;
583
584 /* Create the tags list */
585 ntags = 15 ;
586 tags = cpl_malloc(ntags * sizeof(char *)) ;
587 tags[0] = cpl_sprintf(CR2RES_FLAT_RAW) ;
588 tags[1] = cpl_sprintf(CR2RES_WAVE_UNE_RAW) ;
589 tags[2] = cpl_sprintf(CR2RES_WAVE_FPET_RAW) ;
590 tags[3] = cpl_sprintf(CR2RES_CAL_NODDING_OTHER_RAW) ;
591 tags[4] = cpl_sprintf(CR2RES_CAL_NODDING_JITTER_RAW) ;
592 tags[5] = cpl_sprintf(CR2RES_OBS_NODDING_OTHER_RAW) ;
593 tags[6] = cpl_sprintf(CR2RES_OBS_NODDING_JITTER_RAW) ;
594 tags[7] = cpl_sprintf(CR2RES_OBS_ASTROMETRY_OTHER_RAW) ;
595 tags[8] = cpl_sprintf(CR2RES_OBS_ASTROMETRY_JITTER_RAW) ;
596 tags[9] = cpl_sprintf(CR2RES_OBS_STARING_OTHER_RAW) ;
597 tags[10] = cpl_sprintf(CR2RES_OBS_STARING_JITTER_RAW) ;
598 tags[11] = cpl_sprintf(CR2RES_OBS_STARING_WAVE_SKY_RAW) ;
599 tags[12] = cpl_sprintf(CR2RES_OBS_POLARIMETRY_OTHER_RAW) ;
600 tags[13] = cpl_sprintf(CR2RES_OBS_2D_OBJECT_RAW) ;
601 tags[14] = cpl_sprintf(CR2RES_OBS_2D_SKY_RAW) ;
602
603 /* Get the frameset */
604 out = cr2res_extract_frameset_several_tags(in, (const char**)tags, ntags) ;
605
606 for (i=0 ; i<ntags ; i++) cpl_free(tags[i]) ;
607 cpl_free(tags) ;
608 return out ;
609}
610
611
612
613
hdrl_imagelist * cr2res_calib_imagelist(const hdrl_imagelist *in, int chip, int clean_bad, int subtract_nolight_rows, int subtract_interorder_column, int cosmics_corr, const cpl_frame *flat, const cpl_frame *dark, const cpl_frame *bpm, const cpl_frame *detlin, const cpl_vector *dits, const cpl_vector *ndits, const cpl_vector *ndsamples)
The images calibration routine for a given chip on a list.
cpl_error_code cr2res_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
Definition cr2res_dfs.c:53
const cpl_frame * cr2res_io_find_BPM(const cpl_frameset *in)
Get the first CR2RES_BPM_DRSTYPE frame from a frameset.
Definition cr2res_io.c:369
cpl_vector * cr2res_io_read_ndsamples(const cpl_frameset *in)
Get the NDSAMPLES from a frame set.
Definition cr2res_io.c:492
cpl_vector * cr2res_io_read_dits(const cpl_frameset *in)
Get the DITS from a frame set.
Definition cr2res_io.c:432
hdrl_imagelist * cr2res_io_load_image_list_from_set(const cpl_frameset *in, int detector)
Load an hdrl image list from an images frameset.
Definition cr2res_io.c:838
int cr2res_io_get_ext_idx(const char *filename, int detector, int data)
Get the wished extension number for a detector.
Definition cr2res_io.c:674
int cr2res_io_save_CALIBRATED(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_image **calib_collapsed, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a CALIBRATED frame.
Definition cr2res_io.c:1638
cpl_vector * cr2res_io_read_ndits(const cpl_frameset *in)
Get the NDITs from a frame set.
Definition cr2res_io.c:462
char * cr2res_get_root_name(const char *filename)
Find out the root part of a basename (name without extension).
cpl_frameset * cr2res_extract_frameset_several_tags(const cpl_frameset *in, const char **tags, int ntags)
Extract the frames whose tag is within a list from a frameset.
char * cr2res_get_base_name(const char *filename)
Find out the base name of a file (i.e. without prefix path)
const char * cr2res_get_license(void)
Get the pipeline copyright and license.
cpl_error_code hdrl_image_mul_scalar(hdrl_image *self, hdrl_value value)
Elementwise multiplication of an image with a scalar.
hdrl_image * hdrl_image_duplicate(const hdrl_image *himg)
copy hdrl_image
Definition hdrl_image.c:391
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
Definition hdrl_image.c:379
cpl_error_code hdrl_imagelist_collapse_mean(const hdrl_imagelist *himlist, hdrl_image **out, cpl_image **contrib)
Mean collapsing of image list.
void hdrl_imagelist_delete(hdrl_imagelist *himlist)
Free all memory used by a hdrl_imagelist object including the images.
const hdrl_image * hdrl_imagelist_get_const(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.
cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *himlist)
Get the number of images in the imagelist.
cpl_error_code hdrl_imagelist_collapse_median(const hdrl_imagelist *himlist, hdrl_image **out, cpl_image **contrib)
Median collapsing of image list.