SINFONI Pipeline Reference Manual  2.6.0
sinfo_step_jitter.c
1 /* $Id: sinfo_step_jitter.c,v 1.13 2007-10-08 13:26:50 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: 2007-10-08 13:26:50 $
23  * $Revision: 1.13 $
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_pro_types.h>
55 #include <sinfo_product_config.h>
56 #include <sinfo_prepare_stacked_frames_config.h>
57 #include <sinfo_objnod_config.h>
58 #include <sinfo_standard_star_config.h>
59 #include <sinfo_psf_config.h>
60 #include <sinfo_skycor_config.h>
61 #include <sinfo_new_objnod.h>
62 #include <sinfo_new_stdstar.h>
63 #include <sinfo_new_psf.h>
64 #include <sinfo_new_prepare_stacked_frames.h>
65 #include <sinfo_new_cubes_coadd.h>
66 #include <sinfo_key_names.h>
67 #include <sinfo_raw_types.h>
68 #include <sinfo_functions.h>
69 #include <sinfo_tpl_utils.h>
70 #include <sinfo_tpl_dfs.h>
71 #include <sinfo_hidden.h>
72 #include <sinfo_globals.h>
73 #include <sinfo_msg.h>
74 #include <sinfo_rec_utils.h>
75 #include <sinfo_error.h>
76 #include <sinfo_utils_wrappers.h>
77 /*-----------------------------------------------------------------------------
78  Functions prototypes
79  ----------------------------------------------------------------------------*/
80 
81 static int sinfo_step_jitter_create(cpl_plugin *) ;
82 static int sinfo_step_jitter_exec(cpl_plugin *) ;
83 static int sinfo_step_jitter_destroy(cpl_plugin *) ;
84 static int sinfo_step_jitter(cpl_parameterlist *config, cpl_frameset *set);
85 /*-----------------------------------------------------------------------------
86  Static variables
87  ----------------------------------------------------------------------------*/
88 
89 static char sinfo_step_jitter_description1[] =
90  "This recipe performs science data reduction.\n"
91  "The input files are:\n"
92  "science object and sky frames with tags OBJECT_NODDING and SKY_NODDING or\n"
93  "Telluric standard star frames and sky frames with tags STD and SKY_STD or\n"
94  "PSF standard star and sky frames with tags \n"
95  "PSF_CALIBRATOR and SKY_PSF_CALIBRATOR\n"
96  "and Master calibration frames:\n";
97 
98 
99 static char sinfo_step_jitter_description2[] =
100  "A corresponding (band,preoptics) wavelength map image with tag WAVE_MAP\n"
101  "A corresponding (band,preoptics) master flat field with tag MASTER_FLAT_LAMP\n"
102  "A corresponding (band,preoptics) master bad pixel map with tag MASTER_BP_MAP\n"
103  "A corresponding (band,preoptics) slitlets position frame with tag SLIT_POS\n"
104  "A corresponding (band) distortion table with tag DISTORTION\n"
105  "A corresponding (band) slitlet distance table with tag SLITLETS_DISTANCE\n";
106 
107 
108 static char sinfo_step_jitter_description3[] =
109  "The output is an image resulting from the IMA1 op IMA2 where op indicates\n"
110  "A reference table with the position of the first "
111  "column with tag FIRST_COLUMN\n"
112  "Relevant outputs are:\n"
113  "combined cubes (PRO.CATG=x_OBS x=STD,OBJ,PSF)\n"
114  "reconstructed cube (PRO.CATG=COADD_x_OBS x=STD,OBJ,PSF)\n"
115  "An average along Z of the reconstructed cube \n"
116  "(PRO.CATG=MED_x_OBS x=STD,OBJ,PSF)\n"
117  "The bad pixel map associated to the cube \n"
118  "(PRO.CATG=BP_MAP_COADD_x_OBS x=STD,OBJ,PSF)\n"
119  "\n";
120 
121 
122 static char sinfo_step_jitter_description[1400];
123 
124 /*-----------------------------------------------------------------------------
125  Functions code
126  ----------------------------------------------------------------------------*/
127 /*---------------------------------------------------------------------------*/
132 /*---------------------------------------------------------------------------*/
133 
134 
135 /*---------------------------------------------------------------------------*/
144 /*---------------------------------------------------------------------------*/
145 
146 int
147 cpl_plugin_get_info(cpl_pluginlist *list)
148 {
149 
150  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
151  cpl_plugin *plugin = &recipe->interface;
152 
153  strcpy(sinfo_step_jitter_description,sinfo_step_jitter_description1);
154  strcat(sinfo_step_jitter_description,sinfo_step_jitter_description2);
155  strcat(sinfo_step_jitter_description,sinfo_step_jitter_description3);
156 
157  cpl_plugin_init(plugin,
158  CPL_PLUGIN_API,
159  SINFONI_BINARY_VERSION,
160  CPL_PLUGIN_TYPE_RECIPE,
161  "sinfo_step_jitter",
162  "Object or STD star or PSF star data reduction",
163  sinfo_step_jitter_description,
164  "Andrea Modigliani",
165  "Andrea.Mdigliani@eso.org",
166  sinfo_get_license(),
167  sinfo_step_jitter_create,
168  sinfo_step_jitter_exec,
169  sinfo_step_jitter_destroy);
170 
171  cpl_pluginlist_append(list, plugin);
172 
173  return 0;
174 
175 }
176 
177 /*---------------------------------------------------------------------------*/
185 /*---------------------------------------------------------------------------*/
186 static int sinfo_step_jitter_create(cpl_plugin *plugin)
187 {
188  cpl_recipe * recipe ;
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 
195  /* Create the parameters list in the cpl_recipe object */
196  recipe->parameters = cpl_parameterlist_new() ;
197  cpl_error_reset();
198  irplib_reset();
199 
200 
201  /*
202  * Fill the parameter list.
203  */
204  sinfo_product_config_add(recipe->parameters);
205  sinfo_prepare_stacked_frames_config_add(recipe->parameters);
206  sinfo_objnod_config_add(recipe->parameters);
207  sinfo_skycor_config_add(recipe->parameters);
208  sinfo_standard_star_config_add(recipe->parameters);
209  sinfo_psf_config_add(recipe->parameters);
210 
211  return 0;
212 
213 }
214 
215 /*---------------------------------------------------------------------------*/
221 /*---------------------------------------------------------------------------*/
222 static int sinfo_step_jitter_exec(cpl_plugin *plugin)
223 {
224 
225  cpl_recipe *recipe = (cpl_recipe *) plugin;
226 
227  /* Get the recipe out of the plugin */
228  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
229  recipe = (cpl_recipe *)plugin ;
230  else return -1 ;
231 
232  return sinfo_step_jitter(recipe->parameters, recipe->frames);
233 
234 }
235 
236 /*---------------------------------------------------------------------------*/
242 /*---------------------------------------------------------------------------*/
243 static int sinfo_step_jitter_destroy(cpl_plugin *plugin)
244 {
245 
246  cpl_recipe * recipe ;
247 
248  /* Get the recipe out of the plugin */
249  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
250  recipe = (cpl_recipe *)plugin ;
251  else return -1 ;
252 
253  cpl_parameterlist_delete(recipe->parameters);
254 
255  return 0;
256 
257 }
258 
259 /*---------------------------------------------------------------------------*/
266 /*---------------------------------------------------------------------------*/
267 
268 /*
269  * The actual recipe actually start here.
270  */
271 
272 static int sinfo_step_jitter(cpl_parameterlist *config, cpl_frameset *set)
273 {
274  const char* pro_ctg_cube=NULL;
275  int ind=0;
276  cpl_parameter* p=NULL;
277  int psf_sw=0;
278  int std_sw=0;
279  cpl_frameset* obj_set=NULL;
280  cpl_frame* obj_frm=NULL;
281  char tag[FILE_NAME_SZ];
282  cpl_frameset* ref_set=NULL;
283  sinfo_msg("ok1");
284  if(sinfo_dfs_set_groups(set)) {
285  sinfo_msg_error("Cannot indentify RAW and CALIB frames") ;
286  return -1;
287  }
288 
289  sinfo_msg("ok2");
290  check_nomsg(ref_set=cpl_frameset_duplicate(set));
291  obj_set=cpl_frameset_new();
292  sinfo_extract_obj_products(set,obj_set);
293  if(NULL == (obj_frm = cpl_frameset_get_frame(obj_set,0))) {
294  sinfo_msg_error("No object frames in input set.");
295  cpl_frameset_delete(obj_set);
296  return -1;
297  }
298 
299  sinfo_msg("ok3");
300  strcpy(tag,cpl_frame_get_tag(obj_frm));
301  if(NULL!=sinfo_new_set_obj_procatg(tag)){
302  pro_ctg_cube=sinfo_new_set_obj_procatg(tag);
303  } else {
304  sinfo_msg_error("Frame tag %s not supported.",tag);
305  cpl_frameset_delete(obj_set);
306  return -1;
307  }
308  cpl_frameset_delete(obj_set);
309  sinfo_msg("ok4");
310  /* ===============================================================
311  SCI OBJNOD
312  =============================================================== */
313  /*
314  sinfo_msg("------------------------------") ;
315  sinfo_msg("COADDING CUBES");
316  sinfo_msg("------------------------------") ;
317 
318  ck0(sinfo_new_cubes_coadd(cpl_func,config, set, pro_ctg_cube),
319  "COADDING CUBES") ;
320 
321  sinfo_msg("------------------------------") ;
322  sinfo_msg("COADDED CUBES");
323  sinfo_msg("------------------------------") ;
324  */
325 
326 
327  /* ===============================================================
328  PSF
329  =============================================================== */
330  /*
331  if((strcmp(pro_ctg_cube,PRO_COADD_OBJ) == 0) ||
332  (strcmp(pro_ctg_cube,PRO_COADD_PSF) == 0) ||
333  (strcmp(pro_ctg_cube,PRO_COADD_STD) == 0) ||
334  (strcmp(pro_ctg_cube,PRO_COADD_PUPIL) == 0) ) {
335  */
336 
337  sinfo_msg("ok5");
338  p = cpl_parameterlist_find(config, "sinfoni.psf.switch");
339  psf_sw = cpl_parameter_get_bool(p);
340  sinfo_msg("switch=%d",psf_sw);
341  if(psf_sw) {
342  sinfo_msg("------------------------------") ;
343  sinfo_msg("REDUCE PSF STD STAR FRAMES");
344  sinfo_msg("------------------------------") ;
345  if ( -1 == (ind = sinfo_new_psf(cpl_func,config,set,ref_set) ) )
346  {
347  sinfo_msg("no: %d\n", ind) ;
348  return -1 ;
349  }
350  sinfo_msg("SUCCESS REDUCE PSF STD STAR FRAMES") ;
351  }
352 
353  sinfo_msg("ok6");
354  p = cpl_parameterlist_find(config, "sinfoni.std_star.switch");
355  std_sw = cpl_parameter_get_bool(p);
356  sinfo_msg("switch=%d",std_sw);
357  if(std_sw) {
358  sinfo_msg("------------------------------") ;
359  sinfo_msg("STD STAR DATA REDUCTION");
360  sinfo_msg("------------------------------") ;
361 
362 
363  if ( -1 == (ind = sinfo_new_stdstar(cpl_func,config, set,ref_set) ) )
364  {
365  sinfo_msg("REDUCING STD STAR DATA No: %d",ind) ;
366  return -1 ;
367  }
368  sinfo_msg("STD STAR DATA REDUCTION SUCCESS") ;
369  }
370  sinfo_msg("ok7");
371 
372  // }
373 
374  cleanup:
375 
376  return 0 ;
377 }
378 
379 
void irplib_reset(void)
Reset IRPLIB state.
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.