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