sinfo_rec_jitter.c

00001 /* $Id: sinfo_rec_jitter.c,v 1.23 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  * $Author: amodigli $
00022  * $Date: 2006/12/19 17:01:36 $
00023  * $Revision: 1.23 $
00024  * $Name:  $
00025  */
00026 
00027  /****************************************************************
00028   *           Object Data reduction                              *
00029   ****************************************************************/
00030 
00031 #ifdef HAVE_CONFIG_H
00032 #include <config.h>          /* allows the program compilation */
00033 #endif
00034 
00035 /*-----------------------------------------------------------------------------
00036                                 Includes
00037  ----------------------------------------------------------------------------*/
00038 
00039 /* std */
00040 #include <strings.h>
00041 #include <string.h>
00042 #include <stdio.h>
00043 #include <math.h>
00044 #include <libgen.h>
00045 
00046 
00047 /* cpl */
00048 #include <cpl.h>  
00049 
00050 /* irplib */
00051 #include <irplib_utils.h>
00052 
00053 /* sinfoni */
00054 #include <sinfo_pro_types.h>
00055 #include <sinfo_product_config.h>
00056 #include <sinfo_prepare_stacked_frames_config.h>
00057 #include <sinfo_objnod_config.h>
00058 #include <sinfo_skycor_config.h>
00059 #include <sinfo_psf_config.h>
00060 #include <sinfo_standard_star_config.h>
00061 #include <sinfo_new_prepare_stacked_frames.h>
00062 #include <sinfo_new_cubes_coadd.h>
00063 #include <sinfo_new_stdstar.h>
00064 #include <sinfo_new_psf.h>
00065 #include <sinfo_key_names.h>
00066 #include <sinfo_raw_types.h>
00067 #include <sinfo_functions.h>
00068 #include <sinfo_tpl_utils.h>
00069 #include <sinfo_tpl_dfs.h>
00070 #include <sinfo_hidden.h>
00071 #include <sinfo_globals.h>
00072 #include <sinfo_msg.h>
00073 #include <sinfo_rec_utils.h>
00074 #include <sinfo_error.h>
00075 #include <sinfo_utils_wrappers.h>
00076 
00077 /*-----------------------------------------------------------------------------
00078                             Functions prototypes
00079  ----------------------------------------------------------------------------*/
00080 
00081 static int sinfo_rec_jitter_create(cpl_plugin *) ;
00082 static int sinfo_rec_jitter_exec(cpl_plugin *) ;
00083 static int sinfo_rec_jitter_destroy(cpl_plugin *) ;
00084 static int sinfo_rec_jitter(cpl_parameterlist *config, cpl_frameset *set);
00085 /*-----------------------------------------------------------------------------
00086                             Static variables
00087  ----------------------------------------------------------------------------*/
00088 
00089 static char sinfo_rec_jitter_description1[] =
00090 "This recipe performs science data reduction.\n"
00091 "The input files are:\n"
00092 "science object and sky frames with tags OBJECT_NODDING and SKY_NODDING or\n"
00093 "Telluric standard star frames and sky frames with tags STD and SKY_STD or\n"
00094 "PSF standard star and sky frames with tags \n"
00095 "PSF_CALIBRATOR and SKY_PSF_CALIBRATOR\n"
00096 "and Master calibration frames:\n";
00097 
00098 
00099 static char sinfo_rec_jitter_description2[] =
00100 "A corresponding (band,preoptics) wavelength map image with tag WAVE_MAP\n"
00101 "A corresponding (band,preoptics) master flat field with tag MASTER_FLAT_LAMP\n"
00102 "A corresponding (band,preoptics) master bad pixel map with tag MASTER_BP_MAP\n"
00103 "A corresponding (band,preoptics) slitlets position frame with tag SLIT_POS\n"
00104 "A corresponding (band) distortion table with tag DISTORTION\n"
00105 "A corresponding (band) slitlet distance table with tag SLITLETS_DISTANCE\n";
00106 
00107 
00108 static char sinfo_rec_jitter_description3[] =
00109 "The output is an image resulting from the IMA1 op IMA2 where op indicates\n"
00110 "A reference table with the position of the first "
00111 "column with tag FIRST_COLUMN\n"
00112 "Relevant outputs are:\n"
00113 "combined cubes (PRO.CATG=x_OBS x=STD,OBJ,PSF)\n"
00114 "reconstructed cube (PRO.CATG=COADD_x_OBS x=STD,OBJ,PSF)\n"
00115 "An average along Z of the reconstructed cube \n"
00116 "(PRO.CATG=MED_x_OBS x=STD,OBJ,PSF)\n"
00117 "The bad pixel map associated to the cube \n"
00118 "(PRO.CATG=BP_MAP_COADD_x_OBS x=STD,OBJ,PSF)\n";
00119 
00120 
00121 static char sinfo_rec_jitter_description4[] =
00122 "Information on relevant parameters can be found with\n"
00123 "esorex --params sinfo_rec_jitter\n"
00124 "esorex --help sinfo_rec_jitter\n"
00125 "\n";
00126 
00127 static char sinfo_rec_jitter_description[1400];
00128 
00129 /*-----------------------------------------------------------------------------
00130                                 Functions code
00131  ----------------------------------------------------------------------------*/
00132 /*---------------------------------------------------------------------------*/
00136 /*---------------------------------------------------------------------------*/
00138 /*---------------------------------------------------------------------------*/
00147 /*---------------------------------------------------------------------------*/
00148 
00149 int
00150 cpl_plugin_get_info(cpl_pluginlist *list)
00151 {
00152 
00153   cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00154   cpl_plugin *plugin = &recipe->interface;
00155 
00156   strcpy(sinfo_rec_jitter_description,sinfo_rec_jitter_description1);
00157   strcat(sinfo_rec_jitter_description,sinfo_rec_jitter_description2);
00158   strcat(sinfo_rec_jitter_description,sinfo_rec_jitter_description3);
00159   strcat(sinfo_rec_jitter_description,sinfo_rec_jitter_description4);
00160 
00161   cpl_plugin_init(plugin,
00162           CPL_PLUGIN_API,
00163           SINFONI_BINARY_VERSION,
00164           CPL_PLUGIN_TYPE_RECIPE,
00165           "sinfo_rec_jitter",
00166           "Object or STD star or PSF star data reduction",
00167            sinfo_rec_jitter_description,
00168           "Andrea Modigliani",
00169           "Andrea.Mdigliani@eso.org",
00170           sinfo_get_license(),
00171           sinfo_rec_jitter_create,
00172           sinfo_rec_jitter_exec,
00173           sinfo_rec_jitter_destroy);
00174 
00175   cpl_pluginlist_append(list, plugin);
00176 
00177   return 0;
00178 
00179 }
00180 
00181 /*---------------------------------------------------------------------------*/
00189 /*---------------------------------------------------------------------------*/
00190 static int sinfo_rec_jitter_create(cpl_plugin *plugin)
00191 {
00192     cpl_recipe      * recipe ;
00193 
00194     /* Check that the plugin is part of a valid recipe */
00195     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00196         recipe = (cpl_recipe *)plugin ;
00197     else return -1 ;
00198   cpl_error_reset();
00199   irplib_reset();
00200 
00201     /* Create the parameters list in the cpl_recipe object */
00202     recipe->parameters = cpl_parameterlist_new() ; 
00203 
00204 
00205   /*
00206    * Fill the parameter list.
00207    */
00208 
00209   sinfo_product_config_add(recipe->parameters);
00210   sinfo_prepare_stacked_frames_config_add(recipe->parameters);
00211   sinfo_objnod_config_add(recipe->parameters); 
00212   sinfo_skycor_config_add(recipe->parameters); 
00213   sinfo_standard_star_config_add(recipe->parameters);
00214   sinfo_psf_config_add(recipe->parameters);
00215 
00216   return 0;
00217 
00218 }
00219 
00220 /*---------------------------------------------------------------------------*/
00226 /*---------------------------------------------------------------------------*/
00227 static int sinfo_rec_jitter_exec(cpl_plugin *plugin)
00228 {
00229  
00230   cpl_recipe *recipe = (cpl_recipe *) plugin;
00231 
00232   /* Get the recipe out of the plugin */
00233   if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00234       recipe = (cpl_recipe *)plugin ;
00235   else return -1 ;
00236 
00237   return sinfo_rec_jitter(recipe->parameters, recipe->frames);
00238 
00239 }
00240 
00241 /*---------------------------------------------------------------------------*/
00247 /*---------------------------------------------------------------------------*/
00248 static int sinfo_rec_jitter_destroy(cpl_plugin *plugin)
00249 {
00250 
00251    cpl_recipe  *   recipe ;
00252     
00253     /* Get the recipe out of the plugin */
00254     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00255         recipe = (cpl_recipe *)plugin ;
00256     else return -1 ;
00257 
00258   cpl_parameterlist_delete(recipe->parameters);
00259 
00260   return 0;
00261 
00262 }
00263 
00264 /*---------------------------------------------------------------------------*/
00271 /*---------------------------------------------------------------------------*/
00272 
00273 /*
00274  * The actual recipe actually start here.
00275  */
00276 
00277 static int sinfo_rec_jitter(cpl_parameterlist *config, cpl_frameset *set)
00278 {
00279   const char* pro_ctg_cube;
00280   cpl_parameter* p=NULL;
00281   int psf_sw=0;
00282   int std_sw=0;
00283   sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
00284         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
00285 
00286   if(sinfo_dfs_set_groups(set)) {
00287     sinfo_msg_error("Cannot indentify RAW and CALIB frames") ;
00288     return -1;
00289   }
00290 
00291   /* =============================================================== 
00292      Defines several framesets each with a pair obj-sky, 
00293      stack each pair, put the results in set 
00294      =============================================================== */
00295   ck0(sinfo_cub_stk_frames(config,&set,cpl_func,&pro_ctg_cube),
00296       "Cannot stack RAW frames") ;
00297 
00298   /* =============================================================== 
00299      SCI OBJNOD 
00300      =============================================================== */
00301      sinfo_msg("------------------------------") ; 
00302      sinfo_msg("COADDING CUBES");
00303      sinfo_msg("------------------------------") ; 
00304 
00305      ck0(sinfo_new_cubes_coadd(cpl_func,config, set, pro_ctg_cube),
00306      "COADDING CUBES") ;
00307        
00308      sinfo_msg("------------------------------") ; 
00309      sinfo_msg("COADDED CUBES");
00310      sinfo_msg("------------------------------") ; 
00311 
00312   /* =============================================================== 
00313      PSF
00314      =============================================================== */
00315   
00316   if((strcmp(pro_ctg_cube,PRO_COADD_OBJ) == 0) ||
00317      (strcmp(pro_ctg_cube,PRO_COADD_PSF) == 0) ||
00318      (strcmp(pro_ctg_cube,PRO_COADD_STD) == 0) ||
00319      (strcmp(pro_ctg_cube,PRO_COADD_PUPIL) == 0) ) {
00320 
00321 
00322     p = cpl_parameterlist_find(config, "sinfoni.psf.switch");
00323     psf_sw = cpl_parameter_get_bool(p);
00324     sinfo_msg("switch=%d",psf_sw);
00325     if(psf_sw) {
00326       sinfo_msg("------------------------------") ;
00327       sinfo_msg("REDUCE PSF STD STAR FRAMES");
00328       sinfo_msg("------------------------------") ; 
00329       if ( -1 == sinfo_new_psf(cpl_func,config,set) ) {
00330     sinfo_msg_error("REDUCING PSF STD STAR FRAMES") ;
00331       } else {
00332     sinfo_msg("SUCCESS REDUCE PSF STD STAR FRAMES") ;
00333       }
00334     }
00335  
00336     p = cpl_parameterlist_find(config, "sinfoni.std_star.switch");
00337     std_sw = cpl_parameter_get_bool(p);
00338     sinfo_msg("switch=%d",std_sw);
00339     if(std_sw) {
00340       sinfo_msg("------------------------------") ;
00341       sinfo_msg("STD STAR DATA REDUCTION");
00342       sinfo_msg("------------------------------") ;
00343       if ( -1 == sinfo_new_stdstar(cpl_func,config, set ) ) {
00344     sinfo_msg_error("REDUCING STD STAR DATA") ;
00345       } else {
00346     sinfo_msg("STD STAR DATA REDUCTION SUCCESS") ;
00347       }
00348     }
00349   } 
00350   return 0 ;
00351  cleanup:
00352   irplib_error_dump(CPL_MSG_ERROR,CPL_MSG_ERROR);
00353   return -1;
00354 
00355 }
00356 

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