SINFONI Pipeline Reference Manual  2.5.2
sinfo_rec_objnod.c
1 /* $Id: sinfo_rec_objnod.c,v 1.24 2007-10-26 09:40:28 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: 2007-10-26 09:40:28 $
24  * $Revision: 1.24 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 /****************************************************************
29  * Object Data reduction *
30  ****************************************************************/
31 
32 #ifdef HAVE_CONFIG_H
33 #include <config.h> /* allows the program compilation */
34 #endif
35 
36 /*-----------------------------------------------------------------------------
37  Includes
38  -----------------------------------------------------------------------------*/
39 
40 /* std */
41 #include <strings.h>
42 #include <string.h>
43 #include <stdio.h>
44 #include <math.h>
45 #include <libgen.h>
46 
47 
48 /* cpl */
49 #include <cpl.h>
50 #include <irplib_utils.h>
51 
52 
53 
54 /* sinfoni */
55 #include <sinfo_pro_types.h>
56 #include <sinfo_product_config.h>
57 #include <sinfo_prepare_stacked_frames_config.h>
58 #include <sinfo_objnod_config.h>
59 #include <sinfo_new_cubes_coadd.h>
60 #include <sinfo_new_prepare_stacked_frames.h>
61 #include <sinfo_skycor_config.h>
62 #include <sinfo_key_names.h>
63 #include <sinfo_raw_types.h>
64 #include <sinfo_functions.h>
65 #include <sinfo_tpl_utils.h>
66 #include <sinfo_tpl_dfs.h>
67 #include <sinfo_hidden.h>
68 #include <sinfo_globals.h>
69 #include <sinfo_msg.h>
70 #include <sinfo_rec_utils.h>
71 #include <sinfo_error.h>
72 #include <sinfo_utils_wrappers.h>
73 
74 
75 
76 /*-----------------------------------------------------------------------------
77  Functions prototypes
78  ----------------------------------------------------------------------------*/
79 static int sinfo_rec_objnod_create(cpl_plugin *) ;
80 static int sinfo_rec_objnod_exec(cpl_plugin *) ;
81 static int sinfo_rec_objnod_destroy(cpl_plugin *) ;
82 static int sinfo_rec_objnod(cpl_parameterlist *, cpl_frameset *);
83 
84 /*-----------------------------------------------------------------------------
85  Static variables
86  ----------------------------------------------------------------------------*/
87 
88 static char sinfo_rec_objnod_description1[] =
89  "This recipe performs science data reduction.\n"
90  "The input files are science object and sky frames with tags \n"
91  "OBJECT_NODDING and SKY_NODDING\n"
92  "Master calibration frames:\n";
93 
94 
95 static char sinfo_rec_objnod_description2[] =
96  "A corresponding (band,preoptics) wavelength map image with tag WAVE_MAP\n"
97  "A corresponding (band,preoptics) master flat field with tag MASTER_FLAT_LAMP\n"
98  "A corresponding (band,preoptics) master bad pixel map with tag MASTER_BP_MAP\n"
99  "A corresponding (band,preoptics) slitlets position frame with tag SLIT_POS\n"
100  "A corresponding (band) distortion table with tag DISTORTION\n"
101  "A corresponding (band) slitlet distance table with tag SLITLETS_DISTANCE\n";
102 
103 
104 static char sinfo_rec_objnod_description3[] =
105  "The output is an image resulting from the IMA1 op IMA2 where op indicates\n"
106  "A reference table with the position of the first "
107  "column with tag FIRST_COLUMN\n"
108  "Relevant outputs are:\n"
109  "combined cubes (PRO.CATG=x_OBS x=STD,OBJ,PSF)\n"
110  "reconstructed cube (PRO.CATG=COADD_x_OBS x=STD,OBJ,PSF)\n"
111  "An average along Z of the reconstructed cube \n"
112  "(PRO.CATG=MED_x_OBS x=STD,OBJ,PSF)\n"
113  "The bad pixel map associated to the cube \n"
114  "(PRO.CATG=BP_MAP_COADD_x_OBS x=STD,OBJ,PSF)\n"
115  "\n";
116 
117 static char sinfo_rec_objnod_description[1300];
118 
119 /*-----------------------------------------------------------------------------
120  Functions code
121  ----------------------------------------------------------------------------*/
122 /*---------------------------------------------------------------------------*/
126 /*---------------------------------------------------------------------------*/
128 /*---------------------------------------------------------------------------*/
137 /*---------------------------------------------------------------------------*/
138 
139 
140 int
141 cpl_plugin_get_info(cpl_pluginlist *list)
142 {
143 
144  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
145  cpl_plugin *plugin = &recipe->interface;
146 
147  strcpy(sinfo_rec_objnod_description,sinfo_rec_objnod_description1);
148  strcat(sinfo_rec_objnod_description,sinfo_rec_objnod_description2);
149  strcat(sinfo_rec_objnod_description,sinfo_rec_objnod_description3);
150 
151  cpl_plugin_init(plugin,
152  CPL_PLUGIN_API,
153  SINFONI_BINARY_VERSION,
154  CPL_PLUGIN_TYPE_RECIPE,
155  "sinfo_rec_objnod",
156  "Object data reduction",
157  sinfo_rec_objnod_description,
158  "Andrea Modigliani",
159  "Andrea.Mdigliani@eso.org",
160  sinfo_get_license(),
161  sinfo_rec_objnod_create,
162  sinfo_rec_objnod_exec,
163  sinfo_rec_objnod_destroy);
164 
165  cpl_pluginlist_append(list, plugin);
166 
167  return 0;
168 
169 }
170 
171 /*---------------------------------------------------------------------------*/
179 /*---------------------------------------------------------------------------*/
180 static int sinfo_rec_objnod_create(cpl_plugin *plugin)
181 {
182  cpl_recipe * recipe ;
183 
184  /* Check that the plugin is part of a valid recipe */
185  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
186  recipe = (cpl_recipe *)plugin ;
187  else return -1 ;
188  irplib_reset();
189  cpl_error_reset();
190 
191  /* Create the parameters list in the cpl_recipe object */
192  recipe->parameters = cpl_parameterlist_new() ;
193 
194  /*
195  * Fill the parameter list.
196  */
197 
198  sinfo_product_config_add(recipe->parameters);
199  sinfo_prepare_stacked_frames_config_add(recipe->parameters);
200  sinfo_objnod_config_add(recipe->parameters);
201  sinfo_skycor_config_add(recipe->parameters);
202 
203  return 0;
204 
205 }
206 
207 /*---------------------------------------------------------------------------*/
213 /*---------------------------------------------------------------------------*/
214 static int sinfo_rec_objnod_exec(cpl_plugin *plugin)
215 {
216  cpl_recipe * recipe ;
217 
218  cpl_errorstate initial_errorstate = cpl_errorstate_get();
219 
220  /* Get the recipe out of the plugin */
221  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
222  recipe = (cpl_recipe *)plugin ;
223  else return -1 ;
224 
225  if (!cpl_errorstate_is_equal(initial_errorstate)) {
226  /* Dump the error history since recipe execution start.
227  At this point the recipe cannot recover from the error */
228  cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
229  }
230 
231  return sinfo_rec_objnod(recipe->parameters, recipe->frames);
232 
233 }
234 /*---------------------------------------------------------------------------*/
240 /*---------------------------------------------------------------------------*/
241 static int sinfo_rec_objnod_destroy(cpl_plugin *plugin)
242 {
243  cpl_recipe *recipe = (cpl_recipe *) plugin;
244 
245  /* Get the recipe out of the plugin */
246  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
247  recipe = (cpl_recipe *)plugin ;
248  else return -1 ;
249 
250  cpl_parameterlist_delete(recipe->parameters);
251 
252  return 0;
253 
254 }
255 
256 /*---------------------------------------------------------------------------*/
263 /*---------------------------------------------------------------------------*/
264 
265 /*
266  * The actual recipe actually start here.
267  */
268 
269 static int sinfo_rec_objnod(cpl_parameterlist *config, cpl_frameset *set)
270 {
271  const char* pro_ctg_cube;
272  sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
273  SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
274 
275  if(sinfo_dfs_set_groups(set)) {
276  sinfo_msg_error("Cannot indentify RAW and CALIB frames") ;
277  return -1;
278  }
279 
280  /* ===============================================================
281  Defines several framesets each with a pair obj-sky,
282  stack each pair, put the results in set
283  =============================================================== */
284  ck0(sinfo_cub_stk_frames(config,&set,cpl_func,&pro_ctg_cube),
285  "Cannot stack RAW frames") ;
286 
287 
288  /* ===============================================================
289  SCI OBJNOD
290  =============================================================== */
291 
292  sinfo_msg("------------------------------") ;
293  sinfo_msg("COADDING CUBES");
294  sinfo_msg("------------------------------") ;
295 
296 
297  ck0(sinfo_new_cubes_coadd(cpl_func,config, set, pro_ctg_cube),
298  "COADDING CUBES") ;
299 
300  sinfo_msg("------------------------------") ;
301  sinfo_msg("COADDED CUBES");
302  sinfo_msg("------------------------------") ;
303 
304  cleanup:
305  if (cpl_error_get_code() != CPL_ERROR_NONE) {
306  return -1;
307  } else {
308  return 0;
309  }
310 
311 }