sinfo_rec_mflat.c

00001 /* $Id: sinfo_rec_mflat.c,v 1.22 2008/02/05 08:13:05 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: 2008/02/05 08:13:05 $
00023  * $Revision: 1.22 $
00024  * $Name: HEAD $
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 /* cpl */
00045 #include <cpl.h>    
00046 #include <irplib_utils.h>
00047 /* sinfoni */
00048 #include <sinfo_pro_types.h>
00049 #include <sinfo_utilities.h>
00050 #include <sinfo_general_config.h>
00051 #include <sinfo_product_config.h>
00052 #include <sinfo_bp_config.h>
00053 #include <sinfo_bp_norm_config.h>
00054 #include <sinfo_lamp_flats_config.h>
00055 #include <sinfo_bp_norm.h>
00056 #include <sinfo_new_lamp_flats.h>
00057 #include <sinfo_functions.h>
00058 #include <sinfo_new_add_bp_map.h>
00059 #include <sinfo_tpl_utils.h>
00060 #include <sinfo_tpl_dfs.h>
00061 #include <sinfo_msg.h>
00062 #include <sinfo_error.h>
00063 #include <sinfo_utils_wrappers.h>
00064 
00065 /*-----------------------------------------------------------------------------
00066                             Functions prototypes
00067  ----------------------------------------------------------------------------*/
00068 static int sinfo_rec_mflat_create(cpl_plugin *);
00069 static int sinfo_rec_mflat_exec(cpl_plugin *);
00070 static int sinfo_rec_mflat_destroy(cpl_plugin *);
00071 static int sinfo_rec_mflat(cpl_parameterlist *, cpl_frameset *);
00072 
00073 
00074 /*-----------------------------------------------------------------------------
00075                             Static variables
00076  ----------------------------------------------------------------------------*/
00077 
00078 static char sinfo_rec_mflat_description[] =
00079 "This recipe reduce normal raw flat fields.\n"
00080 "The input files are a set of flat fields with tag FLAT_LAMP\n"
00081 "optionally one may have in input also several bad pixel maps to be coadded.\n"
00082 "The main products are a master flat field (PRO.CATG=MASTER_FLAT_LAMP) image\n"
00083 "a bad pixel map (PRO.CATG=BP_MAP_NO), "
00084 "a master bad pixel map (PRO.CATG=MASTER_BP_MAP) resulting by the coaddition\n"
00085 "of all bad pixel maps.\n"
00086 "Information on relevant parameters can be found with\n"
00087 "esorex --params sinfo_rec_mflat\n"
00088 "esorex --help sinfo_rec_mflat\n"
00089 "\n";
00090 
00091 
00092 
00093 /*-----------------------------------------------------------------------------
00094                                 Functions code
00095  ----------------------------------------------------------------------------*/
00096 /*---------------------------------------------------------------------------*/
00100 /*---------------------------------------------------------------------------*/
00102 /*---------------------------------------------------------------------------*/
00111 /*---------------------------------------------------------------------------*/
00112 
00113 int cpl_plugin_get_info(cpl_pluginlist *list)
00114 {
00115 
00116   cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00117   cpl_plugin *plugin = &recipe->interface;
00118 
00119 
00120   cpl_plugin_init(plugin,
00121           CPL_PLUGIN_API,
00122           SINFONI_BINARY_VERSION,
00123           CPL_PLUGIN_TYPE_RECIPE,
00124           "sinfo_rec_mflat",
00125           "Master flat determination",
00126           sinfo_rec_mflat_description,
00127           "Andrea Modigliani",
00128           "Andrea.Modigliani@eso.org",
00129           sinfo_get_license(),
00130           sinfo_rec_mflat_create,
00131           sinfo_rec_mflat_exec,
00132           sinfo_rec_mflat_destroy);
00133 
00134   cpl_pluginlist_append(list, plugin);
00135 
00136   return 0;
00137 
00138 }
00139 
00140 
00141 /*---------------------------------------------------------------------------*/
00149 /*---------------------------------------------------------------------------*/
00150 
00151 static int sinfo_rec_mflat_create(cpl_plugin *plugin)
00152 {
00153 
00154     cpl_recipe      * recipe ;
00155 
00156     /* Check that the plugin is part of a valid recipe */
00157     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00158         recipe = (cpl_recipe *)plugin ;
00159     else return -1 ;
00160 
00161    /* Create the parameters list in the cpl_recipe object */
00162     recipe->parameters = cpl_parameterlist_new() ; 
00163 
00164   /*
00165    * Fill the parameter list.
00166    */
00167   sinfo_general_config_add(recipe->parameters);
00168   sinfo_product_config_add(recipe->parameters);
00169   sinfo_bp_norm_config_add(recipe->parameters);
00170   sinfo_lamp_flats_config_add(recipe->parameters);
00171 
00172   return 0;
00173 
00174 }
00175 /*---------------------------------------------------------------------------*/
00181 /*---------------------------------------------------------------------------*/
00182 static int sinfo_rec_mflat_exec(cpl_plugin *plugin)
00183 {
00184     cpl_recipe  *   recipe ;
00185     cpl_errorstate initial_errorstate = cpl_errorstate_get();
00186     /* Get the recipe out of the plugin */
00187     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00188         recipe = (cpl_recipe *)plugin ;
00189     else return -1 ;
00190     cpl_error_reset();
00191     irplib_reset();
00192 
00193     if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
00194         /* Dump the error history since recipe execution start.                
00195            At this point the recipe cannot recover from the error */           
00196         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
00197     } 
00198   return sinfo_rec_mflat(recipe->parameters, recipe->frames);
00199 
00200 }
00201 /*---------------------------------------------------------------------------*/
00207 /*---------------------------------------------------------------------------*/
00208 static int sinfo_rec_mflat_destroy(cpl_plugin *plugin)
00209 {
00210 
00211   cpl_recipe *recipe = (cpl_recipe *) plugin;
00212 
00213   /* Get the recipe out of the plugin */
00214   if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00215       recipe = (cpl_recipe *)plugin ;
00216   else return -1 ;
00217 
00218   cpl_parameterlist_delete(recipe->parameters);
00219   return 0;
00220 
00221 }
00222 
00223 /*---------------------------------------------------------------------------*/
00230 /*---------------------------------------------------------------------------*/
00231 /*
00232  * The actual recipe actually start here.
00233  */
00234 
00235 
00236 static int
00237 sinfo_rec_mflat(cpl_parameterlist *config, cpl_frameset *set)
00238 {
00239  
00240   cpl_parameter* p;
00241   cpl_frameset* ref_set=NULL;
00242   int pdensity=0;
00243   int line_cor=0;
00244 
00245   check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.product.density"));
00246   check_nomsg(pdensity=cpl_parameter_get_int(p));
00247 
00248   sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
00249         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
00250   ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
00251 
00252   check_nomsg(p=cpl_parameterlist_find(config, "sinfoni.general.lc_sw"));
00253   check_nomsg(line_cor=cpl_parameter_get_bool(p));
00254   if(line_cor==1) {
00255      check_nomsg(sinfo_ima_line_cor(config,set));
00256   }
00257 
00258 
00259 
00260   check_nomsg(ref_set=cpl_frameset_duplicate(set));
00261   sinfo_bp_config_add(config);  
00262   check_nomsg(p = cpl_parameterlist_find(config,"sinfoni.bp.method"));
00263   check_nomsg(cpl_parameter_set_string(p,"Normal"));   
00264   /* 
00265        ---------------------------------------------------------
00266                 MASTER_FLAT
00267        ---------------------------------------------------------
00268   */
00269  
00270   sinfo_msg("-------------------------------------------");
00271   sinfo_msg("MASTER FLAT DETERMINATION                  ");
00272   sinfo_msg("-------------------------------------------");
00273     
00274   ck0(sinfo_new_lamp_flats(cpl_func,config,set,ref_set),
00275       "MASTER FLAT DETERMINATION FAILED");
00276   sinfo_msg("MASTER FLAT DETERMINATION SUCCESS") ; 
00277 
00278   sinfo_msg("-------------------------------------------");
00279   sinfo_msg("BP_MAP_NO BAD PIXEL MAP DETERMINATION      ");
00280   sinfo_msg("-------------------------------------------");
00281   /* 
00282        ---------------------------------------------------------
00283                 BP_SEARCH
00284        ---------------------------------------------------------
00285   */
00286    
00287   check_nomsg(p = cpl_parameterlist_find(config,"sinfoni.bp.method"));
00288   check_nomsg(cpl_parameter_set_string(p,"Normal"));   
00289   ck0(sinfo_new_bp_search_normal(cpl_func,config,set,ref_set,PRO_BP_MAP_NO),
00290   "BP_MAP_NO BAD PIXEL MAP DETERMINATION FAILED") ;
00291     
00292   sinfo_msg("------------------------------------------");
00293   sinfo_msg("MASTER_BP_MAP BAD PIXEL MAP DETERMINATION ");
00294   sinfo_msg("------------------------------------------");
00295   ck0(sinfo_new_add_bp_map(cpl_func,config, set,ref_set),
00296      "MASTER_BP_MAP BAD PIXEL MAP FAILED") ;
00297   sinfo_msg("MASTER_BP_MAP BAD PIXEL MAP DETERMINATION SUCCESS");
00298     
00299 
00300   if(pdensity < 2) {
00301      check_nomsg(cpl_frameset_erase(set,PRO_BP_MAP_NO));
00302   }
00303 
00304  cleanup:
00305 
00306   sinfo_free_frameset(&ref_set);
00307 
00308   if (cpl_error_get_code() != CPL_ERROR_NONE) {
00309     return -1;
00310   } else {
00311     return 0;
00312   }
00313 
00314 }
00315 

Generated on 3 Mar 2013 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1