IIINSTRUMENT Pipeline Reference Manual  4.4.11
naco_img_twflat.c
1 /* $Id: naco_img_twflat.c,v 1.64 2009-01-29 08:54:58 llundin Exp $
2  *
3  * This file is part of the NACO Pipeline
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: llundin $
23  * $Date: 2009-01-29 08:54:58 $
24  * $Revision: 1.64 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 /*-----------------------------------------------------------------------------
33  Includes
34  -----------------------------------------------------------------------------*/
35 
36 #include <string.h>
37 
38 #include "naco_recipe.h"
39 #include "irplib_flat.h"
40 
41 /*-----------------------------------------------------------------------------
42  Defines
43  -----------------------------------------------------------------------------*/
44 
45 #define RECIPE_STRING "naco_img_twflat"
46 
47 /*-----------------------------------------------------------------------------
48  Private Functions prototypes
49  -----------------------------------------------------------------------------*/
50 
51 static cpl_imagelist * naco_img_twflat_reduce(const irplib_framelist *,
52  const irplib_framelist *);
53 
54 static cpl_error_code naco_img_twflat_threshold(cpl_image *);
55 
56 static cpl_error_code naco_img_twflat_qc(cpl_propertylist *,
57  const irplib_framelist *);
58 
59 static cpl_error_code naco_img_twflat_save(cpl_frameset *,
60  const cpl_parameterlist *,
61  const cpl_propertylist *,
62  const cpl_imagelist *,
63  const cpl_image *, int,
64  const irplib_framelist *);
65 
66 static char * naco_img_twflat_make_tag(const cpl_frame*,
67  const cpl_propertylist *, int);
68 
69 static char * naco_img_twflat_make_dark_tag(const cpl_frame*,
70  const cpl_propertylist *, int);
71 
72 NACO_RECIPE_DEFINE(naco_img_twflat,
73  NACO_PARAM_REJBORD |
74  NACO_PARAM_BPMTHRES |
75  NACO_PARAM_PROPFIT |
76  NACO_PARAM_BPM |
77  NACO_PARAM_ERRORMAP |
78  NACO_PARAM_INTCEPT,
79  "Twilight flat recipe",
80  RECIPE_STRING " -- NACO imaging flat-field creation from "
81  "twilight images.\n"
82  "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
83  "raw-file.fits " NACO_IMG_TWFLAT_RAW " or\n"
84  "raw-or-calib-file.fits " NACO_IMG_DARK_RAW "\n"
85  "The flat frames are divided into groups, each group having identical "
86  "instrument settings. Each group of flats is reduced independently of "
87  "each other. For each group of flats, the set of frames shall contain "
88  "either zero, one or n dark frames with the same instrument settings, "
89  "where n is the number of flats in the group.");
90 
91 /*-----------------------------------------------------------------------------
92  Static variables
93  -----------------------------------------------------------------------------*/
94 
95 static struct {
96  int rej_left;
97  int rej_right;
98  int rej_bottom;
99  int rej_top;
100  double low_thresh;
101  double high_thresh;
102  int prop_flag;
103  int bpm_flag;
104  int errmap_flag;
105  int intercept_flag;
106 } naco_img_twflat_config;
107 
108 /*----------------------------------------------------------------------------*/
112 /*----------------------------------------------------------------------------*/
113 
114 /*-----------------------------------------------------------------------------
115  Functions code
116  -----------------------------------------------------------------------------*/
117 
118 /*----------------------------------------------------------------------------*/
125 /*----------------------------------------------------------------------------*/
126 static int naco_img_twflat(cpl_frameset * framelist,
127  const cpl_parameterlist * parlist)
128 {
129  cpl_errorstate cleanstate = cpl_errorstate_get();
130  irplib_framelist * allframes = NULL;
131  irplib_framelist * flatframes = NULL;
132  irplib_framelist * darkframes = NULL;
133  irplib_framelist * f_one = NULL;
134  irplib_framelist * d_one = NULL;
135  cpl_imagelist * twflat = NULL;
136  cpl_image * bpm_im = NULL;
137  cpl_mask * bpm = NULL;
138  cpl_propertylist * qclist = cpl_propertylist_new();
139  const char ** taglist = NULL;
140  const char * sval;
141  int nb_good = 0;
142  int nsets;
143  int i;
144 
145  /* Retrieve input parameters */
146  /* --r */
147  sval = naco_parameterlist_get_string(parlist, RECIPE_STRING,
148  NACO_PARAM_REJBORD);
149  skip_if (0);
150  skip_if_ne(sscanf(sval, "%d %d %d %d",
151  &naco_img_twflat_config.rej_left,
152  &naco_img_twflat_config.rej_right,
153  &naco_img_twflat_config.rej_bottom,
154  &naco_img_twflat_config.rej_top), 4,
155  "number(s) in string parameter (%s): \"%s\"",
156  CPL_XSTRINGIFY(NACO_PARAM_REJBORD), sval);
157 
158  /* --t */
159  sval = naco_parameterlist_get_string(parlist, RECIPE_STRING,
160  NACO_PARAM_BPMTHRES);
161  skip_if (0);
162  skip_if_ne(sscanf(sval, "%lg %lg",
163  &naco_img_twflat_config.low_thresh,
164  &naco_img_twflat_config.high_thresh), 2,
165  "number(s) in string parameter (%s): \"%s\"",
166  CPL_XSTRINGIFY(NACO_PARAM_BPMTHRES), sval);
167 
168  /* --prop */
169  naco_img_twflat_config.prop_flag
170  = naco_parameterlist_get_bool(parlist, RECIPE_STRING, NACO_PARAM_PROPFIT);
171  skip_if (0);
172  /* --bpm */
173  naco_img_twflat_config.bpm_flag
174  = naco_parameterlist_get_bool(parlist, RECIPE_STRING, NACO_PARAM_BPM);
175  skip_if (0);
176  /* --errmap */
177  naco_img_twflat_config.errmap_flag
178  = naco_parameterlist_get_bool(parlist, RECIPE_STRING, NACO_PARAM_ERRORMAP);
179  skip_if (0);
180  /* --intercept */
181  naco_img_twflat_config.intercept_flag
182  = naco_parameterlist_get_bool(parlist, RECIPE_STRING, NACO_PARAM_INTCEPT);
183 
184  /* Identify the RAW and CALIB frames in the input frameset */
185  skip_if (naco_dfs_set_groups(framelist));
186 
187  allframes = irplib_framelist_cast(framelist);
188  skip_if(allframes == NULL);
189 
190  flatframes = irplib_framelist_extract(allframes, NACO_IMG_TWFLAT_RAW);
191  skip_if(flatframes == NULL);
192 
193  skip_if(irplib_framelist_load_propertylist_all(flatframes, 0, "^("
194  IRPLIB_PFITS_REGEXP_RECAL "|"
195  NACO_PFITS_REGEXP_TWFLAT
196  ")$", CPL_FALSE));
197 
198  darkframes = irplib_framelist_extract(allframes, NACO_IMG_DARK_RAW);
199  irplib_framelist_empty(allframes);
200 
201  if (darkframes == NULL) {
202  naco_error_reset("The set of frames has no darks:");
203  } else {
204  /* dark frame(s) are provided */
205  skip_if(0);
206 
207  skip_if(irplib_framelist_load_propertylist_all(darkframes, 0, "^("
208  NACO_PFITS_REGEXP_TWFLAT_DARK
209  ")$", CPL_FALSE));
210 
211  cpl_free(naco_framelist_set_tag(darkframes,
212  naco_img_twflat_make_dark_tag,
213  &nsets));
214  skip_if(0);
215  }
216 
217  taglist = naco_framelist_set_tag(flatframes, naco_img_twflat_make_tag,
218  &nsets);
219  skip_if(taglist == NULL);
220 
221  cpl_msg_info(cpl_func, "Identified %d setting(s) in %d flat frame(s)",
222  nsets, irplib_framelist_get_size(flatframes));
223 
224  /* Extract settings and reduce each of them */
225  for (i=0 ; i < nsets ; i++) {
226  int nflats;
227 
228  /* Reduce data set nb i */
229  f_one = irplib_framelist_extract(flatframes, taglist[i]);
230 
231  nflats = irplib_framelist_get_size(f_one);
232 
233  /* Reset the tag */
234  skip_if(irplib_framelist_set_tag_all(f_one, NACO_IMG_TWFLAT_RAW));
235 
236  cpl_msg_info(cpl_func, "Reducing flat frame set %d of %d (size=%d) "
237  "with setting: %s", i+1, nsets, nflats, taglist[i]);
238 
239  if (darkframes != NULL) {
240  const char * post_filter = strchr(taglist[i], ':');
241 
242  bug_if(post_filter == NULL);
243 
244  /* Extract those darks with a matching ROM */
245  d_one = irplib_framelist_extract(darkframes, 1+post_filter);
246  if (d_one == NULL) {
247  naco_error_reset("None of the darks match this setting:");
248  } else {
249  /* Reset the tag */
250  bug_if (irplib_framelist_set_tag_all(d_one,
251  NACO_IMG_DARK_RAW));
252  }
253  }
254 
255  twflat = naco_img_twflat_reduce(f_one, d_one);
256 
257  if (twflat == NULL) {
258  if (nsets > 1)
259  irplib_error_recover(cleanstate, "Could not reduce set %d:", i+1);
260  } else {
261  if (naco_img_twflat_config.bpm_flag) {
262  /* Create the Bad pixel map */
263  if ((bpm = cpl_mask_threshold_image_create(
264  cpl_imagelist_get(twflat, 0),
265  naco_img_twflat_config.low_thresh,
266  naco_img_twflat_config.high_thresh)) == NULL) {
267  cpl_msg_warning(cpl_func, "Could not create the bad pixel "
268  "map: '%s' at %s", cpl_error_get_message(),
269  cpl_error_get_where());
270  cpl_error_reset();
271  } else {
272  skip_if(cpl_mask_not(bpm));
273  bpm_im = cpl_image_new_from_mask(bpm);
274  cpl_mask_delete(bpm);
275  bpm = NULL;
276  }
277  }
278  /* Save the products */
279  cpl_msg_info(cpl_func, "Saving the products");
280  if (d_one != NULL) {
281  /* Create a single list of frames used to create the products
282  of this setting - also delete the dark propertylists */
283  cpl_frame * frame = NULL;
284  const cpl_boolean is_calib = irplib_framelist_get_size(d_one)
285  == 1 ? CPL_TRUE : CPL_FALSE;
286 
287  while (irplib_framelist_get_size(d_one) > 0) {
288  frame = irplib_framelist_unset(d_one, 0, NULL);
289 
290  /* FIXME: Need a separate tag for this type of dark */
291  if (is_calib)
292  bug_if(cpl_frame_set_group(frame,
293  CPL_FRAME_GROUP_CALIB));
294 
295  bug_if(irplib_framelist_set(f_one, frame, nflats++));
296 
297  frame = NULL;
298  }
299  cpl_frame_delete(frame);
300  bug_if(irplib_framelist_get_size(d_one) != 0);
301  }
302 
303  skip_if(naco_img_twflat_qc(qclist, f_one));
304 
305  skip_if(naco_img_twflat_save(framelist, parlist, qclist,
306  twflat, bpm_im, i+1, f_one));
307  nb_good++;
308  cpl_propertylist_empty(qclist);
309  cpl_image_delete(bpm_im);
310  cpl_imagelist_delete(twflat);
311  bpm_im = NULL;
312  twflat = NULL;
313  }
314 
315  irplib_framelist_delete(f_one);
316  irplib_framelist_delete(d_one);
317  f_one = NULL;
318  d_one = NULL;
319  }
320 
321  irplib_ensure(nb_good > 0, CPL_ERROR_DATA_NOT_FOUND,
322  "None of the %d sets could be reduced", nsets);
323 
324  end_skip;
325 
326  irplib_framelist_delete(allframes);
327  irplib_framelist_delete(flatframes);
328  irplib_framelist_delete(darkframes);
329  irplib_framelist_delete(f_one);
330  irplib_framelist_delete(d_one);
331  cpl_mask_delete(bpm);
332  cpl_image_delete(bpm_im);
333  cpl_imagelist_delete(twflat);
334  cpl_free(taglist);
335  cpl_propertylist_delete(qclist);
336 
337  return cpl_error_get_code();
338 }
339 
340 /*----------------------------------------------------------------------------*/
352 /*----------------------------------------------------------------------------*/
353 static cpl_imagelist * naco_img_twflat_reduce(const irplib_framelist * f_one,
354  const irplib_framelist * d_one)
355 {
356  const cpl_propertylist * plist
357  = irplib_framelist_get_propertylist_const(f_one, 0);
358  const char * filter = naco_pfits_get_filter(plist);
359  const char * tpl_id = naco_pfits_get_templateid(plist);
360  const char * rom_name = naco_pfits_get_rom_name(plist);
361  cpl_imagelist * i_one = NULL;
362  cpl_image * dark = NULL;
363  cpl_imagelist * results = NULL;
364  cpl_stats * stats_img = NULL;
365  cpl_image * flat;
366  double min_count = DBL_MAX; /* Avoid uninit warning */
367  double max_count = DBL_MAX; /* Avoid uninit warning */
368  double norm;
369  const double dit = naco_pfits_get_dit(plist);
370  const int nflats = irplib_framelist_get_size(f_one);
371  const int ndarks = d_one == NULL ? 0
372  : irplib_framelist_get_size(d_one);
373  int i;
374  cpl_boolean ok_nonpositive;
375 
376 
377  bug_if (0);
378 
379  cpl_msg_info(cpl_func, "Filter: [%s]", filter);
380  cpl_msg_info(cpl_func, "Read-out mode: [%s]", rom_name);
381  cpl_msg_info(cpl_func, "DIT: [%g]", dit);
382 
383  cpl_msg_info(cpl_func, "Reducing %d flats with subtraction of %d dark(s)",
384  nflats, ndarks);
385 
386  irplib_ensure(ndarks == 0 || ndarks == 1 || ndarks == nflats,
387  CPL_ERROR_INCOMPATIBLE_INPUT,
388  "Cannot reduce %d flats with %d darks", nflats, ndarks);
389 
390  ok_nonpositive = strncmp(tpl_id, "NACO_img_cal_SkyFlats",
391  IRPLIB_FITS_STRLEN) == 0 &&
392  strncmp(rom_name, "Uncorr", IRPLIB_FITS_STRLEN) == 0
393  ? CPL_TRUE : CPL_FALSE;
394 
395  /* Load input image set */
396  cpl_msg_info(cpl_func, "---> Loading input set");
397  irplib_check(i_one = irplib_imagelist_load_framelist(f_one, CPL_TYPE_FLOAT,
398  0, 0),
399  "Could not load the images of the flat frames");
400 
401  /* Compute some stats on input images */
402  cpl_msg_info(cpl_func, "---> Computing stats");
403  cpl_msg_info(cpl_func, "image min max med rms");
404  cpl_msg_info(cpl_func, "---------------------------------------------");
405  for (i = 0 ; i < nflats ; i++) {
406  double curr_count;
407 
408  flat = cpl_imagelist_get(i_one, i);
409 
410  bug_if( flat == NULL);
411 
412  stats_img = cpl_stats_new_from_image(flat, CPL_STATS_MIN
413  | CPL_STATS_MAX
414  | CPL_STATS_STDEV
415  | CPL_STATS_MEDIAN);
416 
417  bug_if (stats_img == NULL);
418 
419  curr_count = cpl_stats_get_median(stats_img);
420 
421  cpl_msg_info(cpl_func, "%02d %10.2f %10.2f %10.2f %10.2f", i+1,
422  cpl_stats_get_min(stats_img), cpl_stats_get_max(stats_img),
423  curr_count, cpl_stats_get_stdev(stats_img));
424 
425  cpl_stats_delete(stats_img);
426  stats_img = NULL;
427 
428  if (i==0 || curr_count < min_count) min_count = curr_count;
429  if (i==0 || curr_count > max_count) max_count = curr_count;
430 
431  /* Test only if not Uncorr or not skyflats */
432 
433  irplib_ensure (ok_nonpositive || curr_count > 0.0,
434  CPL_ERROR_ILLEGAL_INPUT,
435  "Flat %d has negative flux=%g using template=%s", i+1,
436  curr_count, tpl_id);
437 
438  if (ndarks == 0) continue;
439 
440  /* Apply dark correction to all planes */
441 
442  if (i == 0 || ndarks > 1) {
443  const cpl_frame * frame = irplib_framelist_get_const(d_one, i);
444  const char * name = cpl_frame_get_filename(frame);
445 
446  cpl_image_delete(dark);
447  irplib_check(dark = cpl_image_load(name, CPL_TYPE_FLOAT, 0, 0),
448  "Could not load FITS-image from %s", name);
449  }
450 
451  skip_if (cpl_image_subtract(flat, dark));
452 
453  }
454 
455  cpl_msg_info(cpl_func, "---------------------------------------------");
456 
457  if (ndarks > 0) {
458 
459  cpl_image_delete(dark);
460  dark = NULL;
461 
462  /* With the darks provided, the proportional method is used */
463  cpl_msg_info(cpl_func, "Switching to proportional fit");
464  naco_img_twflat_config.prop_flag = 1;
465 
466  } else if (!naco_img_twflat_config.prop_flag) {
467  /* See if flux gradient is large enough for a correct fit */
468  const double min_grad = 4.0;
469  /* FIXME: why fabs() ? */
470  if (fabs(max_count) < min_grad * fabs(min_count)) {
471  const double grad = fabs(max_count/min_count);
472 
473  cpl_msg_warning(cpl_func, "Low flux gradient: %g < %g", grad,
474  min_grad);
475  cpl_msg_warning(cpl_func,"A proportional fit may give better "
476  "results (Requires either a single master dark "
477  "frame or one dark per flat frame)");
478  }
479  }
480 
481  /* Fit slopes, get results */
482  if (naco_img_twflat_config.prop_flag) {
483  cpl_msg_info(cpl_func, "---> Fitting slopes proportionally");
484  results = irplib_flat_fit_set(i_one, 0);
485  irplib_ensure(results != NULL, CPL_ERROR_ILLEGAL_INPUT,
486  "Could not create twilight flat-field with "
487  "proportional fit");
488  } else {
489  cpl_msg_info(cpl_func, "---> Fitting slopes non-proportionally");
490  results = irplib_flat_fit_set(i_one, 1);
491  irplib_ensure(results != NULL, CPL_ERROR_ILLEGAL_INPUT,
492  "Could not create twilight flat-field with "
493  "non-proportional fit");
494  }
495  cpl_imagelist_delete(i_one);
496  i_one = NULL;
497 
498  /* Normalize gain */
499  flat = cpl_imagelist_get(results, 0);
500  bug_if( flat == NULL);
501 
502  bug_if(naco_img_twflat_threshold(flat));
503 
504  irplib_check(norm =
505  cpl_image_get_mean_window(flat,
506  naco_img_twflat_config.rej_left+1,
507  naco_img_twflat_config.rej_bottom+1,
508  cpl_image_get_size_x(flat)
509  -naco_img_twflat_config.rej_right,
510  cpl_image_get_size_y(flat)
511  -naco_img_twflat_config.rej_top);
512  cpl_image_divide_scalar(flat, norm),
513  "Could not normalize gain with norm=%g", norm);
514 
515  end_skip;
516 
517  cpl_imagelist_delete(i_one);
518  cpl_stats_delete(stats_img);
519  cpl_image_delete(dark);
520 
521  if (cpl_error_get_code()) {
522  cpl_imagelist_delete(results);
523  results = NULL;
524  }
525 
526  return results;
527 }
528 
529 
530 /*----------------------------------------------------------------------------*/
536 /*----------------------------------------------------------------------------*/
537 static cpl_error_code naco_img_twflat_threshold(cpl_image * self)
538 {
539 
540  cpl_stats * fstats = cpl_stats_new_from_image(self, CPL_STATS_MIN
541  | CPL_STATS_MINPOS);
542 
543  if (cpl_stats_get_min(fstats) <= 0.0) {
544  cpl_mask * bpm = cpl_image_get_bpm(self); /* Just an accessor */
545  cpl_size nbad;
546 
547  /* Reject any non-positive pixel */
548  bug_if(cpl_mask_threshold_image(bpm, self, 0.0, DBL_MAX, CPL_BINARY_0));
549  nbad = cpl_image_count_rejected(self);
550  /* Set the gain for any bad pixel to 1 */
551  bug_if(cpl_image_fill_rejected(self, 1.0));
552 
553  cpl_msg_warning(cpl_func, "Set %d pixel(s) with non-positive gain "
554  "(down to %g at (%d,%d)) to 1", (int)nbad,
555  cpl_stats_get_min(fstats),
556  (int)cpl_stats_get_min_x(fstats),
557  (int)cpl_stats_get_min_y(fstats));
558  }
559 
560  end_skip;
561 
562  cpl_stats_delete(fstats);
563 
564  return cpl_error_get_code();
565 }
566 
567 
568 /*----------------------------------------------------------------------------*/
575 /*----------------------------------------------------------------------------*/
576 static cpl_error_code naco_img_twflat_qc(cpl_propertylist * qclist,
577  const irplib_framelist * rawframes)
578 {
579 
580  const cpl_propertylist * reflist
581  = irplib_framelist_get_propertylist_const(rawframes, 0);
582 
583 
584  bug_if (0);
585 
586  bug_if (cpl_propertylist_copy_property_regexp(qclist, reflist, "^("
587  IRPLIB_PFITS_REGEXP_RECAL
588  ")$", 0));
589 
590  bug_if (irplib_pfits_set_airmass(qclist, rawframes));
591 
592  end_skip;
593 
594  return cpl_error_get_code();
595 }
596 
597 /*----------------------------------------------------------------------------*/
609 /*----------------------------------------------------------------------------*/
610 static cpl_error_code naco_img_twflat_save(cpl_frameset * set_tot,
611  const cpl_parameterlist * parlist,
612  const cpl_propertylist * qclist,
613  const cpl_imagelist * flat,
614  const cpl_image * bpm,
615  int set_nb,
616  const irplib_framelist * f_one)
617 {
618 
619  cpl_frameset * rawframes = irplib_frameset_cast(f_one);
620  char * filename = NULL;
621  const int nflats = cpl_imagelist_get_size(flat);
622 
623 
624  /* This will catch f_one == NULL or plist == NULL */
625  bug_if (nflats != 2 && nflats != 3);
626 
627  /* Write the flat image */
628  filename = cpl_sprintf(RECIPE_STRING "_set%02d" CPL_DFS_FITS, set_nb);
629  skip_if (irplib_dfs_save_image(set_tot, parlist, rawframes,
630  cpl_imagelist_get_const(flat, 0),
631  CPL_BPP_IEEE_FLOAT, RECIPE_STRING,
632  NACO_IMG_TWFLAT_RES, qclist, NULL, naco_pipe_id,
633  filename));
634 
635  if (bpm != NULL) {
636  /* Write the bpm image */
637  cpl_free(filename);
638  filename = cpl_sprintf(RECIPE_STRING "_set%02d_bpm" CPL_DFS_FITS,
639  set_nb);
640  skip_if (irplib_dfs_save_image(set_tot, parlist, rawframes, bpm,
641  CPL_BPP_8_UNSIGNED, RECIPE_STRING,
642  NACO_IMG_TWFLAT_BPM, qclist, NULL,
643  naco_pipe_id, filename));
644  }
645 
646  if (naco_img_twflat_config.intercept_flag && nflats == 3) {
647  /* Write the intercept image */
648  cpl_free(filename);
649  filename = cpl_sprintf(RECIPE_STRING "_set%02d_inter"
650  CPL_DFS_FITS, set_nb);
651  skip_if (irplib_dfs_save_image(set_tot, parlist, rawframes,
652  cpl_imagelist_get_const(flat, 1),
653  CPL_BPP_IEEE_FLOAT, RECIPE_STRING,
654  NACO_IMG_TWFLAT_INTER, qclist, NULL,
655  naco_pipe_id, filename));
656  }
657 
658  if (naco_img_twflat_config.errmap_flag) {
659  /* Write the error map image */
660  cpl_free(filename);
661  filename = cpl_sprintf(RECIPE_STRING "_set%02d_errmap"
662  CPL_DFS_FITS, set_nb);
663  skip_if (irplib_dfs_save_image(set_tot, parlist, rawframes,
664  cpl_imagelist_get_const(flat, nflats - 1),
665  CPL_BPP_IEEE_FLOAT, RECIPE_STRING,
666  NACO_IMG_TWFLAT_ERRMAP, qclist, NULL,
667  naco_pipe_id, filename));
668  }
669 
670  end_skip;
671 
672  cpl_free(filename);
673  cpl_frameset_delete(rawframes);
674 
675  return cpl_error_get_code();
676 }
677 
678 /*----------------------------------------------------------------------------*/
691 /*----------------------------------------------------------------------------*/
692 static char * naco_img_twflat_make_tag(const cpl_frame* self,
693  const cpl_propertylist* plist, int dummy)
694 {
695 
696  char * tag = NULL;
697  const char * filter;
698  const char * mode;
699  const char * name;
700  double dit;
701 
702 
703  bug_if (cpl_error_get_code());
704 
705  bug_if(self == NULL);
706  bug_if(plist == NULL);
707  bug_if(dummy < 0); /* Avoid warning of unused variable */
708 
709 
710  /* filter */
711  filter = naco_pfits_get_filter(plist);
712  skip_if(cpl_error_get_code());
713 
714  /* ROM */
715  name = naco_pfits_get_rom_name(plist);
716  skip_if(cpl_error_get_code());
717 
718  /* mode */
719  mode = naco_pfits_get_mode(plist);
720  skip_if(cpl_error_get_code());
721 
722  /* the DIT */
723  dit = naco_pfits_get_dit(plist);
724  skip_if(cpl_error_get_code());
725 
726  tag = cpl_sprintf("%s:%s:%s:%.5f", filter,
727  name, mode, dit);
728  bug_if(tag == NULL);
729 
730  end_skip;
731 
732  if (cpl_error_get_code()) {
733  cpl_free(tag);
734  tag = NULL;
735  }
736 
737  return tag;
738 
739 }
740 
741 
742 /*----------------------------------------------------------------------------*/
754 /*----------------------------------------------------------------------------*/
755 static char * naco_img_twflat_make_dark_tag(const cpl_frame * self,
756  const cpl_propertylist * plist,
757  int dummy)
758 {
759  char * tag = NULL;
760  const char * mode;
761  const char * name;
762  double dit;
763 
764 
765  bug_if (cpl_error_get_code());
766 
767  bug_if(self == NULL);
768  bug_if(plist == NULL);
769  bug_if(dummy < 0); /* Avoid warning of unused variable */
770 
771 
772  /* ROM */
773  name = naco_pfits_get_rom_name(plist);
774  skip_if(cpl_error_get_code());
775 
776  /* mode */
777  mode = naco_pfits_get_mode(plist);
778  skip_if(cpl_error_get_code());
779 
780  /* the DIT */
781  dit = naco_pfits_get_dit(plist);
782  skip_if(cpl_error_get_code());
783 
784  tag = cpl_sprintf("%s:%s:%.5f", name, mode, dit);
785  bug_if(tag == NULL);
786 
787  end_skip;
788 
789  if (cpl_error_get_code()) {
790  cpl_free(tag);
791  tag = NULL;
792  }
793 
794  return tag;
795 
796 }
cpl_error_code irplib_pfits_set_airmass(cpl_propertylist *self, const irplib_framelist *rawframes)
Update/Set the AIRMASS property.
Definition: irplib_pfits.c:373
int naco_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
Definition: naco_dfs.c:62
const char * naco_parameterlist_get_string(const cpl_parameterlist *self, const char *recipe, naco_parameter bitmask)
Retrieve the value of a NACO string parameter.
cpl_boolean naco_parameterlist_get_bool(const cpl_parameterlist *self, const char *recipe, naco_parameter bitmask)
Retrieve the value of a NACO boolean parameter.
double naco_pfits_get_dit(const cpl_propertylist *self)
find out the DIT
Definition: naco_pfits.c:131
const char * naco_pfits_get_mode(const cpl_propertylist *self)
find out the mode name
Definition: naco_pfits.c:268
const char * naco_pfits_get_rom_name(const cpl_propertylist *self)
find out the read out mode name
Definition: naco_pfits.c:389
const char * naco_pfits_get_templateid(const cpl_propertylist *self)
find out the template ID
Definition: naco_pfits.c:413
const char * naco_pfits_get_filter(const cpl_propertylist *self)
find out the filter
Definition: naco_pfits.c:167
const char ** naco_framelist_set_tag(irplib_framelist *self, char *(*pftag)(const cpl_frame *, const cpl_propertylist *, int), int *pntags)
Retag a framelist according to the given tagging function.
Definition: naco_utils.c:176