SINFONI Pipeline Reference Manual  2.5.2
sinfo_rec_stdstar.c
1 /* $Id: sinfo_rec_stdstar.c,v 1.22 2008-02-12 14:56: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 /*
22  * $Author: amodigli $
23  * $Date: 2008-02-12 14:56:50 $
24  * $Revision: 1.22 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 /****************************************************************
29  * Standard_Star Frames Data Reduction *
30  ****************************************************************/
31 
32 /*-----------------------------------------------------------------------------
33  Includes
34  -----------------------------------------------------------------------------*/
35 
36 #ifdef HAVE_CONFIG_H
37 #include <config.h> /* allows the program compilation */
38 #endif
39 
40 /* std */
41 #include <strings.h>
42 #include <string.h>
43 #include <stdio.h>
44 
45 
46 /* cpl */
47 #include <cpl.h>
48 
49 /* irplib */
50 #include <irplib_utils.h>
51 
52 /* sinfoni */
53 #include <sinfo_pro_types.h>
54 #include <sinfo_product_config.h>
55 #include <sinfo_prepare_stacked_frames_config.h>
56 #include <sinfo_objnod_config.h>
57 #include <sinfo_skycor_config.h>
58 #include <sinfo_standard_star_config.h>
59 #include <sinfo_new_prepare_stacked_frames.h>
60 #include <sinfo_new_cubes_coadd.h>
61 #include <sinfo_new_stdstar.h>
62 #include <sinfo_functions.h>
63 #include <sinfo_tpl_utils.h>
64 #include <sinfo_tpl_dfs.h>
65 #include <sinfo_hidden.h>
66 #include <sinfo_globals.h>
67 #include <sinfo_msg.h>
68 #include <sinfo_rec_utils.h>
69 #include <sinfo_error.h>
70 #include <sinfo_utils_wrappers.h>
71 
72 
73 
74 
75 /*-----------------------------------------------------------------------------
76  Functions prototypes
77  -----------------------------------------------------------------------------*/
78 static int sinfo_rec_stdstar_create(cpl_plugin *) ;
79 static int sinfo_rec_stdstar_exec(cpl_plugin *) ;
80 static int sinfo_rec_stdstar_destroy(cpl_plugin *) ;
81 static int sinfo_rec_stdstar(cpl_parameterlist *, cpl_frameset *);
82 
83 /*-----------------------------------------------------------------------------
84  Static variables
85  -----------------------------------------------------------------------------*/
86 
87 static char sinfo_rec_stdstar_description1[] =
88  "This recipe performs science data reduction.\n"
89  "The input files are science object and sky frames \n"
90  "with tags STD_NODDING and SKY_STD_NODDING\n";
91 
92 
93 static char sinfo_rec_stdstar_description2[] =
94  "Master calibration frames:\n"
95  "A corresponding (band,preoptics) wavelength map image with tag WAVE_MAP\n"
96  "A corresponding (band,preoptics) master flat field with tag MASTER_FLAT_LAMP\n"
97  "A corresponding (band,preoptics) master bad pixel map with tag MASTER_BP_MAP\n"
98  "A corresponding (band,preoptics) slitlets position frame with tag SLIT_POS\n"
99  "A corresponding (band) distortion table with tag DISTORTION\n"
100  "A corresponding (band) slitlet distance table with tag SLITLETS_DISTANCE\n";
101 
102 
103 static char sinfo_rec_stdstar_description3[] =
104  "The output is an image resulting from the IMA1 op IMA2 where op indicates\n"
105  "A reference table with the position of the first column \n"
106  "with tag FIRST_COLUMN\n"
107  "Relevant outputs are:\n"
108  "combined cubes (PRO.CATG=x_OBS x=STD,OBJ,PSF)\n"
109  "reconstructed cube (PRO.CATG=COADD_x_OBS x=STD,OBJ,PSF)\n";
110 
111 
112 static char sinfo_rec_stdstar_description4[] =
113  "An average along Z of the reconstructed cube \n"
114  "(PRO.CATG=MED_x_OBS x=STD,OBJ,PSF)\n"
115  "The bad pixel map associated to the cube \n"
116  "(PRO.CATG=BP_MAP_COADD_x_OBS x=STD,OBJ,PSF)\n"
117  "The std star spectrum image (PRO.CATG=STD_SPECTRUM)\n"
118  "The std start spectrum and efficiency spectrum table (PRO.CATG=STD_SPECTRA)\n"
119  "\n";
120 
121 
122 static char sinfo_rec_stdstar_description[1300];
123 
124 /*-----------------------------------------------------------------------------
125  Functions code
126  ----------------------------------------------------------------------------*/
127 /*--------------------------------------------------------------------------*/
131 /*--------------------------------------------------------------------------*/
133 /*--------------------------------------------------------------------------*/
142 /*--------------------------------------------------------------------------*/
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_stdstar_description,sinfo_rec_stdstar_description1);
153  strcat(sinfo_rec_stdstar_description,sinfo_rec_stdstar_description2);
154  strcat(sinfo_rec_stdstar_description,sinfo_rec_stdstar_description3);
155  strcat(sinfo_rec_stdstar_description,sinfo_rec_stdstar_description4);
156 
157 
158  cpl_plugin_init(plugin,
159  CPL_PLUGIN_API,
160  SINFONI_BINARY_VERSION,
161  CPL_PLUGIN_TYPE_RECIPE,
162  "sinfo_rec_stdstar",
163  "Standard star data reduction",
164  sinfo_rec_stdstar_description,
165  "Andrea Modigliani",
166  "Andrea.Modigliani@eso.org",
167  sinfo_get_license(),
168  sinfo_rec_stdstar_create,
169  sinfo_rec_stdstar_exec,
170  sinfo_rec_stdstar_destroy);
171 
172  cpl_pluginlist_append(list, plugin);
173 
174  return 0;
175 
176 }
177 
178 
179 
180 /*---------------------------------------------------------------------------*/
188 /*---------------------------------------------------------------------------*/
189 
190 
191 static int sinfo_rec_stdstar_create(cpl_plugin *plugin)
192 {
193  cpl_recipe * recipe ;
194 
195  /* Check that the plugin is part of a valid recipe */
196  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
197  recipe = (cpl_recipe *)plugin ;
198  else return -1 ;
199  cpl_error_reset();
200  irplib_reset();
201 
202  /* Create the parameters list in the cpl_recipe object */
203  recipe->parameters = cpl_parameterlist_new() ;
204 
205 
206  /*
207  * Fill the parameter list.
208  */
209  sinfo_product_config_add(recipe->parameters);
210  sinfo_prepare_stacked_frames_config_add(recipe->parameters);
211  sinfo_objnod_config_add(recipe->parameters);
212  sinfo_skycor_config_add(recipe->parameters);
213  sinfo_standard_star_config_add(recipe->parameters);
214 
215  return 0;
216 
217 }
218 
219 /*---------------------------------------------------------------------------*/
225 /*---------------------------------------------------------------------------*/
226 static int sinfo_rec_stdstar_exec(cpl_plugin *plugin)
227 {
228  cpl_recipe * recipe ;
229 
230  /* Get the recipe out of the plugin */
231  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
232  recipe = (cpl_recipe *)plugin ;
233  else return -1 ;
234 
235  return sinfo_rec_stdstar(recipe->parameters, recipe->frames);
236 
237 }
238 
239 /*---------------------------------------------------------------------------*/
245 /*---------------------------------------------------------------------------*/
246 static int sinfo_rec_stdstar_destroy(cpl_plugin *plugin)
247 {
248  cpl_recipe * recipe ;
249 
250  /* Get the recipe out of the plugin */
251  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
252  recipe = (cpl_recipe *)plugin ;
253  else return -1 ;
254 
255  cpl_parameterlist_delete(recipe->parameters);
256  return 0;
257 
258 }
259 
260 
261 /*---------------------------------------------------------------------------*/
268 /*---------------------------------------------------------------------------*/
269 
270 
271 /*
272  * The actual recipe actually start here.
273  */
274 
275 static int
276 sinfo_rec_stdstar(cpl_parameterlist *config, cpl_frameset *set)
277 {
278 
279 
280  const char* pro_ctg_cube;
281  sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
282  SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
283 
284  if(sinfo_dfs_set_groups(set)) {
285  sinfo_msg_error("Cannot indentify RAW and CALIB frames") ;
286  return -1;
287  }
288 
289  /* ===============================================================
290  Defines several framesets each with a pair obj-sky,
291  stack each pair, put the results in set
292  =============================================================== */
293  ck0(sinfo_cub_stk_frames(config,&set,cpl_func,&pro_ctg_cube),
294  "Cannot stack RAW frames");
295 
296  /* ===============================================================
297  SCI SCIENCE
298  =============================================================== */
299 
300  sinfo_msg("------------------------------") ;
301  sinfo_msg("COADDING CUBES");
302  sinfo_msg("------------------------------") ;
303 
304  ck0(sinfo_new_cubes_coadd(cpl_func,config, set, pro_ctg_cube),
305  "COADDING CUBES") ;
306 
307  sinfo_msg("------------------------------") ;
308  sinfo_msg("COADDED CUBES");
309  sinfo_msg("------------------------------") ;
310 
311  /* ===============================================================
312  STDSTAR
313  =============================================================== */
314  sinfo_msg("------------------------------") ;
315  sinfo_msg("STD STAR DATA REDUCTION");
316  sinfo_msg("------------------------------") ;
317 
318  ck0(sinfo_new_stdstar(cpl_func,config, set ),"REDUCING STD STAR DATA") ;
319  sinfo_msg("STD STAR DATA REDUCTION SUCCESS") ;
320 
321 
322  cleanup:
323 
324  if (cpl_error_get_code() != CPL_ERROR_NONE) {
325  return -1;
326  } else {
327  return 0;
328  }
329 
330 
331 }
332