visir_spc_phot.c

00001 /* $Id: visir_spc_phot.c,v 1.146 2010/08/09 13:04:23 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/08/09 13:04:23 $
00024  * $Revision: 1.146 $
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 #include "visir_spc_photom.h"
00040 
00041 
00042 
00043 /*-----------------------------------------------------------------------------
00044                                 Defines
00045  -----------------------------------------------------------------------------*/
00046 
00047 #define RECIPE_STRING   "visir_spc_phot"
00048 
00049 /* FITS keys to be loaded for all raw files */
00050 #define RECIPE_KEYS_REGEXP_ALL            \
00051         VISIR_PFITS_REGEXP_IMG_RECOMBINE  \
00052     "|" VISIR_PFITS_REGEXP_SPC_GET_RES_WL \
00053     "|" VISIR_PFITS_REGEXP_SPC_SENSIT
00054 
00055 /* FITS keys to be loaded for first raw file */
00056 #define RECIPE_KEYS_REGEXP               \
00057         RECIPE_KEYS_REGEXP_ALL           \
00058     "|" VISIR_PFITS_SPC_PHOT_COPY        \
00059     "|" VISIR_PFITS_REGEXP_CAPA          \
00060     "|" VISIR_PFITS_REGEXP_SPC_PHOT_PAF
00061 
00062 /* FITS keys to be loaded for first raw file, in case WCS is used */
00063 #define RECIPE_KEYS_REGEXP_WCS \
00064         RECIPE_KEYS_REGEXP \
00065     "|" IRPLIB_PFITS_WCS_REGEXP
00066 
00067 /*-----------------------------------------------------------------------------
00068                             Private Functions prototypes
00069  -----------------------------------------------------------------------------*/
00070 static cpl_error_code visir_spc_phot_save(cpl_frameset *,
00071                                           const cpl_parameterlist *,
00072                                           const cpl_propertylist *,
00073                                           const cpl_propertylist *,
00074                                           const cpl_image *,
00075                                           const cpl_image *,
00076                                           const cpl_table *);
00077 
00078 VISIR_RECIPE_DEFINE(visir_spc_phot,
00079                     VISIR_PARAM_EMIS_TOL |
00080                     VISIR_PARAM_REFINE | VISIR_PARAM_XCORR |
00081                     VISIR_PARAM_OFFSETS | VISIR_PARAM_OBJECTS |
00082                     VISIR_PARAM_NODPOS | VISIR_PARAM_AUTOBPM |
00083                     VISIR_PARAM_GLITCH | VISIR_PARAM_PURGE |
00084                     VISIR_PARAM_UNION  | VISIR_PARAM_REJECT |
00085                     VISIR_PARAM_STRIPITE | VISIR_PARAM_STRIPMOR |
00086                     VISIR_PARAM_PLOT   | VISIR_PARAM_SLITSKEW |
00087                     VISIR_PARAM_SPECSKEW | VISIR_PARAM_VERTARC |
00088                     VISIR_PARAM_REJLEFT | VISIR_PARAM_REJRIGHT |
00089                     VISIR_PARAM_HORIARC | VISIR_PARAM_FIXCOMBI,
00090                     "Sensitivity computation in spectroscopy",
00091                     "This recipe estimates the dispersion relation using the "
00092                     "atmospheric spectrum\n"
00093                     "in a long-slit spectroscopy half-cycle frame.\n"
00094                     "It also extracts the spectrum of an observed object "
00095                     "using a combined frame.\n"
00096                     "Lastly, it computes the spectral photometry of an "
00097                     "observed standard star.\n"
00098                     "The files listed in the Set Of Frames (sof-file) "
00099                     "must be tagged:\n"
00100                     "VISIR-Long-Slit-Spectroscopy-file.fits "
00101                     VISIR_SPC_PHOT_RAW "\n"
00102                     "VISIR-Quantum-Efficiency-Calibration-file.fits "
00103                     VISIR_CALIB_QEFF_SPC "\n"
00104                     "VISIR-Atmospheric-Emission-Lines-Calibration-file.fits "
00105                     VISIR_CALIB_LINES_SPC
00106                     "\n"
00107                     "VISIR-Spectroscopic-Standard-Star-Catalog.fits "
00108                     VISIR_CALIB_STDSTAR_SPC "\n"
00109                     MAN_VISIR_CALIB_BPM_SPC);
00110 
00111 /*----------------------------------------------------------------------------*/
00115 /*----------------------------------------------------------------------------*/
00116 
00117 /*-----------------------------------------------------------------------------
00118                                 Functions code
00119  -----------------------------------------------------------------------------*/
00120 
00121 /*----------------------------------------------------------------------------*/
00128 /*----------------------------------------------------------------------------*/
00129 static int visir_spc_phot(cpl_frameset            * framelist,
00130                           const cpl_parameterlist * parlist)
00131 {
00132     irplib_framelist * allframes = NULL;
00133     irplib_framelist * rawframes = NULL;
00134     cpl_propertylist * qclist    = cpl_propertylist_new();
00135     cpl_propertylist * paflist   = cpl_propertylist_new();
00136     const char      *   badpix;
00137     const char      *   star_cat;
00138     const char      *   spc_cal_qeff;
00139     const char      *   spc_cal_lines;
00140     const char      *   flat;
00141     cpl_image       **  combinedpair = NULL;
00142     cpl_image       *   combined = NULL;
00143     cpl_table       *   tab = NULL;
00144     cpl_image       *   weight2d = NULL;
00145     double              wlen, slitw, temp, fwhm;
00146     visir_spc_resol     resol;
00147     visir_spc_phot_config config;
00148     cpl_boolean        drop_wcs;
00149     const char       * keys_regexp = "^(" RECIPE_KEYS_REGEXP_WCS ")$";
00150 
00151 
00152     /* Retrieve input parameters */
00153     config.plot = visir_parameterlist_get_int(parlist, RECIPE_STRING, VISIR_PARAM_PLOT);
00154 
00155     config.phi = visir_parameterlist_get_double(parlist, RECIPE_STRING, VISIR_PARAM_SLITSKEW);
00156     config.ksi = visir_parameterlist_get_double(parlist, RECIPE_STRING, VISIR_PARAM_SPECSKEW);
00157     config.eps = visir_parameterlist_get_double(parlist, RECIPE_STRING, VISIR_PARAM_VERTARC);
00158     config.delta = visir_parameterlist_get_double(parlist, RECIPE_STRING, VISIR_PARAM_HORIARC);
00159 
00160     config.do_fixcombi = visir_parameterlist_get_bool(parlist, RECIPE_STRING, VISIR_PARAM_FIXCOMBI);
00161 
00162     config.emis_tol = visir_parameterlist_get_double(parlist, RECIPE_STRING, VISIR_PARAM_EMIS_TOL);
00163 
00164     skip_if (0);
00165 
00166     /* Identify the RAW and CALIB frames in the input frameset */
00167     skip_if (visir_dfs_set_groups(framelist));
00168 
00169     /* Objects observation */
00170     allframes = irplib_framelist_cast(framelist);
00171     skip_if(allframes == NULL);
00172     rawframes = irplib_framelist_extract(allframes, VISIR_SPC_PHOT_RAW);
00173     skip_if (rawframes == NULL);
00174 
00175     irplib_framelist_empty(allframes);
00176 
00177     skip_if(irplib_framelist_load_propertylist(rawframes, 0, 0, keys_regexp,
00178                                                CPL_FALSE));
00179 
00180     skip_if(irplib_framelist_load_propertylist_all(rawframes, 0, "^("
00181                                                    RECIPE_KEYS_REGEXP_ALL
00182                                                    ")$", CPL_FALSE));
00183 
00184     skip_if(visir_dfs_check_framelist_tag(rawframes));
00185     
00186     /* Standard star catalog */
00187     star_cat = irplib_frameset_find_file(framelist, VISIR_CALIB_STDSTAR_SPC);
00188     if (star_cat == NULL) {
00189          cpl_msg_error(cpl_func, "The file with the star catalog is missing");
00190          skip_if(1);
00191     }
00192 
00193     /* Quantum efficiency file */
00194     spc_cal_qeff = irplib_frameset_find_file(framelist, VISIR_CALIB_QEFF_SPC);
00195 
00196     /* Spectral lines calibration file */
00197     spc_cal_lines = irplib_frameset_find_file(framelist, VISIR_CALIB_LINES_SPC);
00198 
00199     /* Bad pixels calibration file */
00200     badpix = irplib_frameset_find_file(framelist, VISIR_CALIB_BPM);
00201 
00202     /* Flatfield calibration file */
00203     flat = irplib_frameset_find_file(framelist, VISIR_CALIB_FLAT);
00204 
00205     /* Get the resolution and central wavelength */
00206     resol = visir_spc_get_res_wl(rawframes, &wlen, &slitw, &temp, &fwhm);
00207 
00208     skip_if (0);
00209 
00210     if (resol == VISIR_SPC_R_GHR) {
00211         cpl_msg_error(cpl_func, "This recipe cannot reduce HR Grism data");
00212         visir_error_set(CPL_ERROR_TYPE_MISMATCH);
00213         skip_if(1);
00214     }
00215         
00216     /* Combine the frames */
00217     combinedpair = visir_img_recombine(RECIPE_STRING, parlist, rawframes, badpix,
00218                                        flat, CPL_GEOM_FIRST, &drop_wcs,
00219                                        !config.do_fixcombi, wlen, resol);
00220 
00221     if (combinedpair == NULL) {
00222         cpl_msg_error(cpl_func, "Could not combine the input frames");
00223         skip_if (1);
00224     }
00225 
00226     cpl_image_delete(combinedpair[1]);
00227     combined = cpl_image_cast(combinedpair[0], CPL_TYPE_DOUBLE);
00228     cpl_image_delete(combinedpair[0]);
00229 
00230     skip_if (0);
00231 
00232     /* Compute here the sensitivity */
00233     cpl_msg_info(cpl_func, "Compute the sensitivity");
00234     tab = visir_spc_phot_sensit(&combined, rawframes, RECIPE_STRING, parlist,
00235                                 &config, star_cat,
00236                                 spc_cal_lines, spc_cal_qeff, &weight2d, qclist,
00237                                 CPL_FALSE, wlen, slitw, temp, fwhm, resol);
00238 
00239     if (tab == NULL) {
00240         cpl_msg_error(cpl_func, "Cannot compute sensitivity: '%s' in %s",
00241                         cpl_error_get_message(), cpl_error_get_where());
00242         skip_if(1);
00243     }
00244 
00245     bug_if (visir_spectro_qc(qclist, paflist, drop_wcs, rawframes, 
00246                              "^(" VISIR_PFITS_SPC_PHOT_COPY ")$",
00247                              "^(" VISIR_PFITS_REGEXP_SPC_PHOT_PAF ")$"));
00248     irplib_framelist_empty(rawframes);
00249    
00250     /* Save the results */
00251     cpl_msg_info(cpl_func, "Save the results");
00252 
00253     /* PRO.CATG */
00254     bug_if (cpl_propertylist_append_string(paflist, CPL_DFS_PRO_CATG,
00255                                            VISIR_SPC_PHOT_COMBINED_PROCATG));
00256 
00257     skip_if (visir_spc_phot_save(framelist, parlist, qclist, paflist,
00258                                  combined, weight2d, tab));
00259 
00260     end_skip;
00261 
00262     cpl_propertylist_delete(qclist);
00263     cpl_propertylist_delete(paflist);
00264     irplib_framelist_delete(allframes);
00265     irplib_framelist_delete(rawframes);
00266     cpl_image_delete(combined);
00267     cpl_table_delete(tab);
00268     cpl_image_delete(weight2d);
00269 
00270     cpl_free(combinedpair);
00271 
00272     return cpl_error_get_code();
00273 }
00274  
00275 /*----------------------------------------------------------------------------*/
00287 /*----------------------------------------------------------------------------*/
00288 static cpl_error_code visir_spc_phot_save(cpl_frameset            * set,
00289                                           const cpl_parameterlist * parlist,
00290                                           const cpl_propertylist  * qclist,
00291                                           const cpl_propertylist  * paflist,
00292                                           const cpl_image         * combined,
00293                                           const cpl_image         * weight2d,
00294                                           const cpl_table         * table)
00295 {
00296 
00297      bug_if (0);
00298 
00299     /* THE TABLE */
00300     skip_if (irplib_dfs_save_table(set, parlist, set, table, NULL, RECIPE_STRING,
00301                                VISIR_SPC_PHOT_TAB_PROCATG,
00302                                qclist, NULL, visir_pipe_id,
00303                                RECIPE_STRING "_tab" CPL_DFS_FITS));
00304 
00305     /* THE COMBINED IMAGE */
00306     skip_if (irplib_dfs_save_image(set, parlist, set, combined, CPL_BPP_IEEE_FLOAT,
00307                                RECIPE_STRING, VISIR_SPC_PHOT_COMBINED_PROCATG,
00308                                qclist, NULL, visir_pipe_id,
00309                                RECIPE_STRING CPL_DFS_FITS));
00310 
00311     /* THE WEIGHT IMAGE */
00312     skip_if (irplib_dfs_save_image(set, parlist, set, weight2d, CPL_BPP_IEEE_FLOAT,
00313                                RECIPE_STRING, VISIR_SPC_PHOT_WEIGHT_PROCATG,
00314                                qclist, NULL, visir_pipe_id,
00315                                RECIPE_STRING "_weight" CPL_DFS_FITS));
00316 
00317 #ifdef VISIR_SAVE_PAF
00318     /* THE PAF FILE FOR QC PARAMETERS */
00319 
00320     skip_if (cpl_dfs_save_paf("VISIR", RECIPE_STRING, paflist,
00321                              RECIPE_STRING CPL_DFS_PAF));
00322 #else
00323     bug_if(paflist == NULL);
00324 #endif
00325 
00326     end_skip;
00327 
00328     return cpl_error_get_code();
00329 
00330 }

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