SINFONI Pipeline Reference Manual  2.5.2
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  ---------------------------------------------------------------------------*/
74 badsky_config *
75 sinfo_parse_cpl_input_badsky(cpl_parameterlist * cpl_cfg,
76  cpl_frameset* sof,
77  cpl_frameset** raw)
78 {
79  badsky_config * cfg ;
80  int status = 0;
81 
82  cfg = sinfo_badsky_cfg_create();
83  parse_section_badpix (cfg, cpl_cfg);
84  parse_section_thresh (cfg, cpl_cfg);
85  parse_section_frames (cfg, cpl_cfg, sof, raw,&status);
86  if(status>0) {
87  sinfo_msg_error("parsing cpl input");
88  sinfo_badsky_cfg_destroy(cfg);
89  cfg = NULL ;
90  return NULL ;
91  }
92  return cfg ;
93 
94 }
95 
107 static void
108 parse_section_frames(badsky_config * cfg,
109  cpl_parameterlist * cpl_cfg,
110  cpl_frameset * sof,
111  cpl_frameset ** raw,
112  int* status)
113 {
114  int i=0;
115  int nraw = 0;
116  //char * tag=NULL;
117 
118  int nraw_good = 0;
119  cpl_frame* frame=NULL;
120  cpl_parameter *p;
121  char spat_res[FILE_NAME_SZ];
122  char lamp_status[FILE_NAME_SZ];
123  char band[FILE_NAME_SZ];
124  int ins_set=0;
125 
126  *raw=cpl_frameset_new();
127 
128 
129  sinfo_contains_frames_type(sof,raw,RAW_SKY);
130  nraw=cpl_frameset_get_size(*raw);
131  if (nraw < 1) {
132  sinfo_msg_error("Too few (%d) raw frames %s present in"
133  "frameset!Aborting...",nraw,RAW_SKY);
134  (*status)++;
135  return;
136  }
137 
138  /* Removed: get "general:infile" read it, check input sinfo_matrix */
139  /* Allocate structures to go into the blackboard */
140  cfg->framelist = cpl_malloc(nraw * sizeof(char*));
141 
142  /* read input frames */
143  for (i=0 ; i<nraw ; i++) {
144  frame = cpl_frameset_get_frame(*raw,i);
145  //tag = (char*)cpl_frame_get_tag(frame) ;
146  if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1)
147  {
148  /* Store file name into framelist */
149  cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
150  nraw_good++;
151  }
152  }
153 
154  if(nraw_good<1) {
155  sinfo_msg_error("Error: no good raw frame in input, something wrong!");
156  (*status)++;
157  return;
158  }
159 
160 
161  if(NULL != cpl_frameset_find(sof,PRO_MASTER_DARK)) {
162  frame = cpl_frameset_find(sof,PRO_MASTER_DARK);
163  strcpy(cfg -> sinfo_dark,
164  cpl_strdup(cpl_frame_get_filename(frame)));
165  } else {
166  sinfo_msg_warning("Frame %s not found!", PRO_MASTER_DARK);
167  }
168 
169  /* Copy relevant information into the blackboard */
170  cfg->nframes = nraw_good ;
171 
172  /* Output */
173  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.out_filename");
174  strcpy(cfg -> outName, cpl_parameter_get_string(p));
175 
176  frame = cpl_frameset_get_frame(*raw,0);
177  sinfo_get_spatial_res(frame,spat_res);
178 
179 
180  switch(sinfo_frame_is_on(frame))
181  {
182  case 0:
183  strcpy(lamp_status,"on");
184  break;
185  case 1:
186  strcpy(lamp_status,"off");
187  break;
188  case -1:
189  strcpy(lamp_status,"undefined");
190  break;
191  default:
192  strcpy(lamp_status,"undefined");
193  break;
194  }
195 
196  sinfo_get_band(frame,band);
197  sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n",
198  spat_res, lamp_status, band);
199 
200 
201  sinfo_get_ins_set(band,&ins_set);
202  return;
203 
204 }
205 
214 static void
215 parse_section_badpix(badsky_config * cfg, cpl_parameterlist * cpl_cfg)
216 {
217  cpl_parameter *p;
218 
219  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.sigma_factor");
220  cfg -> sigmaFactor = cpl_parameter_get_double(p);
221 
222  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.method_index");
223  cfg -> methodInd = cpl_parameter_get_int(p);
224 
225  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.factor");
226  cfg -> factor = cpl_parameter_get_double(p);
227 
228  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.iterations");
229  cfg -> iterations = cpl_parameter_get_int(p);
230 
231  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.low_rejection");
232  cfg -> loReject = cpl_parameter_get_double(p);
233 
234  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.high_rejection");
235  cfg -> hiReject = cpl_parameter_get_double(p);
236 
237  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.llx");
238  cfg -> llx = cpl_parameter_get_int(p);
239 
240  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.lly");
241  cfg -> lly = cpl_parameter_get_int(p);
242 
243  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.urx");
244  cfg -> urx = cpl_parameter_get_int(p);
245 
246  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.ury");
247  cfg -> ury = cpl_parameter_get_int(p);
248 
249 }
250 
259 static void
260 parse_section_thresh(badsky_config * cfg, cpl_parameterlist * cpl_cfg)
261 {
262  cpl_parameter *p;
263 
264  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.threshold_index");
265  cfg -> threshInd = cpl_parameter_get_bool(p);
266 
267  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.mean_factor");
268  cfg -> meanfactor = cpl_parameter_get_double(p);
269 
270 
271  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.min_cut");
272  cfg -> mincut = cpl_parameter_get_double(p);
273 
274  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.max_cut");
275  cfg -> maxcut = cpl_parameter_get_double(p);
276 
277 }
278 
286 void
287 sinfo_badsky_free(badsky_config * cfg)
288 {
289  cpl_free(cfg->framelist);
290  sinfo_badsky_cfg_destroy(cfg);
291 
292  return;
293 
294 }