crires_util_plot.c

00001 /* $Id: crires_util_plot.c,v 1.31 2010/12/21 19:54:42 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/12/21 19:54:42 $
00024  * $Revision: 1.31 $
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 "irplib_wlxcorr.h"
00039 
00040 /*-----------------------------------------------------------------------------
00041                                 Define
00042  -----------------------------------------------------------------------------*/
00043 
00044 #define RECIPE_STRING "crires_util_plot"
00045 
00046 /*-----------------------------------------------------------------------------
00047                             Functions prototypes
00048  -----------------------------------------------------------------------------*/
00049 
00050 static int crires_util_plot_diff(const cpl_table *,const char *, const char *) ;
00051 static int crires_util_plot_spec_pix(cpl_table *, cpl_table *, int) ;
00052 static int crires_util_plot_spec_pix_one(cpl_table *, cpl_table *, int, 
00053         const char *, const char *, const char *) ;
00054 static int crires_util_plot_spec_wl(cpl_table *, cpl_table *, 
00055         const char *, int) ;
00056 static int crires_util_plot_convers(cpl_table *, cpl_table *, 
00057         const char *, int) ;
00058 static int crires_util_plot_sensit(cpl_table *, cpl_table *, 
00059         const char *, int) ;
00060 static int crires_util_plot_spec_wl_one(cpl_table *, cpl_table *, 
00061         const char *, int, const char *, const char *, const char *) ;
00062 
00063 static char crires_util_plot_description[] = "Plot the CRIRES tables.\n" 
00064 "For MEF, specify the extension with --display=extension_number.\n"
00065 "This recipe accepts possibly 2 parameter:\n"
00066 "First parameter:       the table to plot.\n"
00067 "                       (PRO TYPE = "CRIRES_PROTYPE_CATALOG") or\n"
00068 "                       (PRO TYPE = "CRIRES_PROTYPE_PHO_FLUX") or\n"
00069 "                       (PRO TYPE = "CRIRES_PROTYPE_SPEC_PIX") or\n"
00070 "                       (PRO TYPE = "CRIRES_PROTYPE_SPEC_WL") or\n"
00071 "                       (PRO TYPE = "CRIRES_PROTYPE_XCORR") or\n"
00072 "                       (PRO TYPE = "CRIRES_PROTYPE_CONVERS") or\n"
00073 "                       (PRO TYPE = "CRIRES_PROTYPE_SENSIT") or\n"
00074 "                       (PRO TYPE = "CRIRES_PROTYPE_FWHM")\n" 
00075 "Second parameter is optional and must be of the same type and same\n"
00076 "                 table length as the first one. If provided, the two\n"
00077 "                 signals are overplotted. In this case, --adjust can \n"
00078 "                 be used to adjust the second plot average level to \n"
00079 "                 the first one.\n" ;
00080 
00081 CRIRES_RECIPE_DEFINE(crires_util_plot,
00082         CRIRES_PARAM_PMIN       |
00083         CRIRES_PARAM_PMAX       |
00084         CRIRES_PARAM_DISPLAY    |
00085         CRIRES_PARAM_WL_MODEL   |
00086         CRIRES_PARAM_ADJUST,
00087         "Plotting tool for the CRIRES tables",
00088         crires_util_plot_description) ;
00089 
00090 /*-----------------------------------------------------------------------------
00091                             Static variables
00092  -----------------------------------------------------------------------------*/
00093 
00094 static struct {
00095     /* Inputs */
00096     int             pmin ;
00097     int             pmax ;
00098     int             chip ;
00099     int             use_model ;
00100     int             adjust_level ;
00101 } crires_util_plot_config ;
00102 
00103 /*-----------------------------------------------------------------------------
00104                                 Functions code
00105  -----------------------------------------------------------------------------*/
00106 
00107 /*----------------------------------------------------------------------------*/
00114 /*----------------------------------------------------------------------------*/
00115 static int crires_util_plot(
00116         cpl_frameset            *   frameset,
00117         const cpl_parameterlist *   parlist)
00118 {
00119     const char          *   fname ;
00120     const char          *   fname_opt ;
00121     const char          *   title ;
00122     const char          *   sval ;
00123     cpl_propertylist    *   plist ;
00124     cpl_table           *   tab ;
00125     cpl_table           *   tab_opt ;
00126     cpl_array           *   wave ;
00127     cpl_array           *   flux ;
00128     cpl_vector          *   wave_vec ;
00129     cpl_vector          *   flux_vec ;
00130     cpl_bivector        *   flux_biv ;
00131     const char          *   wave_col ;
00132     int                     i ;
00133    
00134     /* Retrieve input parameters */
00135     crires_util_plot_config.pmin = crires_parameterlist_get_int(parlist,
00136             RECIPE_STRING, CRIRES_PARAM_PMIN) ;
00137     crires_util_plot_config.pmax = crires_parameterlist_get_int(parlist,
00138             RECIPE_STRING, CRIRES_PARAM_PMAX) ;
00139     crires_util_plot_config.chip = crires_parameterlist_get_int(parlist,
00140             RECIPE_STRING, CRIRES_PARAM_DISPLAY) ;
00141     crires_util_plot_config.use_model = crires_parameterlist_get_bool(parlist, 
00142             RECIPE_STRING, CRIRES_PARAM_WL_MODEL) ;
00143     crires_util_plot_config.adjust_level=crires_parameterlist_get_bool(parlist, 
00144             RECIPE_STRING, CRIRES_PARAM_ADJUST) ;
00145 
00146     /* Initialise */
00147     if (crires_util_plot_config.use_model)  
00148         wave_col = CRIRES_COL_WAVELENGTH_MODEL ;
00149     else
00150         wave_col = CRIRES_COL_WAVELENGTH ;
00151     
00152     /* Identify the RAW and CALIB frames in the input frameset */
00153     if (crires_dfs_set_groups(frameset, NULL)) {
00154         cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00155         return -1 ;
00156     }
00157 
00158     /* Retrieve raw frames */
00159     fname = cpl_frame_get_filename(cpl_frameset_get_frame(frameset, 0)) ;
00160     if (cpl_frameset_get_size(frameset) > 1) {
00161         fname_opt = cpl_frame_get_filename(
00162                 cpl_frameset_get_frame(frameset, 1)) ;
00163     } else {
00164         fname_opt = NULL ;
00165     }
00166 
00167     /* CRIRES_PROTYPE_CATALOG */
00168     tab = crires_load_table_check(fname, 1, CRIRES_PROTYPE_CATALOG, 
00169             crires_util_plot_config.pmin,
00170             crires_util_plot_config.pmax,
00171             crires_util_plot_config.use_model) ;
00172     if (tab != NULL) {
00173         plist = cpl_propertylist_load(fname, 0) ;
00174         sval = crires_pfits_get_procatg(plist) ;
00175         /* CRIRES_CALPRO_THAR_CAT */
00176         if (!strcmp(sval, CRIRES_CALPRO_THAR_CAT))
00177             title = "t 'Thorium/Argon lines' w lines" ;
00178         /* CRIRES_CALPRO_N2O_CAT */
00179         else if (!strcmp(sval, CRIRES_CALPRO_N2O_CAT))  
00180             title = "t 'N2O gas cell lines' w lines" ;
00181         /* CRIRES_CALPRO_OH_CAT */
00182         else if (!strcmp(sval, CRIRES_CALPRO_OH_CAT))  
00183             title = "t 'OH lines' w lines" ;
00184         /* CRIRES_CALPRO_HITRAN_CAT */
00185         else if (!strcmp(sval, CRIRES_CALPRO_HITRAN_CAT))  
00186             title = "t 'Hitran Spectrum' w lines" ;
00187         /* Default */
00188         else        
00189             title = "t 'signal' w lines" ;
00190         cpl_propertylist_delete(plist) ;
00191 
00192         /* Plot */
00193         cpl_plot_column(
00194                 "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Emission';",
00195                 title, "", tab, CRIRES_COL_WAVELENGTH, CRIRES_COL_EMISSION) ;
00196         cpl_table_delete(tab) ;
00197     }
00198  
00199     /* CRIRES_PROTYPE_PHO_FLUX */
00200     tab = crires_load_table_check(fname, 1, CRIRES_PROTYPE_PHO_FLUX, 
00201             crires_util_plot_config.pmin,
00202             crires_util_plot_config.pmax,
00203             crires_util_plot_config.use_model) ;
00204     if (tab != NULL) {
00205         for (i=1 ; i<cpl_table_get_nrow(tab) ; i++) {
00206             wave=cpl_array_duplicate(
00207                     cpl_table_get_array(tab, CRIRES_COL_PHOTOFLUX, 0));
00208             wave_vec = cpl_vector_wrap(cpl_array_get_size(wave),
00209                     cpl_array_get_data_double(wave)) ;
00210             cpl_array_unwrap(wave) ;
00211             flux=cpl_array_duplicate(
00212                     cpl_table_get_array(tab, CRIRES_COL_PHOTOFLUX, i));
00213             flux_vec = cpl_vector_wrap(cpl_array_get_size(flux),
00214                     cpl_array_get_data_double(flux)) ;
00215             cpl_array_unwrap(flux) ;
00216             flux_biv=cpl_bivector_wrap_vectors(wave_vec, flux_vec) ;
00217 
00218             cpl_plot_bivector(
00219                 "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Flux (Jy)';",
00220                 "t 'Photspheric flux' w lines", "", flux_biv) ;
00221             cpl_bivector_delete(flux_biv) ;
00222         }
00223         cpl_table_delete(tab) ;
00224     }
00225     /* CRIRES_PROTYPE_SPEC_PIX */
00226     tab = crires_load_table_check(fname, crires_util_plot_config.chip, 
00227             CRIRES_PROTYPE_SPEC_PIX, crires_util_plot_config.pmin, 
00228             crires_util_plot_config.pmax, crires_util_plot_config.use_model) ;
00229     if (fname_opt != NULL) {
00230         tab_opt = crires_load_table_check(fname_opt, 
00231                 crires_util_plot_config.chip, CRIRES_PROTYPE_SPEC_PIX, 
00232                 crires_util_plot_config.pmin, crires_util_plot_config.pmax, 
00233                 crires_util_plot_config.use_model);
00234     } else {
00235         tab_opt = NULL ;
00236     }
00237     crires_util_plot_spec_pix(tab, tab_opt,
00238             crires_util_plot_config.adjust_level) ;
00239     cpl_table_delete(tab) ;
00240     if (tab_opt != NULL) cpl_table_delete(tab_opt) ;
00241 
00242     /* CRIRES_PROTYPE_SPEC_WL */
00243     tab = crires_load_table_check(fname, crires_util_plot_config.chip, 
00244             CRIRES_PROTYPE_SPEC_WL, crires_util_plot_config.pmin, 
00245             crires_util_plot_config.pmax, crires_util_plot_config.use_model) ;
00246     if (fname_opt != NULL) {
00247         tab_opt = crires_load_table_check(fname_opt, 
00248                 crires_util_plot_config.chip, CRIRES_PROTYPE_SPEC_WL, 
00249                 crires_util_plot_config.pmin, crires_util_plot_config.pmax, 
00250                 crires_util_plot_config.use_model);
00251     } else {
00252         tab_opt = NULL ;
00253     }
00254     crires_util_plot_spec_wl(tab, tab_opt, wave_col,
00255             crires_util_plot_config.adjust_level) ;
00256     cpl_table_delete(tab) ;
00257     if (tab_opt != NULL) cpl_table_delete(tab_opt) ;
00258 
00259    /* CRIRES_PROTYPE_XCORR */
00260     tab = crires_load_table_check(fname, crires_util_plot_config.chip, 
00261             CRIRES_PROTYPE_XCORR, 
00262             crires_util_plot_config.pmin,
00263             crires_util_plot_config.pmax,
00264             crires_util_plot_config.use_model) ;
00265     if (tab != NULL) {
00266         irplib_wlxcorr_plot_spc_table(tab, "") ;
00267     }
00268 
00269     /* CRIRES_PROTYPE_CONVERS */
00270     tab = crires_load_table_check(fname, crires_util_plot_config.chip, 
00271             CRIRES_PROTYPE_CONVERS, crires_util_plot_config.pmin, 
00272             crires_util_plot_config.pmax, crires_util_plot_config.use_model) ;
00273     if (fname_opt != NULL) {
00274         tab_opt = crires_load_table_check(fname_opt, 
00275                 crires_util_plot_config.chip, CRIRES_PROTYPE_CONVERS, 
00276                 crires_util_plot_config.pmin, crires_util_plot_config.pmax, 
00277                 crires_util_plot_config.use_model);
00278     } else {
00279         tab_opt = NULL ;
00280     }
00281     crires_util_plot_convers(tab, tab_opt, wave_col,
00282             crires_util_plot_config.adjust_level) ;
00283     cpl_table_delete(tab) ;
00284     if (tab_opt != NULL) cpl_table_delete(tab_opt) ;
00285 
00286     /* CRIRES_PROTYPE_SENSIT */
00287     tab = crires_load_table_check(fname, crires_util_plot_config.chip, 
00288             CRIRES_PROTYPE_SENSIT, crires_util_plot_config.pmin, 
00289             crires_util_plot_config.pmax, crires_util_plot_config.use_model) ;
00290     if (fname_opt != NULL) {
00291         tab_opt = crires_load_table_check(fname_opt, 
00292                 crires_util_plot_config.chip, CRIRES_PROTYPE_SENSIT, 
00293                 crires_util_plot_config.pmin, crires_util_plot_config.pmax, 
00294                 crires_util_plot_config.use_model);
00295     } else {
00296         tab_opt = NULL ;
00297     }
00298     crires_util_plot_sensit(tab, tab_opt, wave_col,
00299             crires_util_plot_config.adjust_level) ;
00300     cpl_table_delete(tab) ;
00301     if (tab_opt != NULL) cpl_table_delete(tab_opt) ;
00302 
00303     /* CRIRES_PROTYPE_FWHM */
00304     tab = crires_load_table_check(fname, crires_util_plot_config.chip, 
00305             CRIRES_PROTYPE_FWHM, crires_util_plot_config.pmin, 
00306             crires_util_plot_config.pmax, crires_util_plot_config.use_model) ;
00307     if (tab != NULL) {
00308         cpl_plot_column(
00309         "set grid;set xlabel 'Position (pixels)';set ylabel 'FWHM (pixels)';",
00310                 "t 'FWHM' w lines", "", tab,
00311                 CRIRES_COL_WL_DETPOSX, CRIRES_COL_FWHM) ;
00312         cpl_plot_column(
00313     "set grid;set xlabel 'Position (pixels)';set ylabel 'Y position (pixels)';",
00314                 "t 'Y position' w lines", "", tab,
00315                 CRIRES_COL_WL_DETPOSX, CRIRES_COL_DETPOSY) ;
00316         cpl_table_delete(tab) ;
00317     }
00318  
00319     /* Return */
00320     if (cpl_error_get_code()) 
00321         return -1 ;
00322     else 
00323         return 0 ;
00324 }
00325 
00326 static int crires_util_plot_diff(
00327         const cpl_table *       tab,
00328         const char      *       col1,
00329         const char      *       col2)
00330 {
00331     cpl_bivector    *   toplot ;
00332     cpl_vector      *   vec_x ;
00333     cpl_vector      *   vec_tmp ;
00334     cpl_vector      *   vec_y ;
00335     int                 nrows ;
00336     double              val ;
00337     int                 i ;
00338 
00339     /* Check entries */
00340     if (tab == NULL) return -1 ;
00341     if (!cpl_table_has_column(tab, col1)) return -1 ;
00342     if (!cpl_table_has_column(tab, col2)) return -1 ;
00343 
00344     /* Initialise */
00345     nrows = cpl_table_get_nrow(tab) ;
00346 
00347     /* Get access */
00348     vec_x = cpl_vector_wrap(nrows,
00349             cpl_table_get_data_double((cpl_table*)tab, col1)) ;
00350     vec_tmp = cpl_vector_wrap(nrows,
00351             cpl_table_get_data_double((cpl_table*)tab, col2)) ;
00352 
00353     /* Compute difference */
00354     vec_y = cpl_vector_duplicate(vec_x) ;
00355     cpl_vector_subtract(vec_y, vec_tmp) ;
00356     cpl_vector_unwrap(vec_tmp) ;
00357 
00358     /* Handle special case 0s */
00359     for (i=0 ; i<cpl_vector_get_size(vec_y) ; i++) {
00360         if (fabs(cpl_vector_get(vec_y, i)) > 100) {
00361             if (i==0) val = cpl_vector_get(vec_y, 10) ;
00362             else val = cpl_vector_get(vec_y, i-1) ;
00363             cpl_vector_set(vec_y, i, val) ; 
00364         }
00365     }
00366 
00367     toplot = cpl_bivector_wrap_vectors(vec_x, vec_y) ;
00368 
00369     /* Plot */
00370     cpl_plot_bivector(
00371         "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Wave diff (nm)';",
00372         "t 'Wavelength difference XC-model' w lines", "", toplot) ;
00373 
00374     /* Free and return */
00375     cpl_bivector_unwrap_vectors(toplot) ;
00376     cpl_vector_unwrap(vec_x) ;
00377     cpl_vector_delete(vec_y) ;
00378 
00379     return 0 ;
00380 }
00381 
00382 static int crires_util_plot_spec_pix(
00383         cpl_table   *       tab,
00384         cpl_table   *       tab_opt,
00385         int                 adjust_level)
00386 {
00387 
00388     /* CRIRES_COL_EXTRACT_INT_OPT */
00389     crires_util_plot_spec_pix_one(tab, tab_opt, adjust_level, 
00390             CRIRES_COL_EXTRACT_INT_OPT,
00391 "set grid;set xlabel 'Position (pixels)';set ylabel 'Intensity OPT (ADU/sec)';",
00392             "t 'Extracted Spectrum OPT' w lines") ;
00393 
00394     /* CRIRES_COL_EXTRACT_INT_RECT */
00395     crires_util_plot_spec_pix_one(tab, tab_opt, adjust_level, 
00396             CRIRES_COL_EXTRACT_INT_RECT,
00397 "set grid;set xlabel 'Position (pixels)';set ylabel 'Intensity RECT (ADU/sec)';",
00398             "t 'Extracted Spectrum RECT' w lines") ;
00399 
00400     /* CRIRES_COL_EXTRACT_ERR_OPT */
00401     crires_util_plot_spec_pix_one(tab, tab_opt, adjust_level, 
00402             CRIRES_COL_EXTRACT_ERR_OPT,
00403 "set grid;set xlabel 'Position (pixels)';set ylabel 'Error OPT (ADU/sec)';",
00404             "t 'Error OPT' w lines") ;
00405 
00406     /* CRIRES_COL_EXTRACT_ERR_RECT */
00407     crires_util_plot_spec_pix_one(tab, tab_opt, adjust_level, 
00408             CRIRES_COL_EXTRACT_ERR_RECT,
00409 "set grid;set xlabel 'Position (pixels)';set ylabel 'Error RECT (ADU/sec)';",
00410             "t 'Error RECT' w lines") ;
00411 
00412     /* CRIRES_COL_EXTRACT_WN_OPT */
00413     crires_util_plot_spec_pix_one(tab, tab_opt, adjust_level, 
00414             CRIRES_COL_EXTRACT_WN_OPT,
00415 "set grid;set xlabel 'Position (pixels)';set ylabel 'Weight Norm OPT';", 
00416             "t 'Weight norm OPT' w lines") ;
00417 
00418     /* CRIRES_COL_EXTRACT_WN_RECT */
00419     crires_util_plot_spec_pix_one(tab, tab_opt, adjust_level, 
00420             CRIRES_COL_EXTRACT_WN_RECT,
00421 "set grid;set xlabel 'position (pixels)';set ylabel 'weight norm rect';", 
00422             "t 'weight norm rect' w lines") ;
00423 
00424     /* CRIRES_COL_EXTRACT_BG_NOISE */
00425     crires_util_plot_spec_pix_one(tab, tab_opt, adjust_level, 
00426             CRIRES_COL_EXTRACT_BG_NOISE,
00427 "set grid;set xlabel 'Position (pixels)';set ylabel 'Background noise';", 
00428             "t 'Background noise' w lines") ;
00429 
00430     return 0 ;
00431 }
00432  
00433 static int crires_util_plot_spec_pix_one(
00434         cpl_table   *       tab,
00435         cpl_table   *       tab_opt,
00436         int                 adjust_level,
00437         const char  *       y_col,
00438         const char  *       options,
00439         const char  *       title)
00440 {
00441     double                  mean1, mean2 ;
00442     int                     nrows ;
00443     cpl_vector          **  vectors ;
00444 
00445     /* Check inputs */
00446     if (tab == NULL) return -1 ;
00447     nrows = cpl_table_get_nrow(tab) ;
00448     if (tab_opt != NULL) {
00449         if (cpl_table_get_nrow(tab_opt) != nrows) {
00450             cpl_msg_error(__func__, 
00451                     "The two tables must have the same number of rows") ;
00452             return -1 ;
00453         }
00454     }
00455     
00456     vectors = cpl_malloc(3*sizeof(cpl_vector*)) ;
00457     vectors[0] = NULL ;
00458     vectors[1] = cpl_vector_wrap(nrows, cpl_table_get_data_double(tab, y_col)) ;
00459     if (tab_opt != NULL) {
00460         vectors[2] = cpl_vector_wrap(nrows,
00461                 cpl_table_get_data_double(tab_opt, y_col));
00462         if (adjust_level) {
00463             mean1 = cpl_vector_get_mean(vectors[1]) ;
00464             mean2 = cpl_vector_get_mean(vectors[2]) ;
00465             cpl_vector_multiply_scalar(vectors[2], fabs(mean1/mean2)) ;
00466         }
00467         cpl_plot_vectors(options, title, "", (const cpl_vector **)vectors, 3);
00468         cpl_vector_unwrap(vectors[2]) ;
00469     } else {
00470         cpl_plot_vector(options, title, "", vectors[1]) ;
00471     }
00472     cpl_vector_unwrap(vectors[1]) ;
00473     cpl_free(vectors) ;
00474     return 0 ;
00475 }
00476 
00477 static int crires_util_plot_spec_wl(
00478         cpl_table   *       tab,
00479         cpl_table   *       tab_opt,
00480         const char  *       wave_col,
00481         int                 adjust_level)
00482 {
00483     /* CRIRES_COL_EXTRACT_INT_OPT */
00484     crires_util_plot_spec_wl_one(tab, tab_opt, wave_col, adjust_level, 
00485             CRIRES_COL_EXTRACT_INT_OPT,
00486 "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Intensity OPT (ADU/sec)';",
00487             "t 'Extracted Spectrum OPT' w lines") ;
00488 
00489     /* CRIRES_COL_EXTRACT_INT_RECT */
00490     crires_util_plot_spec_wl_one(tab, tab_opt, wave_col, adjust_level, 
00491             CRIRES_COL_EXTRACT_INT_RECT,
00492 "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Intensity RECT (ADU/sec)';",
00493             "t 'Extracted Spectrum RECT' w lines") ;
00494 
00495     /* CRIRES_COL_EXTRACT_ERR_OPT */
00496     crires_util_plot_spec_wl_one(tab, tab_opt, wave_col, adjust_level, 
00497             CRIRES_COL_EXTRACT_ERR_OPT,
00498 "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Error OPT (ADU/sec)';",
00499             "t 'Error OPT' w lines") ;
00500 
00501     /* CRIRES_COL_EXTRACT_ERR_RECT */
00502     crires_util_plot_spec_wl_one(tab, tab_opt, wave_col, adjust_level, 
00503             CRIRES_COL_EXTRACT_ERR_RECT,
00504 "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Error RECT (ADU/sec)';",
00505             "t 'Error RECT' w lines") ;
00506 
00507     /* CRIRES_COL_EXTRACT_WN_OPT */
00508     crires_util_plot_spec_wl_one(tab, tab_opt, wave_col, adjust_level, 
00509             CRIRES_COL_EXTRACT_WN_OPT,
00510 "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Weight Norm OPT';",
00511             "t 'Weight Norm OPT' w lines") ;
00512 
00513     /* CRIRES_COL_EXTRACT_WN_RECT */
00514     crires_util_plot_spec_wl_one(tab, tab_opt, wave_col, adjust_level, 
00515             CRIRES_COL_EXTRACT_WN_RECT,
00516 "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Weight Norm RECT';",
00517             "t 'Weight Norm RECT' w lines") ;
00518 
00519     /* CRIRES_COL_EXTRACT_BG_NOISE */
00520     crires_util_plot_spec_wl_one(tab, tab_opt, wave_col, adjust_level, 
00521             CRIRES_COL_EXTRACT_BG_NOISE,
00522 "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Background noise';",
00523             "t 'Background noise' w lines") ;
00524 
00525     /* Wavelengths difference */
00526     crires_util_plot_diff(tab, CRIRES_COL_WAVELENGTH,
00527             CRIRES_COL_WAVELENGTH_MODEL) ;
00528     
00529     return 0 ;
00530 }
00531  
00532 static int crires_util_plot_spec_wl_one(
00533         cpl_table   *       tab,
00534         cpl_table   *       tab_opt,
00535         const char  *       wave_col,
00536         int                 adjust_level,
00537         const char  *       y_col,
00538         const char  *       options,
00539         const char  *       title)
00540 {
00541     double                  mean1, mean2 ;
00542     int                     nrows ;
00543     cpl_vector          **  vectors ;
00544 
00545     /* Check inputs */
00546     if (tab == NULL) return -1 ;
00547     nrows = cpl_table_get_nrow(tab) ;
00548     if (tab_opt != NULL) {
00549         if (cpl_table_get_nrow(tab_opt) != nrows) {
00550             cpl_msg_error(__func__, 
00551                     "The two tables must have the same number of rows") ;
00552             return -1 ;
00553         }
00554     }
00555 
00556     if (tab_opt != NULL) {
00557         vectors = cpl_malloc(3*sizeof(cpl_vector*)) ;
00558         vectors[0]=cpl_vector_wrap(nrows,cpl_table_get_data_double(tab, 
00559                     wave_col));
00560         vectors[1] = cpl_vector_wrap(nrows, 
00561                 cpl_table_get_data_double(tab, y_col)) ;
00562         vectors[2] = cpl_vector_wrap(nrows,
00563                 cpl_table_get_data_double(tab_opt, y_col));
00564         if (adjust_level) {
00565             mean1 = cpl_vector_get_mean(vectors[1]) ;
00566             mean2 = cpl_vector_get_mean(vectors[2]) ;
00567             cpl_vector_multiply_scalar(vectors[2], fabs(mean1/mean2)) ;
00568         }
00569         cpl_plot_vectors(options, title, "", (const cpl_vector **)vectors, 3);
00570         cpl_vector_unwrap(vectors[0]) ;
00571         cpl_vector_unwrap(vectors[1]) ;
00572         cpl_vector_unwrap(vectors[2]) ;
00573         cpl_free(vectors) ;
00574     } else {
00575         cpl_plot_column(options, title, "", tab, wave_col, y_col) ;
00576     }
00577     return 0 ;
00578 }
00579 
00580 static int crires_util_plot_convers(
00581         cpl_table   *       tab,
00582         cpl_table   *       tab_opt,
00583         const char  *       wave_col,
00584         int                 adjust_level)
00585 {
00586 
00587     /* Start with the same as for CRIRES_PROTYPE_SPEC_WL */
00588     if (crires_util_plot_spec_wl(tab, tab_opt, wave_col, adjust_level) == -1) 
00589         return -1 ;
00590     
00591     /* CRIRES_COL_CONVERSION_OPT  */
00592     crires_util_plot_spec_wl_one(tab, tab_opt, wave_col, adjust_level, 
00593             CRIRES_COL_CONVERSION_OPT,
00594 "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Conversion OPT (ADU/sec/Jy)';",
00595         "t 'Conversion factor OPT' w lines") ;
00596 
00597     /* CRIRES_COL_CONVERSION_RECT */
00598     crires_util_plot_spec_wl_one(tab, tab_opt, wave_col, adjust_level, 
00599             CRIRES_COL_CONVERSION_RECT,
00600 "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Conversion RECT (ADU/sec/Jy)';",
00601         "t 'Conversion factor RECT' w lines") ;
00602 
00603     /* CRIRES_COL_THROUGHPUT */
00604     crires_util_plot_spec_wl_one(tab, tab_opt, wave_col, adjust_level, 
00605             CRIRES_COL_THROUGHPUT,
00606 "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Throughput (e-/phot)';",
00607         "t 'Throughput' w lines") ;
00608     return 0 ;
00609 }
00610 
00611 static int crires_util_plot_sensit(
00612         cpl_table   *       tab,
00613         cpl_table   *       tab_opt,
00614         const char  *       wave_col,
00615         int                 adjust_level)
00616 {
00617     /* Start with the same as for CRIRES_PROTYPE_CONVERS */
00618     if (crires_util_plot_convers(tab, tab_opt, wave_col, adjust_level) == -1) 
00619         return -1 ;
00620     
00621     /* CRIRES_COL_SENSITIVITY */
00622     crires_util_plot_spec_wl_one(tab, tab_opt, wave_col, adjust_level, 
00623             CRIRES_COL_SENSITIVITY,
00624 "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Sensitivity (Jy/10sig/hour)';",
00625                 "t 'Sensitivity' w lines") ;
00626     return 0 ;
00627 }
00628 

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