UVES Pipeline Reference Manual  5.4.0
uves_cal_mkmaster_impl.c
1 /* *
2  * This file is part of the ESO UVES Pipeline *
3  * Copyright (C) 2004,2005 European Southern Observatory *
4  * *
5  * This library 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, 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA *
18  */
19 
20 /*
21  * $Author: amodigli $
22  * $Date: 2010-12-16 16:57:23 $
23  * $Revision: 1.11 $
24  * $Name: not supported by cvs2svn $
25  * $Log: not supported by cvs2svn $
26  * Revision 1.10 2010/09/24 09:32:02 amodigli
27  * put back QFITS dependency to fix problem spot by NRI on FIBER mode (with MIDAS calibs) data
28  *
29  * Revision 1.8 2010/06/11 11:39:14 amodigli
30  * added bias (stack) and qcdark parameters in input params
31  *
32  * Revision 1.7 2008/03/28 08:53:36 amodigli
33  * IRPLIB_CONCAT2X-->UVES_CONCAT2X
34  *
35  * Revision 1.6 2007/08/21 13:08:26 jmlarsen
36  * Removed irplib_access module, largely deprecated by CPL-4
37  *
38  * Revision 1.5 2007/06/11 13:28:26 jmlarsen
39  * Changed recipe contact address to cpl at eso.org
40  *
41  * Revision 1.4 2007/06/08 13:06:16 jmlarsen
42  * Send bug reports to Andrea
43  *
44  * Revision 1.3 2007/06/06 08:17:33 amodigli
45  * replace tab with 4 spaces
46  *
47  * Revision 1.2 2007/05/14 08:09:48 amodigli
48  * updated input frames and tag description in recipe man page
49  *
50  * Revision 1.1 2007/02/09 13:34:25 jmlarsen
51  * Added mkmaster+spatred recipes
52  *
53  * Revision 1.37 2006/12/08 07:41:43 jmlarsen
54  * Minor doc. change
55  *
56  * Revision 1.36 2006/11/15 15:02:14 jmlarsen
57  * Implemented const safe workarounds for CPL functions
58  *
59  * Revision 1.34 2006/11/15 14:04:08 jmlarsen
60  * Removed non-const version of parameterlist_get_first/last/next which is already
61  * in CPL, added const-safe wrapper, unwrapper and deallocator functions
62  *
63  * Revision 1.33 2006/11/15 08:57:32 amodigli
64  * clearer message on slit FF encoder positions
65  *
66  * Revision 1.32 2006/11/13 12:45:32 jmlarsen
67  * Count SFLAT sets from 1 rather than 0
68  *
69  * Revision 1.31 2006/11/06 15:19:41 jmlarsen
70  * Removed unused include directives
71  *
72  * Revision 1.30 2006/11/03 14:57:44 jmlarsen
73  * Changed message
74  *
75  * Revision 1.29 2006/10/17 12:33:02 jmlarsen
76  * Added semicolon at UVES_RECIPE_DEFINE invocation
77  *
78  * Revision 1.28 2006/10/09 13:01:13 jmlarsen
79  * Use macro to define recipe interface functions
80  *
81  * Revision 1.27 2006/09/27 13:20:51 jmlarsen
82  * Factored out flat reduction
83  *
84  * Revision 1.26 2006/09/19 14:31:20 jmlarsen
85  * uves_insert_frame(): use bitmap to specify which image statistics keywords must be computed
86  *
87  * Revision 1.25 2006/09/19 06:55:58 jmlarsen
88  * Changed interface of uves_frameset to optionally write image statistics kewwords
89  *
90  * Revision 1.24 2006/09/14 08:46:51 jmlarsen
91  * Added support for TFLAT, SCREEN_FLAT frames
92  *
93  * Revision 1.23 2006/08/24 11:36:37 jmlarsen
94  * Write recipe start/stop time to header
95  *
96  * Revision 1.22 2006/08/17 13:56:53 jmlarsen
97  * Reduced max line length
98  *
99  * Revision 1.21 2006/08/11 14:56:05 amodigli
100  * removed Doxygen warnings
101  *
102  * Revision 1.20 2006/07/14 12:19:28 jmlarsen
103  * Support multiple QC tests per product
104  *
105  * Revision 1.19 2006/07/03 13:09:24 amodigli
106  * adjusted description display layout
107  *
108  * Revision 1.18 2006/07/03 13:02:18 jmlarsen
109  * Threshold to zero after bias subtraction
110  *
111  * Revision 1.17 2006/06/16 08:25:45 jmlarsen
112  * Manually propagate ESO.DET. keywords from 1st/2nd input header
113  *
114  * Revision 1.16 2006/06/13 11:57:02 jmlarsen
115  * Check that calibration frames are from the same chip ID
116  *
117  * Revision 1.15 2006/06/01 14:21:27 amodigli
118  * frm --> frm_tmp, dup --> frm_dup
119  *
120  * Revision 1.14 2006/06/01 12:02:56 jmlarsen
121  * Return proper error_code in the function uves_mflat
122  *
123  * Revision 1.13 2006/05/22 10:01:04 amodigli
124  * fixed some bug in msflat generation
125  *
126  * Revision 1.12 2006/05/22 06:47:15 amodigli
127  * fixed some bugs on msflat
128  *
129  * Revision 1.10 2006/05/19 13:07:52 amodigli
130  * modified to support SFLATs
131  *
132  * Revision 1.9 2006/05/17 09:58:25 amodigli
133  * fixed warning
134  *
135  * Revision 1.8 2006/05/17 09:56:36 amodigli
136  * fixed syntax bug
137  *
138  * Revision 1.7 2006/05/17 09:54:55 amodigli
139  * added supposr SFLATs
140  *
141  * Revision 1.6 2006/05/09 07:42:18 amodigli
142  * added QC-LOG
143  *
144  * Revision 1.5 2006/04/06 12:57:43 jmlarsen
145  * Added support for IFLAT, DFLAT -> MASTER_IFLAT, MASTER_DFLAT frames
146  *
147  * Revision 1.4 2006/04/06 09:48:15 amodigli
148  * changed uves_frameset_insert interface to have QC log
149  *
150  * Revision 1.3 2006/04/06 08:37:48 jmlarsen
151  * Support reading MASTER_PDARK
152  *
153  * Revision 1.2 2006/03/24 14:15:18 jmlarsen
154  * Save intermediate result to disk
155  *
156  * Revision 1.1 2006/02/03 07:46:30 jmlarsen
157  * Moved recipe implementations to ./uves directory
158  *
159  * Revision 1.39 2006/01/19 08:47:24 jmlarsen
160  * Inserted missing doxygen end tag
161  *
162  * Revision 1.38 2005/12/19 16:17:55 jmlarsen
163  * Replaced bool -> int
164  *
165  */
166 
167 #ifdef HAVE_CONFIG_H
168 # include <config.h>
169 #endif
170 
171 /*----------------------------------------------------------------------------*/
178 /*----------------------------------------------------------------------------*/
179 
180 /*-----------------------------------------------------------------------------
181  Includes
182  -----------------------------------------------------------------------------*/
183 
184 #include <uves_reduce_mflat.h>
185 #include <uves_mbias_impl.h>
186 #include <uves_mdark_impl.h>
187 #include <uves_dfs.h>
188 #include <uves_parameters.h>
189 #include <uves_recipe.h>
190 #include <uves.h>
191 #include <uves_error.h>
192 
193 #include <cpl.h>
194 
195 /*-----------------------------------------------------------------------------
196  Functions prototypes
197  -----------------------------------------------------------------------------*/
198 
199 static int uves_cal_mkmaster_define_parameters(cpl_parameterlist *parameters);
200 
201 /*-----------------------------------------------------------------------------
202  Recipe standard code
203  -----------------------------------------------------------------------------*/
204 #define cpl_plugin_get_info uves_cal_mkmaster_get_info
205 UVES_RECIPE_DEFINE(
206  UVES_MKMASTER_ID, UVES_MKMASTER_DOM, uves_cal_mkmaster_define_parameters,
207  "Jonas M. Larsen", "cpl@eso.org",
208  "Creates the master bias/dark/flat frame",
209  "This recipe calls " make_str(UVES_MBIAS_ID) " if any raw BIAS frame is provided\n"
210  "otherwise " make_str(UVES_MDARK_ID) " if any raw DARK frame is provided, otherwise\n"
211  "it calls " make_str(UVES_MFLAT_ID) " Pls refer to those recipes for more details\n");
212 
214 /*-----------------------------------------------------------------------------
215  Functions code
216  -----------------------------------------------------------------------------*/
217 /*----------------------------------------------------------------------------*/
223 /*----------------------------------------------------------------------------*/
224 int
225 uves_cal_mkmaster_define_parameters(cpl_parameterlist *parameters)
226 {
227 
228  int result=0;
229  if (uves_master_stack_define_parameters(parameters,
230  make_str(UVES_MKMASTER_ID))
231  != CPL_ERROR_NONE)
232  {
233  return -1;
234  }
235 
236  check_nomsg(uves_qcdark_define_parameters_body(parameters,
237  make_str(UVES_MKMASTER_ID)));
238  result=uves_mflat_define_parameters_body(parameters,
239  make_str(UVES_MKMASTER_ID));
240  cleanup:
241  return result;
242  /* Warning: If parameters are added to mbias/mdark recipes, they need to
243  be propagated to here. Now, just copy the parameters from mflat */
244 }
245 
246 /*----------------------------------------------------------------------------*/
255 /*----------------------------------------------------------------------------*/
256 static void
257 UVES_CONCAT2X(UVES_MKMASTER_ID,exe)(cpl_frameset *frames,
258  const cpl_parameterlist *parameters,
259  const char *starttime)
260 {
261  int blue;
262  bool found_bias = false;
263  bool found_dark = false;
264  bool found_flat = false;
265 
266  assure( frames != NULL, CPL_ERROR_NULL_INPUT, "Null frameset given!");
267 
268  for (blue = 0; blue <= 1; blue++)
269  {
270  found_bias = found_bias || cpl_frameset_find(frames, UVES_BIAS(blue));
271  found_dark = found_dark || cpl_frameset_find(frames, UVES_DARK(blue));
272  found_dark = found_dark || cpl_frameset_find(frames, UVES_PDARK(blue));
273  found_flat = found_flat || cpl_frameset_find(frames, UVES_FLAT(blue));
274  found_flat = found_flat || cpl_frameset_find(frames, UVES_IFLAT(blue));
275  found_flat = found_flat || cpl_frameset_find(frames, UVES_DFLAT(blue));
276  found_flat = found_flat || cpl_frameset_find(frames, UVES_SFLAT(blue));
277  found_flat = found_flat || cpl_frameset_find(frames, UVES_TFLAT(blue));
278  found_flat = found_flat || cpl_frameset_find(frames, UVES_SCREEN_FLAT(blue));
279  }
280 
281  if (found_bias)
282  {
283  uves_msg("Bias frame(s) provided");
284  }
285 
286  if (found_dark)
287  {
288  uves_msg("Dark frame(s) provided");
289  }
290 
291  if (found_flat)
292  {
293  uves_msg("Flat frame(s) provided");
294  }
295 
296  assure( found_bias || found_dark || found_flat,
297  CPL_ERROR_DATA_NOT_FOUND,
298  "Missing raw bias, dark or flat-field frames");
299 
300  if (found_bias && found_dark)
301  {
302  uves_msg_warning("Both bias and dark frames provided. Creating only master bias");
303  }
304  else if (found_bias && found_flat)
305  {
306  uves_msg_warning("Both bias and flat frames provided. Creating only master bias");
307  }
308  else if (found_dark && found_flat)
309  {
310  uves_msg_warning("Both dark and flat frames provided. Creating only master dark");
311  }
312 
313  if (found_bias)
314  {
315  uves_mbias_exe_body(frames, parameters, starttime, make_str(UVES_MKMASTER_ID));
316  }
317  else if (found_dark)
318  {
319  uves_mdark_exe_body(frames, parameters, starttime, make_str(UVES_MKMASTER_ID));
320  }
321  else if (found_flat)
322  {
323  uves_mflat_exe_body(frames, parameters, starttime, make_str(UVES_MKMASTER_ID));
324  }
325  else
326  {
327  /* Impossible */
328  passure( false, "%d %d %d", found_bias, found_dark, found_flat);
329  }
330 
331  cleanup:
332  return;
333 }
334