CR2RE Pipeline Reference Manual 1.6.7
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 hdrl_imagelist * in ;
303 cpl_image * contrib ;
304 const cpl_frame * cur_frame ;
305 const char * cur_fname ;
306 hdrl_image * collapsed_ima[CR2RES_NB_DETECTORS] ;
307 hdrl_image * calibrated_one[CR2RES_NB_DETECTORS] ;
308 hdrl_imagelist * calibrated[CR2RES_NB_DETECTORS] ;
309 cpl_propertylist * ext_plist[CR2RES_NB_DETECTORS] ;
310 hdrl_value mul_factor ;
311 char * out_file;
312 int det_nr ;
313
314 /* Needed for sscanf() */
315 setlocale(LC_NUMERIC, "C");
316
317 /* Initialise */
318 contrib = NULL ;
319 collapse = CR2RES_COLLAPSE_UNSPECIFIED ;
320
321 /* RETRIEVE INPUT PARAMETERS */
322 param = cpl_parameterlist_find_const(parlist,
323 "cr2res.cr2res_util_calib.detector");
324 reduce_det = cpl_parameter_get_int(param);
325 param = cpl_parameterlist_find_const(parlist,
326 "cr2res.cr2res_util_calib.clean_bad");
327 clean_bad = cpl_parameter_get_bool(param);
328 param = cpl_parameterlist_find_const(parlist,
329 "cr2res.cr2res_util_calib.subtract_nolight_rows");
330 subtract_nolight_rows = cpl_parameter_get_bool(param);
331 param = cpl_parameterlist_find_const(parlist,
332 "cr2res.cr2res_util_calib.subtract_interorder_column");
333 subtract_interorder_column = cpl_parameter_get_bool(param);
334 param = cpl_parameterlist_find_const(parlist,
335 "cr2res.cr2res_util_calib.cosmics");
336 cosmics = cpl_parameter_get_bool(param);
337 param = cpl_parameterlist_find_const(parlist,
338 "cr2res.cr2res_util_calib.collapse");
339 sval = cpl_parameter_get_string(param);
340 if (!strcmp(sval, "NONE")) collapse = CR2RES_COLLAPSE_NONE ;
341 else if (!strcmp(sval, "SUM")) collapse = CR2RES_COLLAPSE_SUM ;
342 else if (!strcmp(sval, "MEAN")) collapse = CR2RES_COLLAPSE_MEAN ;
343 else if (!strcmp(sval, "MEDIAN")) collapse = CR2RES_COLLAPSE_MEDIAN ;
344 if (collapse == CR2RES_COLLAPSE_UNSPECIFIED) {
345 cpl_msg_error(__func__, "Cannot understand the collapse method") ;
346 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
347 return -1 ;
348 }
349
350 /* Identify the RAW and CALIB frames in the input frameset */
351 if (cr2res_dfs_set_groups(frameset)) {
352 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
353 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
354 return -1 ;
355 }
356
357 /* Get Calibration frames */
358 detlin_frame = cpl_frameset_find_const(frameset,
359 CR2RES_CAL_DETLIN_COEFFS_PROCATG);
360 master_dark_frame = cpl_frameset_find_const(frameset,
361 CR2RES_CAL_DARK_MASTER_PROCATG) ;
362 master_flat_frame = cpl_frameset_find_const(frameset,
363 CR2RES_CAL_FLAT_MASTER_PROCATG) ;
364 bpm_frame = cr2res_io_find_BPM(frameset) ;
365
366 /* Get the rawframes */
367 rawframes = cr2res_util_calib_find_RAW(frameset) ;
368 if (rawframes==NULL || cpl_frameset_get_size(rawframes) <= 0) {
369 cpl_msg_error(__func__, "Cannot find any RAW file") ;
370 cpl_error_set(__func__, CPL_ERROR_DATA_NOT_FOUND) ;
371 if (rawframes!= NULL) cpl_frameset_delete(rawframes) ;
372 return -1 ;
373 }
374
375 /* Loop on the detectors */
376 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
377 /* Initialise */
378 collapsed_ima[det_nr-1] = NULL ;
379 calibrated[det_nr-1] = NULL ;
380
381 /* Compute only one detector */
382 if (reduce_det != 0 && det_nr != reduce_det) continue ;
383
384 cpl_msg_info(__func__, "Process Detector %d", det_nr) ;
385 cpl_msg_indent_more() ;
386
387 /* Load the DITs if necessary */
388 if (master_dark_frame != NULL) dits = cr2res_io_read_dits(rawframes) ;
389 else dits = NULL ;
390 if (cpl_msg_get_level() == CPL_MSG_DEBUG && dits != NULL)
391 cpl_vector_dump(dits, stdout) ;
392 ndits = cr2res_io_read_ndits(rawframes) ;
393
394 /* Load image list */
395 cpl_msg_info(__func__, "Load the input frames") ;
396 if ((in = cr2res_io_load_image_list_from_set(rawframes,
397 det_nr)) == NULL) {
398 cpl_msg_warning(__func__, "Cannot load images") ;
399 if (dits != NULL) cpl_vector_delete(dits) ;
400 if (ndits != NULL) cpl_vector_delete(ndits) ;
401 cpl_msg_indent_less() ;
402 continue ;
403 }
404 if (hdrl_imagelist_get_size(in) != cpl_frameset_get_size(rawframes)) {
405 cpl_msg_error(__func__, "Inconsistent number of loaded images") ;
406 if (dits != NULL) cpl_vector_delete(dits) ;
407 if (ndits != NULL) cpl_vector_delete(ndits) ;
409 cpl_msg_indent_less() ;
410 continue ;
411 }
412
413 /* Calibrate the images */
414 cpl_msg_info(__func__, "Calibrate the input images") ;
415 if ((calibrated[det_nr-1] = cr2res_calib_imagelist(in, det_nr,
416 clean_bad, subtract_nolight_rows,
417 subtract_interorder_column, cosmics,
418 master_flat_frame,
419 master_dark_frame, bpm_frame, detlin_frame,
420 dits, ndits)) == NULL) {
421 cpl_msg_warning(__func__, "Failed to apply the calibrations") ;
422 cpl_error_reset() ;
423 if (dits != NULL) cpl_vector_delete(dits) ;
424 if (ndits != NULL) cpl_vector_delete(ndits) ;
426 cpl_msg_indent_less() ;
427 continue ;
428 }
430 if (dits != NULL) cpl_vector_delete(dits) ;
431 if (ndits != NULL) cpl_vector_delete(ndits) ;
432
433 /* Collapse */
434 if (collapse == CR2RES_COLLAPSE_MEAN) {
435 cpl_msg_info(__func__, "Collapse (Mean) the calibrated images") ;
436 cpl_msg_indent_more() ;
437 hdrl_imagelist_collapse_mean(calibrated[det_nr-1],
438 &(collapsed_ima[det_nr-1]), &contrib) ;
439 } else if (collapse == CR2RES_COLLAPSE_SUM) {
440 cpl_msg_info(__func__, "Collapse (Sum) the calibrated images") ;
441 cpl_msg_indent_more() ;
442 hdrl_imagelist_collapse_mean(calibrated[det_nr-1],
443 &(collapsed_ima[det_nr-1]), &contrib) ;
444 /* From mean to sum : multiply by the number of images */
445 mul_factor.data = hdrl_imagelist_get_size(calibrated[det_nr-1]) ;
446 mul_factor.error = hdrl_imagelist_get_size(calibrated[det_nr-1]) ;
447 hdrl_image_mul_scalar(collapsed_ima[det_nr-1], mul_factor) ;
448 } else if (collapse == CR2RES_COLLAPSE_MEDIAN) {
449 cpl_msg_info(__func__, "Collapse (Median) the calibrated images") ;
450 cpl_msg_indent_more() ;
451 hdrl_imagelist_collapse_median(calibrated[det_nr-1],
452 &(collapsed_ima[det_nr-1]), &contrib) ;
453 }
454 if (contrib != NULL) {
455 cpl_image_delete(contrib) ;
456 contrib = NULL ;
457 }
458 if (cpl_error_get_code() != CPL_ERROR_NONE) {
459 collapsed_ima[det_nr-1] = NULL ;
460 cpl_msg_warning(__func__, "Failed to Collapse") ;
461 cpl_msg_indent_less() ;
462 cpl_msg_indent_less() ;
463 cpl_error_reset() ;
464 continue ;
465 }
466 cpl_msg_indent_less() ;
467 cpl_msg_indent_less() ;
468 }
469
470 /* Save Products */
471 if (collapse == CR2RES_COLLAPSE_NONE) {
472 int i;
473 /* Save individual calibrated images */
474 /* Loop on the RAW frames */
475 for (i = 0; i < cpl_frameset_get_size(rawframes); i++) {
476 cpl_frameset *cur_fset;
477 /* Get the Current Frame */
478 cur_frame = cpl_frameset_get_position(rawframes, i) ;
479 cur_fname = cpl_frame_get_filename(cur_frame) ;
480
481 /* Save CALIBRATED */
482 out_file=cpl_sprintf("%s_calibrated.fits",
484 cur_fset = cpl_frameset_new() ;
485 cpl_frameset_insert(cur_fset, cpl_frame_duplicate(cur_frame)) ;
486
487 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
488 /* Initialise */
489 ext_plist[det_nr-1] = NULL ;
490 calibrated_one[det_nr-1] = NULL ;
491
492 /* Compute only one detector */
493 if (reduce_det != 0 && det_nr != reduce_det) continue ;
494
495 ext_plist[det_nr-1] = cpl_propertylist_load(cur_fname,
496 cr2res_io_get_ext_idx(cur_fname, det_nr, 1)) ;
497 calibrated_one[det_nr-1] = hdrl_image_duplicate(
498 hdrl_imagelist_get_const(calibrated[det_nr-1], i)) ;
499 }
500 cr2res_io_save_CALIBRATED(out_file, frameset, cur_fset, parlist,
501 calibrated_one, NULL, ext_plist, CR2RES_UTIL_CALIB_PROCATG,
502 RECIPE_STRING) ;
503 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
504 if (ext_plist[det_nr-1] != NULL)
505 cpl_propertylist_delete(ext_plist[det_nr-1]) ;
506 if (calibrated_one[det_nr-1] != NULL)
507 hdrl_image_delete(calibrated_one[det_nr-1]) ;
508 }
509 cpl_frameset_delete(cur_fset) ;
510 cpl_free(out_file);
511 }
512 }
513 else {
514 /* Save COLLAPSED calibrated image */
515 cur_frame = cpl_frameset_get_position(rawframes, 0) ;
516 cur_fname = cpl_frame_get_filename(cur_frame) ;
517 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
518 /* Initialise */
519 ext_plist[det_nr-1] = NULL ;
520
521 /* Compute only one detector */
522 if (reduce_det != 0 && det_nr != reduce_det) continue ;
523
524 ext_plist[det_nr-1] = cpl_propertylist_load(cur_fname,
525 cr2res_io_get_ext_idx(cur_fname, det_nr, 1)) ;
526 }
527 out_file=cpl_sprintf("%s_calibrated_collapsed.fits", RECIPE_STRING) ;
528 cr2res_io_save_CALIBRATED(out_file, frameset, rawframes, parlist,
529 collapsed_ima, NULL, ext_plist, CR2RES_UTIL_CALIB_PROCATG,
530 RECIPE_STRING) ;
531 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
532 if (ext_plist[det_nr-1] != NULL)
533 cpl_propertylist_delete(ext_plist[det_nr-1]) ;
534 }
535 cpl_free(out_file);
536 }
537
538 /* Free */
539 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
540 if (collapsed_ima[det_nr-1] != NULL)
541 hdrl_image_delete(collapsed_ima[det_nr-1]) ;
542 if (calibrated[det_nr-1] != NULL)
543 hdrl_imagelist_delete(calibrated[det_nr-1]) ;
544 }
545 cpl_frameset_delete(rawframes) ;
546 return (int)cpl_error_get_code();
547}
548
549/*----------------------------------------------------------------------------*/
570/*----------------------------------------------------------------------------*/
571static cpl_frameset * cr2res_util_calib_find_RAW(const cpl_frameset * in)
572{
573 cpl_frameset * out ;
574 char ** tags ;
575 int i, ntags ;
576
577 /* Check entries */
578 if (in == NULL) return NULL ;
579
580 /* Create the tags list */
581 ntags = 15 ;
582 tags = cpl_malloc(ntags * sizeof(char *)) ;
583 tags[0] = cpl_sprintf(CR2RES_FLAT_RAW) ;
584 tags[1] = cpl_sprintf(CR2RES_WAVE_UNE_RAW) ;
585 tags[2] = cpl_sprintf(CR2RES_WAVE_FPET_RAW) ;
586 tags[3] = cpl_sprintf(CR2RES_CAL_NODDING_OTHER_RAW) ;
587 tags[4] = cpl_sprintf(CR2RES_CAL_NODDING_JITTER_RAW) ;
588 tags[5] = cpl_sprintf(CR2RES_OBS_NODDING_OTHER_RAW) ;
589 tags[6] = cpl_sprintf(CR2RES_OBS_NODDING_JITTER_RAW) ;
590 tags[7] = cpl_sprintf(CR2RES_OBS_ASTROMETRY_OTHER_RAW) ;
591 tags[8] = cpl_sprintf(CR2RES_OBS_ASTROMETRY_JITTER_RAW) ;
592 tags[9] = cpl_sprintf(CR2RES_OBS_STARING_OTHER_RAW) ;
593 tags[10] = cpl_sprintf(CR2RES_OBS_STARING_JITTER_RAW) ;
594 tags[11] = cpl_sprintf(CR2RES_OBS_STARING_WAVE_SKY_RAW) ;
595 tags[12] = cpl_sprintf(CR2RES_OBS_POLARIMETRY_OTHER_RAW) ;
596 tags[13] = cpl_sprintf(CR2RES_OBS_2D_OBJECT_RAW) ;
597 tags[14] = cpl_sprintf(CR2RES_OBS_2D_SKY_RAW) ;
598
599 /* Get the frameset */
600 out = cr2res_extract_frameset_several_tags(in, (const char**)tags, ntags) ;
601
602 for (i=0 ; i<ntags ; i++) cpl_free(tags[i]) ;
603 cpl_free(tags) ;
604 return out ;
605}
606
607
608
609
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)
The images calibration routine for a given chip on a list.
Definition: cr2res_calib.c:71
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_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:808
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:644
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:1608
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.