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

Generated on Wed Jan 17 08:33:43 2007 for SINFONI Pipeline Reference Manual by  doxygen 1.4.4