SINFONI Pipeline Reference Manual  2.5.2
sinfo_rec_mflat.c
1 /* $Id: sinfo_rec_mflat.c,v 1.22 2008-02-05 08:13:05 amodigli Exp $
2  *
3  * This file is part of the SINFONI 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 /*
21  * $Author: amodigli $
22  * $Date: 2008-02-05 08:13:05 $
23  * $Revision: 1.22 $
24  * $Name: not supported by cvs2svn $
25  */
26 
27 /****************************************************************
28  * Rec_Lampflats Frames Data Reduction *
29  ****************************************************************/
30 
31 #ifdef HAVE_CONFIG_H
32 #include <config.h> /* allows the program compilation */
33 #endif
34 
35 /*-----------------------------------------------------------------------------
36  Includes
37  ----------------------------------------------------------------------------*/
38 
39 /* std */
40 #include <strings.h>
41 #include <string.h>
42 #include <stdio.h>
43 
44 /* cpl */
45 #include <cpl.h>
46 #include <irplib_utils.h>
47 /* sinfoni */
48 #include <sinfo_pro_types.h>
49 #include <sinfo_utilities.h>
50 #include <sinfo_general_config.h>
51 #include <sinfo_product_config.h>
52 #include <sinfo_bp_config.h>
53 #include <sinfo_bp_norm_config.h>
54 #include <sinfo_lamp_flats_config.h>
55 #include <sinfo_bp_norm.h>
56 #include <sinfo_new_lamp_flats.h>
57 #include <sinfo_functions.h>
58 #include <sinfo_new_add_bp_map.h>
59 #include <sinfo_tpl_utils.h>
60 #include <sinfo_tpl_dfs.h>
61 #include <sinfo_msg.h>
62 #include <sinfo_error.h>
63 #include <sinfo_utils_wrappers.h>
64 
65 /*-----------------------------------------------------------------------------
66  Functions prototypes
67  ----------------------------------------------------------------------------*/
68 static int sinfo_rec_mflat_create(cpl_plugin *);
69 static int sinfo_rec_mflat_exec(cpl_plugin *);
70 static int sinfo_rec_mflat_destroy(cpl_plugin *);
71 static int sinfo_rec_mflat(cpl_parameterlist *, cpl_frameset *);
72 
73 
74 /*-----------------------------------------------------------------------------
75  Static variables
76  ----------------------------------------------------------------------------*/
77 
78 static char
79 sinfo_rec_mflat_description[] =
80  "This recipe reduce normal raw flat fields.\n"
81  "The input files are a set of flat fields with tag FLAT_LAMP\n"
82  "optionally one may have in input also several bad pixel maps to be coadded.\n"
83  "The main products are a master flat field (PRO.CATG=MASTER_FLAT_LAMP) image\n"
84  "a bad pixel map (PRO.CATG=BP_MAP_NO), "
85  "a master bad pixel map (PRO.CATG=MASTER_BP_MAP) resulting by the coaddition\n"
86  "of all bad pixel maps.\n"
87  "\n";
88 
89 
90 
91 /*-----------------------------------------------------------------------------
92  Functions code
93  ----------------------------------------------------------------------------*/
94 /*---------------------------------------------------------------------------*/
98 /*---------------------------------------------------------------------------*/
100 /*---------------------------------------------------------------------------*/
109 /*---------------------------------------------------------------------------*/
110 
111 int cpl_plugin_get_info(cpl_pluginlist *list)
112 {
113 
114  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
115  cpl_plugin *plugin = &recipe->interface;
116 
117 
118  cpl_plugin_init(plugin,
119  CPL_PLUGIN_API,
120  SINFONI_BINARY_VERSION,
121  CPL_PLUGIN_TYPE_RECIPE,
122  "sinfo_rec_mflat",
123  "Master flat determination",
124  sinfo_rec_mflat_description,
125  "Andrea Modigliani",
126  "Andrea.Modigliani@eso.org",
127  sinfo_get_license(),
128  sinfo_rec_mflat_create,
129  sinfo_rec_mflat_exec,
130  sinfo_rec_mflat_destroy);
131 
132  cpl_pluginlist_append(list, plugin);
133 
134  return 0;
135 
136 }
137 
138 
139 /*---------------------------------------------------------------------------*/
147 /*---------------------------------------------------------------------------*/
148 
149 static int sinfo_rec_mflat_create(cpl_plugin *plugin)
150 {
151 
152  cpl_recipe * recipe ;
153 
154  /* Check that the plugin is part of a valid recipe */
155  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
156  recipe = (cpl_recipe *)plugin ;
157  else return -1 ;
158 
159  /* Create the parameters list in the cpl_recipe object */
160  recipe->parameters = cpl_parameterlist_new() ;
161 
162  /*
163  * Fill the parameter list.
164  */
165  sinfo_general_config_add(recipe->parameters);
166  sinfo_product_config_add(recipe->parameters);
167  sinfo_bp_norm_config_add(recipe->parameters);
168  sinfo_lamp_flats_config_add(recipe->parameters);
169 
170  return 0;
171 
172 }
173 /*---------------------------------------------------------------------------*/
179 /*---------------------------------------------------------------------------*/
180 static int sinfo_rec_mflat_exec(cpl_plugin *plugin)
181 {
182  cpl_recipe * recipe ;
183  cpl_errorstate initial_errorstate = cpl_errorstate_get();
184  /* Get the recipe out of the plugin */
185  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
186  recipe = (cpl_recipe *)plugin ;
187  else return -1 ;
188  cpl_error_reset();
189  irplib_reset();
190 
191  if (!cpl_errorstate_is_equal(initial_errorstate)) {
192  /* Dump the error history since recipe execution start.
193  At this point the recipe cannot recover from the error */
194  cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
195  }
196  return sinfo_rec_mflat(recipe->parameters, recipe->frames);
197 
198 }
199 /*---------------------------------------------------------------------------*/
205 /*---------------------------------------------------------------------------*/
206 static int sinfo_rec_mflat_destroy(cpl_plugin *plugin)
207 {
208 
209  cpl_recipe *recipe = (cpl_recipe *) plugin;
210 
211  /* Get the recipe out of the plugin */
212  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
213  recipe = (cpl_recipe *)plugin ;
214  else return -1 ;
215 
216  cpl_parameterlist_delete(recipe->parameters);
217  return 0;
218 
219 }
220 
221 /*---------------------------------------------------------------------------*/
228 /*---------------------------------------------------------------------------*/
229 /*
230  * The actual recipe actually start here.
231  */
232 
233 
234 static int
235 sinfo_rec_mflat(cpl_parameterlist *config, cpl_frameset *set)
236 {
237 
238  cpl_parameter* p;
239  cpl_frameset* ref_set=NULL;
240  int pdensity=0;
241  int line_cor=0;
242 
243  check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.product.density"));
244  check_nomsg(pdensity=cpl_parameter_get_int(p));
245 
246  sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
247  SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
248  ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
249 
250  check_nomsg(p=cpl_parameterlist_find(config, "sinfoni.general.lc_sw"));
251  check_nomsg(line_cor=cpl_parameter_get_bool(p));
252  if(line_cor==1) {
253  check_nomsg(sinfo_ima_line_cor(config,set));
254  }
255 
256 
257 
258  check_nomsg(ref_set=cpl_frameset_duplicate(set));
259  sinfo_bp_config_add(config);
260  check_nomsg(p = cpl_parameterlist_find(config,"sinfoni.bp.method"));
261  check_nomsg(cpl_parameter_set_string(p,"Normal"));
262  /*
263  ---------------------------------------------------------
264  MASTER_FLAT
265  ---------------------------------------------------------
266  */
267 
268  sinfo_msg("-------------------------------------------");
269  sinfo_msg("MASTER FLAT DETERMINATION ");
270  sinfo_msg("-------------------------------------------");
271 
272  ck0(sinfo_new_lamp_flats(cpl_func,config,set,ref_set),
273  "MASTER FLAT DETERMINATION FAILED");
274  sinfo_msg("MASTER FLAT DETERMINATION SUCCESS") ;
275 
276  sinfo_msg("-------------------------------------------");
277  sinfo_msg("BP_MAP_NO BAD PIXEL MAP DETERMINATION ");
278  sinfo_msg("-------------------------------------------");
279  /*
280  ---------------------------------------------------------
281  BP_SEARCH
282  ---------------------------------------------------------
283  */
284 
285  check_nomsg(p = cpl_parameterlist_find(config,"sinfoni.bp.method"));
286  check_nomsg(cpl_parameter_set_string(p,"Normal"));
287  ck0(sinfo_new_bp_search_normal(cpl_func,config,set,ref_set,PRO_BP_MAP_NO),
288  "BP_MAP_NO BAD PIXEL MAP DETERMINATION FAILED") ;
289 
290  sinfo_msg("------------------------------------------");
291  sinfo_msg("MASTER_BP_MAP BAD PIXEL MAP DETERMINATION ");
292  sinfo_msg("------------------------------------------");
293  ck0(sinfo_new_add_bp_map(cpl_func,config, set,ref_set),
294  "MASTER_BP_MAP BAD PIXEL MAP FAILED") ;
295  sinfo_msg("MASTER_BP_MAP BAD PIXEL MAP DETERMINATION SUCCESS");
296 
297 
298  if(pdensity < 2) {
299  check_nomsg(cpl_frameset_erase(set,PRO_BP_MAP_NO));
300  }
301 
302  cleanup:
303 
304  sinfo_free_frameset(&ref_set);
305 
306  if (cpl_error_get_code() != CPL_ERROR_NONE) {
307  return -1;
308  } else {
309  return 0;
310  }
311 
312 }
313