sinfo_utl_skycor.c

00001 /* $Id: sinfo_utl_skycor.c,v 1.13 2007/10/26 09:40:28 amodigli Exp $
00002  *
00003  * This file is part of the SINFONI Pipeline
00004  * Copyright (C) 2002,2003 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: amodigli $
00023  * $Date: 2007/10/26 09:40:28 $
00024  * $Revision: 1.13 $
00025  * $Name: sinfo-2_2_5 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
00034  ----------------------------------------------------------------------------*/
00035 #include <string.h>
00036 #include <cpl.h>
00037 #include <irplib_utils.h>
00038 #include <sinfo_skycor.h>
00039 #include <sinfo_skycor_config.h>
00040 #include <sinfo_tpl_utils.h>
00041 #include <sinfo_tpl_dfs.h>
00042 #include <sinfo_pro_types.h>
00043 #include <sinfo_utils_wrappers.h>
00044 #include <sinfo_error.h>
00045 #include <sinfo_msg.h>
00046 #include <sinfo_pro_save.h>
00047 #include <sinfo_globals.h>
00048 /*-----------------------------------------------------------------------------
00049                                 Defines
00050  ----------------------------------------------------------------------------*/
00051 
00052 /*-----------------------------------------------------------------------------
00053                             Functions prototypes
00054 -----------------------------------------------------------------------------*/
00055 static int sinfo_utl_skycor_create(cpl_plugin *) ;
00056 static int sinfo_utl_skycor_exec(cpl_plugin *) ;
00057 static int sinfo_utl_skycor_destroy(cpl_plugin *) ;
00058 static int sinfo_utl_skycor(cpl_parameterlist * config, cpl_frameset* set);
00059 /*-----------------------------------------------------------------------------
00060                             Static variables
00061  -----------------------------------------------------------------------------*/
00062 
00063 static char sinfo_utl_skycor_description[] =
00064 "This recipe perform a correction of possible sky line residuals in the \n"
00065 "object cube after standard data reduction.\n"
00066 "Input frames are cubes with target and sky observations.\n"
00067 "Their tags can be respectively OBS_OBJ (or OBS_PSF or OBS_STD) and OBS_SKY.\n"
00068 "The output is a cube with same tag as the corresponding input target frame.\n"
00069 "\n";
00070 
00071 
00072 /*-----------------------------------------------------------------------------
00073                                 Functions code
00074  ----------------------------------------------------------------------------*/
00075 
00076 /*---------------------------------------------------------------------------*/
00080 /*---------------------------------------------------------------------------*/
00082 /*---------------------------------------------------------------------------*/
00090 /*---------------------------------------------------------------------------*/
00091 int cpl_plugin_get_info(cpl_pluginlist * list)
00092 {
00093     cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
00094     cpl_plugin  *   plugin = &recipe->interface ;
00095 
00096     cpl_plugin_init(plugin,
00097                     CPL_PLUGIN_API,
00098                     SINFONI_BINARY_VERSION,
00099                     CPL_PLUGIN_TYPE_RECIPE,
00100                     "sinfo_utl_skycor",
00101                     "Sky lines residuals correction",
00102                     sinfo_utl_skycor_description,
00103                     "Andrea Modigliani",
00104                     "Andrea.Modigliani@eso.org",
00105                     sinfo_get_license(),
00106                     sinfo_utl_skycor_create,
00107                     sinfo_utl_skycor_exec,
00108                     sinfo_utl_skycor_destroy) ;
00109 
00110     cpl_pluginlist_append(list, plugin) ;
00111     return 0;
00112 }
00113 
00114 /*---------------------------------------------------------------------------*/
00123 /*--------------------------------------------------------------------------*/
00124 static int sinfo_utl_skycor_create(cpl_plugin * plugin)
00125 {
00126     cpl_recipe      * recipe ;
00127 
00128     /* Get the recipe out of the plugin */
00129     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00130         recipe = (cpl_recipe *)plugin ;
00131     else return -1 ;
00132 
00133     /* reset error handling */
00134     irplib_reset();
00135     /* Create the parameters list in the cpl_recipe object */
00136     recipe->parameters = cpl_parameterlist_new() ; 
00137     sinfo_skycor_config_add(recipe->parameters);
00138   
00139     /* Return */
00140     return 0;
00141 }
00142 
00143 /*---------------------------------------------------------------------------*/
00149 /*---------------------------------------------------------------------------*/
00150 static int sinfo_utl_skycor_exec(cpl_plugin * plugin)
00151 {
00152     cpl_recipe  *   recipe ;
00153     int code=0;
00154     /* Get the recipe out of the plugin */
00155     cpl_errorstate initial_errorstate = cpl_errorstate_get();
00156 
00157     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00158         recipe = (cpl_recipe *)plugin ;
00159     else return -1 ;
00160 
00161 
00162     code = sinfo_utl_skycor(recipe->parameters, recipe->frames) ;
00163 
00164     if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
00165         /* Dump the error history since recipe execution start.                
00166            At this point the recipe cannot recover from the error */           
00167         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
00168     } 
00169     return code;
00170 }
00171 
00172 /*---------------------------------------------------------------------------*/
00178 /*---------------------------------------------------------------------------*/
00179 static int sinfo_utl_skycor_destroy(cpl_plugin * plugin)
00180 {
00181     cpl_recipe  *   recipe ;
00182     
00183     /* Get the recipe out of the plugin */
00184     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00185         recipe = (cpl_recipe *)plugin ;
00186     else return -1 ;
00187 
00188     cpl_parameterlist_delete(recipe->parameters) ; 
00189     return 0 ;
00190 }
00191 
00192 
00199 /*---------------------------------------------------------------------------*/
00200 static int 
00201 sinfo_utl_skycor(cpl_parameterlist * config, cpl_frameset* set)
00202 {
00203  
00204   cpl_frame* obj_frm=NULL;
00205   cpl_frame* sky_frm=NULL;
00206   cpl_imagelist* obj_cor=NULL;
00207   const char *   name_o=NULL ;
00208   cpl_frame* product_frame=NULL;
00209 
00210   cpl_propertylist* plist=NULL;
00211   sinfo_skycor_qc* sqc=NULL;
00212   char obj_tag[MAX_NAME_SIZE];
00213   cpl_table* int_obj=NULL;
00214 
00215       sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
00216         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
00217 
00218 
00219   ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
00220 
00221 
00222   // get input data 
00223     obj_frm=cpl_frameset_find(set,PRO_OBS_OBJ);
00224   if(obj_frm == NULL) {
00225     obj_frm=cpl_frameset_find(set,PRO_OBS_PSF);
00226     strcpy(obj_tag,PRO_OBS_PSF);
00227   } else {
00228     strcpy(obj_tag,PRO_OBS_OBJ);
00229   }
00230 
00231 
00232   if(obj_frm == NULL) {
00233     obj_frm=cpl_frameset_find(set,PRO_OBS_STD);
00234     strcpy(obj_tag,PRO_OBS_STD);
00235   }
00236   cknull(obj_frm,"No %s or %s or %s frame found",
00237      PRO_OBS_OBJ,PRO_OBS_PSF,PRO_OBS_STD);
00238   check(sky_frm=cpl_frameset_find(set,PRO_OBS_SKY),
00239         "No %s found",PRO_OBS_SKY);
00240   sqc=sinfo_skycor_qc_new();
00241 
00242   check(plist=cpl_propertylist_load(cpl_frame_get_filename(obj_frm),0),
00243           "Cannot read the FITS header") ;
00244  
00245   ck0(sinfo_skycor(config, obj_frm,sky_frm,sqc,&obj_cor,&int_obj),
00246      "determining sky residuals corrected object");
00247   sinfo_msg("Write out adjusted cube");
00248   /* Set the file name */
00249 
00250   cpl_frameset_erase(set,obj_tag);
00251   cpl_frameset_erase(set,PRO_OBS_SKY);
00252   name_o = "out_obj_cor.fits" ;
00253 
00254 
00255   /* Create product frame */
00256   check_nomsg(product_frame = cpl_frame_new());
00257   check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
00258   check_nomsg(cpl_frame_set_tag(product_frame, obj_tag)) ;
00259   check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
00260   check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
00261   check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
00262         "Error while initialising the product frame") ;
00263   // Add DataFlow keywords 
00264 
00265     /*
00266     check(plist=cpl_propertylist_load(name_o,0),
00267           "Cannot read the FITS header") ;
00268     check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));
00269     check(cpl_dfs_setup_product_header(plist, 
00270                                        product_frame, 
00271                                        set, 
00272                                        parlist,
00273                                        "sinfo_utl_skycor", 
00274                                        "SINFONI", 
00275                                        KEY_VALUE_HPRO_DID),
00276         "Problem in the product DFS-compliance") ;
00277     */
00278 
00279   //save the file 
00280 
00281   check(cpl_imagelist_save(obj_cor, 
00282                name_o,
00283                CPL_BPP_IEEE_FLOAT, 
00284                plist,
00285                CPL_IO_DEFAULT),
00286     "Could not save product");
00287   // Log the saved file in the input frameset 
00288   check_nomsg(cpl_frameset_insert(set,cpl_frame_duplicate(product_frame))) ;
00289   sinfo_free_frame(&product_frame);
00290   /*
00291   ck0(sinfo_pro_save_ims(obj_cor,set,set,"out_obj_cor.fits",
00292              PRO_OBS_OBJ,NULL,cpl_func,config),
00293       "cannot dump cube %s", "obj_cub.fits");
00294   */
00295     
00296 
00297 
00298 
00299   sinfo_free_imagelist(&obj_cor);
00300 
00301 
00302 
00303   name_o = "out_obj_int.fits" ;
00304 
00305   /* Create product frame */
00306   check_nomsg(product_frame = cpl_frame_new());
00307   check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
00308   check_nomsg(cpl_frame_set_tag(product_frame, PRO_SPECTRA_QC)) ;
00309   check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE)) ;
00310   check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
00311   check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
00312       "Error while initialising the product frame") ;
00313   check_nomsg(cpl_propertylist_update_string(plist, "ESO PRO CATG",
00314               PRO_SPECTRA_QC));
00315 
00316 
00317     /* Add DataFlow keywords */
00318     /*    
00319     check(plist=cpl_propertylist_load(name_o,0),
00320           "Cannot read the FITS header") ;
00321 
00322     check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));
00323     check(cpl_dfs_setup_product_header(plist, 
00324                                        product_frame, 
00325                                        set, 
00326                                        parlist,
00327                                        "sinfo_utl_skycor", 
00328                                        "SINFONI", 
00329                                        KEY_VALUE_HPRO_DID),
00330       "Problem in the product DFS-compliance") ;
00331     */
00332 
00333     /* Save the file */
00334     check(cpl_table_save(int_obj, plist, NULL, name_o, 0),
00335       "Could not save product");
00336     sinfo_free_propertylist(&plist) ;
00337  
00338     /* Log the saved file in the input frameset */
00339     check_nomsg(cpl_frameset_insert(set, cpl_frame_duplicate(product_frame))) ;
00340   sinfo_free_frame(&product_frame);
00341 
00342 
00343 
00344 
00345  cleanup:
00346   sinfo_free_imagelist(&obj_cor);
00347   sinfo_free_table(&int_obj);
00348   sinfo_skycor_qc_delete(&sqc);
00349   sinfo_free_propertylist(&plist);
00350   sinfo_free_frame(&product_frame);
00351   if (cpl_error_get_code() != CPL_ERROR_NONE) {
00352     return -1;
00353   } else {
00354     return 0;
00355   }
00356 
00357 
00358 }

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