crires_spec_flat.c

00001 /* $Id: crires_spec_flat.c,v 1.53 2011/02/09 10:16:18 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: 2011/02/09 10:16:18 $
00024  * $Revision: 1.53 $
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 "crires_combine.h"
00039 
00040 /*-----------------------------------------------------------------------------
00041                                 Define
00042  -----------------------------------------------------------------------------*/
00043 
00044 #define RECIPE_STRING "crires_spec_flat"
00045 
00046 /*-----------------------------------------------------------------------------
00047                             Functions prototypes
00048  -----------------------------------------------------------------------------*/
00049 
00050 static cpl_imagelist * crires_spec_flat_reduce(cpl_frameset *, const char *,
00051         const char *) ;
00052 static cpl_imagelist * crires_spec_flat_bpm(cpl_imagelist *, double, 
00053         double, double) ;
00054 static int crires_spec_flat_save(const cpl_imagelist *, const cpl_imagelist *, 
00055         int, cpl_frameset *, const cpl_parameterlist *, cpl_frameset *) ;
00056 static int crires_spec_flat_compare(const cpl_frame *, const cpl_frame *) ;
00057 
00058 static char crires_spec_flat_description[] =
00059 "crires_spec_flat -- Flat-field recipe\n"
00060 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
00061 "raw-file.fits "CRIRES_SPEC_FLAT_RAW" or\n"
00062 "dark-file.fits "CRIRES_CALPRO_DARK" or\n"
00063 "detlin-file.fits "CRIRES_CALPRO_COEFFS_CUBE".\n" ;
00064 
00065 CRIRES_RECIPE_DEFINE(crires_spec_flat,
00066         CRIRES_PARAM_THRESHOLDS     |
00067         CRIRES_PARAM_BPM_RATE       |
00068         CRIRES_PARAM_REPLACE        |
00069         CRIRES_PARAM_CLEAN_FLAT     |
00070         CRIRES_PARAM_NORM_STARTY    |
00071         CRIRES_PARAM_NORM_STOPY     |
00072         CRIRES_PARAM_KAPPA_SIGCLIP  |
00073         CRIRES_PARAM_COLLAPSE_METH,
00074         "Flatfield recipe",
00075         crires_spec_flat_description) ;
00076 
00077 /*-----------------------------------------------------------------------------
00078                             Static variables
00079  -----------------------------------------------------------------------------*/
00080 
00081 static struct {
00082     /* Input */
00083     double                  bpm_low ;
00084     double                  bpm_high ;
00085     double                  bpm_lines_ratio ;
00086     int                     replace_flag ;
00087     int                     clean_flat_flag ;
00088     int                     starty ;
00089     int                     stopy ;
00090     double                  kappa_sigclip ;
00091     crires_collapse_method  coll_meth ;
00092     /* Output */
00093     crires_illum_period     period ;
00094     int                     bpm_nb[CRIRES_NB_DETECTORS] ;
00095     double                  flat_mean[CRIRES_NB_DETECTORS] ;
00096     double                  flat_stdev[CRIRES_NB_DETECTORS] ;
00097     double                  flat_flux[CRIRES_NB_DETECTORS] ;
00098     double                  flat_master_rms[CRIRES_NB_DETECTORS] ;
00099 } crires_spec_flat_config ;
00100 
00101 /*-----------------------------------------------------------------------------
00102                                 Functions code
00103  -----------------------------------------------------------------------------*/
00104 
00105 /*----------------------------------------------------------------------------*/
00112 /*----------------------------------------------------------------------------*/
00113 static int crires_spec_flat(
00114         cpl_frameset            *   frameset,
00115         const cpl_parameterlist *   parlist)
00116 {
00117     const char      *   sval ;
00118     int             *   labels ;
00119     int                 nlabels ;
00120     cpl_frameset    *   rawframes ;
00121     const char      *   dark ;
00122     const char      *   detlin ;
00123     cpl_imagelist   *   flat ;
00124     cpl_frameset    *   flat_one ;
00125     cpl_imagelist   *   bpm ;
00126     int                 i ;
00127 
00128     /* Initialise */
00129     rawframes = NULL ;
00130     for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00131         crires_spec_flat_config.bpm_nb[i] = -1 ;
00132         crires_spec_flat_config.flat_mean[i] = -1.0 ;
00133         crires_spec_flat_config.flat_stdev[i] = -1.0 ;
00134         crires_spec_flat_config.flat_flux[i] = -1.0 ;
00135         crires_spec_flat_config.flat_master_rms[i] = -1.0 ;
00136     }
00137     
00138     /* Retrieve input parameters */
00139     sval = crires_parameterlist_get_string(parlist, RECIPE_STRING, 
00140             CRIRES_PARAM_THRESHOLDS) ;
00141     if (sscanf(sval, "%lg,%lg",
00142                     &crires_spec_flat_config.bpm_low,
00143                     &crires_spec_flat_config.bpm_high)!=2) {
00144         return -1 ;
00145     }
00146     crires_spec_flat_config.replace_flag = crires_parameterlist_get_bool(
00147             parlist, RECIPE_STRING, CRIRES_PARAM_REPLACE) ;
00148     crires_spec_flat_config.clean_flat_flag = crires_parameterlist_get_bool(
00149             parlist, RECIPE_STRING, CRIRES_PARAM_CLEAN_FLAT) ;
00150     crires_spec_flat_config.bpm_lines_ratio = crires_parameterlist_get_double( 
00151             parlist, RECIPE_STRING, CRIRES_PARAM_BPM_RATE) ;
00152     crires_spec_flat_config.starty = crires_parameterlist_get_int(parlist, 
00153             RECIPE_STRING, CRIRES_PARAM_NORM_STARTY) ;
00154     crires_spec_flat_config.stopy = crires_parameterlist_get_int(parlist, 
00155             RECIPE_STRING, CRIRES_PARAM_NORM_STOPY) ;
00156     crires_spec_flat_config.kappa_sigclip = crires_parameterlist_get_double( 
00157             parlist, RECIPE_STRING, CRIRES_PARAM_KAPPA_SIGCLIP) ;
00158     sval = crires_parameterlist_get_string(parlist, RECIPE_STRING,
00159             CRIRES_PARAM_COLLAPSE_METH) ;
00160     if (!strcmp(sval, "avg"))
00161         crires_spec_flat_config.coll_meth = CRIRES_COLLAPSE_AVG ;
00162     else if (!strcmp(sval, "med"))
00163         crires_spec_flat_config.coll_meth = CRIRES_COLLAPSE_MED ;
00164     else if (!strcmp(sval, "sig"))
00165         crires_spec_flat_config.coll_meth = CRIRES_COLLAPSE_SIG ;
00166     else {
00167         cpl_msg_error(__func__, "Invalid collapse method specified");
00168         return -1;
00169     }
00170  
00171     /* Identify the RAW and CALIB frames in the input frameset */
00172     if (crires_dfs_set_groups(frameset, "crires_spec_flat")) {
00173         cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00174         return -1 ;
00175     }
00176 
00177     /* Retrieve calibration data */
00178     dark        = crires_extract_filename(frameset, CRIRES_CALPRO_DARK) ;
00179     detlin      = crires_extract_filename(frameset, CRIRES_CALPRO_COEFFS_CUBE) ;
00180 
00181     /* Retrieve raw frames */
00182     if ((rawframes = crires_extract_frameset(frameset, 
00183                     CRIRES_SPEC_FLAT_RAW)) == NULL) {
00184         cpl_msg_error(__func__, "No raw frame in input") ;
00185         return -1 ;
00186     }
00187 
00188     /* Get the detector illumination period */
00189     crires_spec_flat_config.period =
00190         crires_get_detector_illum_period(
00191                 cpl_frame_get_filename(cpl_frameset_get_frame(rawframes, 0))) ;
00192     if (crires_spec_flat_config.period == CRIRES_ILLUM_UNKNOWN) {
00193         cpl_msg_error(__func__,
00194                 "Cannot determine the detector illumination period") ;
00195         cpl_frameset_delete(rawframes) ;
00196         return -1 ;
00197     } else {
00198         crires_display_detector_illum(crires_spec_flat_config.period) ;
00199     }
00200 
00201     /* Labelise all input frames */
00202     if ((labels = cpl_frameset_labelise(rawframes, crires_spec_flat_compare,
00203                 &nlabels)) == NULL) {
00204         cpl_msg_error(__func__, "Cannot labelise input frames") ;
00205         cpl_frameset_delete(rawframes) ;
00206         return -1 ;
00207     }
00208 
00209     /* Extract settings and reduce each of them */
00210     for (i=0 ; i<nlabels ; i++) {
00211         /* Reduce data set nb i */
00212         cpl_msg_info(__func__, "Reduce data set %d / %d", i+1, nlabels);
00213         cpl_msg_indent_more() ;
00214         flat_one = cpl_frameset_extract(rawframes, labels, i) ;
00215         flat = crires_spec_flat_reduce(flat_one, dark, detlin) ;
00216         cpl_msg_indent_less() ;
00217 
00218         /* Save the products */
00219         cpl_msg_info(__func__, "Save the products") ;
00220         cpl_msg_indent_more() ;
00221         if (flat == NULL) {
00222             cpl_msg_warning(__func__, "Cannot reduce set nb %d", i+1) ;
00223         } else {
00224             if ((bpm = crires_spec_flat_bpm(flat,
00225                             crires_spec_flat_config.bpm_low,
00226                             crires_spec_flat_config.bpm_high,
00227                             crires_spec_flat_config.bpm_lines_ratio)) == NULL) {
00228                 cpl_msg_warning(__func__, "Cannot create bad pixels map") ;
00229             }
00230             crires_spec_flat_save(flat, bpm, i+1, flat_one, parlist, frameset) ;
00231             cpl_imagelist_delete(flat) ;
00232             cpl_imagelist_delete(bpm) ;
00233         }
00234         cpl_msg_indent_less() ;
00235         cpl_frameset_delete(flat_one) ;
00236     }
00237     cpl_frameset_delete(rawframes) ;
00238     cpl_free(labels) ;
00239 
00240     /* Return */
00241     if (cpl_error_get_code()) return -1 ;
00242     else return 0 ;
00243 }
00244 
00245 /*----------------------------------------------------------------------------*/
00253 /*----------------------------------------------------------------------------*/
00254 static cpl_imagelist * crires_spec_flat_reduce(
00255         cpl_frameset    *   flatframes,
00256         const char      *   dark,
00257         const char      *   detlin)
00258 {
00259     cpl_propertylist    *   plist ;
00260     cpl_frame           *   ref_frame ;
00261     const char          *   fname ;
00262     int                     nframes ;
00263     double                  dit_frame, dit_dark ;
00264     cpl_imagelist       *   in ;
00265     cpl_imagelist       *   out ;
00266     cpl_vector          *   medians ;
00267     double                  median ;
00268     cpl_image           *   ima ;
00269     int                     nx, ny, starty, stopy, ly ;
00270     int                     i, j ;
00271 
00272     /* Test entries */
00273     if (flatframes == NULL) return NULL ;
00274 
00275     /* Initialize */
00276     nframes = cpl_frameset_get_size(flatframes) ;
00277     ly = -1 ;
00278 
00279     /* Get the DIT from the RAW frame */
00280     ref_frame = cpl_frameset_get_frame(flatframes, 0) ;
00281     fname = cpl_frame_get_filename(ref_frame) ;
00282     if ((plist=cpl_propertylist_load(cpl_frame_get_filename(ref_frame),
00283                     0)) == NULL) {
00284         cpl_msg_error(__func__, "Getting header from RAW file");
00285         cpl_msg_indent_less() ;
00286         return NULL ;
00287     }
00288     dit_frame = crires_pfits_get_dit(plist) ;
00289     cpl_propertylist_delete(plist) ;
00290     if (cpl_error_get_code()) {
00291         cpl_msg_error(__func__, "Cannot get the DIT from RAW file") ;
00292         cpl_msg_indent_less() ;
00293         return NULL ;
00294     }
00295     cpl_msg_info(__func__, "DIT value: %g sec.", dit_frame) ;
00296     
00297     /* Verify the DIT of the dark */
00298     if (dark != NULL) {
00299         cpl_msg_info(__func__, "Verify the dark DIT") ;
00300         cpl_msg_indent_more() ;
00301         if ((plist=cpl_propertylist_load(dark, 0)) == NULL) {
00302             cpl_msg_error(__func__, "Getting header from DARK");
00303             cpl_msg_indent_less() ;
00304             return NULL ;
00305         }
00306         dit_dark = crires_pfits_get_dit(plist) ;
00307         cpl_propertylist_delete(plist) ;
00308         if (cpl_error_get_code()) {
00309             cpl_msg_error(__func__, "Cannot get the DIT from DARK") ;
00310             cpl_msg_indent_less() ;
00311             return NULL ;
00312         }
00313         if (fabs(dit_dark-dit_frame) > 1e-5) {
00314             cpl_msg_error(__func__, "Mismatch RAW DIT (%g) / DARK DIT (%g)",
00315                     dit_frame, dit_dark) ;
00316             cpl_msg_indent_less() ;
00317             return NULL ;
00318         }
00319         cpl_msg_indent_less() ;
00320     }
00321 
00322     /* Create the image list */
00323     out = cpl_imagelist_new() ;
00324     
00325     /* Loop on the detectors */
00326     for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00327         cpl_msg_info(__func__, "Compute the MASTER FLAT for chip nb %d", i+1) ;
00328         cpl_msg_indent_more() ;
00329 
00330         /* Load the data */
00331         in = crires_load_frameset(flatframes, crires_spec_flat_config.period, 
00332                 i+1, CPL_TYPE_FLOAT) ;
00333         nx = cpl_image_get_size_x(cpl_imagelist_get(in, 0)) ;
00334         ny = cpl_image_get_size_y(cpl_imagelist_get(in, 0)) ;
00335 
00336         /* Correct for dark and non-linearity */
00337         if (crires_calib_chip_list(in, crires_spec_flat_config.period, i+1, 
00338                     NULL, dark, NULL, detlin, dit_frame)) {
00339             cpl_msg_error(__func__, "Cannot apply the calibrations") ;
00340             cpl_imagelist_delete(in) ;
00341             return NULL ;
00342         }
00343 
00344         /* Create medians vector */
00345         medians = cpl_vector_new(nframes) ;
00346 
00347         /* Handle Vignetting */
00348         if (i+1 == 1) 
00349             ly = crires_get_detector_ly1(crires_spec_flat_config.period) ;
00350         if (i+1 == 2) 
00351             ly = crires_get_detector_ly2(crires_spec_flat_config.period) ;
00352         if (i+1 == 3) 
00353             ly = crires_get_detector_ly3(crires_spec_flat_config.period) ;
00354         if (i+1 == 4) 
00355             ly = crires_get_detector_ly4(crires_spec_flat_config.period) ;
00356         starty = crires_spec_flat_config.starty ;
00357         if (starty < 0) {
00358             starty = 1 ;
00359         } else {
00360             starty -= (ly - 1) ;
00361         }
00362         stopy = crires_spec_flat_config.stopy ;
00363         if (stopy < 0) {
00364             stopy = ny ;
00365         } else {
00366             stopy -= (ly - 1) ;
00367         }
00368 
00369         /* Loop on all the frames */
00370         cpl_msg_info(__func__, "Normalise with the median") ;
00371         for (j=0 ; j<nframes ; j++) {
00372             median = cpl_image_get_median_window(cpl_imagelist_get(in, j), 
00373                     1, starty, nx, stopy) ;
00374             if (cpl_error_get_code()) {
00375                 cpl_msg_error(__func__, "Invalid bounds Y : %d-%d", ly,
00376                         ly+ny-1) ;
00377                 cpl_imagelist_delete(in) ;
00378                 cpl_vector_delete(medians) ;
00379                 return NULL ;
00380             }
00381             cpl_vector_set(medians, j, median) ;
00382             cpl_image_divide_scalar(cpl_imagelist_get(in, j), median) ;
00383         }
00384 
00385         /* Fill QCs */
00386         crires_spec_flat_config.flat_mean[i] = cpl_vector_get_mean(medians) ;
00387         if (cpl_vector_get_size(medians) > 1) 
00388             crires_spec_flat_config.flat_stdev[i]=cpl_vector_get_stdev(medians);
00389         else
00390             crires_spec_flat_config.flat_stdev[i] = -1.0 ;
00391         crires_spec_flat_config.flat_flux[i] =
00392             crires_spec_flat_config.flat_mean[i] / dit_frame ;
00393        
00394         /* Collapse the frames */
00395         if ((ima = crires_combine_collapse_imagelist(in, medians, 
00396                         crires_spec_flat_config.kappa_sigclip,
00397                         i+1,
00398                         crires_spec_flat_config.coll_meth)) == NULL) {
00399             cpl_msg_error(__func__, "Cannot average the flats") ;
00400             cpl_imagelist_delete(in) ;
00401             cpl_vector_delete(medians) ;
00402             return NULL ;
00403         }
00404         cpl_vector_delete(medians) ;
00405         cpl_imagelist_delete(in) ;
00406 
00407         /* Add QC */
00408         crires_spec_flat_config.flat_master_rms[i] =
00409             cpl_image_get_stdev(ima) ;
00410         
00411         /* Set the image in the list */
00412         cpl_imagelist_set(out, ima, i) ;
00413         cpl_msg_indent_less() ;
00414     }
00415 
00416     return out ;
00417 }
00418 
00419 /*----------------------------------------------------------------------------*/
00428 /*----------------------------------------------------------------------------*/
00429 static cpl_imagelist * crires_spec_flat_bpm(
00430         cpl_imagelist       *   flat,
00431         double                  low,
00432         double                  high,
00433         double                  bad_per_line_limit)
00434 {
00435     cpl_imagelist   *   bpm ;
00436     int                 nima ;
00437     cpl_image       *   bpm_cur ;
00438     cpl_mask        *   mask_cur ;
00439     cpl_binary      *   pmask_cur ;
00440     int                 nx, ny, cur_bp_nb ;
00441     int                 i, j, k ;
00442 
00443     /* Test entries */
00444     if (flat == NULL) return NULL ;
00445 
00446     /* Initialise */
00447     nima = cpl_imagelist_get_size(flat) ;
00448 
00449     /* Create the output image list */
00450     bpm = cpl_imagelist_new() ;
00451 
00452     /* Loop on the images */
00453     for (i=0 ; i<nima ; i++) {
00454         /* Threshold to get the BPMs */
00455         if ((mask_cur = cpl_mask_threshold_image_create(
00456                         cpl_imagelist_get(flat, i), low, high)) == NULL) {
00457             cpl_msg_error(__func__, "Cannot create bad pixels map") ;
00458             cpl_imagelist_delete(bpm) ;
00459             return NULL ;
00460         }
00461         cpl_mask_not(mask_cur) ;
00462 
00463         /*
00464         Post processing : Big zones of bad pixels are not considered as
00465         bad pixels. Each line containing more than
00466         100*bad_per_line_limit percent bad pixels is reset to contain
00467         anly good pixels.
00468         */
00469         nx = cpl_mask_get_size_x(mask_cur) ;
00470         ny = cpl_mask_get_size_y(mask_cur) ;
00471         pmask_cur = cpl_mask_get_data(mask_cur) ;
00472         for (j=0 ; j<ny ; j++) {
00473             cur_bp_nb = cpl_mask_count_window(mask_cur, 1, j+1, nx, j+1) ;
00474             /* Check if the line has too many bad pixels */
00475             if (cur_bp_nb > bad_per_line_limit * nx) {
00476                 /* Reset the bad pixels on the current line */
00477                 for (k=0 ; k<nx ; k++) {
00478                     pmask_cur[k+j*nx] = CPL_BINARY_0 ;
00479                 }
00480             }
00481         }
00482 
00483         /* Convert mask to image */
00484         bpm_cur = cpl_image_new_from_mask(mask_cur) ;
00485         crires_spec_flat_config.bpm_nb[i] = cpl_mask_count(mask_cur) ;
00486         cpl_imagelist_set(bpm, bpm_cur, i) ;
00487 
00488         /* Clean the flat using the computed BPM */
00489         if (crires_spec_flat_config.clean_flat_flag) {
00490             cpl_image_reject_from_mask(cpl_imagelist_get(flat, i), mask_cur) ;
00491             cpl_detector_interpolate_rejected(cpl_imagelist_get(flat, i)) ;
00492         }
00493         cpl_mask_delete(mask_cur) ;
00494 
00495         /* Set the flat to 1 outside of the bounds */
00496         if (crires_spec_flat_config.replace_flag) {
00497             cpl_image_threshold(cpl_imagelist_get(flat, i),
00498                     low, high, 1.0, 1.0) ;
00499         }
00500     }
00501     return bpm ;
00502 }
00503 
00504 /*----------------------------------------------------------------------------*/
00514 /*----------------------------------------------------------------------------*/
00515 static int crires_spec_flat_save(
00516         const cpl_imagelist     *   flat,
00517         const cpl_imagelist     *   bpm,
00518         int                         set_nb,
00519         cpl_frameset            *   set,
00520         const cpl_parameterlist *   parlist,
00521         cpl_frameset            *   set_tot)
00522 {
00523     cpl_propertylist    **  qclists ;
00524     const cpl_frame     *   ref_frame ;
00525     char                *   filename ;
00526     cpl_propertylist    *   inputlist ;
00527     const char          *   recipe_name = "crires_spec_flat" ;
00528     int                     i ;
00529 
00530     /* Get the reference frame */
00531     ref_frame = irplib_frameset_get_first_from_group(set, CPL_FRAME_GROUP_RAW) ;
00532 
00533     /* Create the QC lists */
00534     qclists = cpl_malloc(CRIRES_NB_DETECTORS * sizeof(cpl_propertylist*)) ;
00535     for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00536         qclists[i] = cpl_propertylist_new() ;
00537         cpl_propertylist_append_int(qclists[i], "ESO QC NBBAD",
00538                 crires_spec_flat_config.bpm_nb[i]) ;
00539         cpl_propertylist_append_double(qclists[i], "ESO QC FLAT MEAN",
00540                 crires_spec_flat_config.flat_mean[i]) ;
00541         cpl_propertylist_append_double(qclists[i], "ESO QC FLAT STDEV",
00542                 crires_spec_flat_config.flat_stdev[i]) ;
00543         cpl_propertylist_append_double(qclists[i], "ESO QC FLAT FLUX",
00544                 crires_spec_flat_config.flat_flux[i]) ;
00545         cpl_propertylist_append_double(qclists[i], "ESO QC FLAT MASTER RMS",
00546                 crires_spec_flat_config.flat_master_rms[i]) ;
00547 
00548         /* Propagate some keywords from input raw frame extensions */
00549         inputlist = cpl_propertylist_load_regexp(
00550                 cpl_frame_get_filename(ref_frame), i+1,
00551                 CRIRES_HEADER_EXT_FORWARD, 0) ;
00552         cpl_propertylist_copy_property_regexp(qclists[i], inputlist, 
00553                 CRIRES_HEADER_EXT_FORWARD, 0) ;
00554         cpl_propertylist_delete(inputlist) ;
00555     }
00556 
00557     /* Write the flat image */
00558     filename = cpl_sprintf("%s_set%02d.fits", recipe_name, set_nb) ;
00559     crires_image_save(set_tot,
00560             parlist,
00561             set, 
00562             flat, 
00563             recipe_name,
00564             CRIRES_CALPRO_FLAT, 
00565             CRIRES_PROTYPE_FLAT,
00566             crires_spec_flat_config.period,
00567             NULL,
00568             (const cpl_propertylist**)qclists, 
00569             PACKAGE "/" PACKAGE_VERSION,
00570             filename) ;
00571     cpl_free(filename) ;
00572 
00573     /* Write the BPM */
00574     if (bpm != NULL) {
00575         filename = cpl_sprintf("%s_set%02d_bpm.fits", recipe_name, set_nb) ;
00576         crires_image_save(set_tot,
00577                 parlist,
00578                 set, 
00579                 bpm, 
00580                 recipe_name,
00581                 CRIRES_CALPRO_BPM, 
00582                 CRIRES_PROTYPE_BPM,
00583                 crires_spec_flat_config.period,
00584                 NULL,
00585                 (const cpl_propertylist**)qclists, 
00586                 PACKAGE "/" PACKAGE_VERSION,
00587                 filename) ;
00588         cpl_free(filename) ;
00589     }
00590 
00591     /* Free and return */
00592     for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00593         cpl_propertylist_delete(qclists[i]) ;
00594     }
00595     cpl_free(qclists) ;
00596     return  0;
00597 }
00598 
00599 /*----------------------------------------------------------------------------*/
00606 /*----------------------------------------------------------------------------*/
00607 static int crires_spec_flat_compare(
00608         const cpl_frame   *   frame1,
00609         const cpl_frame   *   frame2)
00610 {
00611     int                     comparison ;
00612     cpl_propertylist    *   plist1 ;
00613     cpl_propertylist    *   plist2 ;
00614     double                  dval1, dval2 ;
00615 
00616     /* Test entries */
00617     if (frame1==NULL || frame2==NULL) return -1 ;
00618 
00619     /* Get property lists */
00620     if ((plist1=cpl_propertylist_load(cpl_frame_get_filename(frame1),0))==NULL){
00621         cpl_msg_error(__func__, "getting header from reference frame");
00622         return -1 ;
00623     }
00624     if ((plist2=cpl_propertylist_load(cpl_frame_get_filename(frame2),0))==NULL){
00625         cpl_msg_error(__func__, "getting header from reference frame");
00626         cpl_propertylist_delete(plist1) ;
00627         return -1 ;
00628     }
00629 
00630     /* Test status */
00631     if (cpl_error_get_code()) {
00632         cpl_propertylist_delete(plist1) ;
00633         cpl_propertylist_delete(plist2) ;
00634         return -1 ;
00635     }
00636 
00637     comparison = 1 ;
00638 
00639     /* Compare the DIT used */
00640     dval1 = crires_pfits_get_dit(plist1) ;
00641     dval2 = crires_pfits_get_dit(plist2) ;
00642     if (cpl_error_get_code()) {
00643         cpl_msg_error(__func__, "Cannot get the DIT");
00644         cpl_propertylist_delete(plist1) ;
00645         cpl_propertylist_delete(plist2) ;
00646         return -1 ;
00647     }
00648     if (fabs(dval1-dval2) > 1e-3) comparison = 0 ;
00649 
00650     /* Compare the WLEN REF used */
00651     dval1 = crires_pfits_get_refwlen(plist1) ;
00652     dval2 = crires_pfits_get_refwlen(plist2) ;
00653     if (cpl_error_get_code()) {
00654         cpl_msg_error(__func__, "Cannot get the reference wavelength");
00655         cpl_propertylist_delete(plist1) ;
00656         cpl_propertylist_delete(plist2) ;
00657         return -1 ;
00658     }
00659     if (fabs(dval1-dval2) > 1e-3) comparison = 0 ;
00660 
00661     /* Compare the SHUT1 POS used */
00662     dval1 = crires_pfits_get_bafflepos(plist1) ;
00663     dval2 = crires_pfits_get_bafflepos(plist2) ;
00664     if (cpl_error_get_code()) {
00665         cpl_msg_error(__func__, "Cannot get the baffle position");
00666         cpl_propertylist_delete(plist1) ;
00667         cpl_propertylist_delete(plist2) ;
00668         return -1 ;
00669     }
00670     if (fabs(dval1-dval2) > 1e-3) comparison = 0 ;
00671 
00672     cpl_propertylist_delete(plist1) ;
00673     cpl_propertylist_delete(plist2) ;
00674     return comparison ;
00675 }
00676 

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