Main Page   File List  

visir_img_psf.c

00001 /* $Id: visir_img_psf.c,v 1.46 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.46 $
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                             Functions prototypes
00047  -----------------------------------------------------------------------------*/
00048 
00049 static int visir_img_psf_create(cpl_plugin *);
00050 static int visir_img_psf_exec(cpl_plugin *);
00051 static int visir_img_psf_destroy(cpl_plugin *);
00052 static int visir_img_psf(cpl_parameterlist *, cpl_frameset *);
00053 static int visir_img_psf_save(const cpl_table *, const cpl_parameterlist *,
00054                               cpl_frameset *);
00055 
00056 /*-----------------------------------------------------------------------------
00057                             Static variables
00058  -----------------------------------------------------------------------------*/
00059 
00060 static const char * recipename = "visir_img_psf";
00061 
00062 static struct {
00063     /* Inputs */
00064     char        nodding[512];
00065     int         auto_bpm;
00066     int         rem_glitch;
00067     int         purge_bad;
00068 
00069     /* Outputs */
00070 } visir_img_psf_config;
00071 
00072 static char visir_img_psf_description[] =
00073 "This recipe simply computes the FWHM of a bright object.\n" 
00074 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
00075 "VISIR-psf-file.fits IM_CAL_PSF\n";
00076 
00077 /*-----------------------------------------------------------------------------
00078                                 Functions code
00079  -----------------------------------------------------------------------------*/
00080 
00081 /*----------------------------------------------------------------------------*/
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 
00097     if (cpl_plugin_init(plugin,
00098                     CPL_PLUGIN_API,
00099                     VISIR_BINARY_VERSION,
00100                     CPL_PLUGIN_TYPE_RECIPE,
00101                     recipename,
00102                     "PSF recipe",
00103                     visir_img_psf_description,
00104                     "Lars Lundin",
00105                     PACKAGE_BUGREPORT,
00106                     visir_get_license(),
00107                     visir_img_psf_create,
00108                     visir_img_psf_exec,
00109                     visir_img_psf_destroy)) return 1;
00110 
00111     if (cpl_pluginlist_append(list, plugin)) return 1;
00112     
00113     return 0;
00114 }
00115 
00116 /*----------------------------------------------------------------------------*/
00125 /*----------------------------------------------------------------------------*/
00126 static int visir_img_psf_create(cpl_plugin * plugin)
00127 {
00128     cpl_recipe * recipe = (cpl_recipe *)plugin;
00129 
00130     /* Verify plugin type */
00131     if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) return 1;
00132 
00133     /* Create the parameters list in the cpl_recipe object */
00134     recipe->parameters = cpl_parameterlist_new();
00135 
00136     /* Fill the parameters list */
00137     return visir_parameter_set(recipe->parameters, recipename,
00138                                VISIR_PARAM_NODPOS | VISIR_PARAM_AUTOBPM |
00139                                VISIR_PARAM_GLITCH | VISIR_PARAM_PURGE );
00140 }
00141 
00142 /*----------------------------------------------------------------------------*/
00148 /*----------------------------------------------------------------------------*/
00149 static int visir_img_psf_exec(cpl_plugin * plugin)
00150 {
00151     cpl_recipe * recipe = (cpl_recipe *)plugin;
00152 
00153     /* Verify plugin type */
00154     if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) return 1;
00155 
00156     return visir_img_psf(recipe->parameters, recipe->frames);
00157 }
00158 
00159 /*----------------------------------------------------------------------------*/
00165 /*----------------------------------------------------------------------------*/
00166 static int visir_img_psf_destroy(cpl_plugin * plugin)
00167 {
00168     cpl_recipe  *   recipe = (cpl_recipe *)plugin;
00169 
00170     /* Verify plugin type */
00171     if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) return 1;
00172     cpl_parameterlist_delete(recipe->parameters);
00173     return  0;
00174 }
00175 
00176 /*----------------------------------------------------------------------------*/
00183 /*----------------------------------------------------------------------------*/
00184 static int visir_img_psf(cpl_parameterlist   *   parlist,
00185                          cpl_frameset        *   framelist)
00186 {
00187     cpl_parameter   *   par;
00188     const char      *   badpix;
00189     const char      *   flat;
00190     cpl_frameset    *   rawframes = NULL;
00191     cpl_imagelist   *   nodded = NULL;
00192     cpl_table       *   tab = NULL;
00193     int                 nfiles;
00194 
00195 
00196     if (cpl_error_get_code()) return cpl_error_get_code();
00197 
00198     /* Retrieve input parameters */
00199     par = cpl_parameterlist_find(parlist, "visir.visir_img_psf.nodding");
00200     strcpy(visir_img_psf_config.nodding, cpl_parameter_get_string(par));
00201     par = cpl_parameterlist_find(parlist, "visir.visir_img_psf.auto_bpm");
00202     visir_img_psf_config.auto_bpm = cpl_parameter_get_bool(par);
00203     par = cpl_parameterlist_find(parlist, "visir.visir_img_psf.rem_glitch");
00204     visir_img_psf_config.rem_glitch = cpl_parameter_get_bool(par);
00205     par = cpl_parameterlist_find(parlist, "visir.visir_img_psf.purge_bad");
00206     visir_img_psf_config.purge_bad = cpl_parameter_get_bool(par);
00207 
00208 
00209     /* Identify the RAW and CALIB frames in the input frameset */
00210     skip_if (visir_dfs_set_groups(framelist));
00211 
00212     /* Objects observation */
00213     rawframes = irplib_frameset_extract(framelist, VISIR_IMG_PSF_RAW);
00214     skip_if (rawframes == NULL);
00215 
00216     skip_if(visir_dfs_check_frameset_tag(rawframes));
00217     
00218     /* Bad pixels calibration file */
00219     badpix = irplib_frameset_find_file(framelist, VISIR_CALIB_BPM);
00220 
00221     /* Flatfield calibration file */
00222     flat = irplib_frameset_find_file(framelist, VISIR_CALIB_FLAT);
00223 
00224 
00225     /* Combine the frames */
00226     cpl_msg_info(__func__, "Construct the nodded images");
00227     nodded = visir_inputs_combine(rawframes, badpix, flat,
00228                                 visir_img_psf_config.nodding,
00229                                 visir_img_psf_config.auto_bpm,
00230                                 visir_img_psf_config.rem_glitch,
00231                                 visir_img_psf_config.purge_bad,
00232                                 NULL,
00233                                    CPL_FALSE, 0,0, 0,0,0,0);
00234     if (nodded == NULL) {
00235         cpl_msg_error(__func__, "Cannot combine the input frames");
00236         skip_if(1);
00237     }
00238 
00239     nfiles = cpl_imagelist_get_size(nodded);
00240     
00241     /* Create table Allocate and initialise arrays */
00242     tab = visir_table_new_xypos(nodded, "FWHM");
00243 
00244     skip_if (tab == NULL);
00245 
00246     /* Save the combined image */
00247     cpl_msg_info(__func__, "Save the produced combined image");
00248     if (visir_img_psf_save(tab, parlist, framelist)) {
00249         cpl_msg_error(__func__, "Cannot save products");
00250         skip_if(1);
00251     }
00252 
00253     end_skip;
00254 
00255     cpl_frameset_delete(rawframes);
00256     cpl_imagelist_delete(nodded);
00257 
00258     cpl_table_delete(tab);
00259 
00260     return cpl_error_get_code();
00261 }
00262 
00263 /*----------------------------------------------------------------------------*/
00271 /*----------------------------------------------------------------------------*/
00272 static int visir_img_psf_save(
00273         const cpl_table         * tab,
00274         const cpl_parameterlist * parlist,
00275         cpl_frameset            * set)
00276 {
00277 
00278     /* SAVE THE TABLE - and return */
00279     return visir_table_save(parlist, set, tab, recipename,
00280                             VISIR_IMG_PSF_TAB_PROCATG, NULL, NULL);
00281 }

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