sinfo_objspider_ini_by_cpl.c

00001 /*
00002  * This file is part of the ESO SINFONI Pipeline
00003  * Copyright (C) 2004,2005 European Southern Observatory
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
00018  */
00019 
00020 /*----------------------------------------------------------------------------
00021    
00022    File name    :   sinfo_objspider_ini_by_cpl.c
00023    Author       :   Andrea Modigliani
00024    Created on   :   May 22, 2004
00025    Description  :   object cube creation cpl input handling for SPIFFI
00026 
00027  ---------------------------------------------------------------------------*/
00028 
00029 #ifdef HAVE_CONFIG_H
00030 #  include <config.h>
00031 #endif
00032 /*---------------------------------------------------------------------------
00033                                 Includes
00034  ---------------------------------------------------------------------------*/
00035 #include <string.h>
00036 #include "sinfo_objspider_ini_by_cpl.h"
00037 #include "sinfo_functions.h"
00038 #include "sinfo_pro_types.h"
00039 #include "sinfo_hidden.h"
00040 
00041 #include "sinfo_file_handling.h"
00042 /*---------------------------------------------------------------------------
00043                     Functions private to this module
00044  ---------------------------------------------------------------------------*/
00045 
00046 static void 
00047 parse_section_frames(object_config *,
00048                      cpl_frameset* sof, cpl_frameset**stk, int* status);
00049 static void 
00050 parse_section_jittering(object_config *, cpl_parameterlist * cpl_cfg);
00051 static void 
00052 parse_section_resampling(object_config *, cpl_parameterlist * cpl_cfg);
00053 static void 
00054 parse_section_calibration(object_config *);
00055 static void 
00056 parse_section_cubecreation(object_config *, cpl_parameterlist * cpl_cfg);
00057 static void 
00058 parse_section_finetuning(object_config *, cpl_parameterlist * cpl_cfg);
00059 static void 
00060 parse_section_skyextraction(object_config *, cpl_parameterlist * cpl_cfg);
00070 /*-------------------------------------------------------------------------*/
00081 /*--------------------------------------------------------------------------*/
00082 
00083 object_config * 
00084 sinfo_parse_cpl_input_objspider(cpl_parameterlist * cpl_cfg,cpl_frameset* sof,
00085               cpl_frameset** stk)
00086 {
00087    object_config   *  cfg = sinfo_object_cfg_create();
00088    int status=0;
00089    /*
00090     * Perform sanity checks, fill up the structure with what was
00091     * found in the ini file
00092     */
00093 
00094    
00095    parse_section_resampling   (cfg, cpl_cfg);
00096    parse_section_calibration  (cfg);
00097    parse_section_cubecreation (cfg, cpl_cfg);
00098    parse_section_finetuning   (cfg, cpl_cfg); 
00099    parse_section_skyextraction(cfg, cpl_cfg); 
00100    parse_section_jittering    (cfg, cpl_cfg);
00101    parse_section_frames       (cfg, sof,stk,&status);
00102    if (status > 0) {
00103                 sinfo_msg_error("parsing cpl input");
00104                 sinfo_object_cfg_destroy(cfg);
00105                 cfg = NULL ;
00106                 return NULL ;
00107    }
00108  
00109    return cfg ;
00110 }
00111 
00112 static void      
00113 parse_section_frames(object_config * cfg, 
00114              cpl_frameset* sof,
00115                      cpl_frameset** stk,
00116                      int* status)
00117 {
00118    int                     nraw_good =0;
00119 
00120 
00121 
00122    int nframes=0;
00123    int nraw=0;
00124    cpl_frame* frame   = NULL;
00125    int nstk=0;
00126    int             *   labels=NULL ;
00127    int                 nlabels=0 ;
00128    cpl_frameset    *   cur_set=NULL ;
00129    cpl_frame       *   cur_frame=NULL ;
00130    char * tag=NULL;
00131    int i=0;
00132    int wave_map=0;
00133    int pos_slit=0;
00134    int first_col=0;
00135    int halo_sp=0;
00136    char spat_res[FILE_NAME_SZ];
00137    char lamp_status[FILE_NAME_SZ];
00138    char band[FILE_NAME_SZ];
00139    int ins_set=0;
00140 
00141    nframes = cpl_frameset_get_size(sof);
00142 
00143    /* Get the raw and the calibration files */
00144    /* Labelise the input frames according to their tags */
00145    labels = cpl_frameset_labelise(sof, sinfo_compare_tags,&nlabels );
00146    if (labels == NULL) {
00147      sinfo_msg_error( "Cannot labelise the input frames") ;
00148      (*status)++;
00149      return ;
00150    }
00151    if (nlabels == 1) {
00152       /* Only one label - all images are objects observations */
00153       /* Verify that it is really an observation */
00154       cur_frame = cpl_frameset_get_frame(sof, 0) ;
00155       tag = (char*)cpl_frame_get_tag(cur_frame) ;
00156       if (sinfo_is_stack(tag)) {
00157     *stk = cpl_frameset_duplicate(sof) ;
00158     nstk++;
00159       }
00160    } else {
00161      /* For each label */
00162      for (i=0 ; i<nlabels ; i++) {
00163        cur_set = cpl_frameset_extract(sof, labels, i) ;
00164        cur_frame = cpl_frameset_get_frame(cur_set, 0) ;
00165        tag = (char*)cpl_frame_get_tag(cur_frame) ;
00166        if (sinfo_is_stack(tag) == 1) {
00167      /* Stacked frame */
00168      *stk = cpl_frameset_duplicate(cur_set) ;
00169      nstk++;
00170        } else if (sinfo_is_wavemap(tag)) {
00171      /* pos slit calibration file */
00172      strcpy(cfg -> wavemap,cpl_strdup(cpl_frame_get_filename(cur_frame)));
00173      wave_map=1;
00174        } else if (sinfo_is_distlist(tag)) {
00175      /* pos slit calibration file */
00176      strcpy(cfg -> poslist,cpl_strdup(cpl_frame_get_filename(cur_frame)));
00177      pos_slit=1;
00178        } else if (sinfo_is_firstcol(tag)) { 
00179      /* first col calibration file */
00180      strcpy(cfg -> firstCol,cpl_strdup(cpl_frame_get_filename(cur_frame)));
00181      first_col=1;
00182        } else if (sinfo_is_halosp(tag)) { 
00183      /* first col calibration file */
00184      strcpy(cfg->halospectrum,cpl_strdup(cpl_frame_get_filename(cur_frame)));
00185      halo_sp=1;
00186        }
00187        cpl_frameset_delete(cur_set) ;
00188      }
00189    }
00190    cpl_free(labels) ;
00191    if (nstk == 0) {
00192      sinfo_msg_error( "Cannot find good input frames") ;
00193      (*status)++;
00194      return ;
00195    }
00196 
00197    if (wave_map == 0) {
00198      sinfo_msg_error( "Cannot find wave map");
00199      (*status)++;
00200      return ;
00201    }
00202    if (pos_slit == 0) {
00203      sinfo_msg_error( "Cannot find pos slit") ;
00204      (*status)++;
00205      return ;
00206    }
00207    if (first_col == 0) {
00208      sinfo_msg_error( "Cannot find first col") ;
00209      (*status)++;
00210      return ;
00211    }
00212 
00213 
00214    /* TEMPORALLY COMMENTED OUT */
00215    nraw    = cpl_frameset_get_size(*stk);
00216    /* Test if the rawframes have been found */
00217    if (nraw < 1) {
00218      sinfo_msg_error("Cannot find input stacked frames in the input list") ;
00219      (*status)++;
00220      return ;
00221    }
00222 
00223    nraw    = cpl_frameset_get_size(*stk);
00224    if (nraw < 1) {
00225      sinfo_msg_error("no raw frame in input, something wrong!");
00226      exit(-1);
00227    }
00228 
00229    /* Allocate structures to go into the blackboard */
00230    cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
00231 
00232   /* read input frames */
00233    for (i=0 ; i<nraw ; i++) {
00234      frame = cpl_frameset_get_frame(*stk,i);
00235      if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1) {
00236        cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
00237        nraw_good++;
00238      }
00239      /* Store file name into framelist */
00240    }
00241    if (nraw_good < 1) {
00242      sinfo_msg_error("no good raw frame in input!");
00243      (*status)++;
00244      return;
00245    }
00246    /* Copy relevant information into the blackboard */
00247    cfg->nframes         = nraw ;
00248 
00249    strcpy(cfg -> outName, SKYSPIDER_OUT_FILENAME);
00250    strcpy(cfg -> maskname, SKYSPIDER_MASK_OUT_FILENAME);
00251 
00252 
00253    frame = cpl_frameset_get_frame(*stk,0);
00254 
00255    sinfo_get_spatial_res(frame,spat_res);
00256    switch(sinfo_frame_is_on(frame)) {
00257 
00258    case 0: 
00259      strcpy(lamp_status,"on");
00260      break;
00261    case 1: 
00262      strcpy(lamp_status,"off");
00263      break;
00264    case -1:
00265      strcpy(lamp_status,"undefined");
00266      break;
00267    default: 
00268      strcpy(lamp_status,"undefined");
00269      break;
00270    }
00271    sinfo_get_band(frame,band);
00272    sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s ",
00273            spat_res,    lamp_status,    band);
00274 
00275 
00276    sinfo_get_ins_set(band,&ins_set);
00277 
00278 
00279 
00280    return;
00281 }
00282 
00283 
00284 static void     
00285 parse_section_jittering(object_config * cfg,cpl_parameterlist * cpl_cfg)
00286 {
00287   cpl_parameter* p;
00288 
00289   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.jitter_index");
00290   cfg -> jitterind = cpl_parameter_get_bool(p);
00291 
00292   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.size_x");
00293   cfg -> size_x = cpl_parameter_get_int(p);
00294 
00295   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.size_y");
00296   cfg -> size_y = cpl_parameter_get_int(p);
00297 
00298   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.kernel_type");
00299   strcpy(cfg -> kernel_type, cpl_parameter_get_string(p));
00300 
00301   /*
00302   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.mask");
00303   strcpy(cfg -> maskname, cpl_parameter_get_string(p));
00304   */
00305 
00306 }
00307 
00308 static void     
00309 parse_section_resampling(object_config * cfg,cpl_parameterlist* cpl_cfg)
00310 {
00311   cpl_parameter* p;
00312 
00313   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.n_coeffs");
00314   cfg -> ncoeffs = cpl_parameter_get_int(p);
00315   cfg -> nrows=SINFO_RESAMP_NROWS;
00316 
00317 
00318   return ;
00319 }
00320 
00321 static void     
00322 parse_section_calibration(object_config * cfg)
00323 {
00324   /*
00325   cpl_parameter* p;
00326   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.halo_correct_index");
00327   cfg -> halocorrectInd = cpl_parameter_get_bool(p);
00328   */
00329   cfg -> halocorrectInd=0;
00330 
00331   /*
00332   p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.halo_spectrum_filename");
00333   strcpy(cfg -> halospectrum, cpl_parameter_get_string(p));
00334   */
00335 
00336 }
00337 
00338 static void     
00339 parse_section_cubecreation(object_config * cfg,cpl_parameterlist* cpl_cfg)
00340 {
00341   cpl_parameter* p;
00342   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.nord_south_index");
00343   cfg -> northsouthInd = cpl_parameter_get_bool(p);
00344 
00345   /*
00346   p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.slitlets_position_list");
00347   strcpy(cfg -> poslist, cpl_parameter_get_string(p));
00348   */
00349 
00350   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.nslits");
00351   cfg -> nslits = cpl_parameter_get_int(p);
00352 
00353   /*
00354   p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.first_column_filename");
00355   strcpy(cfg -> firstCol, cpl_parameter_get_string(p));
00356   */
00357 
00358    return ;
00359 }
00360 
00361 static void     
00362 parse_section_finetuning(object_config * cfg,cpl_parameterlist* cpl_cfg)
00363 {
00364   cpl_parameter* p;
00365 
00366   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.fine_tuning_method");
00367   strcpy(cfg -> method, cpl_parameter_get_string(p));
00368 
00369   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.order");
00370   cfg -> order = cpl_parameter_get_int(p);
00371 
00372 }
00373 
00374 static void     
00375 parse_section_skyextraction(object_config * cfg,cpl_parameterlist* cpl_cfg)
00376 {
00377 
00378   cpl_parameter* p;
00379   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.lower_rejection");
00380   cfg -> loReject = (float) cpl_parameter_get_double(p);
00381 
00382   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.higher_rejection");
00383   cfg -> hiReject = (float) cpl_parameter_get_double(p);
00384 
00385   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.tolerance");
00386   cfg -> tolerance = cpl_parameter_get_int(p);
00387 
00388 }
00389 
00390 /*-----------------------------------------------------------------*/
00391 void
00392 sinfo_objspider_free(object_config * cfg) {
00393   cpl_free(cfg->framelist);
00394   sinfo_object_cfg_destroy (cfg);
00395   return;
00396 }

Generated on 8 Mar 2011 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1