SINFONI Pipeline Reference Manual  2.6.0
sinfo_rec_jitter.c
1 /* $Id: sinfo_rec_jitter.c,v 1.35 2013-10-14 14:40:00 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: 2013-10-14 14:40:00 $
23  * $Revision: 1.35 $
24  * $Name: not supported by cvs2svn $
25  */
26 
27 /****************************************************************
28  * Object 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 #include <math.h>
44 #include <libgen.h>
45 
46 
47 /* cpl */
48 #include <cpl.h>
49 
50 /* irplib */
51 #include <irplib_utils.h>
52 
53 /* sinfoni */
54 #include <sinfo_utilities.h>
55 #include <sinfo_pro_types.h>
56 #include <sinfo_general_config.h>
57 #include <sinfo_product_config.h>
58 #include <sinfo_prepare_stacked_frames_config.h>
59 #include <sinfo_objnod_config.h>
60 #include <sinfo_skycor_config.h>
61 #include <sinfo_psf_config.h>
62 #include <sinfo_standard_star_config.h>
63 #include <sinfo_new_prepare_stacked_frames.h>
64 #include <sinfo_new_cubes_coadd.h>
65 #include <sinfo_new_stdstar.h>
66 #include <sinfo_new_psf.h>
67 #include <sinfo_key_names.h>
68 #include <sinfo_raw_types.h>
69 #include <sinfo_functions.h>
70 #include <sinfo_tpl_utils.h>
71 #include <sinfo_tpl_dfs.h>
72 #include <sinfo_hidden.h>
73 #include <sinfo_globals.h>
74 #include <sinfo_msg.h>
75 #include <sinfo_rec_utils.h>
76 #include <sinfo_error.h>
77 #include <sinfo_utils_wrappers.h>
78 
79 /*-----------------------------------------------------------------------------
80  Functions prototypes
81  ----------------------------------------------------------------------------*/
82 
83 static int sinfo_rec_jitter_create(cpl_plugin *) ;
84 static int sinfo_rec_jitter_exec(cpl_plugin *) ;
85 static int sinfo_rec_jitter_destroy(cpl_plugin *) ;
86 static int sinfo_rec_jitter(cpl_parameterlist *config, cpl_frameset *set);
87 /*-----------------------------------------------------------------------------
88  Static variables
89  ----------------------------------------------------------------------------*/
90 
91 static char sinfo_rec_jitter_description1[] =
92  "This recipe performs science data reduction.\n"
93  "The input files are:\n"
94  "science object and sky frames with tags OBJECT_NODDING and SKY_NODDING or\n"
95  "Telluric standard star frames and sky frames with tags STD and SKY_STD or\n"
96  "PSF standard star and sky frames with tags \n"
97  "PSF_CALIBRATOR and SKY_PSF_CALIBRATOR\n"
98  "and Master calibration frames:\n";
99 
100 
101 static char sinfo_rec_jitter_description2[] =
102  "A corresponding (band,preoptics) wavelength map image with tag WAVE_MAP\n"
103  "A corresponding (band,preoptics) master flat field with tag MASTER_FLAT_LAMP\n"
104  "A corresponding (band,preoptics) master bad pixel map with tag MASTER_BP_MAP\n"
105  "A corresponding (band,preoptics) slitlets position frame with tag SLIT_POS\n"
106  "A corresponding (band) distortion table with tag DISTORTION\n"
107  "A corresponding (band) slitlet distance table with tag SLITLETS_DISTANCE\n";
108 
109 
110 static char sinfo_rec_jitter_description3[] =
111  "The output is an image resulting from the IMA1 op IMA2 where op indicates\n"
112  "A reference table with the position of the first "
113  "column with tag FIRST_COLUMN\n"
114  "Relevant outputs are:\n"
115  "combined cubes (PRO.CATG=x_OBS x=STD,OBJ,PSF)\n"
116  "reconstructed cube (PRO.CATG=COADD_x_OBS x=STD,OBJ,PSF)\n"
117  "An average along Z of the reconstructed cube \n"
118  "(PRO.CATG=MED_x_OBS x=STD,OBJ,PSF)\n"
119  "The bad pixel map associated to the cube \n"
120  "(PRO.CATG=BP_MAP_COADD_x_OBS x=STD,OBJ,PSF)\n"
121  "\n";
122 
123 static char sinfo_rec_jitter_description[1400];
124 
125 /*-----------------------------------------------------------------------------
126  Functions code
127  ----------------------------------------------------------------------------*/
128 /*---------------------------------------------------------------------------*/
132 /*---------------------------------------------------------------------------*/
134 /*---------------------------------------------------------------------------*/
143 /*---------------------------------------------------------------------------*/
144 
145 int
146 cpl_plugin_get_info(cpl_pluginlist *list)
147 {
148 
149  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
150  cpl_plugin *plugin = &recipe->interface;
151 
152  strcpy(sinfo_rec_jitter_description,sinfo_rec_jitter_description1);
153  strcat(sinfo_rec_jitter_description,sinfo_rec_jitter_description2);
154  strcat(sinfo_rec_jitter_description,sinfo_rec_jitter_description3);
155 
156  cpl_plugin_init(plugin,
157  CPL_PLUGIN_API,
158  SINFONI_BINARY_VERSION,
159  CPL_PLUGIN_TYPE_RECIPE,
160  "sinfo_rec_jitter",
161  "Object or STD star or PSF star data reduction",
162  sinfo_rec_jitter_description,
163  "Andrea Modigliani",
164  "Andrea.Mdigliani@eso.org",
165  sinfo_get_license(),
166  sinfo_rec_jitter_create,
167  sinfo_rec_jitter_exec,
168  sinfo_rec_jitter_destroy);
169 
170  cpl_pluginlist_append(list, plugin);
171 
172  return 0;
173 
174 }
175 
176 /*---------------------------------------------------------------------------*/
184 /*---------------------------------------------------------------------------*/
185 static int sinfo_rec_jitter_create(cpl_plugin *plugin)
186 {
187  cpl_recipe * recipe ;
188 
189 
190  /* Check that the plugin is part of a valid recipe */
191  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
192  recipe = (cpl_recipe *)plugin ;
193  else return -1 ;
194  cpl_error_reset();
195  irplib_reset();
196 
197  /* Create the parameters list in the cpl_recipe object */
198  recipe->parameters = cpl_parameterlist_new() ;
199 
200 
201  /*
202  * Fill the parameter list.
203  */
204 
205  sinfo_general_config_add(recipe->parameters);
206  sinfo_product_config_add(recipe->parameters);
207  sinfo_prepare_stacked_frames_config_add(recipe->parameters);
208  sinfo_objnod_config_add(recipe->parameters);
209  sinfo_skycor_config_add(recipe->parameters);
210  sinfo_standard_star_config_add(recipe->parameters);
211  sinfo_psf_config_add(recipe->parameters);
212 
213 
214 
215  return 0;
216 
217 }
218 
219 /*---------------------------------------------------------------------------*/
225 /*---------------------------------------------------------------------------*/
226 static int sinfo_rec_jitter_exec(cpl_plugin *plugin)
227 {
228 
229  cpl_recipe *recipe = (cpl_recipe *) plugin;
230 
231  cpl_errorstate initial_errorstate = cpl_errorstate_get();
232 
233  /* Get the recipe out of the plugin */
234  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
235  recipe = (cpl_recipe *)plugin ;
236  else return -1 ;
237 
238  if (!cpl_errorstate_is_equal(initial_errorstate)) {
239  /* Dump the error history since recipe execution start.
240  At this point the recipe cannot recover from the error */
241  cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
242  }
243  return sinfo_rec_jitter(recipe->parameters, recipe->frames);
244 
245 }
246 
247 /*---------------------------------------------------------------------------*/
253 /*---------------------------------------------------------------------------*/
254 static int sinfo_rec_jitter_destroy(cpl_plugin *plugin)
255 {
256 
257  cpl_recipe * recipe ;
258 
259  /* Get the recipe out of the plugin */
260  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
261  recipe = (cpl_recipe *)plugin ;
262  else return -1 ;
263 
264  cpl_parameterlist_delete(recipe->parameters);
265 
266  return 0;
267 
268 }
269 
270 /*---------------------------------------------------------------------------*/
277 /*---------------------------------------------------------------------------*/
278 
279 /*
280  * The actual recipe actually start here.
281  */
282 
283 static int sinfo_rec_jitter(cpl_parameterlist *config, cpl_frameset *set)
284 {
285  const char* pro_ctg_cube;
286  cpl_parameter* p=NULL;
287  int psf_sw=0;
288  int std_sw=0;
289  cpl_frameset* ref_set=NULL;
290  int line_cor=0;
291 
292  sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
293  SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
294 
295  if(sinfo_dfs_set_groups(set)) {
296  sinfo_msg_error("Cannot indentify RAW and CALIB frames") ;
297  return -1;
298  }
299 
300  check_nomsg(p=cpl_parameterlist_find(config, "sinfoni.general.lc_sw"));
301  check_nomsg(line_cor=cpl_parameter_get_bool(p));
302  if(line_cor==1) {
303  check_nomsg(sinfo_ima_line_cor(config,set));
304  }
305 
306  check_nomsg(ref_set=cpl_frameset_duplicate(set));
307  /* ===============================================================
308  Defines several framesets each with a pair obj-sky,
309  stack each pair, put the results in set
310  =============================================================== */
311  ck0(sinfo_cub_stk_frames(config,&set,cpl_func,&pro_ctg_cube),
312  "Cannot stack RAW frames") ;
313 
314  /* ===============================================================
315  SCI OBJNOD
316  =============================================================== */
317  sinfo_msg("------------------------------") ;
318  sinfo_msg("COADDING CUBES");
319  sinfo_msg("------------------------------") ;
320  ck0(sinfo_new_cubes_coadd(cpl_func,config, set, pro_ctg_cube),
321  "COADDING CUBES") ;
322 
323  sinfo_msg("------------------------------") ;
324  sinfo_msg("COADDED CUBES");
325  sinfo_msg("------------------------------") ;
326 
327  /* ===============================================================
328  PSF
329  =============================================================== */
330 
331  if((strcmp(pro_ctg_cube,PRO_COADD_PSF) == 0) ||
332  (strcmp(pro_ctg_cube,PRO_COADD_STD) == 0) ||
333  (strcmp(pro_ctg_cube,PRO_COADD_PUPIL) == 0) ) {
334 
335 
336  p = cpl_parameterlist_find(config, "sinfoni.psf.switch");
337  psf_sw = cpl_parameter_get_bool(p);
338  sinfo_msg("switch=%d",psf_sw);
339  if(psf_sw) {
340  sinfo_msg("------------------------------") ;
341  sinfo_msg("REDUCE PSF STD STAR FRAMES");
342  sinfo_msg("------------------------------") ;
343  if ( -1 == sinfo_new_psf(cpl_func,config,set,set) ) {
344  sinfo_msg_error("REDUCING PSF STD STAR FRAMES") ;
345  cpl_error_reset();
346  } else {
347  sinfo_msg("SUCCESS REDUCE PSF STD STAR FRAMES") ;
348  }
349  }
350 
351  p = cpl_parameterlist_find(config, "sinfoni.std_star.switch");
352  std_sw = cpl_parameter_get_bool(p);
353  sinfo_msg("switch=%d",std_sw);
354  if(std_sw) {
355  sinfo_msg("------------------------------") ;
356  sinfo_msg("STD STAR DATA REDUCTION");
357  sinfo_msg("------------------------------") ;
358  if ( -1 == sinfo_new_stdstar(cpl_func,config, set,set ) ) {
359  sinfo_msg_error("REDUCING STD STAR DATA") ;
360  cpl_error_reset();
361  } else {
362  sinfo_msg("STD STAR DATA REDUCTION SUCCESS") ;
363  }
364  }
365  }
366 
367  cleanup:
368  sinfo_free_frameset(&ref_set);
369  if (cpl_error_get_code() != CPL_ERROR_NONE) {
370  sinfo_check_rec_status(0);
371  return -1;
372  } else {
373  return 0;
374  }
375 
376 
377 }
378 
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
void irplib_reset(void)
Reset IRPLIB state.
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69