crires_util_sensitivity.c

00001 /* $Id: crires_util_sensitivity.c,v 1.30 2010/04/23 08:58:43 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: 2010/04/23 08:58:43 $
00024  * $Revision: 1.30 $
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_photom.h"
00039 
00040 /*-----------------------------------------------------------------------------
00041                                 Define
00042  -----------------------------------------------------------------------------*/
00043 
00044 #define RECIPE_STRING "crires_util_sensitivity"
00045 
00046 /*-----------------------------------------------------------------------------
00047                             Functions prototypes
00048  -----------------------------------------------------------------------------*/
00049 
00050 static int crires_util_sensitivity_save(const cpl_table **, 
00051         const cpl_parameterlist *, cpl_frameset *) ;
00052 
00053 static char crires_util_sensitivity_description[] = 
00054 "This recipe accepts 1 parameter:\n"
00055 "First parameter:   the table with the conversion factor.\n"
00056 "                   (PRO TYPE = "CRIRES_PROTYPE_CONVERS")\n"
00057 "\n"
00058 "This recipe produces 1 file:\n"
00059 "First product:     the table with the sensitivity signal.\n"
00060 "                   (PRO TYPE = "CRIRES_PROTYPE_SENSIT")\n" ;
00061 
00062 CRIRES_RECIPE_DEFINE(crires_util_sensitivity,
00063         CRIRES_PARAM_DISPLAY        |
00064         CRIRES_PARAM_EXPTIME,
00065         "Compute the sensitivity",
00066         crires_util_sensitivity_description) ;
00067 
00068 /*-----------------------------------------------------------------------------
00069                             Static variables
00070  -----------------------------------------------------------------------------*/
00071 
00072 static struct {
00073     /* Inputs */
00074     int             display ;
00075     double          exptime ;
00076     /* Outputs */
00077     double          sens_med[CRIRES_NB_DETECTORS] ;
00078 } crires_util_sensitivity_config ;
00079 
00080 /*-----------------------------------------------------------------------------
00081                                 Functions code
00082  -----------------------------------------------------------------------------*/
00083 
00084 /*----------------------------------------------------------------------------*/
00091 /*----------------------------------------------------------------------------*/
00092 static int crires_util_sensitivity(
00093         cpl_frameset            *   frameset,
00094         const cpl_parameterlist *   parlist)
00095 {
00096     cpl_frame           *   fr ;
00097     cpl_table           *   conv_tab[CRIRES_NB_DETECTORS] ;
00098     double                  exptime_comp ;
00099     int                     i, j ;
00100     
00101     /* Retrieve input parameters */
00102     crires_util_sensitivity_config.display = crires_parameterlist_get_int(
00103             parlist, RECIPE_STRING, CRIRES_PARAM_DISPLAY) ;
00104     crires_util_sensitivity_config.exptime = crires_parameterlist_get_double(
00105             parlist, RECIPE_STRING, CRIRES_PARAM_EXPTIME) ;
00106 
00107     /* Identify the RAW and CALIB frames in the input frameset */
00108     if (crires_dfs_set_groups(frameset, NULL)) {
00109         cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00110         return -1 ;
00111     }
00112 
00113     /* Loop on the CRIRES_NB_DETECTORS detectors */
00114     for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00115         cpl_msg_info(__func__, "Sensitivity computation for chip %d", i+1) ;
00116         
00117         /* Initialise */
00118         conv_tab[i] = NULL ;
00119         crires_util_sensitivity_config.sens_med[i] = -1.0 ;
00120 
00121         /* The first frame must be the conversion table */
00122         cpl_msg_info(__func__, "Load the extracted table") ;
00123         cpl_msg_indent_more() ;
00124         fr = cpl_frameset_get_frame(frameset, 0);
00125         if ((conv_tab[i] = crires_load_table_check(cpl_frame_get_filename(fr),
00126                         i+1, CRIRES_PROTYPE_CONVERS, -1, -1, 0)) == NULL) {
00127             cpl_msg_indent_less() ;
00128             continue ;
00129         }
00130         cpl_msg_indent_less() ;
00131 
00132         /* Compute */
00133         cpl_msg_info(__func__, "Sensitivity computation") ;
00134         cpl_msg_indent_more() ;
00135         if ((exptime_comp = crires_photom_sens_engine(conv_tab[i], 
00136                 cpl_frame_get_filename(fr),
00137                 crires_util_sensitivity_config.exptime,
00138                 crires_util_sensitivity_config.display==i+1)) < 0.0 ) {
00139             cpl_msg_error(__func__, "Cannot compute sensitivity") ;
00140             cpl_msg_indent_less() ;
00141             for (j=0 ; j<i ; j++) {
00142                 if (conv_tab[j] != NULL) cpl_table_delete(conv_tab[j]) ;
00143             }
00144             return -1 ;
00145         }
00146         cpl_msg_indent_less() ;
00147         crires_util_sensitivity_config.exptime = exptime_comp ;
00148 
00149         /* Compute the Median */
00150         crires_util_sensitivity_config.sens_med[i] = 
00151             cpl_table_get_column_median(conv_tab[i], CRIRES_COL_SENSITIVITY) ;
00152     }
00153     
00154     /* Save the product */
00155     cpl_msg_info(__func__, "Save the product") ;
00156     cpl_msg_indent_more() ;
00157     if (crires_util_sensitivity_save((const cpl_table **)conv_tab, parlist, 
00158                 frameset)) {
00159         cpl_msg_error(__func__, "Cannot save the product") ;
00160         for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00161             if (conv_tab[i] != NULL) cpl_table_delete(conv_tab[i]) ;
00162         }
00163         cpl_msg_indent_less() ;
00164         return -1 ;
00165     }
00166     for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00167         if (conv_tab[i] != NULL) cpl_table_delete(conv_tab[i]) ;
00168     }
00169     cpl_msg_indent_less() ;
00170 
00171     /* Return */
00172     if (cpl_error_get_code()) return -1 ;
00173     else return 0 ;
00174 }
00175 
00176 /*----------------------------------------------------------------------------*/
00184 /*----------------------------------------------------------------------------*/
00185 static int crires_util_sensitivity_save(
00186         const cpl_table         **  out,
00187         const cpl_parameterlist *   parlist,
00188         cpl_frameset            *   set)
00189 {
00190     cpl_propertylist    **  qclists ;
00191     const cpl_frame     *   ref_frame ;
00192     cpl_propertylist    *   inputlist ;
00193     const char          *   recipe_name = "crires_util_sensitivity" ;
00194     int                     i ;
00195 
00196     /* Get the reference frame */
00197     ref_frame = irplib_frameset_get_first_from_group(set, CPL_FRAME_GROUP_RAW) ;
00198 
00199     /* Create the QC lists */
00200     qclists = cpl_malloc(CRIRES_NB_DETECTORS * sizeof(cpl_propertylist*)) ;
00201     for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00202         qclists[i] = cpl_propertylist_new() ;
00203         cpl_propertylist_append_double(qclists[i], "ESO QC SENSMED",
00204                 crires_util_sensitivity_config.sens_med[i]) ;
00205         cpl_propertylist_append_double(qclists[i], "ESO QC EXPTIME",
00206                 crires_util_sensitivity_config.exptime) ;
00207 
00208         /* Propagate some keywords from input raw frame extensions */
00209         inputlist = cpl_propertylist_load_regexp(
00210                 cpl_frame_get_filename(ref_frame), i+1,
00211                 CRIRES_HEADER_EXT_FORWARD, 0) ;
00212         cpl_propertylist_copy_property_regexp(qclists[i], inputlist,
00213                 CRIRES_HEADER_EXT_FORWARD, 0) ;
00214         cpl_propertylist_delete(inputlist) ;
00215     }
00216 
00217     /* Write the table */
00218     crires_table_save(set,
00219             parlist,
00220             set,
00221             out,
00222             recipe_name,
00223             CRIRES_EXTRACT_SENS_TAB,
00224             CRIRES_PROTYPE_SENSIT,
00225             NULL, 
00226             (const cpl_propertylist **)qclists,
00227             PACKAGE "/" PACKAGE_VERSION,
00228             "crires_util_sensitivity.fits") ;
00229 
00230     /* Free and return */
00231     for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00232         cpl_propertylist_delete(qclists[i]) ;
00233     }
00234     cpl_free(qclists) ;
00235     return  0;
00236 }
00237 

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