visir_img_trans.c

00001 /* $Id: visir_img_trans.c,v 1.70 2009/01/29 08:56:58 llundin Exp $
00002  *
00003  * This file is part of the VISIR 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., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: llundin $
00023  * $Date: 2009/01/29 08:56:58 $
00024  * $Revision: 1.70 $
00025  * $Name: visir-3_5_0 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 
00033 /*-----------------------------------------------------------------------------
00034                                 Includes
00035  -----------------------------------------------------------------------------*/
00036 
00037 #include "visir_recipe.h"
00038 
00039 /*-----------------------------------------------------------------------------
00040                                 Defines 
00041  -----------------------------------------------------------------------------*/
00042 
00043 /* FIXME: Use VISIR_HCYCLE_BPM_THRESHOLD */
00044 #define VISIR_LIMIT_FOR_BAD_PIXELS  32000.0
00045 
00046 #define RECIPE_STRING "visir_img_trans"
00047 
00048 /*-----------------------------------------------------------------------------
00049                             Private Functions prototypes
00050  -----------------------------------------------------------------------------*/
00051 
00052 static cpl_error_code visir_img_trans_save(cpl_frameset *,
00053                                            const cpl_parameterlist *,
00054                                            const cpl_table *);
00055 
00056 VISIR_RECIPE_DEFINE(visir_img_trans, 0, "Instrument Transmission recipe",
00057                     "This recipe computes the transmission at different "
00058                     "wavelengths by\n"
00059                     "comparing the flux of a bright star for different "
00060                     "observations.\n"
00061                     "The files listed in the Set Of Frames (sof-file) "
00062                     "must be tagged:\n"
00063                     "VISIR-transmission-file.fits IM_TEC_TRANS\n"
00064                     "The resuts are given in a table.\n");
00065 
00066 /*----------------------------------------------------------------------------*/
00070 /*----------------------------------------------------------------------------*/
00071 
00072 /*-----------------------------------------------------------------------------
00073                                 Functions code
00074  -----------------------------------------------------------------------------*/
00075 
00076 /*----------------------------------------------------------------------------*/
00083 /*----------------------------------------------------------------------------*/
00084 static int visir_img_trans(cpl_frameset            * framelist,
00085                            const cpl_parameterlist * parlist)
00086 {
00087     irplib_framelist * allframes = NULL;
00088     irplib_framelist * rawframes = NULL;
00089     cpl_imagelist   *   loaded = NULL;
00090     double          *   wls = NULL;
00091     int                 nfiles;
00092     cpl_table       *   tab = NULL;
00093     cpl_table       *   tab2 = NULL;
00094     int                 i;
00095 
00096     
00097     /* Identify the RAW and CALIB frames in the input frameset */
00098     skip_if (visir_dfs_set_groups(framelist));
00099 
00100     /* Objects observation */
00101     allframes = irplib_framelist_cast(framelist);
00102     skip_if(allframes == NULL);
00103     rawframes = irplib_framelist_extract(allframes, VISIR_IMG_TRANS_RAW);
00104     skip_if (rawframes == NULL);
00105 
00106     skip_if(irplib_framelist_load_propertylist_all(rawframes, 0,
00107                                                    visir_property_regexp,
00108                                                    CPL_FALSE));
00109     skip_if(visir_dfs_check_framelist_tag(rawframes));
00110 
00111     /* Load the frames */
00112     cpl_msg_info(cpl_func, "Load the input frames");
00113     if ((loaded = visir_imagelist_load_last(rawframes)) == NULL) {
00114         cpl_msg_error(cpl_func, "Could not load the input frames");
00115         skip_if(1);
00116     }
00117 
00118     nfiles = cpl_imagelist_get_size(loaded);
00119 
00120     skip_if( nfiles <= 0);
00121 
00122     /* Set the pixels above VISIR_LIMIT_FOR_BAD_PIXELS as bad */
00123     for (i=0 ; i < nfiles ; i++) {
00124         cpl_mask * map = cpl_mask_threshold_image_create(
00125                                cpl_imagelist_get(loaded, i),
00126                                VISIR_LIMIT_FOR_BAD_PIXELS,
00127                                DBL_MAX);
00128         if (map == NULL) continue;
00129         cpl_image_reject_from_mask(cpl_imagelist_get(loaded, i), map);
00130         cpl_mask_delete(map);
00131     }
00132 
00133     skip_if(0);
00134     
00135     /* Get the wavelengths from the headers */
00136     cpl_msg_info(cpl_func, "Get the wavelengths from the input headers");
00137     if ((wls = visir_utils_get_wls(rawframes)) == NULL) {
00138         cpl_msg_error(cpl_func, "Could not get wavelengths");
00139         skip_if(1);
00140     }
00141     
00142     /* Create the table and fill it with the relevant information */
00143     tab = visir_table_new_xypos(loaded, "FLUX");
00144     skip_if (tab == NULL);
00145 
00146     tab2 = cpl_table_new(nfiles);
00147     skip_if (tab2 == NULL);
00148 
00149     /* FIXME: A better way to do this, if at all necessary ? */
00150     skip_if (cpl_table_move_column(tab2, "FLUX", tab));
00151 
00152     skip_if (cpl_table_wrap_double(tab, wls, "WAVELENGTH"));
00153     wls = NULL;
00154 
00155     skip_if (cpl_table_move_column(tab, "FLUX", tab2));
00156 
00157     /* FIXME: Verify that this is requested */
00158     for (i=0; i < nfiles; i++) {
00159         if (cpl_table_get_double(tab, "FLUX", i, NULL) > 0) continue;
00160         skip_if (cpl_table_set_double(tab, "FLUX", i,
00161                            cpl_image_get_median(cpl_imagelist_get(loaded, i))));
00162     }
00163 
00164     /* Normalise the FLUX column */
00165     skip_if (cpl_table_divide_scalar(tab, "FLUX",
00166                                      cpl_table_get_column_max(tab, "FLUX")));
00167 
00168     /* Save the products */
00169     cpl_msg_info(cpl_func, "Save the products");
00170     skip_if (visir_img_trans_save(framelist, parlist, tab));
00171 
00172     end_skip;
00173 
00174     irplib_framelist_delete(allframes);
00175     irplib_framelist_delete(rawframes);
00176     cpl_free(wls);    
00177     cpl_table_delete(tab);
00178     cpl_table_delete(tab2);
00179     cpl_imagelist_delete(loaded);
00180 
00181     return cpl_error_get_code();
00182 }
00183 
00184 /*----------------------------------------------------------------------------*/
00192 /*----------------------------------------------------------------------------*/
00193 static cpl_error_code visir_img_trans_save(cpl_frameset            * set,
00194                                            const cpl_parameterlist * parlist,
00195                                            const cpl_table         * tab)
00196 {
00197 
00198     skip_if(irplib_dfs_save_table(set, parlist, set, tab, NULL, RECIPE_STRING,
00199                               VISIR_IMG_TRANS_TAB_PROCATG, NULL, NULL,
00200                               visir_pipe_id, RECIPE_STRING CPL_DFS_FITS));
00201 
00202     end_skip;
00203 
00204     return cpl_error_get_code();
00205 
00206 }

Generated on Mon Feb 6 15:23:49 2012 for VISIR Pipeline Reference Manual by  doxygen 1.5.8