crires_util_profile.c

00001 /* $Id: crires_util_profile.c,v 1.32 2009/07/29 12:37:14 yjung Exp $
00002  *
00003  * This file is part of the crires 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: yjung $
00023  * $Date: 2009/07/29 12:37:14 $
00024  * $Revision: 1.32 $
00025  * $Name: crire-2_1_1 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #include "crires_recipe.h"
00037 
00038 #include "crires_extract.h"
00039 
00040 /*-----------------------------------------------------------------------------
00041                                 Define
00042  -----------------------------------------------------------------------------*/
00043 
00044 #define RECIPE_STRING "crires_util_profile"
00045 
00046 /*-----------------------------------------------------------------------------
00047                             Functions prototypes
00048  -----------------------------------------------------------------------------*/
00049 
00050 static int crires_util_profile_save(const cpl_table **, 
00051         const cpl_parameterlist *, cpl_frameset *) ;
00052 
00053 static char crires_util_profile_description[] = 
00054 "This recipe accepts 1 parameter:\n"
00055 "First parameter:   the profile produced by the spectrum extraction.\n"
00056 "                   (PRO TYPE = "CRIRES_PROTYPE_PROFILE")\n"
00057 "\n"
00058 "This recipe produces 1 file:\n"
00059 "First product:     the table with the FWHMs values of the profile.\n"
00060 "                   (PRO TYPE = "CRIRES_PROTYPE_FWHM")\n" ;
00061 
00062 CRIRES_RECIPE_DEFINE(crires_util_profile,
00063         CRIRES_PARAM_DISPLAY,
00064         "Compute the FWHM of the spectrum along lambda",
00065         crires_util_profile_description) ;
00066 
00067 /*-----------------------------------------------------------------------------
00068                             Static variables
00069  -----------------------------------------------------------------------------*/
00070 
00071 static struct {
00072     /* Inputs */
00073     int                 display ;
00074     /* Outputs */
00075     crires_illum_period period ;
00076 } crires_util_profile_config ;
00077 
00078 /*-----------------------------------------------------------------------------
00079                                 Functions code
00080  -----------------------------------------------------------------------------*/
00081 
00082 /*----------------------------------------------------------------------------*/
00089 /*----------------------------------------------------------------------------*/
00090 static int crires_util_profile(
00091         cpl_frameset            *   frameset,
00092         const cpl_parameterlist *   parlist)
00093 {
00094     cpl_frame       *   fr ;
00095     const char      *   fname ;
00096     cpl_imagelist   *   profile ;
00097     cpl_table       *   tab[CRIRES_NB_DETECTORS] ;
00098     cpl_bivector    *   centers_fwhms ;
00099     int                 nbrows ;
00100     int                 ly ;
00101     int                 i, j ;
00102     
00103     /* Initialise */
00104     ly = -1 ;
00105     
00106     /* Retrieve input parameters */
00107     crires_util_profile_config.display = crires_parameterlist_get_int(parlist,
00108             RECIPE_STRING, CRIRES_PARAM_DISPLAY) ;
00109     
00110     /* Identify the RAW and CALIB frames in the input frameset */
00111     if (crires_dfs_set_groups(frameset, NULL)) {
00112         cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00113         return -1 ;
00114     }
00115 
00116     /* Get the detector illumination period */
00117     fr = cpl_frameset_get_frame(frameset, 0);
00118     crires_util_profile_config.period =
00119         crires_get_detector_illum_period(cpl_frame_get_filename(fr)) ;
00120     if (crires_util_profile_config.period == CRIRES_ILLUM_UNKNOWN) {
00121         cpl_msg_error(__func__,
00122                 "Cannot determine the detector illumination period") ;
00123         return -1 ;
00124     } else {
00125         crires_display_detector_illum(crires_util_profile_config.period) ;
00126     }
00127 
00128     /* The first frame must be the profile image */
00129     cpl_msg_info(__func__, "Input image loading") ;
00130     fname = cpl_frame_get_filename(fr) ;
00131     profile = crires_load_file(fname, crires_util_profile_config.period, 
00132             CPL_TYPE_FLOAT) ;
00133 
00134     /* Get the FWHMs */
00135     cpl_msg_info(__func__, "FWHM computation") ;
00136     cpl_msg_indent_more() ;
00137     for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00138         cpl_msg_info(__func__, "Chip number %d", i+1) ;
00139         cpl_msg_indent_more() ;
00140         if ((centers_fwhms = crires_extract_spatial_fwhm(
00141                         cpl_imagelist_get(profile, i))) == NULL) {
00142             cpl_msg_error(__func__, 
00143                     "Cannot get the FWHM for chip number %d", i+1) ;
00144             cpl_msg_indent_less() ;
00145             cpl_imagelist_delete(profile) ;
00146             for (j=0 ; j<i ; j++) cpl_table_delete(tab[j]) ;
00147             return -1 ;
00148         }
00149         cpl_msg_indent_less() ;
00150 
00151         /* Correct for the position */
00152         if (i+1 == 1) 
00153             ly = crires_get_detector_ly1(crires_util_profile_config.period) ;
00154         if (i+1 == 2) 
00155             ly = crires_get_detector_ly2(crires_util_profile_config.period) ;
00156         if (i+1 == 3) 
00157             ly = crires_get_detector_ly3(crires_util_profile_config.period) ;
00158         if (i+1 == 4) 
00159             ly = crires_get_detector_ly4(crires_util_profile_config.period) ;
00160         cpl_vector_add_scalar(cpl_bivector_get_x(centers_fwhms), (double)ly) ;
00161 
00162         /* Plot if requested */
00163         if(crires_util_profile_config.display == i+1) {
00164             irplib_vector_plot(
00165 "set grid;set xlabel 'Position (pixels)';set ylabel 'Y positions (pixels)';",
00166             "t 'Y positions' w lines", "", cpl_bivector_get_x(centers_fwhms));
00167             irplib_vector_plot(
00168         "set grid;set xlabel 'Position (pixels)';set ylabel 'FWHM (pixels)';",
00169                 "t 'FWHMs' w lines", "", cpl_bivector_get_y(centers_fwhms));
00170         }
00171        
00172         /* Create a table from the vector */
00173         nbrows = cpl_bivector_get_size(centers_fwhms) ;
00174         tab[i] = cpl_table_new(nbrows) ;
00175         cpl_table_new_column(tab[i], CRIRES_COL_WL_DETPOSX, CPL_TYPE_INT) ;
00176         cpl_table_new_column(tab[i], CRIRES_COL_DETPOSY, CPL_TYPE_DOUBLE) ;
00177         cpl_table_new_column(tab[i], CRIRES_COL_FWHM, CPL_TYPE_DOUBLE) ;
00178         for (j=0 ; j<nbrows ; j++) {
00179             cpl_table_set_int(tab[i], CRIRES_COL_WL_DETPOSX, j, j+1) ;
00180             cpl_table_set_double(tab[i], CRIRES_COL_DETPOSY, j,
00181                     cpl_vector_get(cpl_bivector_get_x(centers_fwhms), j));
00182             cpl_table_set_double(tab[i], CRIRES_COL_FWHM, j,
00183                     cpl_vector_get(cpl_bivector_get_y(centers_fwhms), j));
00184         }
00185         cpl_bivector_delete(centers_fwhms) ;
00186     }
00187     cpl_msg_indent_less() ;
00188             
00189     /* Save the product */
00190     cpl_msg_info(__func__, "Save the product") ;
00191     cpl_msg_indent_more() ;
00192     if (crires_util_profile_save((const cpl_table **)tab, parlist, frameset)) {
00193         cpl_msg_error(__func__, "Cannot save the product") ;
00194         cpl_msg_indent_less() ;
00195         for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) cpl_table_delete(tab[i]) ;
00196         return -1 ;
00197     }
00198     for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) cpl_table_delete(tab[i]) ;
00199     cpl_msg_indent_less() ;
00200 
00201     /* Return */
00202     if (cpl_error_get_code()) return -1 ;
00203     else return 0 ;
00204 }
00205 
00206 /*----------------------------------------------------------------------------*/
00214 /*----------------------------------------------------------------------------*/
00215 static int crires_util_profile_save(
00216         const cpl_table         **  out,
00217         const cpl_parameterlist *   parlist,
00218         cpl_frameset            *   set)
00219 {
00220     const char          *   recipe_name = "crires_util_profile" ;
00221 
00222     /* Write the table */
00223     crires_table_save(set,
00224             parlist,
00225             set,
00226             out,
00227             recipe_name,
00228             CRIRES_FWHM_TAB,
00229             CRIRES_PROTYPE_FWHM,
00230             NULL,
00231             NULL,
00232             PACKAGE "/" PACKAGE_VERSION,
00233             "crires_util_profile.fits") ;
00234 
00235     return  0;
00236 }

Generated on 22 Mar 2011 for CRIRES Pipeline Reference Manual by  doxygen 1.6.1