si_utl_bpsearch.c

00001 /* $Id: si_utl_bpsearch.c,v 1.2 2005/10/08 10:34:50 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/08 10:34:50 $
00023  * $Revision: 1.2 $
00024  * $Name:  $
00025  */
00026 
00027  /****************************************************************
00028   *           Bad pixel search  (normal method)                  *
00029   ****************************************************************/
00030 
00031 /* --------------------------------------------------------------- 
00032                          INCLUDES
00033    --------------------------------------------------------------- */
00034 #ifdef HAVE_CONFIG_H
00035 #include <config.h>
00036 #endif
00037 
00038 /* std libraries */
00039 #include <strings.h>
00040 #include <string.h>
00041 #include <stdio.h>
00042 
00043 /* cx */
00044 #include <cxmacros.h>
00045 #include <cxtypes.h>
00046 #include <cxmessages.h>     
00047 
00048 /* qfits */
00049 #include <xmemory.h>
00050 
00051 /* cpl */
00052 #include <cpl_memory.h>     
00053 #include <cpl_parameterlist.h>    
00054 #include <cpl_msg.h>  
00055 #include <cpl_error.h>  
00056 
00057 #include <cpl_recipe.h>     
00058 #include <cpl_plugininfo.h> 
00059 #include <cpl_frameset.h>   
00060 
00061 
00062 /* sinfoni */
00063 #include <sinfoni_general_config.h>
00064 #include <sinfoni_bp_norm_config.h>
00065 #include <sinfoni_bp_lin_config.h>
00066 #include <sinfoni_bp_noise_config.h>
00067 #include <sinfoni_bp_config.h>
00068 #include <sinfoni_pro_types.h>
00069 /* #include <sinfoni_dfs.h> */
00070 #include <bp_noise.h> 
00071 #include <bp_lin.h> 
00072 #include <bp_norm.h>
00073 #include <sinfoni_tpl_utils.h>
00074 #include <sinfoni_tpl_dfs.h>
00075 #include <sinfoni_memory.h>
00076 
00077 /* --------------------------------------------------------------- 
00078                          DEFINES
00079    --------------------------------------------------------------- */
00080 /* --------------------------------------------------------------- 
00081                          FUNCTIONS PROTOTYPES
00082    --------------------------------------------------------------- */
00083 
00084 static cxint sinfoni_rec_bpsearch_create(cpl_plugin *plugin);
00085 static cxint sinfoni_rec_bpsearch_exec(cpl_plugin *plugin);
00086 static cxint sinfoni_rec_bpsearch_destroy(cpl_plugin *plugin);
00087 static cxint sinfoni_rec_bpsearch(cpl_parameterlist *, cpl_frameset *);
00088 int cpl_plugin_get_info(cpl_pluginlist *list);
00089 
00090 
00091 /* --------------------------------------------------------------- 
00092                          STATIC VARIABLES
00093    --------------------------------------------------------------- */
00094 static char si_utl_bpsearch_description[] =
00095 "This recipe performs bad pixel search.\n"
00096 "The input files are\n"
00097 "Raw flat fields with tag FLAT_LAMP  (method 'normal') or \n"
00098 "Raw flat fields with tag FLAT_NS  (method 'normal') or \n"
00099 "A Master flat field with tag MASTER_FLAT_LAMP   (method 'normal') or \n"
00100 "Raw darks with tag DARK   (method 'noise') or \n"
00101 "Raw flats with increasing intensity with tag LINEARITY_LAMP  (method 'linear') or \n"
00102 "The output is a bad pixel map image. \n"
00103 "Its tag may be BP_MAP_NO, or BP_MAP_DI, or BP_MAP_HP, or BP_MAP_NL\n"
00104 "Information on relevant parameters can be found with"
00105 "esorex --params si_utl_bpsearch\n"
00106 "esorex --help si_utl_bpsearch\n"
00107 "\n";
00108 
00109 
00110 /* --------------------------------------------------------------- 
00111                          FUNCTIONS CODE
00112    --------------------------------------------------------------- */
00113 
00114 /*----------------------------------------------------------------------------*/
00122 /*----------------------------------------------------------------------------*/
00123 int
00124 cpl_plugin_get_info(cpl_pluginlist *list)
00125 {
00126 
00127   cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00128   cpl_plugin *plugin = &recipe->interface;
00129 
00130 
00131   cpl_plugin_init(plugin,
00132           CPL_PLUGIN_API,
00133           SINFONI_BINARY_VERSION,
00134           CPL_PLUGIN_TYPE_RECIPE,
00135           "si_utl_bpsearch",
00136           "Search bad pixels",
00137                   si_utl_bpsearch_description,
00138           "Andrea Modigliani",
00139           "Andrea.Modigliani@eso.org",
00140            sinfoni_get_license(),
00141           sinfoni_rec_bpsearch_create,
00142           sinfoni_rec_bpsearch_exec,
00143           sinfoni_rec_bpsearch_destroy);
00144 
00145   cpl_pluginlist_append(list, plugin);
00146 
00147   return 0;
00148 
00149 }
00150 /*----------------------------------------------------------------------------*/
00159 /*----------------------------------------------------------------------------*/
00160 
00161 static cxint
00162 sinfoni_rec_bpsearch_create(cpl_plugin *plugin)
00163 {
00164 
00165   /*
00166    * We have to provide the option we accept to the application.
00167    * We need to setup our parameter list and hook it into the recipe
00168    * interface.
00169    */
00170   cpl_recipe *recipe = (cpl_recipe *)plugin;
00171   recipe->parameters = cpl_parameterlist_new();
00172   if(recipe->parameters == NULL) {
00173     return 1;
00174   }
00175 
00176   /*
00177    * Fill the parameter list.
00178    */
00179 
00180   /* General parameters */
00181   /* Bad pixel parameters */
00182   /* printf("config\n"); */
00183   /*
00184   sinfoni_general_config_add(recipe->parameters); 
00185   */
00186   sinfoni_general_config_add(recipe->parameters);
00187   sinfoni_bp_config_add(recipe->parameters); 
00188   sinfoni_bp_norm_config_add(recipe->parameters); 
00189   sinfoni_bp_lin_config_add(recipe->parameters); 
00190   sinfoni_bp_noise_config_add(recipe->parameters); 
00191   
00192   return 0;
00193 
00194 }
00195 /*----------------------------------------------------------------------------*/
00201 /*----------------------------------------------------------------------------*/
00202 static cxint
00203 sinfoni_rec_bpsearch_exec(cpl_plugin *plugin)
00204 {
00205  
00206   cpl_recipe *recipe = (cpl_recipe *) plugin;
00207   if(recipe->parameters == NULL ) {
00208     return 1;
00209   }
00210   if(recipe->frames == NULL) {
00211     return 1;
00212   }
00213   /* printf("exec\n"); */
00214   cpl_error_reset();
00215   return sinfoni_rec_bpsearch(recipe->parameters, recipe->frames);
00216 
00217 }
00218 /*----------------------------------------------------------------------------*/
00224 /*----------------------------------------------------------------------------*/
00225 
00226 static cxint
00227 sinfoni_rec_bpsearch_destroy(cpl_plugin *plugin)
00228 {
00229   cpl_recipe *recipe = (cpl_recipe *) plugin;
00230   /*
00231    * We just destroy what was created during the plugin initializzation phase
00232    * i.e. the parameter list. The frame set is managed by the application which
00233    * called us, so that we must not touch it.
00234    */
00235 
00236   cpl_parameterlist_delete(recipe->parameters);
00237   return 0;
00238 
00239 }
00240 
00241 /*
00242  * The actual recipe actually start here.
00243  */
00244 /*----------------------------------------------------------------------------*/
00255 /*----------------------------------------------------------------------------*/
00256 
00257 static cxint
00258 sinfoni_rec_bpsearch(cpl_parameterlist *config, cpl_frameset *set)
00259 {
00260   int  ind =0;
00261   const cxchar *_id = "sinfoni_rec_bpsearch";
00262   cpl_parameter *p;          
00263   char out_name[FILE_NAME_SZ];
00264 
00265      char name_s   [FILE_NAME_SZ];
00266 
00267    
00268   /* cpl_parameterlist_dump(config); */
00269 
00270       strcpy(out_name,"out_bp_noise.fits");
00271      p = cpl_parameterlist_find(config, "sinfoni.bp.method");
00272      strcpy(name_s, cpl_parameter_get_string(p));
00273      cpl_msg_info(_id,"Method=%s\n",name_s);
00274      if(sinfoni_dfs_set_groups(set)) {
00275 
00276        cpl_msg_error(_id, "Cannot indentify RAW and CALIB frames") ;
00277        return -1;
00278 
00279     }
00280 
00281     {
00282 
00283     if ( 0 == strcmp(name_s,"Normal") )
00284     {
00285             cpl_msg_info(_id,"Running");
00286             if ( -1 == (ind = badSearchNormal(config, set, PRO_BP_MAP_NO ) ) )
00287         {
00288             cpl_msg_error(_id,"badSearchNormal(), no: %d\n", ind) ;
00289         return -1 ;
00290         }
00291             cpl_msg_info(_id,"success");
00292     }
00293     else if ( 0 == strcmp (name_s, "Noise") )
00294     {
00295             cpl_msg_info(_id,"Running");
00296         if ( -1 == (ind = badSearchNoise(config, set, out_name ) ) )
00297         {
00298             cpl_msg_error(_id,"badSearchNoise(), no: %d\n", ind) ;
00299         return -1 ;
00300         }
00301             cpl_msg_info(_id,"success");
00302     }
00303         else if ( 0 == strcmp (name_s, "Linear") )
00304     {
00305             cpl_msg_info(_id,"Running");
00306         if ( -1 == (ind = badSearchLin( config, set ) ) )
00307         {
00308             cpl_msg_error(_id,"badSearchLin(), no: %d\n", ind) ;
00309         return -1 ;
00310         }
00311             cpl_msg_info(_id,"success");
00312     }
00313     else
00314     {
00315         cpl_msg_error(_id,"wrong name for sort of bad pixel search ");
00316             cpl_msg_error(_id,"reduction recipe given!\n") ;
00317         return -1 ;
00318     }
00319     }    
00320     return 0 ;
00321 
00322 
00323 
00324 }
00325 

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