SINFONI Pipeline Reference Manual  2.6.0
sinfo_badsky_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 
22  File name : sinfo_badsky_ini_by_cpl.c
23  Author : Andrea Modigliani
24  Created on : Jun 16, 2004
25  Description : parse cpl input for the search of static bad pixels
26 
27  ---------------------------------------------------------------------------*/
28 
29 #ifdef HAVE_CONFIG_H
30 # include <config.h>
31 #endif
32 
33 /*---------------------------------------------------------------------------
34  Includes
35  ---------------------------------------------------------------------------*/
36 #include <string.h>
37 #include "sinfo_badsky_ini_by_cpl.h"
38 #include "sinfo_raw_types.h"
39 #include "sinfo_pro_types.h"
40 #include "sinfo_hidden.h"
41 #include "sinfo_globals.h"
42 #include "sinfo_functions.h"
43 #include "sinfo_file_handling.h"
44 /*---------------------------------------------------------------------------
45  Functions private to this module
46  ---------------------------------------------------------------------------*/
47 
48 static void
49 parse_section_frames(badsky_config * cfg, cpl_parameterlist* cpl_cfg,
50 cpl_frameset* sof, cpl_frameset** raw, int* status);
51 static void
52 parse_section_badpix(badsky_config * cfg, cpl_parameterlist* cpl_cfg);
53 static void
54 parse_section_thresh(badsky_config * cfg, cpl_parameterlist* cpl_cfg);
60 /*---------------------------------------------------------------------------
61  Function codes
62  ---------------------------------------------------------------------------*/
75 badsky_config *
76 sinfo_parse_cpl_input_badsky(cpl_parameterlist * cpl_cfg,
77  cpl_frameset* sof,
78  cpl_frameset** raw)
79 {
80  badsky_config * cfg ;
81  int status = 0;
82 
83  cfg = sinfo_badsky_cfg_create();
84  parse_section_badpix (cfg, cpl_cfg);
85  parse_section_thresh (cfg, cpl_cfg);
86  parse_section_frames (cfg, cpl_cfg, sof, raw,&status);
87  if(status>0) {
88  sinfo_msg_error("parsing cpl input");
89  sinfo_badsky_cfg_destroy(cfg);
90  cfg = NULL ;
91  return NULL ;
92  }
93  return cfg ;
94 
95 }
96 
108 static void
109 parse_section_frames(badsky_config * cfg,
110  cpl_parameterlist * cpl_cfg,
111  cpl_frameset * sof,
112  cpl_frameset ** raw,
113  int* status)
114 {
115  int i=0;
116  int nraw = 0;
117  //char * tag=NULL;
118 
119  int nraw_good = 0;
120  cpl_frame* frame=NULL;
121  cpl_parameter *p;
122  char spat_res[FILE_NAME_SZ];
123  char lamp_status[FILE_NAME_SZ];
124  char band[FILE_NAME_SZ];
125  int ins_set=0;
126 
127  *raw=cpl_frameset_new();
128 
129 
130  sinfo_contains_frames_type(sof,raw,RAW_SKY);
131  nraw=cpl_frameset_get_size(*raw);
132  if (nraw < 1) {
133  sinfo_msg_error("Too few (%d) raw frames %s present in"
134  "frameset!Aborting...",nraw,RAW_SKY);
135  (*status)++;
136  return;
137  }
138 
139  /* Removed: get "general:infile" read it, check input sinfo_matrix */
140  /* Allocate structures to go into the blackboard */
141  cfg->framelist = cpl_malloc(nraw * sizeof(char*));
142 
143  /* read input frames */
144  for (i=0 ; i<nraw ; i++) {
145  frame = cpl_frameset_get_frame(*raw,i);
146  //tag = (char*)cpl_frame_get_tag(frame) ;
147  if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1)
148  {
149  /* Store file name into framelist */
150  cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
151  nraw_good++;
152  }
153  }
154 
155  if(nraw_good<1) {
156  sinfo_msg_error("Error: no good raw frame in input, something wrong!");
157  (*status)++;
158  return;
159  }
160 
161 
162  if(NULL != cpl_frameset_find(sof,PRO_MASTER_DARK)) {
163  frame = cpl_frameset_find(sof,PRO_MASTER_DARK);
164  strcpy(cfg -> sinfo_dark,
165  cpl_strdup(cpl_frame_get_filename(frame)));
166  } else {
167  sinfo_msg_warning("Frame %s not found!", PRO_MASTER_DARK);
168  }
169 
170  /* Copy relevant information into the blackboard */
171  cfg->nframes = nraw_good ;
172 
173  /* Output */
174  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.out_filename");
175  strcpy(cfg -> outName, cpl_parameter_get_string(p));
176 
177  frame = cpl_frameset_get_frame(*raw,0);
178  sinfo_get_spatial_res(frame,spat_res);
179 
180 
181  switch(sinfo_frame_is_on(frame))
182  {
183  case 0:
184  strcpy(lamp_status,"on");
185  break;
186  case 1:
187  strcpy(lamp_status,"off");
188  break;
189  case -1:
190  strcpy(lamp_status,"undefined");
191  break;
192  default:
193  strcpy(lamp_status,"undefined");
194  break;
195  }
196 
197  sinfo_get_band(frame,band);
198  sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n",
199  spat_res, lamp_status, band);
200 
201 
202  sinfo_get_ins_set(band,&ins_set);
203  return;
204 
205 }
206 
215 static void
216 parse_section_badpix(badsky_config * cfg, cpl_parameterlist * cpl_cfg)
217 {
218  cpl_parameter *p;
219 
220  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.sigma_factor");
221  cfg -> sigmaFactor = cpl_parameter_get_double(p);
222 
223  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.method_index");
224  cfg -> methodInd = cpl_parameter_get_int(p);
225 
226  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.factor");
227  cfg -> factor = cpl_parameter_get_double(p);
228 
229  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.iterations");
230  cfg -> iterations = cpl_parameter_get_int(p);
231 
232  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.low_rejection");
233  cfg -> loReject = cpl_parameter_get_double(p);
234 
235  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.high_rejection");
236  cfg -> hiReject = cpl_parameter_get_double(p);
237 
238  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.llx");
239  cfg -> llx = cpl_parameter_get_int(p);
240 
241  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.lly");
242  cfg -> lly = cpl_parameter_get_int(p);
243 
244  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.urx");
245  cfg -> urx = cpl_parameter_get_int(p);
246 
247  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.ury");
248  cfg -> ury = cpl_parameter_get_int(p);
249 
250 }
251 
260 static void
261 parse_section_thresh(badsky_config * cfg, cpl_parameterlist * cpl_cfg)
262 {
263  cpl_parameter *p;
264 
265  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.threshold_index");
266  cfg -> threshInd = cpl_parameter_get_bool(p);
267 
268  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.mean_factor");
269  cfg -> meanfactor = cpl_parameter_get_double(p);
270 
271 
272  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.min_cut");
273  cfg -> mincut = cpl_parameter_get_double(p);
274 
275  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.max_cut");
276  cfg -> maxcut = cpl_parameter_get_double(p);
277 
278 }
279 
287 void
288 sinfo_badsky_free(badsky_config * cfg)
289 {
290  cpl_free(cfg->framelist);
291  sinfo_badsky_cfg_destroy(cfg);
292 
293  return;
294 
295 }
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69
#define sinfo_msg_warning(...)
Print an warning message.
Definition: sinfo_msg.h:93