SINFONI Pipeline Reference Manual  2.5.2
sinfo_rec_detlin.c
1 /* $Id: sinfo_rec_detlin.c,v 1.21 2008-02-04 17:23:02 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 /*
22  * $Author: amodigli $
23  * $Date: 2008-02-04 17:23:02 $
24  * $Revision: 1.21 $
25  * $Name: not supported by cvs2svn $
26  */
27 
31 /*---------------------------------------------------------------------------*/
34 /****************************************************************
35  * Bad pixel search (normal method) *
36  ****************************************************************/
37 
38 /* ---------------------------------------------------------------
39  INCLUDES
40  --------------------------------------------------------------- */
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
44 
45 /*----------------------------------------------------------------------------
46  Includes
47  ----------------------------------------------------------------------------*/
48 
49 /* std libraries */
50 #include <strings.h>
51 #include <string.h>
52 #include <stdio.h>
53 
54 /* cpl */
55 #include <cpl.h>
56 
57 /* irplib */
58 #include <irplib_utils.h>
59 
60 
61 /* sinfoni */
62 #include <sinfo_utilities.h>
63 #include <sinfo_general_config.h>
64 #include <sinfo_bp_lin_config.h>
65 #include <sinfo_bp_config.h>
66 #include <sinfo_bp_lin.h>
67 #include <sinfo_product_config.h>
68 
69 #include <sinfo_bp_lin.h>
70 #include <sinfo_tpl_utils.h>
71 #include <sinfo_functions.h>
72 #include <sinfo_tpl_dfs.h>
73 #include <sinfo_msg.h>
74 #include <sinfo_error.h>
75 #include <sinfo_utils_wrappers.h>
76 
77 /*---------------------------------------------------------------------------
78  Functions prototypes
79  ---------------------------------------------------------------------------*/
80 
81 
82 static int sinfo_rec_detlin_create(cpl_plugin *plugin);
83 static int sinfo_rec_detlin_exec(cpl_plugin *plugin);
84 static int sinfo_rec_detlin_destroy(cpl_plugin *plugin);
85 static int sinfo_rec_detlin(cpl_parameterlist *, cpl_frameset *);
86 
87 /*----------------------------------------------------------------------------
88  Static variables
89  ----------------------------------------------------------------------------*/
90 
91 static char sinfo_rec_detlin_description[] =
92  "This recipe computes detector non linearities and a bad pixel map.\n"
93  "The input files are increasing intensity raw flats\n"
94  "their associated tags should be LINEARITY_LAMP.\n"
95  "The output are: \n"
96  "A table (PRO.CATG=LIN_DET_INFO) with information \n"
97  "on the detector non linearities\n"
98  "A table (PRO.CATG=GAIN_INFO) with information on the detector gain\n"
99  "A cube (PRO.CATG=BP_COEFF) with the polynomial fit parameters \n"
100  "of the detector non linearities\n"
101  "A bad pixel map (PRO.CATG=BP_MAP_NL)\n"
102  "\n";
103 /*---------------------------------------------------------------------------
104  Functions code
105  ---------------------------------------------------------------------------*/
106 /*--------------------------------------------------------------------------*/
115 /*--------------------------------------------------------------------------*/
116 
117 
118 int cpl_plugin_get_info(cpl_pluginlist *list)
119 {
120 
121  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
122  cpl_plugin *plugin = &recipe->interface;
123 
124 
125  cpl_plugin_init(plugin,
126  CPL_PLUGIN_API,
127  SINFONI_BINARY_VERSION,
128  CPL_PLUGIN_TYPE_RECIPE,
129  "sinfo_rec_detlin",
130  "Detector's linearity & non linear bad pixels determination.",
131  sinfo_rec_detlin_description,
132  "Andrea Modigliani",
133  "Andrea.Modigliani@eso.org",
134  sinfo_get_license(),
135  sinfo_rec_detlin_create,
136  sinfo_rec_detlin_exec,
137  sinfo_rec_detlin_destroy);
138 
139  cpl_pluginlist_append(list, plugin);
140 
141  return 0;
142 
143 }
144 
145 /*--------------------------------------------------------------------------*/
153 /*--------------------------------------------------------------------------*/
154 static int sinfo_rec_detlin_create(cpl_plugin *plugin)
155 {
156 
157  /*
158  * We have to provide the option we accept to the application.
159  * We need to setup our parameter list and hook it into the recipe
160  * interface.
161  */
162 
163 
164  cpl_recipe * recipe ;
165 
166  /* Check that the plugin is part of a valid recipe */
167  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
168  recipe = (cpl_recipe *)plugin ;
169  else return -1 ;
170 
171  cpl_error_reset();
172  irplib_reset();
173  /* Create the parameters list in the cpl_recipe object */
174  recipe->parameters = cpl_parameterlist_new() ;
175 
176  sinfo_general_config_add(recipe->parameters);
177  sinfo_product_config_add(recipe->parameters);
178  sinfo_bp_lin_config_add(recipe->parameters);
179 
180  return 0;
181 
182 }
183 
184 /*--------------------------------------------------------------------------*/
190 /*--------------------------------------------------------------------------*/
191 
192 static int sinfo_rec_detlin_exec(cpl_plugin *plugin)
193 {
194  cpl_recipe * recipe ;
195 
196  /* Get the recipe out of the plugin */
197  cpl_errorstate initial_errorstate = cpl_errorstate_get();
198 
199  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
200  recipe = (cpl_recipe *)plugin ;
201  else return -1 ;
202 
203  if (!cpl_errorstate_is_equal(initial_errorstate)) {
204  /* Dump the error history since recipe execution start.
205  At this point the recipe cannot recover from the error */
206  cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
207  }
208 
209  return sinfo_rec_detlin(recipe->parameters, recipe->frames);
210 
211 }
212 /*--------------------------------------------------------------------------*/
218 /*--------------------------------------------------------------------------*/
219 
220 static int sinfo_rec_detlin_destroy(cpl_plugin *plugin)
221 {
222  cpl_recipe * recipe ;
223 
224  /* Get the recipe out of the plugin */
225  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
226  recipe = (cpl_recipe *)plugin ;
227  else return -1 ;
228 
229  cpl_parameterlist_delete(recipe->parameters) ;
230 
231  return 0;
232 
233 }
234 
235 /*
236  * The actual recipe actually start here.
237  */
238 /*---------------------------------------------------------------------------*/
259 /*--------------------------------------------------------------------------*/
260 
261 static int sinfo_rec_detlin(cpl_parameterlist *config, cpl_frameset *set)
262 {
263  cpl_parameter *p=NULL;
264  int line_cor=0;
265 
266  sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
267  SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
268  /* Hidden parameters */
269  /* name of the data cube storing the found polynomial coefficients */
270  sinfo_bp_config_add(config);
271  check_nomsg(p = cpl_parameterlist_find(config,"sinfoni.bp.method"));
272  check_nomsg(cpl_parameter_set_string(p,"Linear"));
273 
274  ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
275 
276  check_nomsg(p=cpl_parameterlist_find(config, "sinfoni.general.lc_sw"));
277  check_nomsg(line_cor=cpl_parameter_get_bool(p));
278  if(line_cor==1) {
279  check_nomsg(sinfo_ima_line_cor(config,set));
280  }
281 
282 
283  sinfo_msg("---------------------------------------");
284  sinfo_msg("BP_MAP_NL BAD PIXEL MAP DETERMINATION ");
285  sinfo_msg("---------------------------------------");
286  ck0(sinfo_new_bp_search_lin(cpl_func,config,set),
287  "BP_MAP_NL BAD PIXEL MAP DETERMINATION FAILED") ;
288  sinfo_msg("BP_MAP_NL BAD PIXEL MAP DETERMINATION SUCCESS") ;
289 
290  cleanup:
291 
292  if (cpl_error_get_code() != CPL_ERROR_NONE) {
293  return -1;
294  } else {
295  return 0;
296  }
297 
298 }
299