SINFONI Pipeline Reference Manual  2.6.0
sinfo_baddist_ini_by_cpl.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_baddist_ini_by_cpl.c
22  Author : Andrea Modigliani
23  Created on : Jun 16, 2004
24  Description : parse cpl input for the search of static bad pixels
25 
26  ---------------------------------------------------------------------------*/
27 #ifdef HAVE_CONFIG_H
28 # include <config.h>
29 #endif
30 /*---------------------------------------------------------------------------
31  Includes
32  ---------------------------------------------------------------------------*/
33 #include <string.h>
34 #include "sinfo_baddist_ini_by_cpl.h"
35 #include "sinfo_hidden.h"
36 #include "sinfo_pro_types.h"
37 #include "sinfo_raw_types.h"
38 #include "sinfo_globals.h"
39 #include "sinfo_functions.h"
40 #include "sinfo_file_handling.h"
41 
42 /*---------------------------------------------------------------------------
43  Functions private to this module
44  ---------------------------------------------------------------------------*/
45 
46 static void parse_section_frames(bad_config * cfg,
47 cpl_frameset* sof, const char* procatg, cpl_frameset** raw, int* status);
48 static void parse_section_badpix(bad_config * cfg, cpl_parameterlist* cpl_cfg);
49 static void parse_section_thresh(bad_config * cfg, cpl_parameterlist* cpl_cfg);
50 
74 bad_config *
75 sinfo_parse_cpl_input_baddist(cpl_parameterlist * cpl_cfg,
76  cpl_frameset* sof,
77  const char* procatg,
78  cpl_frameset** raw)
79 {
80  bad_config * cfg ;
81  int status = 0;
82  /* Removed check on ini_file */
83  /* Removed load of ini file */
84 
85  cfg = sinfo_bad_cfg_create();
86 
87  /*
88  * Perform sanity checks, fill up the structure with what was
89  * found in the ini file
90  */
91 
92  parse_section_badpix (cfg, cpl_cfg);
93  parse_section_thresh (cfg, cpl_cfg);
94  parse_section_frames (cfg, sof, procatg, raw,&status);
95  if(status>0) {
96  sinfo_msg_error("parsing cpl input");
97  sinfo_bad_cfg_destroy(cfg);
98  cfg = NULL ;
99  return NULL ;
100  }
101  return cfg ;
102 
103 }
104 
116 static void
117 parse_section_frames(bad_config * cfg,
118  cpl_frameset * sof,
119  const char * procatg,
120  cpl_frameset ** raw,
121  int* status)
122 {
123  int i=0;
124  int nraw = 0;
125  //char * tag=NULL;
126 
127  int nraw_good = 0;
128  cpl_frame* frame=NULL;
129  char spat_res[FILE_NAME_SZ];
130  char lamp_status[FILE_NAME_SZ];
131  char band[FILE_NAME_SZ];
132  int ins_set=0;
133 
134 
135  if(strcmp(procatg,PRO_BP_MAP_DI) == 0 ) {
136 
137  sinfo_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
138  nraw=cpl_frameset_get_size(*raw);
139 
140  } else if(strcmp(procatg,PRO_BP_MAP_NO) == 0 ) {
141 
142  sinfo_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
143  nraw=cpl_frameset_get_size(*raw);
144 
145  } else {
146  sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
147  nraw=cpl_frameset_get_size(*raw);
148 
149  if (nraw==0) {
150  sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
151  nraw=cpl_frameset_get_size(*raw);
152  }
153 
154  }
155  if (nraw==0) {
156  sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
157  nraw=cpl_frameset_get_size(*raw);
158  }
159 
160  if (nraw==0) {
161  sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
162  nraw=cpl_frameset_get_size(*raw);
163  }
164 
165 
166 
167  nraw=cpl_frameset_get_size(*raw);
168  if (nraw < 1) {
169  sinfo_msg_error("Too few (%d) raw frames (%s or %s) present in"
170  "frameset!Aborting...",nraw,
171  RAW_FLAT_LAMP,RAW_FLAT_NS);
172  (*status)++;
173  return;
174  }
175 
176  /* Removed: get "general:infile" read it, check input sinfo_matrix */
177  /* Allocate structures to go into the blackboard */
178  cfg->framelist = cpl_malloc(nraw * sizeof(char*));
179 
180  /* read input frames */
181  for (i=0 ; i<nraw ; i++) {
182  frame = cpl_frameset_get_frame(*raw,i);
183  //tag = (char*)cpl_frame_get_tag(frame) ;
184  if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1)
185  {
186  /* Store file name into framelist */
187  cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
188  nraw_good++;
189  }
190  }
191  if(nraw_good<1) {
192  sinfo_msg_error("Error: no good raw frame in input, something wrong!");
193  (*status)++;
194  return;
195  }
196 
197  /* Copy relevant information into the blackboard */
198  cfg->nframes = nraw_good ;
199 
200  /* Output */
201  strcpy(cfg -> outName, BP_DIST_OUT_FILENAME);
202 
203 
204 
205 
206  frame = cpl_frameset_get_frame(*raw,0);
207  sinfo_get_spatial_res(frame,spat_res);
208 
209  switch(sinfo_frame_is_on(frame))
210  {
211  case 0:
212  strcpy(lamp_status,"on");
213  break;
214  case 1:
215  strcpy(lamp_status,"off");
216  break;
217  case -1:
218  strcpy(lamp_status,"undefined");
219  break;
220  default:
221  strcpy(lamp_status,"undefined");
222  break;
223  }
224 
225  sinfo_get_band(frame,band);
226  sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s \n",
227  spat_res, lamp_status, band);
228  sinfo_get_ins_set(band,&ins_set);
229 
230  return;
231 
232 }
233 
241 static void
242 parse_section_badpix(bad_config * cfg, cpl_parameterlist * cpl_cfg)
243 {
244  cpl_parameter *p;
245 
246  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.sigma_factor");
247  cfg -> sigmaFactor = cpl_parameter_get_double(p);
248 
249  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.method_index");
250  cfg -> methodInd = cpl_parameter_get_int(p);
251 
252  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.factor");
253  cfg -> factor = cpl_parameter_get_double(p);
254 
255  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.iterations");
256  cfg -> iterations = cpl_parameter_get_int(p);
257 
258  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.low_rejection");
259  cfg -> loReject = cpl_parameter_get_double(p);
260 
261  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.high_rejection");
262  cfg -> hiReject = cpl_parameter_get_double(p);
263 
264  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.llx");
265  cfg -> llx = cpl_parameter_get_int(p);
266 
267  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.lly");
268  cfg -> lly = cpl_parameter_get_int(p);
269 
270  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.urx");
271  cfg -> urx = cpl_parameter_get_int(p);
272 
273  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.ury");
274  cfg -> ury = cpl_parameter_get_int(p);
275 
276 }
277 
285 static void
286 parse_section_thresh(bad_config * cfg, cpl_parameterlist * cpl_cfg)
287 {
288  cpl_parameter *p;
289 
290  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.threshold_index");
291  cfg -> threshInd = cpl_parameter_get_bool(p);
292 
293  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.mean_factor");
294  cfg -> meanfactor = cpl_parameter_get_double(p);
295 
296 
297  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.min_cut");
298  cfg -> mincut = cpl_parameter_get_double(p);
299 
300  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.max_cut");
301  cfg -> maxcut = cpl_parameter_get_double(p);
302 
303 }
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69