sinfo_step_distortion.c

00001 /* $Id: sinfo_step_distortion.c,v 1.16 2006/12/28 15:10:36 amodigli Exp $
00002  *
00003  * This file is part of the CPL (Common Pipeline Library)
00004  * Copyright (C) 2002 European Southern Observatory
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library 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 GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; 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: 2006/12/28 15:10:36 $
00024  * $Revision: 1.16 $
00025  * $Name:  $
00026  */
00027 
00028  /****************************************************************
00029   *          Distortion Frames Data Reduction                          *
00030   ****************************************************************/
00031 #include <strings.h>
00032 #include <string.h>
00033 #include <irplib_utils.h>
00034 #include <stdio.h>
00035 
00036 #ifdef HAVE_CONFIG_H
00037 #include <config.h>          
00038 #endif
00039 
00040 #include <cpl.h>      
00041 
00042 
00043 #include <sinfo_key_names.h>
00044 #include <sinfo_globals.h>
00045 #include <sinfo_pro_types.h>
00046 #include <sinfo_product_config.h>
00047 #include <sinfo_prepare_stacked_frames_config.h>
00048 #include <sinfo_north_south_test_config.h>
00049 
00050 #include <sinfo_new_prepare_stacked_frames.h>
00051 #include <sinfo_distortion_config.h>
00052 #include <sinfo_new_find_distortions.h>
00053 #include <sinfo_new_nst.h>
00054 #include <sinfo_hidden.h>
00055 #include <sinfo_tpl_dfs.h>
00056 #include <sinfo_globals.h>
00057 #include <sinfo_functions.h>
00058 #include <sinfo_tpl_utils.h>
00059 #include <sinfo_error.h>
00060 #include <sinfo_utils_wrappers.h>
00061 
00062 int sinfo_step_distortion_create(cpl_plugin *plugin);
00063 int sinfo_step_distortion_exec(cpl_plugin *plugin);
00064 int sinfo_step_distortion_destroy(cpl_plugin *plugin);
00065 static int sinfo_step_distortion(cpl_parameterlist *config, cpl_frameset *set);
00066 
00067 
00068 /*---------------------------------------------------------------------------*/
00072 /*---------------------------------------------------------------------------*/
00073 
00074 
00075 void sinfo_find_distortion_config_add(cpl_parameterlist *); 
00076 
00077  /*
00078   *
00079   * Create the recipe instance, i.e. setup the parameter list for this
00080   * recipe and make it available to the application using the interface.
00081   *
00082   */
00083 
00084 
00085 int
00086 sinfo_step_distortion_create(cpl_plugin *plugin)
00087 {
00088 
00089   /*
00090    * We have to provide the option we accept to the application.
00091    * We need to setup our parameter list and hook it into the recipe
00092    * interface.
00093    */
00094   cpl_recipe *recipe = (cpl_recipe *)plugin;
00095   recipe->parameters = cpl_parameterlist_new();
00096   if(recipe->parameters == NULL) {
00097     return 1;
00098   }
00099   cpl_error_reset();
00100   irplib_reset();
00101 
00102   /*
00103    * Fill the parameter list.
00104    */
00105   sinfo_product_config_add(recipe->parameters);
00106   sinfo_prepare_stacked_frames_config_add(recipe->parameters);
00107   sinfo_distortion_config_add(recipe->parameters);
00108   sinfo_north_south_test_config_add(recipe->parameters);
00109 
00110   return 0;
00111 
00112 }
00113 
00114 int
00115 sinfo_step_distortion_exec(cpl_plugin *plugin)
00116 {
00117 
00118   cpl_recipe *recipe = (cpl_recipe *) plugin;
00119   if(recipe->parameters == NULL) {
00120     return 1;
00121   }
00122   if(recipe->frames == NULL) {
00123     return 1;
00124   }
00125 
00126 
00127   return sinfo_step_distortion(recipe->parameters, recipe->frames);
00128 
00129 }
00130 
00131 int
00132 sinfo_step_distortion_destroy(cpl_plugin *plugin)
00133 {
00134 
00135   cpl_recipe *recipe = (cpl_recipe *) plugin;
00136   /*
00137    * We just destroy what was created during the plugin initializzation phase
00138    * i.e. the parameter list. The frame set is managed by the application which
00139    * called us, so that we must not touch it.
00140    */
00141 
00142   cpl_parameterlist_delete(recipe->parameters);
00143 
00144   return 0;
00145 
00146 }
00147 
00148 int
00149 cpl_plugin_get_info(cpl_pluginlist *list)
00150 {
00151 
00152   cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00153   cpl_plugin *plugin = &recipe->interface;
00154 
00155 
00156   cpl_plugin_init(plugin,
00157           CPL_PLUGIN_API,
00158           SINFONI_BINARY_VERSION,
00159           CPL_PLUGIN_TYPE_RECIPE,
00160           "sinfo_step_distortion",
00161           "Find Distortions in frames",
00162           "TBD",
00163           "A. Modigliani",
00164           "amodigli@eso.org",
00165           "No license",
00166           sinfo_step_distortion_create,
00167           sinfo_step_distortion_exec,
00168           sinfo_step_distortion_destroy);
00169 
00170   cpl_pluginlist_append(list, plugin);
00171 
00172   return 0;
00173 
00174 }
00175 
00176 
00177 /*
00178  * The actual recipe actually start here.
00179  */
00180 
00181 static int
00182 sinfo_step_distortion(cpl_parameterlist *config, cpl_frameset *set)
00183 {
00184  
00185  
00186   cpl_frame* frame=NULL;
00187   char file_name[FILE_NAME_SZ];
00188   cpl_propertylist* plist=NULL;
00189 
00190   cpl_image* ima=NULL;
00191   fake* fk=NULL;
00192 
00193   ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
00194 
00195     /* 
00196        ---------------------------------------------------------
00197                 DISTORTIONS 
00198        ---------------------------------------------------------
00199      */
00200    
00201          
00202   sinfo_msg("COMPUTE DISTORTIONS") ; 
00203   ck0(sinfo_new_find_distortions(cpl_func,config,set),"COMPUTE DISTORTION FAILED");
00204    
00205   if(NULL != cpl_frameset_find(set,PRO_FIBRE_NS_STACKED)) {
00206     frame = cpl_frameset_find(set,PRO_FIBRE_NS_STACKED);
00207     strcpy(file_name,cpl_frame_get_filename(frame));
00208   } else {
00209     sinfo_msg_error("Frame %s not found!", PRO_FIBRE_NS_STACKED);
00210     goto cleanup;
00211   }
00212   ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
00213 
00214   cknull(plist = cpl_propertylist_load(file_name, 0),
00215                 "getting header from reference ima frame %s",file_name);
00216 
00217 
00218   if (cpl_propertylist_contains(plist, KEY_NAME_LAMP_HALO)) {
00219     cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
00220   } else {
00221     cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON) ;
00222   }
00223      
00224   sinfo_free_image(&ima);
00225   sinfo_free_propertylist(&plist);
00226   sinfo_msg("SUCCESS: COMPUTED DISTORTIONS") ; 
00227   
00228     /* 
00229        ---------------------------------------------------------
00230        4th iteration: distort fake frame
00231        ---------------------------------------------------------
00232      */
00233   
00234   sinfo_msg("DISTORT FAKE FRAME");
00235   fk=sinfo_fake_new();
00236 
00237   strcpy(fk->pro_class,PRO_FIBRE_NS_STACKED);
00238   fk->frm_switch=1;
00239   fk->mask_index=1;
00240   fk->ind_index=1;
00241   fk->flat_index=0;
00242   fk->wfix_index=1;
00243   fk->low_rej=0.0;
00244   fk->hig_rej=0.0;
00245   ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, set, 
00246                                        PRO_FIBRE_NS_STACKED_DIST, 0,fk),
00247                                        "FAILED STACKING FRAME") ;
00248 
00249   sinfo_msg("SUCCESS: DISTORTED FAKE FRAME\n") ; 
00250   sinfo_fake_delete(&fk);
00251     
00252 
00253   if(NULL != cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_DIST)) {
00254     frame = cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_DIST);
00255     strcpy(file_name,cpl_frame_get_filename(frame));
00256   } else {
00257     sinfo_msg_error("Frame %s not found!", PRO_FIBRE_NS_STACKED_DIST);
00258     goto cleanup;
00259   }
00260   ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
00261     
00262   cknull(plist = cpl_propertylist_load(file_name, 0),
00263                   "getting header from reference ima frame %s",file_name);
00264 
00265 
00266   if (cpl_propertylist_contains(plist, KEY_NAME_LAMP_HALO)) {
00267     cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
00268   } else {
00269     cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON) ;
00270   }
00271   sinfo_free_propertylist(&plist);
00272   sinfo_free_image(&ima);
00273   sinfo_msg("SUCCESS: COMPUTED DISTORTIONS\n") ; 
00274  
00275   
00276    
00277   
00278     /* 
00279        ---------------------------------------------------------
00280                                NST 
00281        ---------------------------------------------------------
00282     */
00283      
00284   sinfo_msg("RUN NORD SUD TEST") ; 
00285   ck0(sinfo_new_nst(cpl_func,config, set ),"NORTH SOUTH TEST FAILED") ;
00286   sinfo_msg("SUCCESS: RUNNED NORD SUD TEST") ; 
00287   sinfo_msg("SUCCESS: RECIPE\n") ;
00288 
00289   return 0 ;
00290 
00291  cleanup:
00292 
00293   sinfo_fake_delete(&fk);
00294   sinfo_free_propertylist(&plist) ;
00295   sinfo_free_image(&ima);
00296   irplib_error_dump(CPL_MSG_ERROR,CPL_MSG_ERROR);
00297 
00298   return -1;
00299 }
00300 

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