sinfo_utl_skycor.c

00001 /* $Id: sinfo_utl_skycor.c,v 1.5 2007/01/10 08:29:31 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/01/10 08:29:31 $
00024  * $Revision: 1.5 $
00025  * $Name:  $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
00034  ----------------------------------------------------------------------------*/
00035 #include <cpl.h>
00036 #include <irplib_utils.h>
00037 #include <irplib_error.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     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00156         recipe = (cpl_recipe *)plugin ;
00157     else return -1 ;
00158 
00159 
00160     code = sinfo_utl_skycor(recipe->parameters, recipe->frames) ;
00161     return code;
00162 }
00163 
00164 /*---------------------------------------------------------------------------*/
00170 /*---------------------------------------------------------------------------*/
00171 static int sinfo_utl_skycor_destroy(cpl_plugin * plugin)
00172 {
00173     cpl_recipe  *   recipe ;
00174     
00175     /* Get the recipe out of the plugin */
00176     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00177         recipe = (cpl_recipe *)plugin ;
00178     else return -1 ;
00179 
00180     cpl_parameterlist_delete(recipe->parameters) ; 
00181     return 0 ;
00182 }
00183 
00184 
00191 /*---------------------------------------------------------------------------*/
00192 static int 
00193 sinfo_utl_skycor(cpl_parameterlist * config, cpl_frameset* set)
00194 {
00195  
00196   cpl_frame* obj_frm=NULL;
00197   cpl_frame* sky_frm=NULL;
00198   cpl_imagelist* obj_cor=NULL;
00199   const char *   name_o=NULL ;
00200   cpl_frame* product_frame=NULL;
00201 
00202   cpl_propertylist* plist=NULL;
00203   sinfo_skycor_qc* sqc=NULL;
00204   char obj_tag[MAX_NAME_SIZE];
00205   cpl_table* int_obj=NULL;
00206 
00207       sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
00208         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
00209 
00210 
00211   ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
00212 
00213 
00214   // get input data 
00215     obj_frm=cpl_frameset_find(set,PRO_OBS_OBJ);
00216   if(obj_frm == NULL) {
00217     obj_frm=cpl_frameset_find(set,PRO_OBS_PSF);
00218     strcpy(obj_tag,PRO_OBS_PSF);
00219   } else {
00220     strcpy(obj_tag,PRO_OBS_OBJ);
00221   }
00222 
00223 
00224   if(obj_frm == NULL) {
00225     obj_frm=cpl_frameset_find(set,PRO_OBS_STD);
00226     strcpy(obj_tag,PRO_OBS_STD);
00227   }
00228   cknull(obj_frm,"No %s or %s or %s frame found",
00229      PRO_OBS_OBJ,PRO_OBS_PSF,PRO_OBS_STD);
00230   check(sky_frm=cpl_frameset_find(set,PRO_OBS_SKY),
00231         "No %s found",PRO_OBS_SKY);
00232   sqc=sinfo_skycor_qc_new();
00233 
00234   check(plist=cpl_propertylist_load(cpl_frame_get_filename(obj_frm),0),
00235           "Cannot read the FITS header") ;
00236  
00237   ck0(sinfo_skycor(config, obj_frm,sky_frm,sqc,&obj_cor,&int_obj),
00238      "determining sky residuals corrected object");
00239   sinfo_msg("Write out adjusted cube");
00240   /* Set the file name */
00241 
00242   cpl_frameset_erase(set,obj_tag);
00243   cpl_frameset_erase(set,PRO_OBS_SKY);
00244   name_o = "out_obj_cor.fits" ;
00245 
00246 
00247   /* Create product frame */
00248   check_nomsg(product_frame = cpl_frame_new());
00249   check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
00250   check_nomsg(cpl_frame_set_tag(product_frame, PRO_OBS_OBJ)) ;
00251   check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
00252   check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
00253   check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
00254       "Error while initialising the product frame") ;
00255   // Add DataFlow keywords 
00256 
00257     /*
00258     check(plist=cpl_propertylist_load(name_o,0),
00259           "Cannot read the FITS header") ;
00260     check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));
00261     check(cpl_dfs_setup_product_header(plist, 
00262                                        product_frame, 
00263                                        set, 
00264                                        parlist,
00265                                        "sinfo_utl_skycor", 
00266                                        "SINFONI", 
00267                                        KEY_VALUE_HPRO_DID),
00268       "Problem in the product DFS-compliance") ;
00269     */
00270 
00271   //save the file 
00272 
00273   check(cpl_imagelist_save(obj_cor, 
00274                name_o,
00275                CPL_BPP_DEFAULT, 
00276                plist,
00277                CPL_IO_DEFAULT),
00278     "Could not save product");
00279 
00280   // Log the saved file in the input frameset 
00281   check_nomsg(cpl_frameset_insert(set,cpl_frame_duplicate(product_frame))) ;
00282   sinfo_free_frame(&product_frame);
00283   /*
00284   sinfo_msg("ok1");
00285   ck0(sinfo_pro_save_ims(obj_cor,set,set,"out_obj_cor.fits",
00286              PRO_OBS_OBJ,NULL,cpl_func,config),
00287       "cannot dump cube %s", "obj_cub.fits");
00288   sinfo_msg("ok2");
00289   */
00290     
00291 
00292 
00293   sinfo_free_imagelist(&obj_cor);
00294 
00295 
00296 
00297   name_o = "out_obj_int.fits" ;
00298 
00299   /* Create product frame */
00300   check_nomsg(product_frame = cpl_frame_new());
00301   check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
00302   check_nomsg(cpl_frame_set_tag(product_frame, PRO_SPECTRA_QC)) ;
00303   check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE)) ;
00304   check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
00305   check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
00306       "Error while initialising the product frame") ;
00307   check_nomsg(cpl_propertylist_update_string(plist, "ESO PRO CATG",
00308               PRO_SPECTRA_QC));
00309 
00310 
00311     /* Add DataFlow keywords */
00312     /*    
00313     check(plist=cpl_propertylist_load(name_o,0),
00314           "Cannot read the FITS header") ;
00315 
00316     check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));
00317     check(cpl_dfs_setup_product_header(plist, 
00318                                        product_frame, 
00319                                        set, 
00320                                        parlist,
00321                                        "sinfo_utl_skycor", 
00322                                        "SINFONI", 
00323                                        KEY_VALUE_HPRO_DID),
00324       "Problem in the product DFS-compliance") ;
00325     */
00326 
00327     /* Save the file */
00328     check(cpl_table_save(int_obj, plist, NULL, name_o, 0),
00329       "Could not save product");
00330     sinfo_free_propertylist(&plist) ;
00331  
00332     /* Log the saved file in the input frameset */
00333     check_nomsg(cpl_frameset_insert(set, cpl_frame_duplicate(product_frame))) ;
00334   sinfo_free_frame(&product_frame);
00335 
00336 
00337 
00338 
00339  cleanup:
00340   sinfo_free_imagelist(&obj_cor);
00341   sinfo_free_table(&int_obj);
00342   sinfo_skycor_qc_delete(&sqc);
00343   sinfo_free_propertylist(&plist);
00344   sinfo_free_frame(&product_frame);
00345   if (cpl_error_get_code() != CPL_ERROR_NONE) {
00346     irplib_error_dump(CPL_MSG_ERROR,CPL_MSG_ERROR);
00347     return -1;
00348   } else {
00349     return 0;
00350   }
00351 
00352 
00353 }

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