Main Page   File List  

visir_img_trans.c

00001 /* $Id: visir_img_trans.c,v 1.51 2006/01/22 08:22:10 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: 2006/01/22 08:22:10 $
00024  * $Revision: 1.51 $
00025  * $Name:  $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #include <cpl.h>
00037 
00038 #include "irplib_utils.h"
00039 
00040 #include "visir_utils.h"
00041 #include "visir_pfits.h"
00042 #include "visir_dfs.h"
00043 #include "visir_inputs.h"
00044 
00045 /*-----------------------------------------------------------------------------
00046                                 Define 
00047  -----------------------------------------------------------------------------*/
00048 
00049 /* FIXME: Use VISIR_HCYCLE_BPM_THRESHOLD */
00050 #define VISIR_LIMIT_FOR_BAD_PIXELS  32000.0
00051 
00052 /*-----------------------------------------------------------------------------
00053                             Functions prototypes
00054  -----------------------------------------------------------------------------*/
00055 
00056 static int visir_img_trans_create(cpl_plugin *);
00057 static int visir_img_trans_exec(cpl_plugin *);
00058 static int visir_img_trans_destroy(cpl_plugin *);
00059 static int visir_img_trans(cpl_parameterlist *, cpl_frameset *);
00060 static int visir_img_trans_save(const cpl_table *, const cpl_parameterlist *, 
00061                                 cpl_frameset *);
00062 
00063 /*-----------------------------------------------------------------------------
00064                             Static variables
00065  -----------------------------------------------------------------------------*/
00066 
00067 static const char * recipename = "visir_img_trans";
00068 
00069 static char visir_img_trans_description[] =
00070 "This recipe computes the transmission at different wavelengths by\n"
00071 "comparing the flux of a bright star for different observations.\n"
00072 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
00073 "VISIR-transmission-file.fits IM_TEC_TRANS\n"
00074 "The resuts are given in a table.\n";
00075 
00076 /*-----------------------------------------------------------------------------
00077                                 Functions code
00078  -----------------------------------------------------------------------------*/
00079 
00080 /*----------------------------------------------------------------------------*/
00089 /*----------------------------------------------------------------------------*/
00090 int cpl_plugin_get_info(cpl_pluginlist * list)
00091 {
00092     cpl_recipe  *   recipe = cpl_calloc(1, sizeof(*recipe));
00093     cpl_plugin  *   plugin = &recipe->interface;
00094 
00095 
00096     if (cpl_plugin_init(plugin,
00097                     CPL_PLUGIN_API,
00098                     VISIR_BINARY_VERSION,
00099                     CPL_PLUGIN_TYPE_RECIPE,
00100                     recipename,
00101                     "Instrument transmission recipe",
00102                     visir_img_trans_description,
00103                     "Lars Lundin",
00104                     PACKAGE_BUGREPORT,
00105                     visir_get_license(),
00106                     visir_img_trans_create,
00107                     visir_img_trans_exec,
00108                     visir_img_trans_destroy)) return 1;
00109 
00110     if (cpl_pluginlist_append(list, plugin)) return 1;
00111     
00112     return 0;
00113 }
00114 
00115 /*----------------------------------------------------------------------------*/
00124 /*----------------------------------------------------------------------------*/
00125 static int visir_img_trans_create(cpl_plugin * plugin)
00126 {
00127     cpl_recipe * recipe = (cpl_recipe *)plugin;
00128 
00129     /* Verify plugin type */
00130     if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) return 1;
00131 
00132     /* Create the parameters list in the cpl_recipe object */
00133     recipe->parameters = cpl_parameterlist_new();
00134 
00135     return 0;
00136 }
00137 
00138 /*----------------------------------------------------------------------------*/
00144 /*----------------------------------------------------------------------------*/
00145 static int visir_img_trans_exec(cpl_plugin * plugin)
00146 {
00147     cpl_recipe * recipe = (cpl_recipe *)plugin;
00148 
00149     /* Verify plugin type */
00150     if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) return 1;
00151 
00152     return visir_img_trans(recipe->parameters, recipe->frames);
00153 }
00154 
00155 /*----------------------------------------------------------------------------*/
00161 /*----------------------------------------------------------------------------*/
00162 static int visir_img_trans_destroy(cpl_plugin * plugin)
00163 {
00164     cpl_recipe  *   recipe = (cpl_recipe *)plugin;
00165 
00166     /* Verify plugin type */
00167     if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) return 1;
00168     cpl_parameterlist_delete(recipe->parameters);
00169     return  0;
00170 }
00171 
00172 /*----------------------------------------------------------------------------*/
00179 /*----------------------------------------------------------------------------*/
00180 static int visir_img_trans(
00181         cpl_parameterlist   *   parlist,
00182         cpl_frameset        *   framelist)
00183 {
00184     cpl_frameset    *   rawframes = NULL;
00185     cpl_imagelist   *   loaded = NULL;
00186     double          *   wls = NULL;
00187     int                 nfiles;
00188     cpl_table       *   tab = NULL;
00189     cpl_table       *   tab2 = NULL;
00190     int                 i;
00191 
00192     
00193     if (cpl_error_get_code()) return cpl_error_get_code();
00194 
00195     /* Identify the RAW and CALIB frames in the input frameset */
00196     skip_if (visir_dfs_set_groups(framelist));
00197 
00198     /* Objects observation */
00199     rawframes = irplib_frameset_extract(framelist, VISIR_IMG_TRANS_RAW);
00200     skip_if (rawframes == NULL);
00201 
00202     skip_if(visir_dfs_check_frameset_tag(rawframes));
00203 
00204     /* Load the frames */
00205     cpl_msg_info(__func__, "Load the input frames");
00206     if ((loaded = visir_imagelist_load_last(rawframes)) == NULL) {
00207         cpl_msg_error(__func__, "Cannot load the input frames");
00208         skip_if(1);
00209     }
00210 
00211     nfiles = cpl_imagelist_get_size(loaded);
00212 
00213     skip_if( nfiles <= 0);
00214 
00215     /* Set the pixels above VISIR_LIMIT_FOR_BAD_PIXELS as bad */
00216     for (i=0 ; i < nfiles ; i++) {
00217         cpl_mask * map = cpl_mask_threshold_image_create(
00218                                cpl_imagelist_get(loaded, i),
00219                                VISIR_LIMIT_FOR_BAD_PIXELS,
00220                                CPL_PIXEL_MAXVAL);
00221         if (map == NULL) continue;
00222         cpl_image_reject_from_mask(cpl_imagelist_get(loaded, i), map);
00223         cpl_mask_delete(map);
00224     }
00225 
00226     skip_if(cpl_error_get_code());
00227     
00228     /* Get the wavelengths from the headers */
00229     cpl_msg_info(__func__, "Get the wavelengths from the input headers");
00230     if ((wls = visir_utils_get_wls(rawframes)) == NULL) {
00231         cpl_msg_error(__func__, "Cannot get wavelengths");
00232         skip_if(1);
00233     }
00234     
00235     /* Create the table and fill it with the relevant information */
00236     tab = visir_table_new_xypos(loaded, "FLUX");
00237     skip_if (tab == NULL);
00238 
00239     tab2 = cpl_table_new(nfiles);
00240     skip_if (tab2 == NULL);
00241 
00242     /* FIXME: A better way to do this, if at all necessary ? */
00243     skip_if (cpl_table_move_column(tab2, "FLUX", tab));
00244 
00245     skip_if (cpl_table_wrap_double(tab, wls, "WAVELENGTH"));
00246     wls = NULL;
00247 
00248     skip_if (cpl_table_move_column(tab, "FLUX", tab2));
00249 
00250     /* FIXME: Verify that this is requested */
00251     for (i=0; i < nfiles; i++) {
00252         if (cpl_table_get_double(tab, "FLUX", i, NULL) > 0) continue;
00253         skip_if (cpl_table_set_double(tab, "FLUX", i,
00254                            cpl_image_get_median(cpl_imagelist_get(loaded, i))));
00255     }
00256 
00257     /* Normalise the FLUX column */
00258     skip_if (cpl_table_divide_scalar(tab, "FLUX",
00259                                      cpl_table_get_column_max(tab, "FLUX")));
00260 
00261     /* Save the products */
00262     cpl_msg_info(__func__, "Save the products");
00263     if (visir_img_trans_save(tab, parlist, framelist)) {
00264         cpl_msg_error(__func__, "Cannot save products");
00265         skip_if(1);
00266     }
00267 
00268     end_skip;
00269 
00270     cpl_free(wls);    
00271     cpl_table_delete(tab);
00272     cpl_table_delete(tab2);
00273     cpl_imagelist_delete(loaded);
00274     cpl_frameset_delete(rawframes);
00275 
00276     return cpl_error_get_code();
00277 }
00278 
00279 /*----------------------------------------------------------------------------*/
00287 /*----------------------------------------------------------------------------*/
00288 static int visir_img_trans_save(
00289         const cpl_table         * tab,
00290         const cpl_parameterlist * parlist,
00291         cpl_frameset            * set)
00292 {
00293 
00294     return visir_table_save(parlist, set, tab, recipename,
00295                             VISIR_IMG_TRANS_TAB_PROCATG, NULL, NULL);
00296 
00297 }

Generated on Mon Jan 23 12:16:36 2006 for VISIR Pipeline Reference Manual by doxygen1.2.18