sinfo_step_distortion.c

00001 /* $Id: sinfo_step_distortion.c,v 1.20 2008/02/12 14:56:50 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: 2008/02/12 14:56:50 $
00024  * $Revision: 1.20 $
00025  * $Name: HEAD $
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 //Only for sinfo_propertylist_has
00062 #include <sinfo_dfs.h>
00063 
00064 int sinfo_step_distortion_create(cpl_plugin *plugin);
00065 int sinfo_step_distortion_exec(cpl_plugin *plugin);
00066 int sinfo_step_distortion_destroy(cpl_plugin *plugin);
00067 static int sinfo_step_distortion(cpl_parameterlist *config, cpl_frameset *set);
00068 
00069 
00070 /*---------------------------------------------------------------------------*/
00074 /*---------------------------------------------------------------------------*/
00075 
00076 
00077 void sinfo_find_distortion_config_add(cpl_parameterlist *); 
00078 
00079  /*
00080   *
00081   * Create the recipe instance, i.e. setup the parameter list for this
00082   * recipe and make it available to the application using the interface.
00083   *
00084   */
00085 
00086 
00087 int
00088 sinfo_step_distortion_create(cpl_plugin *plugin)
00089 {
00090 
00091   /*
00092    * We have to provide the option we accept to the application.
00093    * We need to setup our parameter list and hook it into the recipe
00094    * interface.
00095    */
00096   cpl_recipe *recipe = (cpl_recipe *)plugin;
00097   recipe->parameters = cpl_parameterlist_new();
00098   if(recipe->parameters == NULL) {
00099     return 1;
00100   }
00101   cpl_error_reset();
00102   irplib_reset();
00103 
00104   /*
00105    * Fill the parameter list.
00106    */
00107   sinfo_product_config_add(recipe->parameters);
00108   sinfo_prepare_stacked_frames_config_add(recipe->parameters);
00109   sinfo_distortion_config_add(recipe->parameters);
00110   sinfo_north_south_test_config_add(recipe->parameters);
00111 
00112   return 0;
00113 
00114 }
00115 
00116 int
00117 sinfo_step_distortion_exec(cpl_plugin *plugin)
00118 {
00119 
00120   cpl_recipe *recipe = (cpl_recipe *) plugin;
00121   if(recipe->parameters == NULL) {
00122     return 1;
00123   }
00124   if(recipe->frames == NULL) {
00125     return 1;
00126   }
00127 
00128 
00129   return sinfo_step_distortion(recipe->parameters, recipe->frames);
00130 
00131 }
00132 
00133 int
00134 sinfo_step_distortion_destroy(cpl_plugin *plugin)
00135 {
00136 
00137   cpl_recipe *recipe = (cpl_recipe *) plugin;
00138   /*
00139    * We just destroy what was created during the plugin initializzation phase
00140    * i.e. the parameter list. The frame set is managed by the application which
00141    * called us, so that we must not touch it.
00142    */
00143 
00144   cpl_parameterlist_delete(recipe->parameters);
00145 
00146   return 0;
00147 
00148 }
00149 
00150 int
00151 cpl_plugin_get_info(cpl_pluginlist *list)
00152 {
00153 
00154   cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00155   cpl_plugin *plugin = &recipe->interface;
00156 
00157 
00158   cpl_plugin_init(plugin,
00159           CPL_PLUGIN_API,
00160           SINFONI_BINARY_VERSION,
00161           CPL_PLUGIN_TYPE_RECIPE,
00162           "sinfo_step_distortion",
00163           "Find Distortions in frames",
00164           "TBD",
00165           "A. Modigliani",
00166           "amodigli@eso.org",
00167           "No license",
00168           sinfo_step_distortion_create,
00169           sinfo_step_distortion_exec,
00170           sinfo_step_distortion_destroy);
00171 
00172   cpl_pluginlist_append(list, plugin);
00173 
00174   return 0;
00175 
00176 }
00177 
00178 
00179 /*
00180  * The actual recipe actually start here.
00181  */
00182 
00183 static int
00184 sinfo_step_distortion(cpl_parameterlist *config, cpl_frameset *set)
00185 {
00186  
00187  
00188   cpl_frame* frame=NULL;
00189   char file_name[FILE_NAME_SZ];
00190   cpl_propertylist* plist=NULL;
00191 
00192   cpl_image* ima=NULL;
00193   fake* fk=NULL;
00194 
00195   ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
00196 
00197     /* 
00198        ---------------------------------------------------------
00199                 DISTORTIONS 
00200        ---------------------------------------------------------
00201      */
00202    
00203          
00204   sinfo_msg("COMPUTE DISTORTIONS") ; 
00205   ck0(sinfo_new_find_distortions(cpl_func,config,set),
00206       "COMPUTE DISTORTION FAILED");
00207    
00208   if(NULL != cpl_frameset_find(set,PRO_FIBRE_NS_STACKED)) {
00209     frame = cpl_frameset_find(set,PRO_FIBRE_NS_STACKED);
00210     strcpy(file_name,cpl_frame_get_filename(frame));
00211   } else {
00212     sinfo_msg_error("Frame %s not found!", PRO_FIBRE_NS_STACKED);
00213     goto cleanup;
00214   }
00215   ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
00216 
00217   cknull(plist = cpl_propertylist_load(file_name, 0),
00218                 "getting header from reference ima frame %s",file_name);
00219 
00220 
00221   if (sinfo_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
00222     cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
00223   } else {
00224     cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON) ;
00225   }
00226      
00227   sinfo_free_image(&ima);
00228   sinfo_free_propertylist(&plist);
00229   sinfo_msg("SUCCESS: COMPUTED DISTORTIONS") ; 
00230   
00231     /* 
00232        ---------------------------------------------------------
00233        4th iteration: distort fake frame
00234        ---------------------------------------------------------
00235      */
00236   
00237   sinfo_msg("DISTORT FAKE FRAME");
00238   fk=sinfo_fake_new();
00239 
00240   strcpy(fk->pro_class,PRO_FIBRE_NS_STACKED);
00241   fk->frm_switch=1;
00242   fk->mask_index=1;
00243   fk->ind_index=1;
00244   fk->flat_index=0;
00245   fk->wfix_index=1;
00246   fk->low_rej=0.0;
00247   fk->hig_rej=0.0;
00248   ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, set, 
00249                                        PRO_FIBRE_NS_STACKED_DIST, 0,fk),
00250                                        "FAILED STACKING FRAME") ;
00251 
00252   sinfo_msg("SUCCESS: DISTORTED FAKE FRAME\n") ; 
00253   sinfo_fake_delete(&fk);
00254     
00255 
00256   if(NULL != cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_DIST)) {
00257     frame = cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_DIST);
00258     strcpy(file_name,cpl_frame_get_filename(frame));
00259   } else {
00260     sinfo_msg_error("Frame %s not found!", PRO_FIBRE_NS_STACKED_DIST);
00261     goto cleanup;
00262   }
00263   ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
00264     
00265   cknull(plist = cpl_propertylist_load(file_name, 0),
00266                   "getting header from reference ima frame %s",file_name);
00267 
00268 
00269   if (sinfo_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
00270     cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
00271   } else {
00272     cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON) ;
00273   }
00274   sinfo_free_propertylist(&plist);
00275   sinfo_free_image(&ima);
00276   sinfo_msg("SUCCESS: COMPUTED DISTORTIONS\n") ; 
00277  
00278   
00279    
00280   
00281     /* 
00282        ---------------------------------------------------------
00283                                NST 
00284        ---------------------------------------------------------
00285     */
00286      
00287   sinfo_msg("RUN NORD SUD TEST") ; 
00288   ck0(sinfo_new_nst(cpl_func,config, set ),"NORTH SOUTH TEST FAILED") ;
00289   sinfo_msg("SUCCESS: RUNNED NORD SUD TEST") ; 
00290   sinfo_msg("SUCCESS: RECIPE\n") ;
00291 
00292 
00293  cleanup:
00294 
00295   sinfo_fake_delete(&fk);
00296   sinfo_free_propertylist(&plist) ;
00297   sinfo_free_image(&ima);
00298 
00299   if (cpl_error_get_code() != CPL_ERROR_NONE) {
00300     return -1;
00301   } else {
00302     return 0;
00303   }
00304 }
00305 

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