sinfo_bp_noise.c

00001 /*
00002  * This file is part of the ESO SINFONI Pipeline
00003  * Copyright (C) 2004,2005 European Southern Observatory
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
00018  */
00019 /*----------------------------------------------------------------------------
00020    
00021    File name    :       sinfo_bp_noise.c
00022    Author       :    J. Schreiber
00023    Created on   :    May 5, 2003
00024    Description  :    Different methods for searching for bad pixels
00025                         used in the recipe spiffi_bp_noise 
00026 
00027  ---------------------------------------------------------------------------*/
00028 #ifdef HAVE_CONFIG_H
00029 #  include <config.h>
00030 #endif
00031 
00032 /*----------------------------------------------------------------------------
00033                                 Includes
00034  ---------------------------------------------------------------------------*/
00035 #include "sinfo_bp_noise.h"
00036 #include "sinfo_detnoise_ini_by_cpl.h"
00037 #include "sinfo_pro_save.h"
00038 #include "sinfo_pro_types.h"
00039 #include "sinfo_raw_types.h"
00040 #include "sinfo_functions.h"
00041 #include "sinfo_detlin.h"
00042 #include "sinfo_error.h"
00043 #include "sinfo_utils_wrappers.h"
00044 
00050 /*----------------------------------------------------------------------------
00051                                 Defines
00052  ---------------------------------------------------------------------------*/
00053 /*----------------------------------------------------------------------------
00054                              Function Definitions
00055  ---------------------------------------------------------------------------*/
00056 
00074 int 
00075 sinfo_new_bp_search_noise (const char* plugin_id,
00076                                cpl_parameterlist* config, 
00077                                cpl_frameset* sof, 
00078                                const char* out_name )
00079 {
00080 
00081     detnoise_config * cfg =NULL;
00082 
00083     cpl_imagelist * image_list=NULL ;
00084     cpl_image * img_tmp=NULL ;
00085     cpl_image       *  mask=NULL ;
00086     cpl_parameter *p=NULL;
00087     cpl_frameset* raw=NULL;
00088     cpl_table* qclog_tbl=NULL;
00089     char key_value[FILE_NAME_SZ];
00090     int i=0;
00091     int n_bad =0;
00092 
00093     /*parse the file names and parameters to the detnoise_config data 
00094       structure cfg*/
00095     check_nomsg(raw=cpl_frameset_new());
00096     ck0(sinfo_extract_raw_frames_type1(sof,raw,RAW_DARK),
00097         "Error extracting %s frames",RAW_DARK);
00098     cknull(cfg = sinfo_parse_cpl_input_detnoise(config,sof,&raw),
00099            " could not parse .ini file!") ;
00100     check_nomsg(image_list = cpl_imagelist_new());
00101     for ( i = 0 ; i < cfg->nframes ; i++ )
00102     {
00103       if(sinfo_is_fits_file (cfg->framelist[i]) != 1) {
00104     sinfo_msg_error("Input file %s is not FITS",cfg->framelist[i] );
00105     goto cleanup;
00106       }
00107       check_nomsg(img_tmp=cpl_image_load(cfg->framelist[i],
00108                                          CPL_TYPE_FLOAT,0,0));
00109 
00110       check_nomsg(cpl_imagelist_set(image_list,img_tmp,i));
00111     }
00112 
00113     /*-----------------------------------------------------------------
00114      *---------------------- SEARCH FOR BAD PIXELS---------------------
00115      *-----------------------------------------------------------------*/
00116     sinfo_msg("Noise Search for bad pixels");
00117     /*---generate the bad pixel mask-------------*/
00118     cknull(mask=sinfo_new_search_bad_pixels_via_noise (image_list, 
00119                                cfg->threshSigmaFactor,
00120                                cfg->loReject,
00121                                cfg->hiReject),
00122        " could not create bad pixel mask!") ;
00123     
00124     n_bad = sinfo_new_count_bad_pixels(mask) ;
00125     sinfo_msg ("number of bad pixels: %d\n", n_bad) ;
00126 
00127     /* QC LOG */
00128     cknull_nomsg(qclog_tbl = sinfo_qclog_init());
00129     check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.bp.method"));
00130     snprintf(key_value, MAX_NAME_SIZE-1,"%s",cpl_parameter_get_string(p));
00131     ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,"QC BP-MAP METHOD",key_value,
00132                                      "BP search method","%s"));
00133     ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC BP-MAP NBADPIX",n_bad,
00134                                      "No of bad pixels","%d"));
00135 
00136     ck0(sinfo_pro_save_ima(mask,raw,sof,(char *) out_name,
00137                PRO_BP_MAP_HP,qclog_tbl,plugin_id,config),
00138                            "cannot save ima %s", out_name);
00139 
00140     sinfo_free_image(&mask);
00141     sinfo_free_table(&qclog_tbl);
00142     sinfo_free_imagelist(&image_list) ;
00143     sinfo_detnoise_free(cfg);
00144     sinfo_free_frameset(&raw);
00145 
00146     return 0 ;
00147 
00148  cleanup:
00149 
00150     sinfo_free_table(&qclog_tbl);
00151     sinfo_free_imagelist(&image_list) ;
00152     sinfo_free_image(&mask) ;
00153     sinfo_detnoise_free(cfg);
00154     sinfo_free_frameset(&raw);
00155    return -1 ;
00156 
00157 }

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