SINFONI Pipeline Reference Manual  2.5.2
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_frameset * cur_set=NULL ;
130  cpl_frame * cur_frame=NULL ;
131  char * tag=NULL;
132  int i=0;
133  int wave_map=0;
134  int pos_slit=0;
135  int first_col=0;
136  //int halo_sp=0;
137  char spat_res[FILE_NAME_SZ];
138  char lamp_status[FILE_NAME_SZ];
139  char band[FILE_NAME_SZ];
140  int ins_set=0;
141 
142  //nframes = cpl_frameset_get_size(sof);
143 
144  /* Get the raw and the calibration files */
145  /* Labelise the input frames according to their tags */
146  labels = cpl_frameset_labelise(sof, sinfo_compare_tags,&nlabels );
147  if (labels == NULL) {
148  sinfo_msg_error( "Cannot labelise the input frames") ;
149  (*status)++;
150  return ;
151  }
152  if (nlabels == 1) {
153  /* Only one label - all images are objects observations */
154  /* Verify that it is really an observation */
155  cur_frame = cpl_frameset_get_frame(sof, 0) ;
156  tag = (char*)cpl_frame_get_tag(cur_frame) ;
157  if (sinfo_is_stack(tag)) {
158  *stk = cpl_frameset_duplicate(sof) ;
159  nstk++;
160  }
161  } else {
162  /* For each label */
163  for (i=0 ; i<nlabels ; i++) {
164  cur_set = cpl_frameset_extract(sof, labels, i) ;
165  cur_frame = cpl_frameset_get_frame(cur_set, 0) ;
166  tag = (char*)cpl_frame_get_tag(cur_frame) ;
167  if (sinfo_is_stack(tag) == 1) {
168  /* Stacked frame */
169  *stk = cpl_frameset_duplicate(cur_set) ;
170  nstk++;
171  } else if (sinfo_is_wavemap(tag)) {
172  /* pos slit calibration file */
173  strcpy(cfg -> wavemap,cpl_strdup(cpl_frame_get_filename(cur_frame)));
174  wave_map=1;
175  } else if (sinfo_is_distlist(tag)) {
176  /* pos slit calibration file */
177  strcpy(cfg -> poslist,cpl_strdup(cpl_frame_get_filename(cur_frame)));
178  pos_slit=1;
179  } else if (sinfo_is_firstcol(tag)) {
180  /* first col calibration file */
181  strcpy(cfg -> firstCol,cpl_strdup(cpl_frame_get_filename(cur_frame)));
182  first_col=1;
183  } else if (sinfo_is_halosp(tag)) {
184  /* first col calibration file */
185  strcpy(cfg->halospectrum,cpl_strdup(cpl_frame_get_filename(cur_frame)));
186  //halo_sp=1;
187  }
188  cpl_frameset_delete(cur_set) ;
189  }
190  }
191  cpl_free(labels) ;
192  if (nstk == 0) {
193  sinfo_msg_error( "Cannot find good input frames") ;
194  (*status)++;
195  return ;
196  }
197 
198  if (wave_map == 0) {
199  sinfo_msg_error( "Cannot find wave map");
200  (*status)++;
201  return ;
202  }
203  if (pos_slit == 0) {
204  sinfo_msg_error( "Cannot find pos slit") ;
205  (*status)++;
206  return ;
207  }
208  if (first_col == 0) {
209  sinfo_msg_error( "Cannot find first col") ;
210  (*status)++;
211  return ;
212  }
213 
214 
215  /* TEMPORALLY COMMENTED OUT */
216  nraw = cpl_frameset_get_size(*stk);
217  /* Test if the rawframes have been found */
218  if (nraw < 1) {
219  sinfo_msg_error("Cannot find input stacked frames in the input list") ;
220  (*status)++;
221  return ;
222  }
223 
224  nraw = cpl_frameset_get_size(*stk);
225  if (nraw < 1) {
226  sinfo_msg_error("no raw frame in input, something wrong!");
227  exit(-1);
228  }
229 
230  /* Allocate structures to go into the blackboard */
231  cfg->framelist = cpl_malloc(nraw * sizeof(char*));
232 
233  /* read input frames */
234  for (i=0 ; i<nraw ; i++) {
235  frame = cpl_frameset_get_frame(*stk,i);
236  if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1) {
237  cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
238  nraw_good++;
239  }
240  /* Store file name into framelist */
241  }
242  if (nraw_good < 1) {
243  sinfo_msg_error("no good raw frame in input!");
244  (*status)++;
245  return;
246  }
247  /* Copy relevant information into the blackboard */
248  cfg->nframes = nraw ;
249 
250  strcpy(cfg -> outName, SKYSPIDER_OUT_FILENAME);
251  strcpy(cfg -> maskname, SKYSPIDER_MASK_OUT_FILENAME);
252 
253 
254  frame = cpl_frameset_get_frame(*stk,0);
255 
256  sinfo_get_spatial_res(frame,spat_res);
257  switch(sinfo_frame_is_on(frame)) {
258 
259  case 0:
260  strcpy(lamp_status,"on");
261  break;
262  case 1:
263  strcpy(lamp_status,"off");
264  break;
265  case -1:
266  strcpy(lamp_status,"undefined");
267  break;
268  default:
269  strcpy(lamp_status,"undefined");
270  break;
271  }
272  sinfo_get_band(frame,band);
273  sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s ",
274  spat_res, lamp_status, band);
275 
276 
277  sinfo_get_ins_set(band,&ins_set);
278 
279 
280 
281  return;
282 }
283 
284 
285 static void
286 parse_section_jittering(object_config * cfg,cpl_parameterlist * cpl_cfg)
287 {
288  cpl_parameter* p;
289 
290  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.jitter_index");
291  cfg -> jitterind = cpl_parameter_get_bool(p);
292 
293  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.size_x");
294  cfg -> size_x = cpl_parameter_get_int(p);
295 
296  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.size_y");
297  cfg -> size_y = cpl_parameter_get_int(p);
298 
299  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.kernel_type");
300  strcpy(cfg -> kernel_type, cpl_parameter_get_string(p));
301 
302  /*
303  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.mask");
304  strcpy(cfg -> maskname, cpl_parameter_get_string(p));
305  */
306 
307 }
308 
309 static void
310 parse_section_resampling(object_config * cfg,cpl_parameterlist* cpl_cfg)
311 {
312  cpl_parameter* p;
313 
314  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.n_coeffs");
315  cfg -> ncoeffs = cpl_parameter_get_int(p);
316  cfg -> nrows=SINFO_RESAMP_NROWS;
317 
318 
319  return ;
320 }
321 
322 static void
323 parse_section_calibration(object_config * cfg)
324 {
325  /*
326  cpl_parameter* p;
327  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.halo_correct_index");
328  cfg -> halocorrectInd = cpl_parameter_get_bool(p);
329  */
330  cfg -> halocorrectInd=0;
331 
332  /*
333  p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.halo_spectrum_filename");
334  strcpy(cfg -> halospectrum, cpl_parameter_get_string(p));
335  */
336 
337 }
338 
339 static void
340 parse_section_cubecreation(object_config * cfg,cpl_parameterlist* cpl_cfg)
341 {
342  cpl_parameter* p;
343  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.nord_south_index");
344  cfg -> northsouthInd = cpl_parameter_get_bool(p);
345 
346  /*
347  p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.slitlets_position_list");
348  strcpy(cfg -> poslist, cpl_parameter_get_string(p));
349  */
350 
351  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.nslits");
352  cfg -> nslits = cpl_parameter_get_int(p);
353 
354  /*
355  p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.first_column_filename");
356  strcpy(cfg -> firstCol, cpl_parameter_get_string(p));
357  */
358 
359  return ;
360 }
361 
362 static void
363 parse_section_finetuning(object_config * cfg,cpl_parameterlist* cpl_cfg)
364 {
365  cpl_parameter* p;
366 
367  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.fine_tuning_method");
368  strcpy(cfg -> method, cpl_parameter_get_string(p));
369 
370  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.order");
371  cfg -> order = cpl_parameter_get_int(p);
372 
373 }
374 
375 static void
376 parse_section_skyextraction(object_config * cfg,cpl_parameterlist* cpl_cfg)
377 {
378 
379  cpl_parameter* p;
380  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.lower_rejection");
381  cfg -> loReject = (float) cpl_parameter_get_double(p);
382 
383  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.higher_rejection");
384  cfg -> hiReject = (float) cpl_parameter_get_double(p);
385 
386  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.tolerance");
387  cfg -> tolerance = cpl_parameter_get_int(p);
388 
389 }
390 
391 /*-----------------------------------------------------------------*/
392 void
393 sinfo_objspider_free(object_config * cfg) {
394  cpl_free(cfg->framelist);
395  sinfo_object_cfg_destroy (cfg);
396  return;
397 }