visir_spc_wcal_ech.c

00001 /* $Id: visir_spc_wcal_ech.c,v 1.70 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.70 $
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                                  Defines
00042  -----------------------------------------------------------------------------*/
00043 
00044 #define RECIPE_STRING "visir_spc_wcal_ech"
00045 
00046 /*-----------------------------------------------------------------------------
00047                             Private Functions prototypes
00048  -----------------------------------------------------------------------------*/
00049 static cpl_error_code visir_spc_wcal_ech_save(cpl_frameset *,
00050                                               const cpl_parameterlist *,
00051                                               const cpl_propertylist *,
00052                                               const cpl_propertylist *,
00053                                               const cpl_table *);
00054 
00055 VISIR_RECIPE_DEFINE(visir_spc_wcal_ech,
00056                     VISIR_PARAM_ZERODIST | VISIR_PARAM_ORDEROFF |
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 in Echelle",
00063                     "This recipe estimates the dispersion relation using the "
00064                     "atmospheric spectrum\n"
00065                     "in a grism spectroscopy half-cycle frame.\n"
00066                     "The files listed in the Set Of Frames (sof-file) "
00067                     "must be tagged:\n"
00068                     "VISIR-Echelle-Spectroscopy-file.fits "
00069                     VISIR_SPC_WCAL_ECH_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     int         orderoffset;
00086     double      phi;
00087     double      ksi;
00088     double      eps;
00089     double      delta;
00090 
00091 } visir_spc_wcal_ech_config;
00092 
00093 
00094 /*----------------------------------------------------------------------------*/
00098 /*----------------------------------------------------------------------------*/
00099 
00100 /*-----------------------------------------------------------------------------
00101                                 Functions code
00102  -----------------------------------------------------------------------------*/
00103 
00104 /*----------------------------------------------------------------------------*/
00111 /*----------------------------------------------------------------------------*/
00112 static int visir_spc_wcal_ech(cpl_frameset            * framelist,
00113                               const cpl_parameterlist * parlist)
00114 {
00115     irplib_framelist * allframes = NULL;
00116     irplib_framelist * rawframes = NULL;
00117     cpl_propertylist * qclist    = cpl_propertylist_new();
00118     cpl_propertylist * paflist   = cpl_propertylist_new();
00119     const char      *   spc_cal_qeff;
00120     const char      *   spc_cal_lines;
00121     cpl_imagelist   *   hcycle = NULL;
00122     cpl_image       *   imhcycle = NULL;
00123     cpl_table       *   spc_table = NULL;
00124     cpl_image       *   order = NULL;
00125     double              wlen, slitw, temp, fwhm;
00126     int                 icol1, icol2;
00127     int                 jcol1, jcol2;
00128     visir_spc_resol     resol;
00129 
00130 
00131     visir_spc_wcal_ech_config.auto_bpm = 
00132         visir_parameterlist_get_bool(parlist, RECIPE_STRING, VISIR_PARAM_AUTOBPM);
00133     visir_spc_wcal_ech_config.plot =
00134         visir_parameterlist_get_int(parlist, RECIPE_STRING, VISIR_PARAM_PLOT);
00135 
00136     visir_spc_wcal_ech_config.phi = 
00137         visir_parameterlist_get_double(parlist,RECIPE_STRING,VISIR_PARAM_SLITSKEW);
00138     visir_spc_wcal_ech_config.ksi = 
00139         visir_parameterlist_get_double(parlist,RECIPE_STRING,VISIR_PARAM_SPECSKEW);
00140     visir_spc_wcal_ech_config.eps = 
00141         visir_parameterlist_get_double(parlist,RECIPE_STRING, VISIR_PARAM_VERTARC);
00142     visir_spc_wcal_ech_config.delta = 
00143         visir_parameterlist_get_double(parlist,RECIPE_STRING, VISIR_PARAM_HORIARC);
00144 
00145     visir_spc_wcal_ech_config.orderoffset = 
00146         visir_parameterlist_get_int(parlist, RECIPE_STRING, VISIR_PARAM_ORDEROFF);
00147 
00148     jcol1 = visir_parameterlist_get_int(parlist, RECIPE_STRING,
00149                                         VISIR_PARAM_REJLEFT);
00150     jcol2 = visir_parameterlist_get_int(parlist, RECIPE_STRING,
00151                                         VISIR_PARAM_REJRIGHT);
00152 
00153     skip_if (0);
00154 
00155     /* Identify the RAW and CALIB frames in the input frameset */
00156     skip_if (visir_dfs_set_groups(framelist));
00157 
00158     /* Objects observation */
00159     allframes = irplib_framelist_cast(framelist);
00160     skip_if(allframes == NULL);
00161     rawframes = irplib_framelist_extract(allframes, VISIR_SPC_WCAL_ECH_RAW);
00162     skip_if (rawframes == NULL);
00163 
00164     irplib_framelist_empty(allframes);
00165 
00166     skip_if(irplib_framelist_load_propertylist(rawframes, 0, 0, "^("
00167                                                VISIR_PFITS_REGEXP_LOAD_IMAGELIST
00168                                                "|"
00169                                                VISIR_PFITS_REGEXP_SPC_GET_RES_WL
00170                                                "|" VISIR_PFITS_REGEXP_CAPA "|"
00171                                                VISIR_PFITS_REGEXP_SPC_WCAL_PAF
00172                                                ")$", CPL_FALSE));
00173 
00174     skip_if(irplib_framelist_load_propertylist_all(rawframes, 0, "^("
00175                                                VISIR_PFITS_REGEXP_LOAD_IMAGELIST
00176                                                "|"
00177                                                VISIR_PFITS_REGEXP_SPC_GET_RES_WL
00178                                                ")$", CPL_FALSE));
00179 
00180     skip_if(visir_dfs_check_framelist_tag(rawframes));
00181     
00182     /* Quantum efficiency file */
00183     spc_cal_qeff = irplib_frameset_find_file(framelist, VISIR_CALIB_QEFF_SPC);
00184 
00185     /* Spectral lines calibration file */
00186     spc_cal_lines = irplib_frameset_find_file(framelist, VISIR_CALIB_LINES_SPC);
00187 
00188     /* Get Resolution and Central Wavelength */
00189     resol = visir_spc_get_res_wl(rawframes, &wlen, &slitw, &temp, &fwhm);
00190    
00191     skip_if (0);
00192 
00193     if (resol != VISIR_SPC_R_GHR) {
00194         if (visir_spc_wcal_ech_config.orderoffset == 0) {
00195             cpl_msg_warning(cpl_func,"Reducing non-HR Grism data as main order");
00196         } else {
00197             cpl_msg_error(cpl_func, "This recipe cannot reduce non-HR Grism "
00198                           "data with an order-offset of %d",
00199                           visir_spc_wcal_ech_config.orderoffset);
00200             visir_error_set(CPL_ERROR_TYPE_MISMATCH);
00201             skip_if(1);
00202         }
00203     }
00204    
00205     /* Get the hcycle image from the reference file */
00206     hcycle = visir_load_hcycle(rawframes, 0);
00207     skip_if (0);
00208 
00209     imhcycle = cpl_imagelist_get(hcycle, 0);
00210 
00211     skip_if (visir_spc_det_fix(&imhcycle, 1, CPL_FALSE,
00212                                wlen, resol,
00213                                visir_spc_wcal_ech_config.phi,
00214                                visir_spc_wcal_ech_config.ksi,
00215                                visir_spc_wcal_ech_config.eps,
00216                                visir_spc_wcal_ech_config.delta, 
00217                                visir_spc_wcal_ech_config.plot));
00218 
00219     skip_if (visir_spc_echelle_limit(&icol1, &icol2, wlen,
00220                                      visir_spc_wcal_ech_config.orderoffset, 1,
00221                            cpl_image_get_size_y(imhcycle)));
00222 
00223     skip_if(visir_qc_append_background(qclist, rawframes, icol1, icol2));
00224 
00225     if (jcol1 != 0) {
00226         cpl_msg_info(cpl_func, "Ignoring %d leftmost columns from %d to %d",
00227                      jcol1, icol1, icol1 + jcol1);
00228         icol1 += jcol1;
00229     }
00230     if (jcol2 != 0) {
00231         cpl_msg_info(cpl_func, "Ignoring %d rightmost columns from %d to %d",
00232                      jcol2, icol2 - jcol2, icol2);
00233         icol2 -= jcol2;
00234     }
00235 
00236     if (icol1 != 1 || icol2 != cpl_image_get_size_x(imhcycle)) {
00237 
00238         order = visir_spc_column_extract(imhcycle, icol1, icol2,
00239                                           visir_spc_wcal_ech_config.plot);
00240         skip_if (0);
00241     } else {
00242         /* Cannot really succeed from here... */
00243         order = imhcycle;
00244     }
00245 
00246     skip_if (visir_spc_wavecal(order, qclist, wlen, slitw, temp, fwhm, resol,
00247                                visir_spc_wcal_ech_config.orderoffset,
00248                                spc_cal_lines, spc_cal_qeff,
00249                                &spc_table, visir_spc_wcal_ech_config.plot));
00250 
00251     /* This column is not part of the product */
00252     skip_if (cpl_table_erase_column(spc_table, "SPC_EMISSIVITY"));
00253 
00254     bug_if (visir_spectro_qc(qclist, paflist, CPL_FALSE, rawframes, NULL,
00255                              "^(" VISIR_PFITS_REGEXP_SPC_WCAL_PAF ")$"));
00256     irplib_framelist_empty(rawframes);
00257    
00258     /* Save the spectrum */
00259     cpl_msg_info(cpl_func, "Saving the produced spectrum");
00260 
00261     /* PRO.CATG */
00262     bug_if (cpl_propertylist_append_string(paflist, CPL_DFS_PRO_CATG,
00263                                            VISIR_SPC_WCAL_ECH_TAB_PROCATG));
00264 
00265     skip_if (visir_spc_wcal_ech_save(framelist, parlist, qclist, paflist,
00266                                      spc_table));
00267 
00268     end_skip;
00269 
00270     cpl_propertylist_delete(qclist);
00271     cpl_propertylist_delete(paflist);
00272     irplib_framelist_delete(allframes);
00273     irplib_framelist_delete(rawframes);
00274     cpl_table_delete(spc_table);
00275     if (order != imhcycle) cpl_image_delete(order);
00276     cpl_imagelist_delete(hcycle);
00277 
00278     return cpl_error_get_code();
00279 }
00280 
00281 /*----------------------------------------------------------------------------*/
00291 /*----------------------------------------------------------------------------*/
00292 static cpl_error_code visir_spc_wcal_ech_save(cpl_frameset            * set, 
00293                                               const cpl_parameterlist * parlist,
00294                                               const cpl_propertylist  * qclist,
00295                                               const cpl_propertylist  * paflist,
00296                                               const cpl_table         * table)
00297 {
00298     bug_if (0);
00299 
00300     /* THE TABLE */
00301     skip_if (irplib_dfs_save_table(set, parlist, set, table, NULL, RECIPE_STRING,
00302                                VISIR_SPC_WCAL_ECH_TAB_PROCATG,
00303                                qclist, NULL, visir_pipe_id,
00304                                RECIPE_STRING "_spectrum_tab" CPL_DFS_FITS));
00305 
00306 #ifdef VISIR_SAVE_PAF
00307     /* THE PAF FILE FOR QC PARAMETERS */
00308     skip_if (cpl_dfs_save_paf("VISIR", RECIPE_STRING, paflist,
00309                              RECIPE_STRING CPL_DFS_PAF));
00310 #else
00311     bug_if(paflist == NULL);
00312 #endif
00313 
00314     end_skip;
00315 
00316     return cpl_error_get_code();
00317 }

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