SINFONI Pipeline Reference Manual  2.5.2
sinfo_badnorm_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_badnorm_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 
34 #include <string.h>
35 #include "sinfo_badnorm_ini_by_cpl.h"
36 #include "sinfo_raw_types.h"
37 #include "sinfo_pro_types.h"
38 #include "sinfo_hidden.h"
39 #include "sinfo_globals.h"
40 #include "sinfo_functions.h"
41 #include "sinfo_file_handling.h"
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 
71 bad_config *
72 sinfo_parse_cpl_input_badnorm(cpl_parameterlist * cpl_cfg,
73  cpl_frameset* sof,
74  const char* procatg,
75  cpl_frameset** raw)
76 {
77  bad_config * cfg ;
78  int status = 0;
79  /* Removed check on ini_file */
80  /* Removed load of ini file */
81 
82  cfg = sinfo_bad_cfg_create();
83 
84  /*
85  * Perform sanity checks, fill up the structure with what was
86  * found in the ini file
87  */
88 
89  parse_section_badpix (cfg, cpl_cfg);
90  parse_section_thresh (cfg, cpl_cfg);
91  parse_section_frames (cfg, sof, procatg, raw,&status);
92  if(status>0) {
93  sinfo_msg_error("parsing cpl input");
94  sinfo_bad_cfg_destroy(cfg);
95  cfg = NULL ;
96  return NULL ;
97  }
98  return cfg ;
99 
100 }
101 
102 
115 static void
116 parse_section_frames(bad_config * cfg,
117  cpl_frameset * sof,
118  const char * procatg,
119  cpl_frameset ** raw,
120  int* status)
121 {
122  int i=0;
123  int nraw = 0;
124  //char * tag=NULL;
125 
126  int nraw_good = 0;
127  cpl_frame* frame=NULL;
128  char spat_res[FILE_NAME_SZ];
129  char lamp_status[FILE_NAME_SZ];
130  char band[FILE_NAME_SZ];
131  int ins_set=0;
132  if(strcmp(procatg,PRO_BP_MAP_DI) == 0 ) {
133 
134  sinfo_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
135  nraw=cpl_frameset_get_size(*raw);
136 
137  } else if(strcmp(procatg,PRO_BP_MAP_NO) == 0 ) {
138 
139  sinfo_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
140  nraw=cpl_frameset_get_size(*raw);
141 
142  } else {
143  sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
144  nraw=cpl_frameset_get_size(*raw);
145 
146  if (nraw==0) {
147  sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
148  nraw=cpl_frameset_get_size(*raw);
149  }
150 
151  }
152  if (nraw==0) {
153  sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
154  nraw=cpl_frameset_get_size(*raw);
155  }
156 
157  if (nraw==0) {
158  sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
159  nraw=cpl_frameset_get_size(*raw);
160  }
161 
162 
163  if (nraw < 1) {
164  sinfo_msg_error("Too few (%d) raw frames (%s or %s or %s) present in"
165  "frameset!Aborting...",nraw,
166  PRO_MASTER_FLAT_LAMP,RAW_FLAT_LAMP,RAW_FLAT_NS);
167  (*status)++;
168  return;
169  }
170 
171  /* Removed: get "general:infile" read it, check input sinfo_matrix */
172  /* Allocate structures to go into the blackboard */
173  cfg->framelist = cpl_malloc(nraw * sizeof(char*));
174 
175  /* read input frames */
176  for (i=0 ; i<nraw ; i++) {
177  frame = cpl_frameset_get_frame(*raw,i);
178  //tag = (char*)cpl_frame_get_tag(frame) ;
179  if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1)
180  {
181  /* Store file name into framelist */
182  cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
183  nraw_good++;
184  }
185  }
186 
187  if(nraw_good<1) {
188  sinfo_msg_error("Error: no good raw frame in input, something wrong!");
189  (*status)++;
190  return;
191  }
192 
193  /* Copy relevant information into the blackboard */
194  cfg->nframes = nraw_good ;
195 
196  /* Output */
197  if (strcmp(procatg,PRO_BP_MAP_NO) == 0) {
198  strcpy(cfg -> outName, BP_NORM_OUT_FILENAME);
199  } else if (strcmp(procatg,PRO_BP_MAP_DI) == 0) {
200  strcpy(cfg -> outName, BP_DIST_OUT_FILENAME);
201  } else if (strcmp(procatg,PRO_DEFAULT) == 0) {
202  strcpy(cfg -> outName, BP_NORM_OUT_FILENAME);
203  } else {
204  sinfo_msg_error("Error: PRO.CATG %s, not supported!",procatg);
205  (*status)++;
206  return;
207  }
208 
209 
210 
211  frame = cpl_frameset_get_frame(*raw,0);
212  sinfo_get_spatial_res(frame,spat_res);
213 
214 
215  switch(sinfo_frame_is_on(frame))
216  {
217  case 0:
218  strcpy(lamp_status,"on");
219  break;
220  case 1:
221  strcpy(lamp_status,"off");
222  break;
223  case -1:
224  strcpy(lamp_status,"undefined");
225  break;
226  default:
227  strcpy(lamp_status,"undefined");
228  break;
229  }
230 
231  sinfo_get_band(frame,band);
232  sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n",
233  spat_res, lamp_status, band);
234 
235 
236  sinfo_get_ins_set(band,&ins_set);
237 
238  return;
239 
240 }
241 
251 static void
252 parse_section_badpix(bad_config * cfg, cpl_parameterlist * cpl_cfg)
253 {
254  cpl_parameter *p;
255 
256  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.sigma_factor");
257  cfg -> sigmaFactor = cpl_parameter_get_double(p);
258 
259  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.method_index");
260  cfg -> methodInd = cpl_parameter_get_int(p);
261 
262  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.factor");
263  cfg -> factor = cpl_parameter_get_double(p);
264 
265  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.iterations");
266  cfg -> iterations = cpl_parameter_get_int(p);
267 
268  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.low_rejection");
269  cfg -> loReject = cpl_parameter_get_double(p);
270 
271  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.high_rejection");
272  cfg -> hiReject = cpl_parameter_get_double(p);
273 
274  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.llx");
275  cfg -> llx = cpl_parameter_get_int(p);
276 
277  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.lly");
278  cfg -> lly = cpl_parameter_get_int(p);
279 
280  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.urx");
281  cfg -> urx = cpl_parameter_get_int(p);
282 
283  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.ury");
284  cfg -> ury = cpl_parameter_get_int(p);
285 
286 }
287 
297 static void
298 parse_section_thresh(bad_config * cfg, cpl_parameterlist * cpl_cfg)
299 {
300  cpl_parameter *p;
301 
302  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.threshold_index");
303  cfg -> threshInd = cpl_parameter_get_bool(p);
304 
305  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.mean_factor");
306  cfg -> meanfactor = cpl_parameter_get_double(p);
307 
308 
309  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.min_cut");
310  cfg -> mincut = cpl_parameter_get_double(p);
311 
312  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.max_cut");
313  cfg -> maxcut = cpl_parameter_get_double(p);
314 
315 }
323 void
324 sinfo_badnorm_free(bad_config ** cfg)
325 {
326  if((*cfg) != NULL) {
327  if((*cfg)->framelist != NULL) {
328  cpl_free((*cfg)->framelist);
329  (*cfg)->framelist=NULL;
330  }
331  sinfo_bad_cfg_destroy((*cfg));
332  *cfg =NULL;
333  }
334  return;
335 
336 }