isaac_img_dark.c

00001 /* $Id: isaac_img_dark.c,v 1.34 2010/03/02 13:26:12 llundin Exp $
00002  *
00003  * This file is part of the ISAAC 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: llundin $
00023  * $Date: 2010/03/02 13:26:12 $
00024  * $Revision: 1.34 $
00025  * $Name: HEAD $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #include <cpl.h>
00037 #include <math.h>
00038 
00039 #include "irplib_utils.h"
00040 
00041 #include "isaac_utils.h"
00042 #include "isaac_pfits.h"
00043 #include "isaac_dfs.h"
00044 
00045 /*-----------------------------------------------------------------------------
00046                                 Define
00047  -----------------------------------------------------------------------------*/
00048 
00049 #define ISAAC_DARK_HSIZE_SW_DEF     6
00050 #define ISAAC_DARK_HSIZE_LW_DEF     2
00051 
00052 /*-----------------------------------------------------------------------------
00053                             Functions prototypes
00054  -----------------------------------------------------------------------------*/
00055 
00056 static int isaac_img_dark_create(cpl_plugin *);
00057 static int isaac_img_dark_exec(cpl_plugin *);
00058 static int isaac_img_dark_destroy(cpl_plugin *);
00059 static int isaac_img_dark(cpl_parameterlist *, cpl_frameset *);
00060 
00061 static int isaac_img_dark_avg_reduce(cpl_frameset *, cpl_image **);
00062 static cpl_matrix * isaac_img_dark_ron_reduce(cpl_frameset *);
00063 static int isaac_img_dark_compare(const cpl_frame *, const cpl_frame *); 
00064 static int isaac_img_dark_save(cpl_image *, cpl_matrix *, int, cpl_frameset *, 
00065         cpl_parameterlist *, cpl_frameset *);
00066 
00067 /*-----------------------------------------------------------------------------
00068                             Static variables
00069  -----------------------------------------------------------------------------*/
00070 
00071 static struct {
00072     /* Inputs */
00073     int         hsize;
00074     int         nsamples;
00075     /* Outputs */
00076     double      dark_med;
00077     double      dark_stdev;
00078 } isaac_img_dark_config;
00079 
00080 static char isaac_img_dark_description[] = 
00081 "isaac_img_dark -- ISAAC imaging dark recipe.\n"
00082 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
00083 "raw-file.fits "ISAAC_IMG_DARK_RAW"\n";
00084 
00085 /*-----------------------------------------------------------------------------
00086                                 Functions code
00087  -----------------------------------------------------------------------------*/
00088 
00089 /*----------------------------------------------------------------------------*/
00097 /*----------------------------------------------------------------------------*/
00098 int cpl_plugin_get_info(cpl_pluginlist * list)
00099 {
00100     cpl_recipe  *   recipe = cpl_calloc(1, sizeof(*recipe));
00101     cpl_plugin  *   plugin = &recipe->interface;
00102 
00103     cpl_plugin_init(plugin,
00104                     CPL_PLUGIN_API,
00105                     ISAAC_BINARY_VERSION,
00106                     CPL_PLUGIN_TYPE_RECIPE,
00107                     "isaac_img_dark",
00108                     "Dark recipe",
00109                     isaac_img_dark_description,
00110                     "Lars Lundin",
00111                     PACKAGE_BUGREPORT,
00112                     isaac_get_license(),
00113                     isaac_img_dark_create,
00114                     isaac_img_dark_exec,
00115                     isaac_img_dark_destroy);
00116 
00117     cpl_pluginlist_append(list, plugin);
00118     
00119     return 0;
00120 }
00121 
00122 /*----------------------------------------------------------------------------*/
00131 /*----------------------------------------------------------------------------*/
00132 static int isaac_img_dark_create(cpl_plugin * plugin)
00133 {
00134     cpl_recipe      * recipe;
00135     cpl_parameter   * p;
00136 
00137     /* Get the recipe out of the plugin */
00138     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00139         recipe = (cpl_recipe *)plugin;
00140     else return -1;
00141 
00142     /* Create the parameters list in the cpl_recipe object */
00143     recipe->parameters = cpl_parameterlist_new();
00144 
00145     /* Fill the parameters list */
00146     /* --nsamples */
00147     p = cpl_parameter_new_value("isaac.isaac_img_dark.nsamples",
00148             CPL_TYPE_INT, "number of samples for RON computation", 
00149             "isaac.isaac_img_dark", 100);
00150     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "nsamples");
00151     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00152     cpl_parameterlist_append(recipe->parameters, p);
00153     /* --hsize */
00154     p = cpl_parameter_new_value("isaac.isaac_img_dark.hsize",
00155             CPL_TYPE_INT, "half size of the window for RON computation", 
00156             "isaac.isaac_img_dark", -1);
00157     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "hsize");
00158     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00159     cpl_parameterlist_append(recipe->parameters, p);
00160 
00161     /* Return */
00162     return 0;
00163 }
00164 
00165 /*----------------------------------------------------------------------------*/
00171 /*----------------------------------------------------------------------------*/
00172 static int isaac_img_dark_exec(cpl_plugin * plugin)
00173 {
00174     cpl_recipe  *   recipe;
00175 
00176     /* Get the recipe out of the plugin */
00177     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00178         recipe = (cpl_recipe *)plugin;
00179     else return -1;
00180 
00181     return isaac_img_dark(recipe->parameters, recipe->frames);
00182 }
00183 
00184 /*----------------------------------------------------------------------------*/
00190 /*----------------------------------------------------------------------------*/
00191 static int isaac_img_dark_destroy(cpl_plugin * plugin)
00192 {
00193     cpl_recipe  *   recipe;
00194 
00195     /* Get the recipe out of the plugin */
00196     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00197         recipe = (cpl_recipe *)plugin;
00198     else return -1;
00199 
00200     cpl_parameterlist_delete(recipe->parameters);
00201     return 0;
00202 }
00203 
00204 /*----------------------------------------------------------------------------*/
00211 /*----------------------------------------------------------------------------*/
00212 static int isaac_img_dark(
00213         cpl_parameterlist   *   parlist, 
00214         cpl_frameset        *   framelist)
00215 {
00216     cpl_parameter   *   par;
00217     int                 nsets;
00218     int             *   selection;
00219     cpl_frameset    *   f_one;
00220     cpl_image       *   avg;
00221     cpl_matrix      *   rons;
00222     cpl_boolean         did_reduce = CPL_FALSE;
00223     int                 i;
00224 
00225     /* Retrieve input parameters */
00226     par = cpl_parameterlist_find(parlist, "isaac.isaac_img_dark.hsize"); 
00227     isaac_img_dark_config.hsize = cpl_parameter_get_int(par);
00228     par = cpl_parameterlist_find(parlist, "isaac.isaac_img_dark.nsamples"); 
00229     isaac_img_dark_config.nsamples = cpl_parameter_get_int(par);
00230 
00231     /* Identify the RAW and CALIB frames in the input frameset */
00232     if (isaac_dfs_set_groups(framelist)) {
00233         cpl_msg_error(cpl_func, "Cannot identify RAW and CALIB frames");
00234         return -1;
00235     }
00236 
00237     /* Labelize all input frames */
00238     cpl_msg_info(cpl_func, "Identify the different settings");
00239     selection=cpl_frameset_labelise(framelist, isaac_img_dark_compare, &nsets);
00240     if (selection == NULL) {
00241         cpl_msg_error(cpl_func, "Cannot labelise input frames");
00242         return -1; 
00243     }
00244    
00245     /* Extract settings and reduce each of them */
00246     for (i=0; i<nsets; i++) {
00247         /* Initialise */
00248         isaac_img_dark_config.dark_med = -1.0;
00249         isaac_img_dark_config.dark_stdev = -1.0;
00250         avg = NULL;
00251         
00252         /* Reduce data set nb i */
00253         cpl_msg_info(cpl_func, "Reduce data set no %d out of %d", i+1, nsets);
00254         cpl_msg_indent_more();
00255         f_one = cpl_frameset_extract(framelist, selection, i);
00256         
00257         /* At least 2 frames required */
00258         if (cpl_frameset_get_size(f_one) < 2) {
00259             cpl_msg_warning(cpl_func, "Setting %d skipped (not enough frames)",
00260                     i+1);
00261         } else {
00262             /* AVG part */
00263             cpl_msg_info(cpl_func, "Compute the master dark");
00264             cpl_msg_indent_more();
00265             if (isaac_img_dark_avg_reduce(f_one, &avg)) {
00266                 cpl_msg_warning(cpl_func, "Cannot reduce set number %d", i+1);
00267             }
00268             cpl_msg_indent_less();
00269             /* RON part */
00270             cpl_msg_info(cpl_func, "Compute the read-out noise");
00271             cpl_msg_indent_more();
00272             if ((rons = isaac_img_dark_ron_reduce(f_one)) == NULL) {
00273                 cpl_msg_warning(cpl_func, "Cannot reduce set number %d", i+1);
00274             }
00275             cpl_msg_indent_less();
00276             /* Save the products */
00277             if (isaac_img_dark_save(avg, rons, i+1, f_one, parlist, 
00278                         framelist) !=0 ){
00279                 cpl_msg_error(cpl_func, "Cannot save the products");
00280                 if (avg) cpl_image_delete(avg);
00281                 if (rons) cpl_matrix_delete(rons);
00282                 return -1;
00283             }
00284             if (rons) cpl_matrix_delete(rons);
00285             if (!cpl_error_get_code()) did_reduce = CPL_TRUE;
00286         }
00287         if (avg) cpl_image_delete(avg);
00288         cpl_frameset_delete(f_one);
00289         cpl_msg_indent_less();
00290     }
00291     
00292     /* Free and return */
00293     cpl_free(selection); 
00294 
00295     cpl_ensure_code(did_reduce, CPL_ERROR_ILLEGAL_INPUT);
00296 
00297     return cpl_error_set_where(cpl_func); /* Propagate error, if any */
00298 }
00299 
00300 /*----------------------------------------------------------------------------*/
00307 /*----------------------------------------------------------------------------*/
00308 static int isaac_img_dark_avg_reduce(
00309         cpl_frameset    *   framelist,
00310         cpl_image       **  avg)
00311 {
00312     cpl_imagelist   *   iset;
00313     cpl_vector      *   medians;
00314     cpl_image       *   image;
00315     int                 i;
00316                     
00317     /* Test entries */
00318     if (framelist == NULL) return -1;
00319     
00320     /* Load the image set */
00321     if ((iset = cpl_imagelist_load_frameset(framelist, CPL_TYPE_FLOAT, 1, 
00322                     0)) == NULL) {
00323         cpl_msg_error(cpl_func, "Cannot load the data");
00324         return -1;
00325     }
00326 
00327     /* Average it to the master dark */
00328     if ((*avg = cpl_imagelist_collapse_create(iset)) == NULL) {
00329         cpl_msg_error(cpl_func, "Cannot average the data set");
00330         cpl_imagelist_delete(iset);
00331         return -1;
00332     }
00333 
00334     /* Compute mean-rms of the median values */
00335     medians = cpl_vector_new(cpl_imagelist_get_size(iset));
00336     for (i=0; i<cpl_imagelist_get_size(iset); i++) {
00337         image = cpl_imagelist_get(iset, i);
00338         cpl_vector_set(medians, i, cpl_image_get_median(image));
00339     }
00340     cpl_imagelist_delete(iset);
00341     isaac_img_dark_config.dark_med = cpl_vector_get_mean(medians);
00342     isaac_img_dark_config.dark_stdev = cpl_vector_get_stdev(medians);
00343 
00344     /* Free and Return */
00345     cpl_vector_delete(medians);
00346     return 0;
00347 }
00348 
00349 /*----------------------------------------------------------------------------*/
00360 /*----------------------------------------------------------------------------*/
00361 static cpl_matrix * isaac_img_dark_ron_reduce(cpl_frameset * framelist)
00362 {
00363     cpl_frame           *   cur_frame;
00364     cpl_propertylist    *   plist;
00365     char                    arm;
00366     const char          *   sval;
00367     cpl_imagelist       *   iset;
00368     cpl_matrix          *   rons;
00369     cpl_image           *   tmp_im;
00370     double                  rms;
00371     double                  norm;
00372     int                     ndit;
00373     int                     zone_def[4];
00374     int                     i;
00375 
00376     /* Test entries */
00377     if (framelist == NULL) return NULL;
00378 
00379     /* Initialise */
00380     rons = NULL;
00381     
00382     /* Check the arm used */
00383     if (cpl_error_get_code()) return NULL;
00384     cur_frame = cpl_frameset_get_frame(framelist, 0);
00385     plist = cpl_propertylist_load(cpl_frame_get_filename(cur_frame), 0);
00386     sval = isaac_pfits_get_arm(plist);
00387     if (cpl_error_get_code()) {
00388         cpl_msg_error(cpl_func, "Cannot get the used arm");
00389         cpl_propertylist_delete(plist);
00390         return NULL;
00391     }
00392     arm = (int)(sval[0]);
00393     cpl_propertylist_delete(plist);
00394 
00395     /* Load the current set */
00396     if ((iset = cpl_imagelist_load_frameset(framelist, CPL_TYPE_FLOAT, 1, 
00397                     0)) == NULL) {
00398         cpl_msg_error(cpl_func, "Cannot load the data");
00399         return NULL;
00400     }
00401    
00402     /* Switch on the arm */
00403     switch (arm) {
00404         case 'S':
00405             /* Create the matrix */
00406             rons = cpl_matrix_new(cpl_imagelist_get_size(iset)-1, 4);
00407             if (isaac_img_dark_config.hsize < 0) 
00408                 isaac_img_dark_config.hsize = ISAAC_DARK_HSIZE_SW_DEF;
00409 
00410             /* Loop on all pairs */
00411             for (i=0; i<cpl_imagelist_get_size(iset)-1; i++) {
00412                 cpl_msg_info(cpl_func, "Pair number %d", i+1);
00413                 /* Get the norm factor */
00414                 if (cpl_error_get_code()) {
00415                     cpl_matrix_delete(rons);
00416                     cpl_imagelist_delete(iset);
00417                     return NULL;
00418                 }
00419                 cur_frame = cpl_frameset_get_frame(framelist, i);
00420                 plist = cpl_propertylist_load(cpl_frame_get_filename(cur_frame),
00421                         0);
00422                 ndit = isaac_pfits_get_ndit(plist);
00423                 cpl_propertylist_delete(plist);
00424                 if (cpl_error_get_code()) {
00425                     cpl_msg_error(cpl_func, "Cannot get the NDIT");
00426                     cpl_matrix_delete(rons);
00427                     cpl_imagelist_delete(iset);
00428                     return NULL;
00429                 }
00430                 norm = 0.5 * ndit;
00431                 norm = sqrt(norm);
00432                 
00433                 /* Compute the current subtracted image */
00434                 if ((tmp_im = cpl_image_subtract_create(
00435                                 cpl_imagelist_get(iset, i),
00436                                 cpl_imagelist_get(iset, i+1))) == NULL) {
00437                     cpl_msg_error(cpl_func, "Cannot subtract the images");
00438                     cpl_imagelist_delete(iset);
00439                     cpl_matrix_delete(rons);
00440                     return NULL;
00441                 }
00442 
00443                 /* Get measurement for lower-left quadrant */
00444                 zone_def[0] = 1;
00445                 zone_def[1] = (int)(cpl_image_get_size_x(tmp_im)/2);
00446                 zone_def[2] = 1;
00447                 zone_def[3] = (int)(cpl_image_get_size_y(tmp_im)/2);
00448                 cpl_flux_get_noise_window(tmp_im, zone_def, 
00449                         isaac_img_dark_config.hsize, 
00450                         isaac_img_dark_config.nsamples, &rms, NULL);
00451                 cpl_matrix_set(rons, i, 0, rms * norm);
00452                 cpl_msg_info(cpl_func, "RON in LL quadrant: %g", rms * norm);
00453  
00454                 /* Get measurement for lower-right quadrant */
00455                 zone_def[0] = (int)(cpl_image_get_size_x(tmp_im)/2) + 1;
00456                 zone_def[1] = cpl_image_get_size_x(tmp_im);
00457                 zone_def[2] = 1;
00458                 zone_def[3] = (int)(cpl_image_get_size_y(tmp_im)/2);
00459                 cpl_flux_get_noise_window(tmp_im, zone_def, 
00460                         isaac_img_dark_config.hsize, 
00461                         isaac_img_dark_config.nsamples, &rms, NULL);
00462                 cpl_matrix_set(rons, i, 1, rms * norm);
00463                 cpl_msg_info(cpl_func, "RON in LR quadrant: %g", rms * norm);
00464                 
00465                 /* Get measurement for upper-left quadrant */
00466                 zone_def[0] = 1;
00467                 zone_def[1] = (int)(cpl_image_get_size_x(tmp_im)/2);
00468                 zone_def[2] = (int)(cpl_image_get_size_y(tmp_im)/2) + 1;
00469                 zone_def[3] = cpl_image_get_size_y(tmp_im);
00470                 cpl_flux_get_noise_window(tmp_im, zone_def, 
00471                         isaac_img_dark_config.hsize, 
00472                         isaac_img_dark_config.nsamples, &rms, NULL);
00473                 cpl_matrix_set(rons, i, 2, rms * norm);
00474                 cpl_msg_info(cpl_func, "RON in UL quadrant: %g", rms * norm);
00475                 
00476                 /* Get measurement for upper-right quadrant */
00477                 zone_def[0] = (int)(cpl_image_get_size_x(tmp_im)/2) + 1;
00478                 zone_def[1] = cpl_image_get_size_x(tmp_im);
00479                 zone_def[2] = (int)(cpl_image_get_size_y(tmp_im)/2) + 1;
00480                 zone_def[3] = cpl_image_get_size_y(tmp_im);
00481                 cpl_flux_get_noise_window(tmp_im, zone_def, 
00482                         isaac_img_dark_config.hsize, 
00483                         isaac_img_dark_config.nsamples, &rms, NULL);
00484                 cpl_matrix_set(rons, i, 3, rms * norm);
00485                 cpl_msg_info(cpl_func, "RON in UR quadrant: %g", rms * norm);
00486                 cpl_image_delete(tmp_im);
00487             }
00488             break;
00489         case 'L':
00490             /* Create the matrix */
00491             rons = cpl_matrix_new(cpl_imagelist_get_size(iset)-1, 1);
00492             if (isaac_img_dark_config.hsize < 0) 
00493                 isaac_img_dark_config.hsize = ISAAC_DARK_HSIZE_LW_DEF;
00494 
00495             /* Loop on all pairs */
00496             for (i=0; i<cpl_imagelist_get_size(iset)-1; i++) {
00497                 cpl_msg_info(cpl_func, "Pair number %d", i+1);
00498                 /* Get the norm factor */
00499                 if (cpl_error_get_code()) {
00500                     cpl_matrix_delete(rons);
00501                     cpl_imagelist_delete(iset);
00502                     return NULL;
00503                 }
00504                 cur_frame = cpl_frameset_get_frame(framelist, i);
00505                 plist = cpl_propertylist_load(cpl_frame_get_filename(cur_frame),
00506                         0);
00507                 ndit = isaac_pfits_get_ndit(plist);
00508                 cpl_propertylist_delete(plist);
00509                 if (cpl_error_get_code()) {
00510                     cpl_msg_error(cpl_func, "Cannot get the NDIT");
00511                     cpl_matrix_delete(rons);
00512                     cpl_imagelist_delete(iset);
00513                     return NULL;
00514                 }
00515                 norm = 0.5 * ndit;
00516                 norm = sqrt(norm);
00517                 
00518                 /* Compute the current subtracted image */
00519                 if ((tmp_im = cpl_image_subtract_create(
00520                                 cpl_imagelist_get(iset, i),
00521                                 cpl_imagelist_get(iset, i+1))) == NULL) {
00522                     cpl_msg_error(cpl_func, "Cannot subtract the images");
00523                     cpl_imagelist_delete(iset);
00524                     cpl_matrix_delete(rons);
00525                     return NULL;
00526                 }
00527 
00528                 /* Get measurement */
00529                 cpl_flux_get_noise_window(tmp_im, NULL, 
00530                         isaac_img_dark_config.hsize, 
00531                         isaac_img_dark_config.nsamples, &rms, NULL);
00532                 cpl_matrix_set(rons, i, 0, rms * norm);
00533                 cpl_msg_info(cpl_func, "RON: %g", rms * norm);
00534                 cpl_image_delete(tmp_im);
00535             }
00536             break;
00537         default:
00538             cpl_msg_error(cpl_func, "Unsupported arm");
00539             cpl_imagelist_delete(iset);
00540             cpl_matrix_delete(rons);
00541             return NULL;
00542             break;
00543     }
00544     
00545     /* Free and return */
00546     cpl_imagelist_delete(iset);
00547     return rons;
00548 }
00549 
00550 /*----------------------------------------------------------------------------*/
00561 /*----------------------------------------------------------------------------*/
00562 static int isaac_img_dark_save(
00563         cpl_image           *   avg,
00564         cpl_matrix          *   rons,
00565         int                     set_nb,
00566         cpl_frameset        *   set,
00567         cpl_parameterlist   *   parlist,
00568         cpl_frameset        *   set_tot)
00569 {
00570     cpl_propertylist    *   plist;
00571     cpl_propertylist    *   qclist;
00572     cpl_propertylist    *   paflist;
00573     const cpl_frame           *   ref_frame;
00574     char                *   filename;
00575     char                    qc_str[128];
00576     int                     i;
00577 
00578     /* Get the QC params in qclist */
00579     qclist = cpl_propertylist_new();
00580     cpl_propertylist_append_double(qclist, "ESO QC DARKMED",
00581             isaac_img_dark_config.dark_med);
00582     cpl_propertylist_append_double(qclist, "ESO QC DARKSTDEV",
00583             isaac_img_dark_config.dark_stdev);
00584     if (rons != NULL) {
00585         switch (cpl_matrix_get_ncol(rons)) {
00586             case 1:
00587                 for (i=0; i<cpl_matrix_get_nrow(rons); i++) {
00588                     sprintf(qc_str, "ESO QC RON%d", i+1);
00589                     cpl_propertylist_append_double(qclist, qc_str, 
00590                             cpl_matrix_get(rons, i, 0));
00591                 }
00592                 break;
00593             case 4:
00594                 for (i=0; i<cpl_matrix_get_nrow(rons); i++) {
00595                     sprintf(qc_str, "ESO QC LL RON%d", i+1);
00596                     cpl_propertylist_append_double(qclist, qc_str, 
00597                             cpl_matrix_get(rons, i, 0));
00598                     sprintf(qc_str, "ESO QC LR RON%d", i+1);
00599                     cpl_propertylist_append_double(qclist, qc_str, 
00600                             cpl_matrix_get(rons, i, 1));
00601                     sprintf(qc_str, "ESO QC UL RON%d", i+1);
00602                     cpl_propertylist_append_double(qclist, qc_str, 
00603                             cpl_matrix_get(rons, i, 2));
00604                     sprintf(qc_str, "ESO QC UR RON%d", i+1);
00605                     cpl_propertylist_append_double(qclist, qc_str, 
00606                             cpl_matrix_get(rons, i, 3));
00607                 }
00608                 break;
00609             default:
00610                 cpl_msg_error(cpl_func, "Invalid RONs matrix format");
00611                 break;
00612         }
00613     }
00614     
00615     /* Write the average image */
00616     filename = cpl_sprintf("isaac_img_dark_set%02d_avg.fits", set_nb);
00617     irplib_dfs_save_image(set_tot,
00618             parlist,
00619             set,
00620             avg,
00621             CPL_BPP_IEEE_FLOAT,
00622             "isaac_img_dark",
00623             ISAAC_IMG_DARK_AVG,
00624             qclist,
00625             NULL,
00626             PACKAGE "/" PACKAGE_VERSION,
00627             filename);
00628     cpl_free(filename);
00629 
00630     /* Get the reference frame */
00631     ref_frame = irplib_frameset_get_first_from_group(set, CPL_FRAME_GROUP_RAW);
00632     
00633     /* Get FITS header from reference file */
00634     if ((plist=cpl_propertylist_load(cpl_frame_get_filename(ref_frame),
00635                     0)) == NULL) {
00636         cpl_msg_error(cpl_func, "getting header from reference frame");
00637         cpl_propertylist_delete(qclist);
00638         return -1;
00639     }
00640  
00641     /* Get the keywords for the paf file */
00642     paflist = cpl_propertylist_new();
00643     cpl_propertylist_copy_property_regexp(paflist, plist,
00644         "^(ARCFILE|MJD-OBS|ESO TPL ID|ESO DPR TECH|DATE-OBS|ESO DET DIT|"
00645         "ESO DET NDIT|ESO DET NCORRS|ESO DET NDSAMPLES|ESO DET MODE NAME)$", 0);
00646     cpl_propertylist_delete(plist);
00647    
00648     /* Copy the QC in paflist */
00649     cpl_propertylist_copy_property_regexp(paflist, qclist, "", 0);
00650     cpl_propertylist_delete(qclist);
00651 
00652     /* PRO.CATG */
00653     cpl_propertylist_update_string(paflist, CPL_DFS_PRO_CATG,
00654                                    ISAAC_IMG_DARK_AVG);
00655 
00656     /* Save the PAF file */
00657     filename = cpl_sprintf("isaac_img_dark_set%02d.paf", set_nb);
00658     cpl_dfs_save_paf("ISAAC",
00659             "isaac_img_dark",
00660             paflist,
00661             filename);
00662     cpl_free(filename);
00663     cpl_propertylist_delete(paflist);
00664     return  0;
00665 }
00666 
00667 /*----------------------------------------------------------------------------*/
00674 /*----------------------------------------------------------------------------*/
00675 static int isaac_img_dark_compare(
00676         const cpl_frame *   frame1, 
00677         const cpl_frame *   frame2) 
00678 {
00679     int                     comparison;
00680     cpl_propertylist    *   plist1;
00681     cpl_propertylist    *   plist2;
00682     double                  dval1, dval2;
00683     int                     ival1, ival2;
00684 
00685     /* Test entries */
00686     if (frame1==NULL || frame2==NULL) return -1;
00687 
00688     /* Get property lists */
00689     if ((plist1=cpl_propertylist_load(cpl_frame_get_filename(frame1),
00690                     0)) == NULL) {
00691         cpl_msg_error(cpl_func, "getting header from reference frame");
00692         return -1;
00693     }
00694     if ((plist2=cpl_propertylist_load(cpl_frame_get_filename(frame2),
00695                     0)) == NULL) {
00696         cpl_msg_error(cpl_func, "getting header from reference frame");
00697         cpl_propertylist_delete(plist1);
00698         return -1;
00699     }
00700     
00701     /* Test status */
00702     if (cpl_error_get_code()) {
00703         cpl_propertylist_delete(plist1);
00704         cpl_propertylist_delete(plist2);
00705         return -1;
00706     }
00707      
00708     /* Compare exposure time */
00709     comparison = 1;
00710     dval1 = isaac_pfits_get_dit(plist1);
00711     dval2 = isaac_pfits_get_dit(plist2);
00712     if (cpl_error_get_code()) {
00713         cpl_msg_error(cpl_func, "cannot get exposure time");
00714         cpl_propertylist_delete(plist1);
00715         cpl_propertylist_delete(plist2);
00716         return -1;
00717     }
00718     if (fabs(dval1-dval2) > 1e-5) comparison = 0;
00719 
00720     /* Compare NDIT */
00721     ival1 = isaac_pfits_get_ndit(plist1);
00722     ival2 = isaac_pfits_get_ndit(plist2);
00723     if (cpl_error_get_code()) {
00724         cpl_msg_error(cpl_func, "cannot get NDIT");
00725         cpl_propertylist_delete(plist1);
00726         cpl_propertylist_delete(plist2);
00727         return -1;
00728     }
00729     if (ival1 != ival2) comparison = 0;
00730 
00731     /* Compare the readout mode */
00732     ival1 = isaac_pfits_get_rom(plist1);
00733     ival2 = isaac_pfits_get_rom(plist2);
00734     if (cpl_error_get_code()) {
00735         cpl_msg_error(cpl_func, "cannot get read-out mode");
00736         cpl_propertylist_delete(plist1);
00737         cpl_propertylist_delete(plist2);
00738         return -1;
00739     }
00740     if (ival1 != ival2) comparison = 0;
00741 
00742     /* Free and return */
00743     cpl_propertylist_delete(plist1);
00744     cpl_propertylist_delete(plist2);
00745     return comparison;
00746 }
00747 

Generated on Wed Mar 9 15:43:10 2011 for ISAAC Pipeline Reference Manual by  doxygen 1.5.8