isaac_img_dark.c

00001 /* $Id: isaac_img_dark.c,v 1.37 2012/09/07 09:17:31 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: 2012/09/07 09:17:31 $
00024  * $Revision: 1.37 $
00025  * $Name: isaac-6_1_3 $
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     cpl_size            nsets;
00218     cpl_size        *   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,
00254                      (int)nsets);
00255         cpl_msg_indent_more();
00256         f_one = cpl_frameset_extract(framelist, selection, i);
00257         
00258         /* At least 2 frames required */
00259         if (cpl_frameset_get_size(f_one) < 2) {
00260             cpl_msg_warning(cpl_func, "Setting %d skipped (not enough frames)",
00261                     i+1);
00262         } else {
00263             /* AVG part */
00264             cpl_msg_info(cpl_func, "Compute the master dark");
00265             cpl_msg_indent_more();
00266             if (isaac_img_dark_avg_reduce(f_one, &avg)) {
00267                 cpl_msg_warning(cpl_func, "Cannot reduce set number %d", i+1);
00268             }
00269             cpl_msg_indent_less();
00270             /* RON part */
00271             cpl_msg_info(cpl_func, "Compute the read-out noise");
00272             cpl_msg_indent_more();
00273             if ((rons = isaac_img_dark_ron_reduce(f_one)) == NULL) {
00274                 cpl_msg_warning(cpl_func, "Cannot reduce set number %d", i+1);
00275             }
00276             cpl_msg_indent_less();
00277             /* Save the products */
00278             if (isaac_img_dark_save(avg, rons, i+1, f_one, parlist, 
00279                         framelist) !=0 ){
00280                 cpl_msg_error(cpl_func, "Cannot save the products");
00281                 if (avg) cpl_image_delete(avg);
00282                 if (rons) cpl_matrix_delete(rons);
00283                 return -1;
00284             }
00285             if (rons) cpl_matrix_delete(rons);
00286             if (!cpl_error_get_code()) did_reduce = CPL_TRUE;
00287         }
00288         if (avg) cpl_image_delete(avg);
00289         cpl_frameset_delete(f_one);
00290         cpl_msg_indent_less();
00291     }
00292     
00293     /* Free and return */
00294     cpl_free(selection); 
00295 
00296     cpl_ensure_code(did_reduce, CPL_ERROR_ILLEGAL_INPUT);
00297 
00298     return cpl_error_set_where(cpl_func); /* Propagate error, if any */
00299 }
00300 
00301 /*----------------------------------------------------------------------------*/
00308 /*----------------------------------------------------------------------------*/
00309 static int isaac_img_dark_avg_reduce(
00310         cpl_frameset    *   framelist,
00311         cpl_image       **  avg)
00312 {
00313     cpl_imagelist   *   iset;
00314     cpl_vector      *   medians;
00315     cpl_image       *   image;
00316     int                 i;
00317                     
00318     /* Test entries */
00319     if (framelist == NULL) return -1;
00320     
00321     /* Load the image set */
00322     if ((iset = cpl_imagelist_load_frameset(framelist, CPL_TYPE_FLOAT, 1, 
00323                     0)) == NULL) {
00324         cpl_msg_error(cpl_func, "Cannot load the data");
00325         return -1;
00326     }
00327 
00328     /* Average it to the master dark */
00329     if ((*avg = cpl_imagelist_collapse_create(iset)) == NULL) {
00330         cpl_msg_error(cpl_func, "Cannot average the data set");
00331         cpl_imagelist_delete(iset);
00332         return -1;
00333     }
00334 
00335     /* Compute mean-rms of the median values */
00336     medians = cpl_vector_new(cpl_imagelist_get_size(iset));
00337     for (i=0; i<cpl_imagelist_get_size(iset); i++) {
00338         image = cpl_imagelist_get(iset, i);
00339         cpl_vector_set(medians, i, cpl_image_get_median(image));
00340     }
00341     cpl_imagelist_delete(iset);
00342     isaac_img_dark_config.dark_med = cpl_vector_get_mean(medians);
00343     isaac_img_dark_config.dark_stdev = cpl_vector_get_stdev(medians);
00344 
00345     /* Free and Return */
00346     cpl_vector_delete(medians);
00347     return 0;
00348 }
00349 
00350 /*----------------------------------------------------------------------------*/
00361 /*----------------------------------------------------------------------------*/
00362 static cpl_matrix * isaac_img_dark_ron_reduce(cpl_frameset * framelist)
00363 {
00364     cpl_frame           *   cur_frame;
00365     cpl_propertylist    *   plist;
00366     char                    arm;
00367     const char          *   sval;
00368     cpl_imagelist       *   iset;
00369     cpl_matrix          *   rons;
00370     cpl_image           *   tmp_im;
00371     double                  rms;
00372     double                  norm;
00373     int                     ndit;
00374     cpl_size                zone_def[4];
00375     int                     i;
00376 
00377     /* Test entries */
00378     if (framelist == NULL) return NULL;
00379 
00380     /* Initialise */
00381     rons = NULL;
00382     
00383     /* Check the arm used */
00384     if (cpl_error_get_code()) return NULL;
00385     cur_frame = cpl_frameset_get_frame(framelist, 0);
00386     plist = cpl_propertylist_load(cpl_frame_get_filename(cur_frame), 0);
00387     sval = isaac_pfits_get_arm(plist);
00388     if (cpl_error_get_code()) {
00389         cpl_msg_error(cpl_func, "Cannot get the used arm");
00390         cpl_propertylist_delete(plist);
00391         return NULL;
00392     }
00393     arm = (int)(sval[0]);
00394     cpl_propertylist_delete(plist);
00395 
00396     /* Load the current set */
00397     if ((iset = cpl_imagelist_load_frameset(framelist, CPL_TYPE_FLOAT, 1, 
00398                     0)) == NULL) {
00399         cpl_msg_error(cpl_func, "Cannot load the data");
00400         return NULL;
00401     }
00402    
00403     /* Switch on the arm */
00404     switch (arm) {
00405         case 'S':
00406             /* Create the matrix */
00407             rons = cpl_matrix_new(cpl_imagelist_get_size(iset)-1, 4);
00408             if (isaac_img_dark_config.hsize < 0) 
00409                 isaac_img_dark_config.hsize = ISAAC_DARK_HSIZE_SW_DEF;
00410 
00411             /* Loop on all pairs */
00412             for (i=0; i<cpl_imagelist_get_size(iset)-1; i++) {
00413                 cpl_msg_info(cpl_func, "Pair number %d", i+1);
00414                 /* Get the norm factor */
00415                 if (cpl_error_get_code()) {
00416                     cpl_matrix_delete(rons);
00417                     cpl_imagelist_delete(iset);
00418                     return NULL;
00419                 }
00420                 cur_frame = cpl_frameset_get_frame(framelist, i);
00421                 plist = cpl_propertylist_load(cpl_frame_get_filename(cur_frame),
00422                         0);
00423                 ndit = isaac_pfits_get_ndit(plist);
00424                 cpl_propertylist_delete(plist);
00425                 if (cpl_error_get_code()) {
00426                     cpl_msg_error(cpl_func, "Cannot get the NDIT");
00427                     cpl_matrix_delete(rons);
00428                     cpl_imagelist_delete(iset);
00429                     return NULL;
00430                 }
00431                 norm = 0.5 * ndit;
00432                 norm = sqrt(norm);
00433                 
00434                 /* Compute the current subtracted image */
00435                 if ((tmp_im = cpl_image_subtract_create(
00436                                 cpl_imagelist_get(iset, i),
00437                                 cpl_imagelist_get(iset, i+1))) == NULL) {
00438                     cpl_msg_error(cpl_func, "Cannot subtract the images");
00439                     cpl_imagelist_delete(iset);
00440                     cpl_matrix_delete(rons);
00441                     return NULL;
00442                 }
00443 
00444                 /* Get measurement for lower-left quadrant */
00445                 zone_def[0] = 1;
00446                 zone_def[1] = cpl_image_get_size_x(tmp_im)/2;
00447                 zone_def[2] = 1;
00448                 zone_def[3] = cpl_image_get_size_y(tmp_im)/2;
00449                 cpl_flux_get_noise_window(tmp_im, zone_def, 
00450                         isaac_img_dark_config.hsize, 
00451                         isaac_img_dark_config.nsamples, &rms, NULL);
00452                 cpl_matrix_set(rons, i, 0, rms * norm);
00453                 cpl_msg_info(cpl_func, "RON in LL quadrant: %g", rms * norm);
00454  
00455                 /* Get measurement for lower-right quadrant */
00456                 zone_def[0] = cpl_image_get_size_x(tmp_im)/2 + 1;
00457                 zone_def[1] = cpl_image_get_size_x(tmp_im);
00458                 zone_def[2] = 1;
00459                 zone_def[3] = cpl_image_get_size_y(tmp_im)/2;
00460                 cpl_flux_get_noise_window(tmp_im, zone_def, 
00461                         isaac_img_dark_config.hsize, 
00462                         isaac_img_dark_config.nsamples, &rms, NULL);
00463                 cpl_matrix_set(rons, i, 1, rms * norm);
00464                 cpl_msg_info(cpl_func, "RON in LR quadrant: %g", rms * norm);
00465                 
00466                 /* Get measurement for upper-left quadrant */
00467                 zone_def[0] = 1;
00468                 zone_def[1] = cpl_image_get_size_x(tmp_im)/2;
00469                 zone_def[2] = cpl_image_get_size_y(tmp_im)/2 + 1;
00470                 zone_def[3] = cpl_image_get_size_y(tmp_im);
00471                 cpl_flux_get_noise_window(tmp_im, zone_def, 
00472                         isaac_img_dark_config.hsize, 
00473                         isaac_img_dark_config.nsamples, &rms, NULL);
00474                 cpl_matrix_set(rons, i, 2, rms * norm);
00475                 cpl_msg_info(cpl_func, "RON in UL quadrant: %g", rms * norm);
00476                 
00477                 /* Get measurement for upper-right quadrant */
00478                 zone_def[0] = cpl_image_get_size_x(tmp_im)/2 + 1;
00479                 zone_def[1] = cpl_image_get_size_x(tmp_im);
00480                 zone_def[2] = cpl_image_get_size_y(tmp_im)/2 + 1;
00481                 zone_def[3] = cpl_image_get_size_y(tmp_im);
00482                 cpl_flux_get_noise_window(tmp_im, zone_def, 
00483                         isaac_img_dark_config.hsize, 
00484                         isaac_img_dark_config.nsamples, &rms, NULL);
00485                 cpl_matrix_set(rons, i, 3, rms * norm);
00486                 cpl_msg_info(cpl_func, "RON in UR quadrant: %g", rms * norm);
00487                 cpl_image_delete(tmp_im);
00488             }
00489             break;
00490         case 'L':
00491             /* Create the matrix */
00492             rons = cpl_matrix_new(cpl_imagelist_get_size(iset)-1, 1);
00493             if (isaac_img_dark_config.hsize < 0) 
00494                 isaac_img_dark_config.hsize = ISAAC_DARK_HSIZE_LW_DEF;
00495 
00496             /* Loop on all pairs */
00497             for (i=0; i<cpl_imagelist_get_size(iset)-1; i++) {
00498                 cpl_msg_info(cpl_func, "Pair number %d", i+1);
00499                 /* Get the norm factor */
00500                 if (cpl_error_get_code()) {
00501                     cpl_matrix_delete(rons);
00502                     cpl_imagelist_delete(iset);
00503                     return NULL;
00504                 }
00505                 cur_frame = cpl_frameset_get_frame(framelist, i);
00506                 plist = cpl_propertylist_load(cpl_frame_get_filename(cur_frame),
00507                         0);
00508                 ndit = isaac_pfits_get_ndit(plist);
00509                 cpl_propertylist_delete(plist);
00510                 if (cpl_error_get_code()) {
00511                     cpl_msg_error(cpl_func, "Cannot get the NDIT");
00512                     cpl_matrix_delete(rons);
00513                     cpl_imagelist_delete(iset);
00514                     return NULL;
00515                 }
00516                 norm = 0.5 * ndit;
00517                 norm = sqrt(norm);
00518                 
00519                 /* Compute the current subtracted image */
00520                 if ((tmp_im = cpl_image_subtract_create(
00521                                 cpl_imagelist_get(iset, i),
00522                                 cpl_imagelist_get(iset, i+1))) == NULL) {
00523                     cpl_msg_error(cpl_func, "Cannot subtract the images");
00524                     cpl_imagelist_delete(iset);
00525                     cpl_matrix_delete(rons);
00526                     return NULL;
00527                 }
00528 
00529                 /* Get measurement */
00530                 cpl_flux_get_noise_window(tmp_im, NULL, 
00531                         isaac_img_dark_config.hsize, 
00532                         isaac_img_dark_config.nsamples, &rms, NULL);
00533                 cpl_matrix_set(rons, i, 0, rms * norm);
00534                 cpl_msg_info(cpl_func, "RON: %g", rms * norm);
00535                 cpl_image_delete(tmp_im);
00536             }
00537             break;
00538         default:
00539             cpl_msg_error(cpl_func, "Unsupported arm");
00540             cpl_matrix_delete(rons);
00541             rons = 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 6 08:18:22 2013 for ISAAC Pipeline Reference Manual by  doxygen 1.5.8