SINFONI Pipeline Reference Manual  2.6.0
sinfo_objspider_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_objspider_ini_by_cpl.c
23  Author : Andrea Modigliani
24  Created on : May 22, 2004
25  Description : object cube creation cpl input handling for SPIFFI
26 
27  ---------------------------------------------------------------------------*/
28 
29 #ifdef HAVE_CONFIG_H
30 # include <config.h>
31 #endif
32 /*---------------------------------------------------------------------------
33  Includes
34  ---------------------------------------------------------------------------*/
35 #include <string.h>
36 #include "sinfo_objspider_ini_by_cpl.h"
37 #include "sinfo_functions.h"
38 #include "sinfo_pro_types.h"
39 #include "sinfo_hidden.h"
40 #include "sinfo_cpl_size.h"
41 
42 #include "sinfo_file_handling.h"
43 /*---------------------------------------------------------------------------
44  Functions private to this module
45  ---------------------------------------------------------------------------*/
46 
47 static void
48 parse_section_frames(object_config *,
49  cpl_frameset* sof, cpl_frameset**stk, int* status);
50 static void
51 parse_section_jittering(object_config *, cpl_parameterlist * cpl_cfg);
52 static void
53 parse_section_resampling(object_config *, cpl_parameterlist * cpl_cfg);
54 static void
55 parse_section_calibration(object_config *);
56 static void
57 parse_section_cubecreation(object_config *, cpl_parameterlist * cpl_cfg);
58 static void
59 parse_section_finetuning(object_config *, cpl_parameterlist * cpl_cfg);
60 static void
61 parse_section_skyextraction(object_config *, cpl_parameterlist * cpl_cfg);
71 /*-------------------------------------------------------------------------*/
82 /*--------------------------------------------------------------------------*/
83 
84 object_config *
85 sinfo_parse_cpl_input_objspider(cpl_parameterlist * cpl_cfg,cpl_frameset* sof,
86  cpl_frameset** stk)
87 {
88  object_config * cfg = sinfo_object_cfg_create();
89  int status=0;
90  /*
91  * Perform sanity checks, fill up the structure with what was
92  * found in the ini file
93  */
94 
95 
96  parse_section_resampling (cfg, cpl_cfg);
97  parse_section_calibration (cfg);
98  parse_section_cubecreation (cfg, cpl_cfg);
99  parse_section_finetuning (cfg, cpl_cfg);
100  parse_section_skyextraction(cfg, cpl_cfg);
101  parse_section_jittering (cfg, cpl_cfg);
102  parse_section_frames (cfg, sof,stk,&status);
103  if (status > 0) {
104  sinfo_msg_error("parsing cpl input");
105  sinfo_object_cfg_destroy(cfg);
106  cfg = NULL ;
107  return NULL ;
108  }
109 
110  return cfg ;
111 }
112 
113 static void
114 parse_section_frames(object_config * cfg,
115  cpl_frameset* sof,
116  cpl_frameset** stk,
117  int* status)
118 {
119  int nraw_good =0;
120 
121 
122 
123  //int nframes=0;
124  int nraw=0;
125  cpl_frame* frame = NULL;
126  int nstk=0;
127  cpl_size * labels=NULL ;
128  cpl_size nlabels=0 ;
129  cpl_frame * cur_frame=NULL ;
130  char * tag=NULL;
131  int i=0;
132  int wave_map=0;
133  int pos_slit=0;
134  int first_col=0;
135  //int halo_sp=0;
136  char spat_res[FILE_NAME_SZ];
137  char lamp_status[FILE_NAME_SZ];
138  char band[FILE_NAME_SZ];
139  int ins_set=0;
140 
141  //nframes = cpl_frameset_get_size(sof);
142 
143  /* Get the raw and the calibration files */
144  /* Labelise the input frames according to their tags */
145  labels = cpl_frameset_labelise(sof, sinfo_compare_tags,&nlabels );
146  if (labels == NULL) {
147  sinfo_msg_error( "Cannot labelise the input frames") ;
148  (*status)++;
149  return ;
150  }
151  if (nlabels == 1) {
152  /* Only one label - all images are objects observations */
153  /* Verify that it is really an observation */
154  cur_frame = cpl_frameset_get_frame(sof, 0) ;
155  tag = (char*)cpl_frame_get_tag(cur_frame) ;
156  if (sinfo_is_stack(tag)) {
157  *stk = cpl_frameset_duplicate(sof) ;
158  nstk++;
159  }
160  } else {
161  /* For each label */
162  for (i=0 ; i<nlabels ; i++) {
163  cpl_frameset* cur_set = cpl_frameset_extract(sof, labels, i) ;
164  cur_frame = cpl_frameset_get_frame(cur_set, 0) ;
165  tag = (char*)cpl_frame_get_tag(cur_frame) ;
166  if (sinfo_is_stack(tag) == 1) {
167  /* Stacked frame */
168  *stk = cpl_frameset_duplicate(cur_set) ;
169  nstk++;
170  } else if (sinfo_is_wavemap(tag)) {
171  /* pos slit calibration file */
172  strcpy(cfg -> wavemap,cpl_strdup(cpl_frame_get_filename(cur_frame)));
173  wave_map=1;
174  } else if (sinfo_is_distlist(tag)) {
175  /* pos slit calibration file */
176  strcpy(cfg -> poslist,cpl_strdup(cpl_frame_get_filename(cur_frame)));
177  pos_slit=1;
178  } else if (sinfo_is_firstcol(tag)) {
179  /* first col calibration file */
180  strcpy(cfg -> firstCol,cpl_strdup(cpl_frame_get_filename(cur_frame)));
181  first_col=1;
182  } else if (sinfo_is_halosp(tag)) {
183  /* first col calibration file */
184  strcpy(cfg->halospectrum,cpl_strdup(cpl_frame_get_filename(cur_frame)));
185  //halo_sp=1;
186  }
187  cpl_frameset_delete(cur_set) ;
188  }
189  }
190  cpl_free(labels) ;
191  if (nstk == 0) {
192  sinfo_msg_error( "Cannot find good input frames") ;
193  (*status)++;
194  return ;
195  }
196 
197  if (wave_map == 0) {
198  sinfo_msg_error( "Cannot find wave map");
199  (*status)++;
200  return ;
201  }
202  if (pos_slit == 0) {
203  sinfo_msg_error( "Cannot find pos slit") ;
204  (*status)++;
205  return ;
206  }
207  if (first_col == 0) {
208  sinfo_msg_error( "Cannot find first col") ;
209  (*status)++;
210  return ;
211  }
212 
213 
214  /* TEMPORALLY COMMENTED OUT */
215  nraw = cpl_frameset_get_size(*stk);
216  /* Test if the rawframes have been found */
217  if (nraw < 1) {
218  sinfo_msg_error("Cannot find input stacked frames in the input list") ;
219  (*status)++;
220  return ;
221  }
222 
223  nraw = cpl_frameset_get_size(*stk);
224  if (nraw < 1) {
225  sinfo_msg_error("no raw frame in input, something wrong!");
226  exit(-1);
227  }
228 
229  /* Allocate structures to go into the blackboard */
230  cfg->framelist = cpl_malloc(nraw * sizeof(char*));
231 
232  /* read input frames */
233  for (i=0 ; i<nraw ; i++) {
234  frame = cpl_frameset_get_frame(*stk,i);
235  if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1) {
236  cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
237  nraw_good++;
238  }
239  /* Store file name into framelist */
240  }
241  if (nraw_good < 1) {
242  sinfo_msg_error("no good raw frame in input!");
243  (*status)++;
244  return;
245  }
246  /* Copy relevant information into the blackboard */
247  cfg->nframes = nraw ;
248 
249  strcpy(cfg -> outName, SKYSPIDER_OUT_FILENAME);
250  strcpy(cfg -> maskname, SKYSPIDER_MASK_OUT_FILENAME);
251 
252 
253  frame = cpl_frameset_get_frame(*stk,0);
254 
255  sinfo_get_spatial_res(frame,spat_res);
256  switch(sinfo_frame_is_on(frame)) {
257 
258  case 0:
259  strcpy(lamp_status,"on");
260  break;
261  case 1:
262  strcpy(lamp_status,"off");
263  break;
264  case -1:
265  strcpy(lamp_status,"undefined");
266  break;
267  default:
268  strcpy(lamp_status,"undefined");
269  break;
270  }
271  sinfo_get_band(frame,band);
272  sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s ",
273  spat_res, lamp_status, band);
274 
275 
276  sinfo_get_ins_set(band,&ins_set);
277 
278 
279 
280  return;
281 }
282 
283 
284 static void
285 parse_section_jittering(object_config * cfg,cpl_parameterlist * cpl_cfg)
286 {
287  cpl_parameter* p;
288 
289  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.jitter_index");
290  cfg -> jitterind = cpl_parameter_get_bool(p);
291 
292  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.size_x");
293  cfg -> size_x = cpl_parameter_get_int(p);
294 
295  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.size_y");
296  cfg -> size_y = cpl_parameter_get_int(p);
297 
298  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.kernel_type");
299  strcpy(cfg -> kernel_type, cpl_parameter_get_string(p));
300 
301  /*
302  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.mask");
303  strcpy(cfg -> maskname, cpl_parameter_get_string(p));
304  */
305 
306 }
307 
308 static void
309 parse_section_resampling(object_config * cfg,cpl_parameterlist* cpl_cfg)
310 {
311  cpl_parameter* p;
312 
313  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.n_coeffs");
314  cfg -> ncoeffs = cpl_parameter_get_int(p);
315  cfg -> nrows=SINFO_RESAMP_NROWS;
316 
317 
318  return ;
319 }
320 
321 static void
322 parse_section_calibration(object_config * cfg)
323 {
324  /*
325  cpl_parameter* p;
326  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.halo_correct_index");
327  cfg -> halocorrectInd = cpl_parameter_get_bool(p);
328  */
329  cfg -> halocorrectInd=0;
330 
331  /*
332  p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.halo_spectrum_filename");
333  strcpy(cfg -> halospectrum, cpl_parameter_get_string(p));
334  */
335 
336 }
337 
338 static void
339 parse_section_cubecreation(object_config * cfg,cpl_parameterlist* cpl_cfg)
340 {
341  cpl_parameter* p;
342  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.nord_south_index");
343  cfg -> northsouthInd = cpl_parameter_get_bool(p);
344 
345  /*
346  p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.slitlets_position_list");
347  strcpy(cfg -> poslist, cpl_parameter_get_string(p));
348  */
349 
350  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.nslits");
351  cfg -> nslits = cpl_parameter_get_int(p);
352 
353  /*
354  p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.first_column_filename");
355  strcpy(cfg -> firstCol, cpl_parameter_get_string(p));
356  */
357 
358  return ;
359 }
360 
361 static void
362 parse_section_finetuning(object_config * cfg,cpl_parameterlist* cpl_cfg)
363 {
364  cpl_parameter* p;
365 
366  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.fine_tuning_method");
367  strcpy(cfg -> method, cpl_parameter_get_string(p));
368 
369  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.order");
370  cfg -> order = cpl_parameter_get_int(p);
371 
372 }
373 
374 static void
375 parse_section_skyextraction(object_config * cfg,cpl_parameterlist* cpl_cfg)
376 {
377 
378  cpl_parameter* p;
379  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.lower_rejection");
380  cfg -> loReject = (float) cpl_parameter_get_double(p);
381 
382  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.higher_rejection");
383  cfg -> hiReject = (float) cpl_parameter_get_double(p);
384 
385  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.tolerance");
386  cfg -> tolerance = cpl_parameter_get_int(p);
387 
388 }
389 
390 /*-----------------------------------------------------------------*/
391 void
392 sinfo_objspider_free(object_config * cfg) {
393  cpl_free(cfg->framelist);
394  sinfo_object_cfg_destroy (cfg);
395  return;
396 }
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69