sinfo_rec_wavecal.c

00001 /* $Id: sinfo_rec_wavecal.c,v 1.18 2006/12/19 17:01:36 amodigli Exp $
00002  *
00003  * This file is part of the SINFONI Pipeline
00004  * Copyright (C) 2002,2003 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020  
00021 /*
00022  * $Author: amodigli $
00023  * $Date: 2006/12/19 17:01:36 $
00024  * $Revision: 1.18 $
00025  * $Name:  $
00026  */
00027 
00028  /****************************************************************
00029   *          Wave_Cal Frames Data Reduction                          *
00030   ****************************************************************/
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #ifdef HAVE_CONFIG_H
00037 #include <config.h>          /* allows the program compilation */
00038 #endif
00039 
00040 /* std */
00041 #include <strings.h>
00042 #include <string.h>
00043 #include <stdio.h>
00044 
00045 
00046 /* cpl */
00047 #include <cpl.h>      
00048 
00049 /* irplib */
00050 #include <irplib_utils.h>
00051 
00052 /* sinfoni */
00053 #include <sinfo_pro_types.h>
00054 #include <sinfo_product_config.h>
00055 #include <sinfo_prepare_stacked_frames_config.h>
00056 #include <sinfo_wavecal_config.h>
00057 #include <sinfo_raw_types.h>
00058 #include <sinfo_tpl_utils.h>
00059 #include <sinfo_tpl_dfs.h>
00060 #include <sinfo_hidden.h>
00061 #include <sinfo_globals.h>
00062 #include <sinfo_functions.h>
00063 #include <sinfo_msg.h>
00064 #include <sinfo_new_prepare_stacked_frames.h>
00065 #include <sinfo_new_wave_cal_slit2.h>
00066 #include <sinfo_error.h>
00067 #include <sinfo_utils_wrappers.h>
00068 
00069 /*-----------------------------------------------------------------------------
00070                             Functions prototypes
00071  -----------------------------------------------------------------------------*/
00072 static int sinfo_rec_wavecal_create(cpl_plugin *);
00073 static int sinfo_rec_wavecal_exec(cpl_plugin *);
00074 static int sinfo_rec_wavecal_destroy(cpl_plugin *);
00075 static int sinfo_rec_wavecal(cpl_parameterlist *, cpl_frameset *);
00076 
00077 /*-----------------------------------------------------------------------------
00078                             Static variables
00079  -----------------------------------------------------------------------------*/
00080 
00081 static char sinfo_rec_wavecal_description1[] =
00082 "This recipe performs wavelength calibration.\n"
00083 "The input files are on/off arc lamp frames with tag WAVE_LAMP\n"
00084 "Master calibration frame input is:\n"
00085 "A corresponding (band) reference line table with tag REF_LINE_ARC\n"
00086 "A corresponding (band) distortion table with tag DISTORTION\n"
00087 "A corresponding (band,preoptic) master flat with tag MASTER_FLAT_LAMP\n"
00088 "A corresponding (band,preoptics) master bad "
00089 "pixel map with tag MASTER_BP_MAP\n";
00090 
00091 
00092 static char sinfo_rec_wavecal_description2[] =
00093 "If wcal-estimate_ind=TRUE, a corresponding (band,preoptics) slitlet position\n"
00094 "guess table SLIT_POS_GUESS (for example a copy of the SLIT_POS product)\n"
00095 "If wcal-calib_indicator=FALSE, a corresponding (band,preoptics) parabolic \n"
00096 "fit coefficients table WAVE_COEF_SLIT\n"
00097 "If sinfoni.wavecal.slitpos_boostrap_switch=FALSE \n"
00098 "(wcal-calib-slitpos_bootstrap=0),\n"
00099 "a corresponding (band,preoptics) slitlets position table with tag SLIT_POS\n";
00100 
00101 
00102 
00103 static char sinfo_rec_wavecal_description3[] =
00104 "The main products are:\n"
00105 "The master flat field corrected for distortions \n"
00106 "(PRO.CATG=MFLAT_STACKED_DIST)\n"
00107 "The arc lamp frames stacked (PRO.CATG=WAVE_LAMP_STACKED)\n"
00108 "The wavelength map (PRO.CATG=WAVE_MAP)\n"
00109 "The slitlet position table (PRO.CATG=SLIT_POS)\n"
00110 "A parabolic fit coefficients table (PRO.CATG=WAVE_COEF_SLIT)\n"
00111 "Parameters relative to arc lamp line fit: (PRO.CATG=WAVE_FIT_PARAMS)\n"
00112 "Information on relevant parameters can be found with\n"
00113 "esorex --params sinfo_rec_wavecal\n"
00114 "esorex --help sinfo_rec_wavecal\n"
00115 "\n";
00116 
00117 
00118 static char sinfo_rec_wavecal_description[1300];
00119 
00120 /*-----------------------------------------------------------------------------
00121                                 Functions code
00122  ----------------------------------------------------------------------------*/
00123 /*---------------------------------------------------------------------------*/
00127 /*---------------------------------------------------------------------------*/
00128 
00130 /*---------------------------------------------------------------------------*/
00139 /*---------------------------------------------------------------------------*/
00140 
00141 int
00142 cpl_plugin_get_info(cpl_pluginlist *list)
00143 {
00144 
00145   cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00146   cpl_plugin *plugin = &recipe->interface;
00147 
00148 
00149   strcpy(sinfo_rec_wavecal_description,sinfo_rec_wavecal_description1);
00150   strcat(sinfo_rec_wavecal_description,sinfo_rec_wavecal_description2);
00151   strcat(sinfo_rec_wavecal_description,sinfo_rec_wavecal_description3);
00152 
00153   cpl_plugin_init(plugin,
00154           CPL_PLUGIN_API,
00155           SINFONI_BINARY_VERSION,
00156           CPL_PLUGIN_TYPE_RECIPE,
00157           "sinfo_rec_wavecal",
00158           "Wavelength calibration and slitpos determination",
00159           sinfo_rec_wavecal_description,
00160           "Andrea Modigliani",
00161           "Andrea.Modigliani@eso.org",
00162           sinfo_get_license(),
00163           sinfo_rec_wavecal_create,
00164           sinfo_rec_wavecal_exec,
00165           sinfo_rec_wavecal_destroy);
00166  
00167   cpl_pluginlist_append(list, plugin);
00168 
00169   return 0;
00170 
00171 }
00172 
00173 /*---------------------------------------------------------------------------*/
00181 /*---------------------------------------------------------------------------*/
00182  
00183 static int sinfo_rec_wavecal_create(cpl_plugin *plugin)
00184 {
00185    cpl_recipe      * recipe ;
00186 
00187     /* Check that the plugin is part of a valid recipe */
00188     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00189         recipe = (cpl_recipe *)plugin ;
00190     else return -1 ;
00191     cpl_error_reset();
00192     irplib_reset();
00193 
00194     /* Create the parameters list in the cpl_recipe object */
00195     recipe->parameters = cpl_parameterlist_new() ; 
00196 
00197 
00198   /*
00199    * Fill the parameter list.
00200    */
00201 
00202   /* Wavelength calibration  */
00203   sinfo_product_config_add(recipe->parameters);
00204   sinfo_prepare_stacked_frames_config_add(recipe->parameters);
00205   sinfo_wavecal_config_add(recipe->parameters);
00206   return 0;
00207 
00208 }
00209 
00210 /*---------------------------------------------------------------------------*/
00216 /*---------------------------------------------------------------------------*/
00217 
00218 
00219 static int sinfo_rec_wavecal_exec(cpl_plugin *plugin)
00220 {
00221 
00222   cpl_recipe *recipe = (cpl_recipe *) plugin;
00223 
00224   /* Get the recipe out of the plugin */
00225   if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00226       recipe = (cpl_recipe *)plugin ;
00227   else return -1 ;
00228 
00229   return sinfo_rec_wavecal(recipe->parameters, recipe->frames);
00230 
00231 }
00232 
00233 /*---------------------------------------------------------------------------*/
00239 /*---------------------------------------------------------------------------*/
00240 static int sinfo_rec_wavecal_destroy(cpl_plugin *plugin)
00241 {
00242   cpl_recipe  *   recipe ;
00243     /* Get the recipe out of the plugin */
00244     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00245         recipe = (cpl_recipe *)plugin ;
00246     else return -1 ;
00247 
00248   cpl_parameterlist_delete(recipe->parameters);
00249 
00250   return 0;
00251 
00252 }
00253 
00254 /*---------------------------------------------------------------------------*/
00261 /*---------------------------------------------------------------------------*/
00262 /*
00263  * The actual recipe actually start here.
00264  */
00265 
00266 static int sinfo_rec_wavecal(cpl_parameterlist *config, cpl_frameset *set)
00267 {
00268  
00269   int sw=0;
00270   fake* fk=NULL;
00271   cpl_parameter* p=NULL;
00272   cpl_frameset* wrk_set=NULL;
00273   cpl_frame* frame=NULL;
00274   int ind_index=0;
00275   fk=sinfo_fake_new();
00276 
00277    sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
00278         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
00279 
00280   ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
00281 
00282   /* hidden parameters */
00283   check_nomsg(p=cpl_parameterlist_find(config,
00284                                        "sinfoni.wavecal.slitpos_boostrap"));
00285   check_nomsg(sw=cpl_parameter_get_bool(p));
00286   if( (sw == 1) ) {
00287     check_nomsg(wrk_set=cpl_frameset_duplicate(set));
00288 
00289     check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.stacked.ind_index"));
00290     check_nomsg(ind_index=cpl_parameter_get_bool(p));
00291     check_nomsg(cpl_parameter_set_bool(p,TRUE));
00292 
00293     sinfo_msg("---------------------------------------");
00294     sinfo_msg("%s FRAME DETERMINATION", PRO_WAVE_LAMP_STACKED);
00295     sinfo_msg("---------------------------------------");
00296     ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, wrk_set, 
00297                      PRO_WAVE_LAMP_STACKED,0,fk),
00298        "FAILED STACKING FRAME %s",PRO_WAVE_LAMP_STACKED);
00299     
00300     sinfo_msg("%s FRAME DETERMINATION SUCCESS", PRO_WAVE_LAMP_STACKED);
00301     
00302     ck0(sinfo_new_wave_cal_slit2(cpl_func,config, wrk_set),
00303     "FIRST PART OF WAVELENGTH CALIBRATION FAILED") ;
00304     sinfo_msg("FIRST PART OF WAVELENGTH CALIBRATION") ;
00305      
00306     check_nomsg(frame = cpl_frameset_find(wrk_set,PRO_SLIT_POS_GUESS));
00307     check_nomsg(cpl_frameset_insert(set,cpl_frame_duplicate(frame)));
00308     check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.stacked.ind_index"));
00309     if(ind_index == 1) {
00310        check_nomsg(cpl_parameter_set_bool(p,TRUE));
00311        check_nomsg(p=cpl_parameterlist_find(config,
00312                                            "sinfoni.wavecal.slitpos_boostrap"));
00313        check_nomsg(cpl_parameter_set_bool(p,TRUE));
00314        sinfo_msg("Set ind_index to TRUE");
00315     } else {
00316        check_nomsg(cpl_parameter_set_bool(p,FALSE));
00317        check_nomsg(p=cpl_parameterlist_find(config,
00318                                           "sinfoni.wavecal.slitpos_boostrap"));
00319        check_nomsg(cpl_parameter_set_bool(p,FALSE));
00320        sinfo_msg("Set ind_index to FALSE");
00321     }
00322     sinfo_free_frameset(&wrk_set);
00323   }
00324  
00325 
00326   sinfo_msg("---------------------------------------------");
00327   sinfo_msg("%s FRAME DETERMINATION", PRO_WAVE_LAMP_STACKED);
00328   sinfo_msg("---------------------------------------------");
00329  
00330   ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, set, 
00331                        PRO_WAVE_LAMP_STACKED,0,fk),
00332       "%s FRAME DETERMINATION FAILED",PRO_WAVE_LAMP_STACKED);
00333   sinfo_msg("%s FRAME DETERMINATION SUCCESS", PRO_WAVE_LAMP_STACKED);
00334 
00335   sinfo_msg("---------------------------------------------");
00336   sinfo_msg("WAVELENGTH CALIBRATION");
00337   sinfo_msg("---------------------------------------------");
00338   
00339   ck0(sinfo_new_wave_cal_slit2(cpl_func,config, set),
00340       "FAILED WAVELENGTH CALIBRATION");
00341   sinfo_msg("SUCCESS WAVELENGTH CALIBRATION");
00342 
00343   sinfo_fake_delete(&fk);
00344   return 0 ;
00345 
00346  cleanup:
00347 
00348   sinfo_free_frameset(&wrk_set);
00349   sinfo_fake_delete(&fk);
00350   irplib_error_dump(CPL_MSG_ERROR,CPL_MSG_ERROR);
00351   return -1 ;
00352 
00353 }

Generated on Wed Jan 17 08:33:43 2007 for SINFONI Pipeline Reference Manual by  doxygen 1.4.4