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