visir_spc_wcal.c

00001 /* $Id: visir_spc_wcal.c,v 1.71 2012/01/12 13:56:27 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: 2012/01/12 13:56:27 $
00024  * $Revision: 1.71 $
00025  * $Name: visir-3_5_0 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #include "visir_recipe.h"
00037 #include "visir_spectro.h"
00038 #include "visir_spc_distortion.h"
00039 
00040 
00041 /*-----------------------------------------------------------------------------
00042                                 Defines
00043  -----------------------------------------------------------------------------*/
00044 
00045 #define RECIPE_STRING   "visir_spc_wcal"
00046 
00047 /*-----------------------------------------------------------------------------
00048                             Private Functions prototypes
00049  -----------------------------------------------------------------------------*/
00050 static cpl_error_code visir_spc_wcal_save(cpl_frameset *,
00051                                           const cpl_parameterlist *,
00052                                           const cpl_propertylist *,
00053                                           const cpl_propertylist *,
00054                                           const cpl_table *);
00055 
00056 VISIR_RECIPE_DEFINE(visir_spc_wcal,
00057                     VISIR_PARAM_AUTOBPM |
00058                     VISIR_PARAM_PLOT   | VISIR_PARAM_SLITSKEW |
00059                     VISIR_PARAM_SPECSKEW | VISIR_PARAM_VERTARC |
00060                     VISIR_PARAM_REJLEFT | VISIR_PARAM_REJRIGHT |
00061                     VISIR_PARAM_HORIARC,
00062                     "Spectroscopic wavelength calibration recipe",
00063                     "This recipe estimates the dispersion relation using the "
00064                     "atmospheric spectrum\n"
00065                     "in a long-slit spectroscopy half-cycle frame.\n"
00066                     "The files listed in the Set Of Frames (sof-file) "
00067                     "must be tagged:\n"
00068                     "VISIR-Long-Slit-Spectroscopy-file.fits "
00069                     VISIR_SPC_WCAL_RAW "\n"
00070                     "VISIR-Quantum-Efficiency-Calibration-file.fits "
00071                     VISIR_CALIB_QEFF_SPC "\n"
00072                     "VISIR-Atmospheric-Emission-Lines-Calibration-file.fits "
00073                     VISIR_CALIB_LINES_SPC
00074                     "\n"
00075                     MAN_VISIR_CALIB_BPM_SPC);
00076 
00077 /*-----------------------------------------------------------------------------
00078                             Static variables
00079  -----------------------------------------------------------------------------*/
00080 
00081 static struct {
00082     /* Inputs */
00083     int         auto_bpm;
00084     int         plot;
00085     double      phi;
00086     double      ksi;
00087     double      eps;
00088     double      delta;
00089 
00090 } visir_spc_wcal_config;
00091 
00092 /*----------------------------------------------------------------------------*/
00096 /*----------------------------------------------------------------------------*/
00097 
00098 /*-----------------------------------------------------------------------------
00099                                 Functions code
00100  -----------------------------------------------------------------------------*/
00101 
00102 /*----------------------------------------------------------------------------*/
00109 /*----------------------------------------------------------------------------*/
00110 static int visir_spc_wcal(cpl_frameset            * framelist,
00111                           const cpl_parameterlist * parlist)
00112 {
00113     irplib_framelist * allframes = NULL;
00114     irplib_framelist * rawframes = NULL;
00115     cpl_propertylist * qclist    = cpl_propertylist_new();
00116     cpl_propertylist * paflist   = cpl_propertylist_new();
00117     const char      *   spc_cal_qeff;
00118     const char      *   spc_cal_lines;
00119     cpl_imagelist   *   hcycle = NULL;
00120     cpl_image       *   imhcycle = NULL;
00121     cpl_image       *   imhcyclenarrow = NULL;
00122     cpl_table       *   spc_table = NULL;
00123     double              wlen, slitw, temp, fwhm;
00124     visir_spc_resol     resol;
00125     int                icol1, icol2;
00126     int                jcol1, jcol2;
00127 
00128 
00129     visir_spc_wcal_config.auto_bpm = 
00130         visir_parameterlist_get_bool(parlist, RECIPE_STRING, VISIR_PARAM_AUTOBPM);
00131     visir_spc_wcal_config.plot = visir_parameterlist_get_int(parlist, RECIPE_STRING, VISIR_PARAM_PLOT);
00132 
00133     visir_spc_wcal_config.phi = 
00134         visir_parameterlist_get_double(parlist, RECIPE_STRING, VISIR_PARAM_SLITSKEW);
00135     visir_spc_wcal_config.ksi = 
00136         visir_parameterlist_get_double(parlist, RECIPE_STRING, VISIR_PARAM_SPECSKEW);
00137     visir_spc_wcal_config.eps = 
00138         visir_parameterlist_get_double(parlist, RECIPE_STRING, VISIR_PARAM_VERTARC);
00139     visir_spc_wcal_config.delta = 
00140         visir_parameterlist_get_double(parlist, RECIPE_STRING, VISIR_PARAM_HORIARC);
00141 
00142     jcol1 = visir_parameterlist_get_int(parlist, RECIPE_STRING,
00143                                         VISIR_PARAM_REJLEFT);
00144     jcol2 = visir_parameterlist_get_int(parlist, RECIPE_STRING,
00145                                         VISIR_PARAM_REJRIGHT);
00146 
00147     skip_if (0);
00148 
00149     /* Identify the RAW and CALIB frames in the input frameset */
00150     skip_if (visir_dfs_set_groups(framelist));
00151 
00152     /* Objects observation */
00153     allframes = irplib_framelist_cast(framelist);
00154     skip_if(allframes == NULL);
00155     rawframes = irplib_framelist_extract(allframes, VISIR_SPC_WCAL_RAW);
00156     skip_if (rawframes == NULL);
00157 
00158     irplib_framelist_empty(allframes);
00159 
00160     skip_if(irplib_framelist_load_propertylist(rawframes, 0, 0, "^("
00161                                                VISIR_PFITS_REGEXP_LOAD_IMAGELIST
00162                                                "|"
00163                                                VISIR_PFITS_REGEXP_SPC_GET_RES_WL
00164                                                "|" VISIR_PFITS_REGEXP_CAPA "|"
00165                                                VISIR_PFITS_REGEXP_SPC_WCAL_PAF
00166                                                ")$", CPL_FALSE));
00167 
00168     skip_if(irplib_framelist_load_propertylist_all(rawframes, 0, "^("
00169                                                VISIR_PFITS_REGEXP_LOAD_IMAGELIST
00170                                                "|"
00171                                                VISIR_PFITS_REGEXP_SPC_GET_RES_WL
00172                                                ")$", CPL_FALSE));
00173 
00174     skip_if(visir_dfs_check_framelist_tag(rawframes));
00175     
00176     /* Quantum efficiency file */
00177     spc_cal_qeff = irplib_frameset_find_file(framelist, VISIR_CALIB_QEFF_SPC);
00178 
00179     /* Spectral lines calibration file */
00180     spc_cal_lines = irplib_frameset_find_file(framelist, VISIR_CALIB_LINES_SPC);
00181 
00182     /* Get Resolution and Central Wavelength */
00183     resol = visir_spc_get_res_wl(rawframes, &wlen, &slitw, &temp, &fwhm);
00184 
00185     skip_if (0);
00186 
00187     if (resol == VISIR_SPC_R_GHR) {
00188         cpl_msg_error(cpl_func, "This recipe cannot reduce HR Grism data");
00189         visir_error_set(CPL_ERROR_TYPE_MISMATCH);
00190         skip_if(1);
00191     }
00192 
00193     skip_if(visir_qc_append_background(qclist, rawframes, 0, 0));
00194 
00195     /* Get the hcycle image from the reference file */
00196     hcycle = visir_load_hcycle(rawframes, 0);
00197     skip_if (0);
00198 
00199     imhcycle = cpl_imagelist_get(hcycle, 0);
00200 
00201     skip_if (visir_spc_det_fix(&imhcycle, 1, CPL_FALSE,
00202                                wlen, resol,
00203                                visir_spc_wcal_config.phi,
00204                                visir_spc_wcal_config.ksi,
00205                                visir_spc_wcal_config.eps,
00206                                visir_spc_wcal_config.delta, 
00207                                visir_spc_wcal_config.plot));
00208 
00209     icol1 = 1;
00210     icol2 = cpl_image_get_size_x(imhcycle);
00211 
00212     if (jcol1 != 0) {
00213         cpl_msg_info(cpl_func, "Ignoring %d leftmost columns", jcol1);
00214         icol1 += jcol1;
00215     }
00216     if (jcol2 != 0) {
00217         cpl_msg_info(cpl_func, "Ignoring %d rightmost columns", jcol2);
00218         icol2 -= jcol2;
00219     }
00220 
00221     if (jcol1 != 0 || jcol2 != 0) {
00222         imhcyclenarrow = visir_spc_column_extract(imhcycle, icol1, icol2,
00223                                           visir_spc_wcal_config.plot);
00224         skip_if (0);
00225 
00226     } else {
00227         imhcyclenarrow = imhcycle;
00228     }
00229 
00230     skip_if (visir_spc_wavecal(imhcyclenarrow, qclist, wlen, slitw, temp, fwhm,
00231                                resol, 0,
00232                                spc_cal_lines, spc_cal_qeff,
00233                                &spc_table, visir_spc_wcal_config.plot));
00234 
00235     /* This column is not part of the product */
00236     skip_if (cpl_table_erase_column(spc_table, "SPC_EMISSIVITY"));
00237 
00238     bug_if (visir_spectro_qc(qclist, paflist, CPL_FALSE, rawframes, NULL,
00239                              "^(" VISIR_PFITS_REGEXP_SPC_WCAL_PAF ")$"));
00240     irplib_framelist_empty(rawframes);
00241    
00242     /* Save the spectrum */
00243     cpl_msg_info(cpl_func, "Saving the produced spectrum");
00244 
00245     /* PRO.CATG */
00246     bug_if (cpl_propertylist_append_string(paflist, CPL_DFS_PRO_CATG,
00247                                            VISIR_SPC_WCAL_TAB_PROCATG));
00248 
00249     skip_if (visir_spc_wcal_save(framelist, parlist, qclist, paflist, spc_table));
00250 
00251     end_skip;
00252 
00253     cpl_propertylist_delete(qclist);
00254     cpl_propertylist_delete(paflist);
00255     irplib_framelist_delete(allframes);
00256     irplib_framelist_delete(rawframes);
00257     cpl_table_delete(spc_table);
00258     cpl_imagelist_delete(hcycle);
00259     if (imhcyclenarrow != imhcycle) cpl_image_delete(imhcyclenarrow);
00260 
00261 
00262     return cpl_error_get_code();
00263 }
00264  
00265 /*----------------------------------------------------------------------------*/
00275 /*----------------------------------------------------------------------------*/
00276 static cpl_error_code visir_spc_wcal_save(cpl_frameset            * set, 
00277                                           const cpl_parameterlist * parlist,
00278                                           const cpl_propertylist  * qclist,
00279                                           const cpl_propertylist  * paflist,
00280                                           const cpl_table         * table)
00281 {
00282     bug_if (0);
00283 
00284     /* THE TABLE */
00285     skip_if (irplib_dfs_save_table(set, parlist, set, table, NULL, RECIPE_STRING,
00286                                VISIR_SPC_WCAL_TAB_PROCATG,
00287                                qclist, NULL, visir_pipe_id,
00288                                RECIPE_STRING "_spectrum_tab" CPL_DFS_FITS));
00289 
00290 #ifdef VISIR_SAVE_PAF
00291     /* THE PAF FILE FOR QC PARAMETERS */
00292     skip_if (cpl_dfs_save_paf("VISIR", RECIPE_STRING, paflist,
00293                              RECIPE_STRING CPL_DFS_PAF));
00294 #else
00295     bug_if(paflist == NULL);
00296 #endif
00297 
00298     end_skip;
00299 
00300     return cpl_error_get_code();
00301 }

Generated on Mon Feb 6 15:23:49 2012 for VISIR Pipeline Reference Manual by  doxygen 1.5.8