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 #include "sinfo_cpl_size.h"
00041 
00042 #include "sinfo_file_handling.h"
00043 /*---------------------------------------------------------------------------
00044                     Functions private to this module
00045  ---------------------------------------------------------------------------*/
00046 
00047 static void 
00048 parse_section_frames(object_config *,
00049                      cpl_frameset* sof, cpl_frameset**stk, int* status);
00050 static void 
00051 parse_section_jittering(object_config *, cpl_parameterlist * cpl_cfg);
00052 static void 
00053 parse_section_resampling(object_config *, cpl_parameterlist * cpl_cfg);
00054 static void 
00055 parse_section_calibration(object_config *);
00056 static void 
00057 parse_section_cubecreation(object_config *, cpl_parameterlist * cpl_cfg);
00058 static void 
00059 parse_section_finetuning(object_config *, cpl_parameterlist * cpl_cfg);
00060 static void 
00061 parse_section_skyextraction(object_config *, cpl_parameterlist * cpl_cfg);
00071 /*-------------------------------------------------------------------------*/
00082 /*--------------------------------------------------------------------------*/
00083 
00084 object_config * 
00085 sinfo_parse_cpl_input_objspider(cpl_parameterlist * cpl_cfg,cpl_frameset* sof,
00086               cpl_frameset** stk)
00087 {
00088    object_config   *  cfg = sinfo_object_cfg_create();
00089    int status=0;
00090    /*
00091     * Perform sanity checks, fill up the structure with what was
00092     * found in the ini file
00093     */
00094 
00095    
00096    parse_section_resampling   (cfg, cpl_cfg);
00097    parse_section_calibration  (cfg);
00098    parse_section_cubecreation (cfg, cpl_cfg);
00099    parse_section_finetuning   (cfg, cpl_cfg); 
00100    parse_section_skyextraction(cfg, cpl_cfg); 
00101    parse_section_jittering    (cfg, cpl_cfg);
00102    parse_section_frames       (cfg, sof,stk,&status);
00103    if (status > 0) {
00104                 sinfo_msg_error("parsing cpl input");
00105                 sinfo_object_cfg_destroy(cfg);
00106                 cfg = NULL ;
00107                 return NULL ;
00108    }
00109  
00110    return cfg ;
00111 }
00112 
00113 static void      
00114 parse_section_frames(object_config * cfg, 
00115              cpl_frameset* sof,
00116                      cpl_frameset** stk,
00117                      int* status)
00118 {
00119    int                     nraw_good =0;
00120 
00121 
00122 
00123    int nframes=0;
00124    int nraw=0;
00125    cpl_frame* frame   = NULL;
00126    int nstk=0;
00127    cpl_size             *   labels=NULL ;
00128    cpl_size                 nlabels=0 ;
00129    cpl_frameset    *   cur_set=NULL ;
00130    cpl_frame       *   cur_frame=NULL ;
00131    char * tag=NULL;
00132    int i=0;
00133    int wave_map=0;
00134    int pos_slit=0;
00135    int first_col=0;
00136    int halo_sp=0;
00137    char spat_res[FILE_NAME_SZ];
00138    char lamp_status[FILE_NAME_SZ];
00139    char band[FILE_NAME_SZ];
00140    int ins_set=0;
00141 
00142    nframes = cpl_frameset_get_size(sof);
00143 
00144    /* Get the raw and the calibration files */
00145    /* Labelise the input frames according to their tags */
00146    labels = cpl_frameset_labelise(sof, sinfo_compare_tags,&nlabels );
00147    if (labels == NULL) {
00148      sinfo_msg_error( "Cannot labelise the input frames") ;
00149      (*status)++;
00150      return ;
00151    }
00152    if (nlabels == 1) {
00153       /* Only one label - all images are objects observations */
00154       /* Verify that it is really an observation */
00155       cur_frame = cpl_frameset_get_frame(sof, 0) ;
00156       tag = (char*)cpl_frame_get_tag(cur_frame) ;
00157       if (sinfo_is_stack(tag)) {
00158     *stk = cpl_frameset_duplicate(sof) ;
00159     nstk++;
00160       }
00161    } else {
00162      /* For each label */
00163      for (i=0 ; i<nlabels ; i++) {
00164        cur_set = cpl_frameset_extract(sof, labels, i) ;
00165        cur_frame = cpl_frameset_get_frame(cur_set, 0) ;
00166        tag = (char*)cpl_frame_get_tag(cur_frame) ;
00167        if (sinfo_is_stack(tag) == 1) {
00168      /* Stacked frame */
00169      *stk = cpl_frameset_duplicate(cur_set) ;
00170      nstk++;
00171        } else if (sinfo_is_wavemap(tag)) {
00172      /* pos slit calibration file */
00173      strcpy(cfg -> wavemap,cpl_strdup(cpl_frame_get_filename(cur_frame)));
00174      wave_map=1;
00175        } else if (sinfo_is_distlist(tag)) {
00176      /* pos slit calibration file */
00177      strcpy(cfg -> poslist,cpl_strdup(cpl_frame_get_filename(cur_frame)));
00178      pos_slit=1;
00179        } else if (sinfo_is_firstcol(tag)) { 
00180      /* first col calibration file */
00181      strcpy(cfg -> firstCol,cpl_strdup(cpl_frame_get_filename(cur_frame)));
00182      first_col=1;
00183        } else if (sinfo_is_halosp(tag)) { 
00184      /* first col calibration file */
00185      strcpy(cfg->halospectrum,cpl_strdup(cpl_frame_get_filename(cur_frame)));
00186      halo_sp=1;
00187        }
00188        cpl_frameset_delete(cur_set) ;
00189      }
00190    }
00191    cpl_free(labels) ;
00192    if (nstk == 0) {
00193      sinfo_msg_error( "Cannot find good input frames") ;
00194      (*status)++;
00195      return ;
00196    }
00197 
00198    if (wave_map == 0) {
00199      sinfo_msg_error( "Cannot find wave map");
00200      (*status)++;
00201      return ;
00202    }
00203    if (pos_slit == 0) {
00204      sinfo_msg_error( "Cannot find pos slit") ;
00205      (*status)++;
00206      return ;
00207    }
00208    if (first_col == 0) {
00209      sinfo_msg_error( "Cannot find first col") ;
00210      (*status)++;
00211      return ;
00212    }
00213 
00214 
00215    /* TEMPORALLY COMMENTED OUT */
00216    nraw    = cpl_frameset_get_size(*stk);
00217    /* Test if the rawframes have been found */
00218    if (nraw < 1) {
00219      sinfo_msg_error("Cannot find input stacked frames in the input list") ;
00220      (*status)++;
00221      return ;
00222    }
00223 
00224    nraw    = cpl_frameset_get_size(*stk);
00225    if (nraw < 1) {
00226      sinfo_msg_error("no raw frame in input, something wrong!");
00227      exit(-1);
00228    }
00229 
00230    /* Allocate structures to go into the blackboard */
00231    cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
00232 
00233   /* read input frames */
00234    for (i=0 ; i<nraw ; i++) {
00235      frame = cpl_frameset_get_frame(*stk,i);
00236      if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1) {
00237        cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
00238        nraw_good++;
00239      }
00240      /* Store file name into framelist */
00241    }
00242    if (nraw_good < 1) {
00243      sinfo_msg_error("no good raw frame in input!");
00244      (*status)++;
00245      return;
00246    }
00247    /* Copy relevant information into the blackboard */
00248    cfg->nframes         = nraw ;
00249 
00250    strcpy(cfg -> outName, SKYSPIDER_OUT_FILENAME);
00251    strcpy(cfg -> maskname, SKYSPIDER_MASK_OUT_FILENAME);
00252 
00253 
00254    frame = cpl_frameset_get_frame(*stk,0);
00255 
00256    sinfo_get_spatial_res(frame,spat_res);
00257    switch(sinfo_frame_is_on(frame)) {
00258 
00259    case 0: 
00260      strcpy(lamp_status,"on");
00261      break;
00262    case 1: 
00263      strcpy(lamp_status,"off");
00264      break;
00265    case -1:
00266      strcpy(lamp_status,"undefined");
00267      break;
00268    default: 
00269      strcpy(lamp_status,"undefined");
00270      break;
00271    }
00272    sinfo_get_band(frame,band);
00273    sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s ",
00274            spat_res,    lamp_status,    band);
00275 
00276 
00277    sinfo_get_ins_set(band,&ins_set);
00278 
00279 
00280 
00281    return;
00282 }
00283 
00284 
00285 static void     
00286 parse_section_jittering(object_config * cfg,cpl_parameterlist * cpl_cfg)
00287 {
00288   cpl_parameter* p;
00289 
00290   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.jitter_index");
00291   cfg -> jitterind = cpl_parameter_get_bool(p);
00292 
00293   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.size_x");
00294   cfg -> size_x = cpl_parameter_get_int(p);
00295 
00296   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.size_y");
00297   cfg -> size_y = cpl_parameter_get_int(p);
00298 
00299   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.kernel_type");
00300   strcpy(cfg -> kernel_type, cpl_parameter_get_string(p));
00301 
00302   /*
00303   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.mask");
00304   strcpy(cfg -> maskname, cpl_parameter_get_string(p));
00305   */
00306 
00307 }
00308 
00309 static void     
00310 parse_section_resampling(object_config * cfg,cpl_parameterlist* cpl_cfg)
00311 {
00312   cpl_parameter* p;
00313 
00314   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.n_coeffs");
00315   cfg -> ncoeffs = cpl_parameter_get_int(p);
00316   cfg -> nrows=SINFO_RESAMP_NROWS;
00317 
00318 
00319   return ;
00320 }
00321 
00322 static void     
00323 parse_section_calibration(object_config * cfg)
00324 {
00325   /*
00326   cpl_parameter* p;
00327   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.halo_correct_index");
00328   cfg -> halocorrectInd = cpl_parameter_get_bool(p);
00329   */
00330   cfg -> halocorrectInd=0;
00331 
00332   /*
00333   p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.halo_spectrum_filename");
00334   strcpy(cfg -> halospectrum, cpl_parameter_get_string(p));
00335   */
00336 
00337 }
00338 
00339 static void     
00340 parse_section_cubecreation(object_config * cfg,cpl_parameterlist* cpl_cfg)
00341 {
00342   cpl_parameter* p;
00343   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.nord_south_index");
00344   cfg -> northsouthInd = cpl_parameter_get_bool(p);
00345 
00346   /*
00347   p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.slitlets_position_list");
00348   strcpy(cfg -> poslist, cpl_parameter_get_string(p));
00349   */
00350 
00351   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.nslits");
00352   cfg -> nslits = cpl_parameter_get_int(p);
00353 
00354   /*
00355   p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.first_column_filename");
00356   strcpy(cfg -> firstCol, cpl_parameter_get_string(p));
00357   */
00358 
00359    return ;
00360 }
00361 
00362 static void     
00363 parse_section_finetuning(object_config * cfg,cpl_parameterlist* cpl_cfg)
00364 {
00365   cpl_parameter* p;
00366 
00367   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.fine_tuning_method");
00368   strcpy(cfg -> method, cpl_parameter_get_string(p));
00369 
00370   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.order");
00371   cfg -> order = cpl_parameter_get_int(p);
00372 
00373 }
00374 
00375 static void     
00376 parse_section_skyextraction(object_config * cfg,cpl_parameterlist* cpl_cfg)
00377 {
00378 
00379   cpl_parameter* p;
00380   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.lower_rejection");
00381   cfg -> loReject = (float) cpl_parameter_get_double(p);
00382 
00383   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.higher_rejection");
00384   cfg -> hiReject = (float) cpl_parameter_get_double(p);
00385 
00386   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.tolerance");
00387   cfg -> tolerance = cpl_parameter_get_int(p);
00388 
00389 }
00390 
00391 /*-----------------------------------------------------------------*/
00392 void
00393 sinfo_objspider_free(object_config * cfg) {
00394   cpl_free(cfg->framelist);
00395   sinfo_object_cfg_destroy (cfg);
00396   return;
00397 }

Generated on 3 Mar 2013 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1