visir_spc_wcal_ech.c

00001 /* $Id: visir_spc_wcal_ech.c,v 1.69 2010/03/09 12:52:18 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: 2010/03/09 12:52:18 $
00024  * $Revision: 1.69 $
00025  * $Name: HEAD $
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      *   badpix;
00120     const char      *   spc_cal_qeff;
00121     const char      *   spc_cal_lines;
00122     const char      *   flat;
00123     cpl_imagelist   *   hcycle = NULL;
00124     cpl_image       *   imhcycle = NULL;
00125     cpl_table       *   spc_table = NULL;
00126     cpl_image       *   order = NULL;
00127     double              wlen, slitw, temp, fwhm;
00128     int                 icol1, icol2;
00129     int                 jcol1, jcol2;
00130     visir_spc_resol     resol;
00131 
00132 
00133     visir_spc_wcal_ech_config.auto_bpm = 
00134         visir_parameterlist_get_bool(parlist, RECIPE_STRING, VISIR_PARAM_AUTOBPM);
00135     visir_spc_wcal_ech_config.plot =
00136         visir_parameterlist_get_int(parlist, RECIPE_STRING, VISIR_PARAM_PLOT);
00137 
00138     visir_spc_wcal_ech_config.phi = 
00139         visir_parameterlist_get_double(parlist,RECIPE_STRING,VISIR_PARAM_SLITSKEW);
00140     visir_spc_wcal_ech_config.ksi = 
00141         visir_parameterlist_get_double(parlist,RECIPE_STRING,VISIR_PARAM_SPECSKEW);
00142     visir_spc_wcal_ech_config.eps = 
00143         visir_parameterlist_get_double(parlist,RECIPE_STRING, VISIR_PARAM_VERTARC);
00144     visir_spc_wcal_ech_config.delta = 
00145         visir_parameterlist_get_double(parlist,RECIPE_STRING, VISIR_PARAM_HORIARC);
00146 
00147     visir_spc_wcal_ech_config.orderoffset = 
00148         visir_parameterlist_get_int(parlist, RECIPE_STRING, VISIR_PARAM_ORDEROFF);
00149 
00150     jcol1 = visir_parameterlist_get_int(parlist, RECIPE_STRING,
00151                                         VISIR_PARAM_REJLEFT);
00152     jcol2 = visir_parameterlist_get_int(parlist, RECIPE_STRING,
00153                                         VISIR_PARAM_REJRIGHT);
00154 
00155     skip_if (0);
00156 
00157     /* Identify the RAW and CALIB frames in the input frameset */
00158     skip_if (visir_dfs_set_groups(framelist));
00159 
00160     /* Objects observation */
00161     allframes = irplib_framelist_cast(framelist);
00162     skip_if(allframes == NULL);
00163     rawframes = irplib_framelist_extract(allframes, VISIR_SPC_WCAL_ECH_RAW);
00164     skip_if (rawframes == NULL);
00165 
00166     irplib_framelist_empty(allframes);
00167 
00168     skip_if(irplib_framelist_load_propertylist(rawframes, 0, 0, "^("
00169                                                VISIR_PFITS_REGEXP_LOAD_IMAGELIST
00170                                                "|"
00171                                                VISIR_PFITS_REGEXP_SPC_GET_RES_WL
00172                                                "|" VISIR_PFITS_REGEXP_CAPA "|"
00173                                                VISIR_PFITS_REGEXP_SPC_WCAL_PAF
00174                                                ")$", CPL_FALSE));
00175 
00176     skip_if(irplib_framelist_load_propertylist_all(rawframes, 0, "^("
00177                                                VISIR_PFITS_REGEXP_LOAD_IMAGELIST
00178                                                "|"
00179                                                VISIR_PFITS_REGEXP_SPC_GET_RES_WL
00180                                                ")$", CPL_FALSE));
00181 
00182     skip_if(visir_dfs_check_framelist_tag(rawframes));
00183     
00184     /* Quantum efficiency file */
00185     spc_cal_qeff = irplib_frameset_find_file(framelist, VISIR_CALIB_QEFF_SPC);
00186 
00187     /* Spectral lines calibration file */
00188     spc_cal_lines = irplib_frameset_find_file(framelist, VISIR_CALIB_LINES_SPC);
00189 
00190     /* Bad pixels calibration file */
00191     badpix = irplib_frameset_find_file(framelist, VISIR_CALIB_BPM);
00192 
00193     /* Flatfield calibration file */
00194     flat = irplib_frameset_find_file(framelist, VISIR_CALIB_FLAT);
00195 
00196 
00197     /* Get Resolution and Central Wavelength */
00198     resol = visir_spc_get_res_wl(rawframes, &wlen, &slitw, &temp, &fwhm);
00199 
00200    
00201     skip_if (0);
00202 
00203     if (resol != VISIR_SPC_R_GHR) {
00204         if (visir_spc_wcal_ech_config.orderoffset == 0) {
00205             cpl_msg_warning(cpl_func,"Reducing non-HR Grism data as main order");
00206         } else {
00207             cpl_msg_error(cpl_func, "This recipe cannot reduce non-HR Grism "
00208                           "data with an order-offset of %d",
00209                           visir_spc_wcal_ech_config.orderoffset);
00210             visir_error_set(CPL_ERROR_TYPE_MISMATCH);
00211             skip_if(1);
00212         }
00213     }
00214    
00215     /* Get the hcycle image from the reference file */
00216     hcycle = visir_load_hcycle(rawframes, 0);
00217     skip_if (0);
00218 
00219     imhcycle = cpl_imagelist_get(hcycle, 0);
00220 
00221     skip_if (visir_spc_det_fix(&imhcycle, 1, CPL_FALSE,
00222                                wlen, resol,
00223                                visir_spc_wcal_ech_config.phi,
00224                                visir_spc_wcal_ech_config.ksi,
00225                                visir_spc_wcal_ech_config.eps,
00226                                visir_spc_wcal_ech_config.delta, 
00227                                visir_spc_wcal_ech_config.plot));
00228 
00229     skip_if (visir_spc_echelle_limit(&icol1, &icol2, wlen,
00230                                      visir_spc_wcal_ech_config.orderoffset, 1,
00231                            cpl_image_get_size_y(imhcycle)));
00232 
00233     skip_if(visir_qc_append_background(qclist, rawframes, icol1, icol2));
00234 
00235     if (jcol1 != 0) {
00236         cpl_msg_info(cpl_func, "Ignoring %d leftmost columns from %d to %d",
00237                      jcol1, icol1, icol1 + jcol1);
00238         icol1 += jcol1;
00239     }
00240     if (jcol2 != 0) {
00241         cpl_msg_info(cpl_func, "Ignoring %d rightmost columns from %d to %d",
00242                      jcol2, icol2 - jcol2, icol2);
00243         icol2 -= jcol2;
00244     }
00245 
00246     if (icol1 != 1 || icol2 != cpl_image_get_size_x(imhcycle)) {
00247 
00248         order = visir_spc_column_extract(imhcycle, icol1, icol2,
00249                                           visir_spc_wcal_ech_config.plot);
00250         skip_if (0);
00251     } else {
00252         /* Cannot really succeed from here... */
00253         order = imhcycle;
00254     }
00255 
00256     skip_if (visir_spc_wavecal(order, qclist, wlen, slitw, temp, fwhm, resol,
00257                                visir_spc_wcal_ech_config.orderoffset,
00258                                spc_cal_lines, spc_cal_qeff,
00259                                &spc_table, visir_spc_wcal_ech_config.plot));
00260 
00261     /* This column is not part of the product */
00262     skip_if (cpl_table_erase_column(spc_table, "SPC_EMISSIVITY"));
00263 
00264     bug_if (visir_spectro_qc(qclist, paflist, CPL_FALSE, rawframes, NULL,
00265                              "^(" VISIR_PFITS_REGEXP_SPC_WCAL_PAF ")$"));
00266     irplib_framelist_empty(rawframes);
00267    
00268     /* Save the spectrum */
00269     cpl_msg_info(cpl_func, "Saving the produced spectrum");
00270 
00271     /* PRO.CATG */
00272     bug_if (cpl_propertylist_append_string(paflist, CPL_DFS_PRO_CATG,
00273                                            VISIR_SPC_WCAL_ECH_TAB_PROCATG));
00274 
00275     skip_if (visir_spc_wcal_ech_save(framelist, parlist, qclist, paflist,
00276                                      spc_table));
00277 
00278     end_skip;
00279 
00280     cpl_propertylist_delete(qclist);
00281     cpl_propertylist_delete(paflist);
00282     irplib_framelist_delete(allframes);
00283     irplib_framelist_delete(rawframes);
00284     cpl_table_delete(spc_table);
00285     if (order != imhcycle) cpl_image_delete(order);
00286     cpl_imagelist_delete(hcycle);
00287 
00288     return cpl_error_get_code();
00289 }
00290 
00291 /*----------------------------------------------------------------------------*/
00301 /*----------------------------------------------------------------------------*/
00302 static cpl_error_code visir_spc_wcal_ech_save(cpl_frameset            * set, 
00303                                               const cpl_parameterlist * parlist,
00304                                               const cpl_propertylist  * qclist,
00305                                               const cpl_propertylist  * paflist,
00306                                               const cpl_table         * table)
00307 {
00308     bug_if (0);
00309 
00310     /* THE TABLE */
00311     skip_if (irplib_dfs_save_table(set, parlist, set, table, NULL, RECIPE_STRING,
00312                                VISIR_SPC_WCAL_ECH_TAB_PROCATG,
00313                                qclist, NULL, visir_pipe_id,
00314                                RECIPE_STRING "_spectrum_tab" CPL_DFS_FITS));
00315 
00316 #ifdef VISIR_SAVE_PAF
00317     /* THE PAF FILE FOR QC PARAMETERS */
00318     skip_if (cpl_dfs_save_paf("VISIR", RECIPE_STRING, paflist,
00319                              RECIPE_STRING CPL_DFS_PAF));
00320 #else
00321     bug_if(paflist == NULL);
00322 #endif
00323 
00324     end_skip;
00325 
00326     return cpl_error_get_code();
00327 }

Generated on Thu Mar 24 11:59:39 2011 for VISIR Pipeline Reference Manual by  doxygen 1.5.8