si_rec_mflat.c

00001 /* $Id: si_rec_mflat.c,v 1.22 2005/10/14 16:09:47 amodigli Exp $
00002  *
00003  * This file is part of the CPL (Common Pipeline Library)
00004  * Copyright (C) 2002 European Southern Observatory
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library 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 GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; 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: 2005/10/14 16:09:47 $
00023  * $Revision: 1.22 $
00024  * $Name:  $
00025  */
00026 
00027  /****************************************************************
00028   *          Rec_Lampflats Frames 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 
00044 /* cx */
00045 #include <cxmacros.h>
00046 #include <cxtypes.h>
00047 #include <cxmessages.h>  
00048 
00049 /* qfits */
00050 #include <xmemory.h>
00051 
00052 /* cpl */
00053 #include <cpl.h>    
00054 
00055 /* sinfoni */
00056 #include <sinfoni_pro_types.h>
00057 #include <sinfoni_bp_config.h>
00058 #include <sinfoni_bp_norm_config.h>
00059 #include <sinfoni_lamp_flats_config.h>
00060 #include <bp_norm.h>
00061 #include <lamp_flats.h>
00062 #include <sinfoni_functions.h>
00063 #include <add_bp_map.h>
00064 #include <cubecreate.h>
00065 #include <create_resampled.h>
00066 #include <sinfoni_tpl_utils.h>
00067 #include <sinfoni_tpl_dfs.h>
00068 #include <sinfoni_memory.h>
00069 
00070 
00071 /*-----------------------------------------------------------------------------
00072                             Functions prototypes
00073  -----------------------------------------------------------------------------*/
00074 
00075  static cxint si_rec_mflat(cpl_parameterlist *, cpl_frameset *);
00076 
00077 
00078 /*-----------------------------------------------------------------------------
00079                             Static variables
00080  -----------------------------------------------------------------------------*/
00081 
00082 static char si_rec_mflat_description[] =
00083 "This recipe reduce normal raw flat fields.\n"
00084 "The input files are a set of flat fields with tag FLAT_LAMP\n"
00085 "optionally one may have in input also several bad pixel maps to be coadded.\n"
00086 "The main products are a master flat field (PRO.CATG=MASTER_FLAT_LAMP) image\n"
00087 "a bad pixel map (PRO.CATG=BP_MAP_NO), "
00088 "a master bad pixel map (PRO.CATG=MASTER_BP_MAP) resulting by the coaddition\n"
00089 "of all bad pixel maps.\n"
00090 "Information on relevant parameters can be found with\n"
00091 "esorex --params si_rec_mflat\n"
00092 "esorex --help si_rec_mflat\n"
00093 "\n";
00094 
00095 
00096 
00097 /*-----------------------------------------------------------------------------
00098                                 Functions code
00099  -----------------------------------------------------------------------------*/
00100 
00101  /*
00102   *
00103   * Create the recipe instance, i.e. setup the parameter list for this
00104   * recipe and make it available to the application using the interface.
00105   *
00106   */
00107 
00108 
00109 cxint
00110 si_rec_mflat_create(cpl_plugin *plugin)
00111 {
00112 
00113   /*
00114    * We have to provide the option we accept to the application.
00115    * We need to setup our parameter list and hook it into the recipe
00116    * interface.
00117    */
00118   cpl_recipe *recipe = (cpl_recipe *)plugin;
00119   recipe->parameters = cpl_parameterlist_new();
00120   if(recipe->parameters == NULL) {
00121     return 1;
00122   }
00123 
00124   /*
00125    * Fill the parameter list.
00126    */
00127   sinfoni_bp_norm_config_add(recipe->parameters);
00128   sinfoni_lamp_flats_config_add(recipe->parameters);
00129 
00130 
00131   return 0;
00132 
00133 }
00134 
00135 cxint
00136 si_rec_mflat_exec(cpl_plugin *plugin)
00137 {
00138 
00139   cpl_recipe *recipe = (cpl_recipe *) plugin;
00140   if(recipe->parameters == NULL) {
00141     return 1;
00142   }
00143   if(recipe->frames == NULL) {
00144     return 1;
00145   }
00146   cpl_error_reset();
00147   return si_rec_mflat(recipe->parameters, recipe->frames);
00148 
00149 }
00150 
00151 cxint
00152 si_rec_mflat_destroy(cpl_plugin *plugin)
00153 {
00154 
00155   cpl_recipe *recipe = (cpl_recipe *) plugin;
00156   /*
00157    * We just destroy what was created during the plugin initializzation phase
00158    * i.e. the parameter list. The frame set is managed by the application which
00159    * called us, so that we must not touch it.
00160    */
00161   /* cx_print("destroy\n"); */
00162   cpl_parameterlist_delete(recipe->parameters);
00163 
00164   return 0;
00165 
00166 }
00167 
00168 
00169 int
00170 cpl_plugin_get_info(cpl_pluginlist *list)
00171 {
00172 
00173   cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00174   cpl_plugin *plugin = &recipe->interface;
00175 
00176 
00177   cpl_plugin_init(plugin,
00178           CPL_PLUGIN_API,
00179           SINFONI_BINARY_VERSION,
00180           CPL_PLUGIN_TYPE_RECIPE,
00181           "si_rec_mflat",
00182           "Master flat determination",
00183           si_rec_mflat_description,
00184           "Andrea Modigliani",
00185           "Andrea.Modigliani@eso.org",
00186           sinfoni_get_license(),
00187           si_rec_mflat_create,
00188           si_rec_mflat_exec,
00189           si_rec_mflat_destroy);
00190 
00191   cpl_pluginlist_append(list, plugin);
00192 
00193   return 0;
00194 
00195 }
00196 
00197 
00198 /*
00199  * The actual recipe actually start here.
00200  */
00201 
00202 
00203 static cxint
00204 si_rec_mflat(cpl_parameterlist *config, cpl_frameset *set)
00205 {
00206  
00207   const char *_id = "si_rec_mflat";
00208   int  ind =0;
00209   cpl_parameter* p;
00210 
00211   if(sinfoni_dfs_set_groups(set)) {
00212 
00213     cpl_msg_error(_id, "Cannot indentify RAW and CALIB frames") ;
00214     return -1;
00215 
00216   }
00217   sinfoni_bp_config_add(config);  
00218   p = cpl_parameterlist_find(config,"sinfoni.bp.method");
00219   cpl_parameter_set_string(p,"Normal");   
00220     /* 
00221        ---------------------------------------------------------
00222                 MASTER_FLAT
00223        ---------------------------------------------------------
00224      */
00225  
00226     cpl_msg_info(_id,"-------------------------------------------");
00227     cpl_msg_info(_id,"MASTER FLAT DETERMINATION                  ");
00228     cpl_msg_info(_id,"-------------------------------------------");
00229     
00230     {
00231         if ( -1 == (ind = lamp_flats(_id,config, set ) ) )
00232         {
00233         cpl_msg_error(_id,"no: %d\n", ind) ;
00234             sinfoni_memory_status();
00235         return -1 ;
00236     }
00237       
00238     cpl_msg_info (_id,"MASTER FLAT DETERMINATION SUCCESS") ; 
00239     }   
00240    
00241 
00242     cpl_msg_info(_id,"-------------------------------------------");
00243     cpl_msg_info(_id,"BP_MAP_NO BAD PIXEL MAP DETERMINATION      ");
00244     cpl_msg_info(_id,"-------------------------------------------");
00245     /* 
00246        ---------------------------------------------------------
00247                 BP_SEARCH
00248        ---------------------------------------------------------
00249      */
00250    
00251       p = cpl_parameterlist_find(config,"sinfoni.bp.method");
00252       cpl_parameter_set_string(p,"Normal");   
00253 
00254 
00255     {
00256             if ( -1 == (ind = badSearchNormal(_id,config,set,PRO_BP_MAP_NO)))
00257         {
00258             cpl_msg_error(_id,"badSearchNormal(), no: %d\n", ind) ;
00259         sinfoni_memory_status();
00260         return -1 ;
00261         }
00262             cpl_msg_info(_id,"BP_MAP_NO BAD PIXEL MAP DETERMINATION SUCCESS");
00263     }
00264 
00265   
00266      cpl_msg_info(_id,"------------------------------------------");
00267      cpl_msg_info(_id,"MASTER_BP_MAP BAD PIXEL MAP DETERMINATION ");
00268      cpl_msg_info(_id,"------------------------------------------");
00269     
00270      {
00271           if ( -1 == (ind = add_bp_map(_id,config, set) ) )
00272         {
00273        cpl_msg_error(_id,"add_bp_map(), no: %d\n", ind) ;
00274             sinfoni_memory_status();
00275        return -1 ;
00276     }
00277         cpl_msg_info(_id,"MASTER_BP_MAP BAD PIXEL MAP DETERMINATION SUCCESS");
00278      }
00279      sinfoni_memory_status(); 
00280     
00281     return 0 ; 
00282 }
00283 
00284 
00285 
00286 

Generated on Wed Oct 26 13:08:54 2005 for SINFONI Pipeline Reference Manual by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001