SINFONI Pipeline Reference Manual  2.6.0
sinfo_bp_noise.c
1 /*
2  * This file is part of the ESO SINFONI Pipeline
3  * Copyright (C) 2004,2005 European Southern Observatory
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
18  */
19 /*----------------------------------------------------------------------------
20 
21  File name : sinfo_bp_noise.c
22  Author : J. Schreiber
23  Created on : May 5, 2003
24  Description : Different methods for searching for bad pixels
25  used in the recipe spiffi_bp_noise
26 
27  ---------------------------------------------------------------------------*/
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31 
32 /*----------------------------------------------------------------------------
33  Includes
34  ---------------------------------------------------------------------------*/
35 #include "sinfo_bp_noise.h"
36 #include "sinfo_detnoise_ini_by_cpl.h"
37 #include "sinfo_pro_save.h"
38 #include "sinfo_pro_types.h"
39 #include "sinfo_raw_types.h"
40 #include "sinfo_functions.h"
41 #include "sinfo_detlin.h"
42 #include "sinfo_error.h"
43 #include "sinfo_utils_wrappers.h"
44 
50 /*----------------------------------------------------------------------------
51  Defines
52  ---------------------------------------------------------------------------*/
53 /*----------------------------------------------------------------------------
54  Function Definitions
55  ---------------------------------------------------------------------------*/
56 
74 int
75 sinfo_new_bp_search_noise (const char* plugin_id,
76  cpl_parameterlist* config,
77  cpl_frameset* sof,
78  const char* out_name )
79 {
80 
81  detnoise_config * cfg =NULL;
82 
83  cpl_imagelist * image_list=NULL ;
84  cpl_image * img_tmp=NULL ;
85  cpl_image * mask=NULL ;
86  cpl_parameter *p=NULL;
87  cpl_frameset* raw=NULL;
88  cpl_table* qclog_tbl=NULL;
89  char key_value[FILE_NAME_SZ];
90  int i=0;
91  int n_bad =0;
92 
93  /*parse the file names and parameters to the detnoise_config data
94  structure cfg*/
95  check_nomsg(raw=cpl_frameset_new());
96  ck0(sinfo_extract_raw_frames_type1(sof,raw,RAW_DARK),
97  "Error extracting %s frames",RAW_DARK);
98  cknull(cfg = sinfo_parse_cpl_input_detnoise(config,sof,&raw),
99  " could not parse .ini file!") ;
100  check_nomsg(image_list = cpl_imagelist_new());
101  for ( i = 0 ; i < cfg->nframes ; i++ )
102  {
103  if(sinfo_is_fits_file (cfg->framelist[i]) != 1) {
104  sinfo_msg_error("Input file %s is not FITS",cfg->framelist[i] );
105  goto cleanup;
106  }
107  check_nomsg(img_tmp=cpl_image_load(cfg->framelist[i],
108  CPL_TYPE_FLOAT,0,0));
109 
110  check_nomsg(cpl_imagelist_set(image_list,img_tmp,i));
111  }
112 
113  /*-----------------------------------------------------------------
114  *---------------------- SEARCH FOR BAD PIXELS---------------------
115  *-----------------------------------------------------------------*/
116  sinfo_msg("Noise Search for bad pixels");
117  /*---generate the bad pixel mask-------------*/
118  cknull(mask=sinfo_new_search_bad_pixels_via_noise (image_list,
119  cfg->threshSigmaFactor,
120  cfg->loReject,
121  cfg->hiReject),
122  " could not create bad pixel mask!") ;
123 
124  n_bad = sinfo_new_count_bad_pixels(mask) ;
125  sinfo_msg ("number of bad pixels: %d\n", n_bad) ;
126 
127  /* QC LOG */
128  cknull_nomsg(qclog_tbl = sinfo_qclog_init());
129  check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.bp.method"));
130  snprintf(key_value, MAX_NAME_SIZE-1,"%s",cpl_parameter_get_string(p));
131  ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,"QC BP-MAP METHOD",key_value,
132  "BP search method","%s"));
133  ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC BP-MAP NBADPIX",n_bad,
134  "No of bad pixels","%d"));
135 
136  ck0(sinfo_pro_save_ima(mask,raw,sof,(char *) out_name,
137  PRO_BP_MAP_HP,qclog_tbl,plugin_id,config),
138  "cannot save ima %s", out_name);
139 
140  sinfo_free_image(&mask);
141  sinfo_free_table(&qclog_tbl);
142  sinfo_free_imagelist(&image_list) ;
143  sinfo_detnoise_free(cfg);
144  sinfo_free_frameset(&raw);
145 
146  return 0 ;
147 
148  cleanup:
149 
150  sinfo_free_table(&qclog_tbl);
151  sinfo_free_imagelist(&image_list) ;
152  sinfo_free_image(&mask) ;
153  sinfo_detnoise_free(cfg);
154  sinfo_free_frameset(&raw);
155  return -1 ;
156 
157 }
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69