vircam_twilight_flat_combine.c

00001 /* $Id: vircam_twilight_flat_combine.c,v 1.40 2007/11/26 09:59:06 jim Exp $
00002  *
00003  * This file is part of the VIRCAM Pipeline
00004  * Copyright (C) 2005 Cambridge Astronomy Survey Unit
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: jim $
00023  * $Date: 2007/11/26 09:59:06 $
00024  * $Revision: 1.40 $
00025  * $Name:  $
00026  */
00027 
00028 /* Includes */
00029 
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033 
00034 #include <stdio.h>
00035 #include <cpl.h>
00036 #include <math.h>
00037 
00038 #include "vircam_utils.h"
00039 #include "vircam_mask.h"
00040 #include "vircam_dfs.h"
00041 #include "vircam_mods.h"
00042 #include "vircam_stats.h"
00043 #include "vircam_fits.h"
00044 #include "vircam_pfits.h"
00045 #include "vircam_channel.h"
00046 #include "vircam_paf.h"
00047 #include "vircam_wcsutils.h"
00048 
00049 /* Define values for bit mask that flags dummy results */
00050 
00051 #define MEANTWI     1
00052 #define CONFMAP     2
00053 #define RATIMG      4
00054 #define STATS_TAB   8
00055 
00056 /* Function prototypes */
00057 
00058 static int vircam_twilight_flat_combine_create(cpl_plugin *) ;
00059 static int vircam_twilight_flat_combine_exec(cpl_plugin *) ;
00060 static int vircam_twilight_flat_combine_destroy(cpl_plugin *) ;
00061 static int vircam_twilight_flat_combine(cpl_parameterlist *, cpl_frameset *) ;
00062 static int vircam_twilight_flat_combine_save(cpl_frameset *framelist, 
00063                                              cpl_parameterlist *parlist);
00064 static void vircam_twilight_flat_combine_dummy_products(void);
00065 static void vircam_twilight_flat_combine_normal(int jext);
00066 static int vircam_twilight_flat_combine_lastbit(int jext, 
00067                                                 cpl_frameset *framelist,
00068                                                 cpl_parameterlist *parlist);
00069 static void vircam_twilight_flat_combine_init(void);
00070 static void vircam_twilight_flat_combine_tidy(int level);
00071 
00072 /* Static global variables */
00073 
00074 static struct {
00075 
00076     /* Input */
00077 
00078     float       lthr;
00079     float       hthr;
00080     int         combtype;
00081     int         scaletype;
00082     int         xrej;
00083     float       thresh;
00084     int         ncells;
00085     int         extenum;
00086 
00087     /* Output */
00088 
00089     float       flatrms;
00090     float       flatratio_med;
00091     float       flatratio_rms;
00092 
00093 } vircam_twilight_flat_combine_config;
00094 
00095 
00096 static struct {
00097     vir_fits         **good;
00098     int              ngood;
00099     int              *labels;
00100     cpl_frameset     *twilightlist;
00101     cpl_frame        *master_dark;
00102     cpl_frame        *master_twilight_flat;
00103     vir_mask         *master_mask;
00104     cpl_frame        *chantab;
00105 
00106     cpl_image        *outimage;
00107     cpl_image        *outconf;
00108     vir_fits         **twilights;
00109     int              ntwilights;
00110     cpl_propertylist *drs;
00111     cpl_propertylist *drs2;
00112     unsigned char    *rejmask;
00113     unsigned char    *rejplus;
00114     vir_fits         *mfimage;
00115     cpl_image        *ratioimg;
00116     cpl_table        *ratioimstats;
00117     vir_tfits        *ctable;
00118     vir_fits         *mdark;
00119     cpl_propertylist *phupaf;
00120 } ps;
00121 
00122 static int isfirst;
00123 static cpl_frame *product_frame_mean_twi = NULL;
00124 static cpl_frame *product_frame_conf = NULL;
00125 static cpl_frame *product_frame_ratioimg = NULL;
00126 static cpl_frame *product_frame_ratioimg_stats = NULL;
00127 static int we_expect;
00128 static int we_get;
00129 
00130 static char vircam_twilight_flat_combine_description[] =
00131 "vircam_twilight_flat_combine -- VIRCAM twilight flat combine recipe.\n\n"
00132 "Combine a list of twilight flat frames into a mean frame. Optionally\n"
00133 "compare the output frame to a master twilight flat frame\n\n"
00134 "The program accepts the following files in the SOF:\n\n"
00135 "    Tag                   Description\n"
00136 "    -----------------------------------------------------------------------\n"
00137 "    %-21s A list of raw twilight flat images\n"
00138 "    %-21s A master dark frame\n"
00139 "    %-21s Optional reference twilight flat frame\n"
00140 "    %-21s Optional channel table or\n"
00141 "    %-21s Optional initial channel table\n"
00142 "    %-21s Optional master bad pixel map or\n"
00143 "    %-21s Optional master confidence map\n"
00144 "If no master twilight flat is made available, then no comparison will be\n"
00145 "done. This means there will be no output ratio image. If a master twilight\n"
00146 "is available, but no channel table is, then a ratio image will be formed\n"
00147 "but no stats will be written."
00148 "\n";
00149 
00280 /* Function code */
00281 
00282 /*---------------------------------------------------------------------------*/
00290 /*---------------------------------------------------------------------------*/
00291 
00292 int cpl_plugin_get_info(cpl_pluginlist *list) {
00293     cpl_recipe  *recipe = cpl_calloc(1,sizeof(*recipe));
00294     cpl_plugin  *plugin = &recipe->interface;
00295     char alldesc[SZ_ALLDESC];
00296     (void)snprintf(alldesc,SZ_ALLDESC,vircam_twilight_flat_combine_description,
00297                    VIRCAM_TWI_RAW,VIRCAM_CAL_DARK,VIRCAM_REF_TWILIGHT_FLAT,
00298                    VIRCAM_CAL_CHANTAB,VIRCAM_CAL_CHANTAB_INIT,VIRCAM_CAL_BPM,
00299                    VIRCAM_CAL_CONF);
00300 
00301     cpl_plugin_init(plugin,
00302                     CPL_PLUGIN_API,
00303                     VIRCAM_BINARY_VERSION,
00304                     CPL_PLUGIN_TYPE_RECIPE,
00305                     "vircam_twilight_flat_combine",
00306                     "VIRCAM twilight combination recipe",
00307                     alldesc,
00308                     "Jim Lewis",
00309                     "jrl@ast.cam.ac.uk",
00310                     vircam_get_license(),
00311                     vircam_twilight_flat_combine_create,
00312                     vircam_twilight_flat_combine_exec,
00313                     vircam_twilight_flat_combine_destroy);
00314 
00315     cpl_pluginlist_append(list,plugin);
00316 
00317     return(0);
00318 }
00319 
00320 /*---------------------------------------------------------------------------*/
00329 /*---------------------------------------------------------------------------*/
00330 
00331 static int vircam_twilight_flat_combine_create(cpl_plugin *plugin) {
00332     cpl_recipe      *recipe;
00333     cpl_parameter   *p;
00334 
00335     /* Get the recipe out of the plugin */
00336 
00337     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00338         recipe = (cpl_recipe *)plugin;
00339     else 
00340         return(-1);
00341 
00342     /* Create the parameters list in the cpl_recipe object */
00343 
00344     recipe->parameters = cpl_parameterlist_new();
00345 
00346     /* Lower threshold for rejecting underexposed images */
00347 
00348     p = cpl_parameter_new_value("vircam.vircam_twilight_flat_combine.lthr",
00349                                 CPL_TYPE_DOUBLE,
00350                                 "Low rejection threshold for underexpsed images",
00351                                 "vircam.vircam_twilight_flat_combine",
00352                                 0.0);
00353     cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"lthr");
00354     cpl_parameterlist_append(recipe->parameters,p);
00355 
00356     /* Upper threshold for rejecting overexposed images */
00357 
00358     p = cpl_parameter_new_value("vircam.vircam_twilight_flat_combine.hthr",
00359                                 CPL_TYPE_DOUBLE,
00360                                 "High rejection threshold for overexposed images",
00361                                 "vircam.vircam_twilight_flat_combine",
00362                                 65535.0);
00363     cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"hthr");
00364     cpl_parameterlist_append(recipe->parameters,p);
00365 
00366     /* Fill in the parameters. First the combination type */
00367 
00368     p = cpl_parameter_new_range("vircam.vircam_twilight_flat_combine.combtype",
00369                                 CPL_TYPE_INT,
00370                                 "1 == Median,\n 2 == Mean",
00371                                 "vircam.vircam_twilight_flat_combine",
00372                                 2,1,2);
00373     cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"combtype");
00374     cpl_parameterlist_append(recipe->parameters,p);
00375 
00376     /* The requested scaling */
00377 
00378     p = cpl_parameter_new_range("vircam.vircam_twilight_flat_combine.scaletype",
00379                                 CPL_TYPE_INT,
00380                                 "0 == none,\n 1 == additive offset,\n 2 == multiplicative offset,\n 3 == exposure time scaling + additive offset",
00381                                 "vircam.vircam_twilight_flat_combine",
00382                                 2,0,3);
00383     cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"scaletype");
00384     cpl_parameterlist_append(recipe->parameters,p);
00385     
00386     /* Extra rejection cycle */
00387 
00388     p = cpl_parameter_new_value("vircam.vircam_twilight_flat_combine.xrej",
00389                                 CPL_TYPE_BOOL,
00390                                 "True if using extra rejection cycle",
00391                                 "vircam.vircam_twilight_flat_combine",
00392                                 TRUE);
00393     cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"xrej");
00394     cpl_parameterlist_append(recipe->parameters,p);
00395 
00396     /* Rejection threshold */
00397 
00398     p = cpl_parameter_new_value("vircam.vircam_twilight_flat_combine.thresh",
00399                                 CPL_TYPE_DOUBLE,
00400                                 "Rejection threshold in sigma above background",
00401                                 "vircam.vircam_twilight_flat_combine",5.0);
00402     cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"thresh");
00403     cpl_parameterlist_append(recipe->parameters,p);
00404 
00405     /* How many cells to divide each data channel */
00406 
00407     p = cpl_parameter_new_enum("vircam.vircam_twilight_flat_combine.ncells",
00408                                CPL_TYPE_INT,
00409                                "Number of cells for data channel stats",
00410                                "vircam.vircam_twilight_flat_combine",8,7,1,2,4,
00411                                8,16,32,64);
00412     cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"ncells");
00413     cpl_parameterlist_append(recipe->parameters,p);     
00414 
00415     /* Extension number of input frames to use */
00416 
00417     p = cpl_parameter_new_range("vircam.vircam_twilight_flat_combine.extenum",
00418                                 CPL_TYPE_INT,
00419                                 "Extension number to be done, 0 == all",
00420                                 "vircam.vircam_twilight_flat_combine",
00421                                 1,0,16);
00422     cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"ext");
00423     cpl_parameterlist_append(recipe->parameters,p);
00424         
00425     /* Get out of here */
00426 
00427     return(0);
00428 }
00429     
00430     
00431 /*---------------------------------------------------------------------------*/
00437 /*---------------------------------------------------------------------------*/
00438 
00439 static int vircam_twilight_flat_combine_exec(cpl_plugin *plugin) {
00440     cpl_recipe  *recipe;
00441 
00442     /* Get the recipe out of the plugin */
00443 
00444     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00445         recipe = (cpl_recipe *)plugin;
00446     else 
00447         return(-1);
00448 
00449     return(vircam_twilight_flat_combine(recipe->parameters,recipe->frames));
00450 }
00451                                 
00452 /*---------------------------------------------------------------------------*/
00458 /*---------------------------------------------------------------------------*/
00459 
00460 static int vircam_twilight_flat_combine_destroy(cpl_plugin *plugin) {
00461     cpl_recipe *recipe ;
00462 
00463     /* Get the recipe out of the plugin */
00464 
00465     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00466         recipe = (cpl_recipe *)plugin;
00467     else 
00468         return(-1);
00469 
00470     cpl_parameterlist_delete(recipe->parameters);
00471     return(0);
00472 }
00473 
00474 /*---------------------------------------------------------------------------*/
00481 /*---------------------------------------------------------------------------*/
00482 
00483 static int vircam_twilight_flat_combine(cpl_parameterlist *parlist, 
00484                                         cpl_frameset *framelist) {
00485     const char *fctid="vircam_twilight_flat_combine";
00486     int nlab,j,jst,jfn,retval,status,live,nx,ny,ndit;
00487     long i;
00488     cpl_parameter *p;
00489     vir_fits *ff;
00490     cpl_propertylist *pp;
00491 
00492     /* Check validity of input frameset */
00493 
00494     if (framelist == NULL || cpl_frameset_get_size(framelist) <= 0) {
00495         cpl_msg_error(fctid,"Input framelist NULL or has no input data\n");
00496         return(-1);
00497     }
00498 
00499     /* Initialise some things */
00500 
00501     vircam_twilight_flat_combine_init();
00502     we_expect = MEANTWI + CONFMAP;
00503 
00504     /* Get the parameters */
00505 
00506     p = cpl_parameterlist_find(parlist,"vircam.vircam_twilight_flat_combine.lthr");
00507     vircam_twilight_flat_combine_config.lthr = 
00508         (float)cpl_parameter_get_double(p);
00509     p = cpl_parameterlist_find(parlist,
00510                                "vircam.vircam_twilight_flat_combine.hthr");
00511     vircam_twilight_flat_combine_config.hthr = 
00512         (float)cpl_parameter_get_double(p);
00513     p = cpl_parameterlist_find(parlist,
00514                                "vircam.vircam_twilight_flat_combine.combtype");
00515     vircam_twilight_flat_combine_config.combtype = cpl_parameter_get_int(p);
00516     p = cpl_parameterlist_find(parlist,
00517                                "vircam.vircam_twilight_flat_combine.scaletype");
00518     vircam_twilight_flat_combine_config.scaletype = cpl_parameter_get_int(p);
00519     p = cpl_parameterlist_find(parlist,
00520                                "vircam.vircam_twilight_flat_combine.xrej");
00521     vircam_twilight_flat_combine_config.xrej = cpl_parameter_get_bool(p);
00522     p = cpl_parameterlist_find(parlist,
00523                                "vircam.vircam_twilight_flat_combine.thresh");
00524     vircam_twilight_flat_combine_config.thresh = 
00525         (float)cpl_parameter_get_double(p);
00526     p = cpl_parameterlist_find(parlist,
00527                                "vircam.vircam_twilight_flat_combine.ncells");
00528     vircam_twilight_flat_combine_config.ncells = cpl_parameter_get_int(p);
00529     p = cpl_parameterlist_find(parlist,
00530                                "vircam.vircam_twilight_flat_combine.extenum");
00531     vircam_twilight_flat_combine_config.extenum = cpl_parameter_get_int(p);
00532 
00533     /* Sort out raw from calib frames */
00534 
00535     if (vircam_dfs_set_groups(framelist) != VIR_OK) {
00536         cpl_msg_error(fctid,"Cannot identify RAW and CALIB frames");
00537         vircam_twilight_flat_combine_tidy(2);
00538         return(-1);
00539     }
00540 
00541     /* Get the twilight frames */
00542 
00543     if ((ps.labels = cpl_frameset_labelise(framelist,vircam_compare_tags,
00544                                            &nlab)) == NULL) {
00545         cpl_msg_error(fctid,"Cannot labelise the input frames");
00546         vircam_twilight_flat_combine_tidy(2);
00547         return(-1);
00548     }
00549     if ((ps.twilightlist = vircam_frameset_subgroup(framelist,ps.labels,nlab,
00550                                                     VIRCAM_TWI_RAW)) == NULL) {
00551         cpl_msg_error(fctid,"Cannot find twilight frames in input frameset");
00552         vircam_twilight_flat_combine_tidy(2);
00553         return(-1);
00554     }
00555     ps.ntwilights = cpl_frameset_get_size(ps.twilightlist);
00556 
00557     /* Check to see if there is a master dark frame */
00558 
00559     if ((ps.master_dark = vircam_frameset_subgroup_1(framelist,ps.labels,nlab,
00560                                                      VIRCAM_CAL_DARK)) == NULL) {
00561         cpl_msg_error(fctid,"No master dark found");
00562         vircam_twilight_flat_combine_tidy(2);
00563         return(-1);
00564     }
00565         
00566     /* Check to see if there is a master twilight flat frame */
00567 
00568     if ((ps.master_twilight_flat = vircam_frameset_subgroup_1(framelist,
00569                                                               ps.labels,nlab,
00570                                                               VIRCAM_REF_TWILIGHT_FLAT)) == NULL)
00571         cpl_msg_info(fctid,"No master twilight flat found -- no ratio image will be formed");
00572     else
00573         we_expect |= RATIMG;
00574         
00575     /* Check to see if there is a master bad pixel map. If there isn't one 
00576        then look for a confidence map */
00577 
00578     ps.master_mask = vircam_mask_define(framelist,ps.labels,nlab);
00579 
00580     /* Check to see if there is a channel table */
00581 
00582     if ((ps.chantab = vircam_frameset_subgroup_1(framelist,ps.labels,nlab,
00583                                                  VIRCAM_CAL_CHANTAB)) == NULL) {
00584         if ((ps.chantab = vircam_frameset_subgroup_1(framelist,ps.labels,nlab,
00585                                                      VIRCAM_CAL_CHANTAB_INIT)) == NULL) {
00586             cpl_msg_info(fctid,"No channel table found -- no ratio image stats and no linearisation will be done");
00587         } else {
00588             cpl_msg_info(fctid,"Channel table is labelled INIT -- no linearisation will be done");
00589             if (we_expect & RATIMG)
00590                 we_expect |= STATS_TAB;
00591         }
00592     } else if (we_expect & RATIMG) {
00593         we_expect |= STATS_TAB;
00594     }
00595 
00596     /* Get the number of DITs */
00597 
00598     pp = cpl_propertylist_load(cpl_frame_get_filename(cpl_frameset_get_frame(ps.twilightlist,0)),0);
00599     if (vircam_pfits_get_ndit(pp,&ndit) != VIR_OK) {
00600         cpl_msg_error(fctid,"No value for NDIT available");
00601         freepropertylist(pp);
00602         vircam_twilight_flat_combine_tidy(2);
00603         return(-1);
00604     }
00605     cpl_propertylist_delete(pp);
00606 
00607     /* Now, how many image extensions do we want to do? If the extension
00608        number is zero, then we loop for all possible extensions. If it
00609        isn't then we just do the extension specified */
00610 
00611     vircam_exten_range(vircam_twilight_flat_combine_config.extenum,
00612                        (const cpl_frame *)cpl_frameset_get_frame(ps.twilightlist,0),
00613                        &jst,&jfn);
00614     if (jst == -1 || jfn == -1) {
00615         cpl_msg_error(fctid,"Unable to continue");
00616         vircam_twilight_flat_combine_tidy(2);
00617         return(-1);
00618     }
00619 
00620     /* Get some space for the good frames */
00621 
00622     ps.good = cpl_malloc(ps.ntwilights*sizeof(vir_fits *));
00623 
00624     /* Now loop for all the extension... */
00625 
00626     for (j = jst; j <= jfn; j++) {
00627         status = VIR_OK;
00628         we_get = 0;
00629         isfirst = (j == jst);
00630 
00631         /* Load the images and the master dark. */
00632 
00633         ps.twilights = vircam_fits_load_list(ps.twilightlist,CPL_TYPE_FLOAT,j);
00634         if (ps.twilights == NULL) {
00635             cpl_msg_info(fctid,"Extension %d twilights wouldn't load",j);
00636             retval = vircam_twilight_flat_combine_lastbit(j,framelist,parlist);
00637             if (retval != 0)
00638                 return(-1);
00639             continue;
00640         }
00641 
00642         /* Are any of these twilight flats any good? */
00643         
00644         ps.ngood = 0;
00645         for (i = 0; i < ps.ntwilights; i++) {
00646             ff = ps.twilights[i];
00647             vircam_pfits_get_detlive(vircam_fits_get_ehu(ff),&live);
00648             if (! live) {
00649                 cpl_msg_info(fctid,"Detector flagged dead %s",
00650                              vircam_fits_get_fullname(ff));
00651                 vircam_fits_set_error(ff,VIR_FATAL);
00652             } else {
00653                 ps.good[ps.ngood] = ff;
00654                 ps.ngood += 1;
00655             }
00656         }
00657 
00658         /* If there are no good images, then signal that we need to create 
00659            dummy products and move on */
00660 
00661         if (ps.ngood == 0) {
00662             cpl_msg_info(fctid,"All images flagged bad for this extension");
00663             retval = vircam_twilight_flat_combine_lastbit(j,framelist,parlist);
00664             if (retval != 0)
00665                 return(-1);
00666             continue;
00667         }
00668 
00669         /* Sort out the images that are either over or under exposed */
00670 
00671         vircam_overexp(ps.good,&(ps.ngood),
00672                        vircam_twilight_flat_combine_config.lthr,
00673                        vircam_twilight_flat_combine_config.hthr,0);
00674 
00675         /* Check to see how many are left. If there aren't any, then
00676            signal a major error */
00677 
00678         if (ps.ngood == 0) {
00679             cpl_msg_info(fctid,"All images either under or overexposed");
00680             retval = vircam_twilight_flat_combine_lastbit(j,framelist,parlist);
00681             if (retval != 0)
00682                 return(-1);
00683             continue;
00684         }
00685 
00686         /* Load up the mask */
00687 
00688         nx = cpl_image_get_size_x(vircam_fits_get_image(ps.good[0]));
00689         ny = cpl_image_get_size_y(vircam_fits_get_image(ps.good[0]));
00690         if (vircam_mask_load(ps.master_mask,j,nx,ny) == VIR_FATAL) {
00691             cpl_msg_info(fctid,"Unable to load mask image %s[%d]",
00692                          vircam_mask_get_filename(ps.master_mask),j);
00693             cpl_msg_info(fctid,"Forcing all pixels to be good from now on");
00694             vircam_mask_force(ps.master_mask,nx,ny);
00695         }
00696 
00697         /* Right, we want to dark correct, so we need to load the mean 
00698            dark and make sure it isn't a dummy */
00699 
00700         ps.mdark = vircam_fits_load(ps.master_dark,CPL_TYPE_FLOAT,j);
00701         if (ps.mdark == NULL) {
00702             cpl_msg_info(fctid,"Can't load master dark for extension %d",j);
00703             retval = vircam_twilight_flat_combine_lastbit(j,framelist,parlist);
00704             if (retval != 0)
00705                 return(-1);
00706             continue;
00707         } else if (vircam_is_dummy(vircam_fits_get_ehu(ps.mdark))) {
00708             cpl_msg_info(fctid,"Can't master dark extension %d is a dummy",j);
00709             retval = vircam_twilight_flat_combine_lastbit(j,framelist,parlist);
00710             if (retval != 0)
00711                 return(-1);
00712             continue;
00713         }
00714 
00715         /* Loop for each image and dark correct */
00716 
00717         cpl_msg_info(fctid,"Dark correcting extension %d\n",j);
00718         for (i = 0; i < ps.ngood; i++)
00719             vircam_darkcor((ps.good)[i],ps.mdark,1.0,&status);
00720 
00721         /* We need to load the channel table (if it exists) for linearisation
00722            and for the ratio image stats table */
00723 
00724         if (ps.chantab != NULL) {
00725             ps.ctable = vircam_tfits_load(ps.chantab,j);
00726             if (ps.ctable == NULL) {
00727                 cpl_msg_info(fctid,"Channel table extension %d won't load",j);
00728             } else if (vircam_chantab_verify(vircam_tfits_get_table(ps.ctable)) != VIR_OK) {
00729                 cpl_msg_info(fctid,"Channel table extension %d has errors",j);
00730                 freetfits(ps.ctable);
00731             } else { 
00732                 pp = cpl_propertylist_load(cpl_frame_get_filename(ps.chantab),
00733                                            j);
00734                 if (vircam_is_dummy(pp)) {
00735                     cpl_msg_info(fctid,
00736                                  "Channel table extensions %d is a dummy",j);
00737                     freetfits(ps.ctable);
00738                 }
00739                 freepropertylist(pp);
00740             }
00741         } else 
00742             ps.ctable = NULL;
00743                 
00744         /* Loop for each of the input images and linearise it if there
00745            is a channel table */
00746 
00747         if (ps.ctable != NULL) {
00748             cpl_msg_info(fctid,"Linearising extension %d\n",j);
00749             for (i = 0; i < ps.ngood; i++)
00750                 (void)vircam_lincor((ps.good)[i],ps.ctable,1,ndit,&status);
00751         }
00752 
00753         /* Call the combine module */
00754 
00755         cpl_msg_info(fctid,"Doing combination for extension %d\n",j);
00756         (void)vircam_imcombine(ps.good,ps.ngood,
00757                                vircam_twilight_flat_combine_config.combtype,
00758                                vircam_twilight_flat_combine_config.scaletype,
00759                                vircam_twilight_flat_combine_config.xrej,
00760                                vircam_twilight_flat_combine_config.thresh,
00761                                &(ps.outimage),&(ps.rejmask),&(ps.rejplus),
00762                                &(ps.drs),&status);
00763 
00764         /* If these correction and combination routines failed at any stage
00765            then get out of here */
00766 
00767         if (status == VIR_OK) {
00768             we_get |= MEANTWI;
00769             vircam_twilight_flat_combine_normal(j);
00770         } else {
00771             cpl_msg_info(fctid,"A processing step failed");
00772         }
00773 
00774         /* Create any dummies and save the products */
00775         
00776         retval = vircam_twilight_flat_combine_lastbit(j,framelist,parlist);
00777         if (retval != 0)
00778             return(-1);
00779 
00780     }
00781     vircam_twilight_flat_combine_tidy(2);
00782     return(0);
00783 }
00784 
00785 
00786 /*---------------------------------------------------------------------------*/
00793 /*---------------------------------------------------------------------------*/
00794 
00795 static int vircam_twilight_flat_combine_save(cpl_frameset *framelist, 
00796                                              cpl_parameterlist *parlist) {
00797     cpl_propertylist *plist,*elist,*p,*pafprop;
00798     int status;
00799     const char *fctid = "vircam_twilight_flat_combine_save";
00800     const char *outfile = "twilightcomb.fits";
00801     const char *outdiff = "twilightratio.fits";
00802     const char *outdimst = "twilightratiotab.fits";
00803     const char *outconf = "twilightconf.fits";
00804     const char *outfilepaf = "twilightcomb";
00805     const char *outdiffpaf = "twilightratio";
00806     const char *recipeid = "vircam_twilight_flat_combine";
00807 
00808     /* If we need to make a PHU then do that now based on the first frame
00809        in the input frame list */
00810 
00811     if (isfirst) {
00812 
00813         /* Create a new product frame object and define some tags */
00814 
00815         product_frame_mean_twi = cpl_frame_new();
00816         cpl_frame_set_filename(product_frame_mean_twi,outfile);
00817         cpl_frame_set_tag(product_frame_mean_twi,VIRCAM_PRO_TWILIGHT_FLAT);
00818         cpl_frame_set_type(product_frame_mean_twi,CPL_FRAME_TYPE_IMAGE);
00819         cpl_frame_set_group(product_frame_mean_twi,CPL_FRAME_GROUP_PRODUCT);
00820         cpl_frame_set_level(product_frame_mean_twi,CPL_FRAME_LEVEL_FINAL);
00821 
00822         /* Set up the PHU header */
00823 
00824         plist = vircam_fits_get_phu(ps.twilights[0]);
00825         ps.phupaf = vircam_paf_phu_items(plist);
00826         vircam_dfs_set_product_primary_header(plist,product_frame_mean_twi,
00827                                               framelist,parlist,
00828                                               (char *)recipeid,
00829                                               "PRO-1.15");
00830 
00831         /* 'Save' the PHU image */                       
00832 
00833         if (cpl_image_save(NULL,outfile,CPL_BPP_8_UNSIGNED,plist,
00834                            CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
00835             cpl_msg_error(fctid,"Cannot save product PHU");
00836             cpl_frame_delete(product_frame_mean_twi);
00837             return(-1);
00838         }
00839         cpl_frameset_insert(framelist,product_frame_mean_twi);
00840 
00841         /* Create a new product frame object and define some tags for the
00842            output confidence map */
00843 
00844         product_frame_conf = cpl_frame_new();
00845         cpl_frame_set_filename(product_frame_conf,outconf);
00846         cpl_frame_set_tag(product_frame_conf,VIRCAM_PRO_CONF);
00847         cpl_frame_set_type(product_frame_conf,CPL_FRAME_TYPE_IMAGE);
00848         cpl_frame_set_group(product_frame_conf,CPL_FRAME_GROUP_PRODUCT);
00849         cpl_frame_set_level(product_frame_conf,CPL_FRAME_LEVEL_FINAL);
00850 
00851         /* Set up the PHU header */
00852 
00853         plist = vircam_fits_get_phu(ps.twilights[0]);
00854         vircam_dfs_set_product_primary_header(plist,product_frame_conf,
00855                                               framelist,parlist,
00856                                               (char *)recipeid,
00857                                               "PRO-1.15");
00858 
00859         /* 'Save' the PHU image */                       
00860 
00861         if (cpl_image_save(NULL,outconf,CPL_BPP_8_UNSIGNED,plist,
00862                            CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
00863             cpl_msg_error(fctid,"Cannot save product PHU");
00864             cpl_frame_delete(product_frame_conf);
00865             return(-1);
00866         }
00867         cpl_frameset_insert(framelist,product_frame_conf);
00868 
00869         /* Create a new product frame object for the difference image */
00870 
00871         if (we_expect & RATIMG) {
00872             product_frame_ratioimg = cpl_frame_new();
00873             cpl_frame_set_filename(product_frame_ratioimg,outdiff);
00874             cpl_frame_set_tag(product_frame_ratioimg,
00875                               VIRCAM_PRO_RATIOIMG_TWILIGHT_FLAT);
00876             cpl_frame_set_type(product_frame_ratioimg,CPL_FRAME_TYPE_IMAGE);
00877             cpl_frame_set_group(product_frame_ratioimg,
00878                                 CPL_FRAME_GROUP_PRODUCT);
00879             cpl_frame_set_level(product_frame_ratioimg,CPL_FRAME_LEVEL_FINAL);
00880 
00881             /* Set up the PHU header */
00882 
00883             plist = vircam_fits_get_phu(ps.twilights[0]);
00884             vircam_dfs_set_product_primary_header(plist,product_frame_ratioimg,
00885                                                   framelist,parlist,
00886                                                   (char *)recipeid,
00887                                                   "PRO-1.15");
00888 
00889             /* 'Save' the PHU image */                   
00890 
00891             if (cpl_image_save(NULL,outdiff,CPL_BPP_8_UNSIGNED,plist,
00892                                CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
00893                 cpl_msg_error(fctid,"Cannot save product PHU");
00894                 cpl_frame_delete(product_frame_ratioimg);
00895                 return(-1);
00896             }
00897             cpl_frameset_insert(framelist,product_frame_ratioimg);
00898         }
00899 
00900         /* Create a new product frame object for the difference image stats 
00901            table */
00902 
00903         if (we_expect & STATS_TAB) {
00904             product_frame_ratioimg_stats = cpl_frame_new();
00905             cpl_frame_set_filename(product_frame_ratioimg_stats,outdimst);
00906             cpl_frame_set_tag(product_frame_ratioimg_stats,
00907                               VIRCAM_PRO_RATIOIMG_TWILIGHT_FLAT_STATS);
00908             cpl_frame_set_type(product_frame_ratioimg_stats,
00909                                CPL_FRAME_TYPE_TABLE);
00910             cpl_frame_set_group(product_frame_ratioimg_stats,
00911                                 CPL_FRAME_GROUP_PRODUCT);
00912             cpl_frame_set_level(product_frame_ratioimg_stats,
00913                                 CPL_FRAME_LEVEL_FINAL);
00914 
00915             /* Set up PHU header */
00916 
00917             plist = vircam_fits_get_phu(ps.twilights[0]);
00918             vircam_dfs_set_product_primary_header(plist,
00919                                                   product_frame_ratioimg_stats,
00920                                                   framelist,parlist,
00921                                                   (char *)recipeid,
00922                                                   "PRO-1.15");
00923 
00924             /* Fiddle with the extension header now */
00925 
00926             elist = vircam_fits_get_ehu(ps.twilights[0]);
00927             p = cpl_propertylist_duplicate(elist);
00928             vircam_merge_propertylists(p,ps.drs);
00929             if (! (we_get & STATS_TAB))
00930                 vircam_dummy_property(p);
00931             vircam_dfs_set_product_exten_header(p,product_frame_ratioimg_stats,
00932                                                 framelist,parlist,
00933                                                 (char *)recipeid,
00934                                                 "PRO-1.15");
00935             status = VIR_OK;
00936             vircam_removewcs(p,&status);
00937 
00938             /* And finally the difference image stats table */
00939 
00940             if (cpl_table_save(ps.ratioimstats,plist,p,outdimst,
00941                                CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
00942                 cpl_msg_error(fctid,"Cannot save product table extension");
00943                 cpl_propertylist_delete(p);
00944                 return(-1);
00945             }
00946             cpl_propertylist_delete(p);
00947             cpl_frameset_insert(framelist,product_frame_ratioimg_stats);
00948         }
00949     }
00950 
00951     /* Get the extension property list */
00952 
00953     plist = vircam_fits_get_ehu(ps.twilights[0]);
00954     vircam_merge_propertylists(plist,ps.drs);
00955 
00956     /* Fiddle with the header now */
00957 
00958     p = cpl_propertylist_duplicate(plist);
00959     if (! (we_get & MEANTWI)) 
00960         vircam_dummy_property(p);
00961     vircam_dfs_set_product_exten_header(p,product_frame_mean_twi,framelist,
00962                                         parlist,(char *)recipeid,
00963                                         "PRO-1.15");
00964                 
00965     /* Now save the mean twilight flat image extension */
00966 
00967     cpl_propertylist_update_float(p,"ESO QC FLATRMS",
00968                                   vircam_twilight_flat_combine_config.flatrms);
00969     cpl_propertylist_set_comment(p,"ESO QC FLATRMS","RMS of output flat");
00970     if (cpl_image_save(ps.outimage,outfile,CPL_BPP_IEEE_FLOAT,p,
00971                        CPL_IO_EXTEND) != CPL_ERROR_NONE) {
00972         cpl_msg_error(fctid,"Cannot save product image extension");
00973         cpl_propertylist_delete(p);
00974         return(-1);
00975     }
00976 
00977     /* Write out PAF for mean image */
00978 
00979     pafprop = vircam_paf_req_items(p);
00980     vircam_merge_propertylists(pafprop,ps.phupaf);
00981     vircam_paf_append(pafprop,vircam_fits_get_phu(ps.twilights[0]),
00982                       "ESO INS FILT1 NAME");
00983     if (vircam_paf_print((char *)outfilepaf,
00984                          "VIRCAM/vircam_twilight_flat_combine",
00985                          "QC file",pafprop) != VIR_OK)
00986         cpl_msg_warning(fctid,"Unable to save PAF for mean twilight");
00987     cpl_propertylist_delete(pafprop);
00988     cpl_propertylist_delete(p);
00989 
00990     /* Now save the twilight ratio image extension */
00991 
00992     if (we_expect & RATIMG) {
00993         p = cpl_propertylist_duplicate(plist);
00994         if (! (we_get & RATIMG))
00995             vircam_dummy_property(p);
00996         cpl_propertylist_update_float(p,"ESO QC FLATRATIO_MED",
00997                                       vircam_twilight_flat_combine_config.flatratio_med);
00998         cpl_propertylist_set_comment(p,"ESO QC FLATRATIO_MED",
00999                                      "Median of ratio map");
01000         cpl_propertylist_update_float(p,"ESO QC FLATRATIO_RMS",
01001                                       vircam_twilight_flat_combine_config.flatratio_rms);
01002         cpl_propertylist_set_comment(p,"ESO QC FLATRATIO_RMS",
01003                                      "RMS of ratio map");
01004         vircam_dfs_set_product_exten_header(p,product_frame_ratioimg,
01005                                             framelist,parlist,
01006                                             (char *)recipeid,
01007                                             "PRO-1.15");
01008         if (cpl_image_save(ps.ratioimg,outdiff,CPL_BPP_IEEE_FLOAT,p,
01009                            CPL_IO_EXTEND) != CPL_ERROR_NONE) {
01010             cpl_propertylist_delete(p);
01011             cpl_msg_error(fctid,"Cannot save product image extension");
01012             return(-1);
01013         }
01014 
01015         /* Write out PAF for difference image */
01016 
01017         pafprop = vircam_paf_req_items(p);
01018         vircam_merge_propertylists(pafprop,ps.phupaf);
01019         vircam_paf_append(pafprop,vircam_fits_get_phu(ps.twilights[0]),
01020                           "ESO INS FILT1 NAME");
01021         if (vircam_paf_print((char *)outdiffpaf,
01022                              "VIRCAM/vircam_twilight_flat_combine",
01023                              "QC file",pafprop) != VIR_OK)
01024             cpl_msg_warning(fctid,"Unable to save PAF for twilight ratio image");
01025         cpl_propertylist_delete(pafprop);
01026         cpl_propertylist_delete(p);
01027     }
01028 
01029     /* Now any further ratio image stats tables */
01030 
01031     if (! isfirst && (we_expect & STATS_TAB)) {
01032         p = cpl_propertylist_duplicate(plist);
01033         if (! (we_get & STATS_TAB))
01034             vircam_dummy_property(p);
01035         vircam_dfs_set_product_exten_header(p,product_frame_ratioimg_stats,
01036                                             framelist,parlist,
01037                                             (char *)recipeid,
01038                                             "PRO-1.15");
01039         status = VIR_OK;
01040         vircam_removewcs(p,&status);
01041         if (cpl_table_save(ps.ratioimstats,NULL,p,outdimst,CPL_IO_EXTEND)
01042                            != CPL_ERROR_NONE) {
01043             cpl_msg_error(fctid,"Cannot save product table extension");
01044             cpl_propertylist_delete(p);
01045             return(-1);
01046         }       
01047         cpl_propertylist_delete(p);
01048     }
01049 
01050     /* Fiddle with the header now */
01051 
01052     vircam_merge_propertylists(plist,ps.drs2);
01053     p = cpl_propertylist_duplicate(plist);
01054     if (! (we_get & CONFMAP)) 
01055         vircam_dummy_property(p);
01056 
01057     /* Now save the confidence map */
01058 
01059     vircam_dfs_set_product_exten_header(p,product_frame_conf,framelist,
01060                                         parlist,(char *)recipeid,
01061                                         "PRO-1.15");
01062     if (cpl_image_save(ps.outconf,outconf,CPL_BPP_16_SIGNED,p,
01063                        CPL_IO_EXTEND) != CPL_ERROR_NONE) {
01064         cpl_msg_error(fctid,"Cannot save product image extension");
01065         cpl_propertylist_delete(p);
01066         return(-1);
01067     }
01068     cpl_propertylist_delete(p);
01069 
01070     /* Get out of here */
01071 
01072     return(0);
01073 }
01074 
01075 /*---------------------------------------------------------------------------*/
01079 /*---------------------------------------------------------------------------*/
01080 
01081 static void vircam_twilight_flat_combine_dummy_products(void) {
01082 
01083     /* See if you even need to be here */
01084 
01085     if (we_get == we_expect)
01086         return;
01087 
01088     /* First an output combined twilight frame */
01089 
01090     if (! (we_get & MEANTWI)) {
01091         ps.outimage = vircam_dummy_image(ps.twilights[0]);
01092         vircam_twilight_flat_combine_config.flatrms = 0.0;
01093     }
01094 
01095     /* Now the confidence map */
01096 
01097     if (! (we_get & CONFMAP)) {
01098         ps.outconf = vircam_dummy_image(ps.twilights[0]);
01099         vircam_twilight_flat_combine_config.flatrms = 0.0;
01100     }
01101 
01102     /* Do a ratio image */
01103 
01104     if ((we_expect & RATIMG) && ! (we_get & RATIMG)) {
01105         vircam_twilight_flat_combine_config.flatratio_med = 0.0;
01106         vircam_twilight_flat_combine_config.flatratio_rms = 0.0;
01107         ps.ratioimg = vircam_dummy_image(ps.twilights[0]);
01108     }
01109 
01110     /* If a ratio image stats table is required, then do that now */
01111    
01112     if ((we_expect & STATS_TAB) && ! (we_get & STATS_TAB)) 
01113         ps.ratioimstats = vircam_create_diffimg_stats(0);
01114 
01115     return;
01116 }
01117 
01118 /*---------------------------------------------------------------------------*/
01123 /*---------------------------------------------------------------------------*/
01124 
01125 static void vircam_twilight_flat_combine_normal(int jext) {
01126     int nx,ny,ncells,status;
01127     long npi;
01128     unsigned char *bpm;
01129     float *idata,med,sig,gdiff,grms;
01130     const char *fctid="vircam_twilight_flat_combine_normal";
01131 
01132     /* Load up a bad pixel mask */
01133 
01134     nx = cpl_image_get_size_x(ps.outimage);
01135     ny = cpl_image_get_size_y(ps.outimage);
01136     npi = nx*ny;
01137     vircam_mask_load(ps.master_mask,jext,nx,ny);
01138     bpm = vircam_mask_get_data(ps.master_mask);
01139 
01140     /* Create the bad pixel mask */
01141     
01142     status = VIR_OK;
01143     (void)vircam_mkconf(ps.outimage,(char *)"None Available",ps.master_mask,
01144                         &(ps.outconf),&(ps.drs2),&status);
01145     if (status == VIR_OK) 
01146         we_get |= CONFMAP;
01147     else {
01148         cpl_msg_info(fctid,"Confidence map creation failed extension %d",jext);
01149         status = VIR_OK;
01150     }
01151         
01152     /* Work out the RMS of the mean twilight frame */
01153 
01154     idata = cpl_image_get_data(ps.outimage);
01155     vircam_medsig(idata,bpm,npi,&med,&sig);
01156 
01157     /* Divide through by the median */
01158 
01159     cpl_propertylist_update_float(ps.drs,"ESO DRS MEDFLAT",med);
01160     cpl_propertylist_set_comment(ps.drs,"ESO DRS MEDFLAT",
01161                                  "Median value before normalisation");
01162     cpl_image_divide_scalar(ps.outimage,med);
01163     vircam_medmad(idata,bpm,npi,&med,&sig);
01164     sig *= 1.48;
01165     vircam_twilight_flat_combine_config.flatrms = sig;
01166 
01167     /* Load up the master twilight flat */
01168 
01169     if (ps.master_twilight_flat != NULL) {
01170         ps.mfimage = vircam_fits_load(ps.master_twilight_flat,CPL_TYPE_FLOAT,jext);
01171         if (ps.mfimage == NULL) {
01172             cpl_msg_info(fctid,"Master twilight extension %d won't load",jext);
01173         } else if (vircam_is_dummy(vircam_fits_get_ehu(ps.mfimage))) {
01174             cpl_msg_info(fctid,"Master twilight extension %d is a dummy",jext);
01175             freefits(ps.mfimage);
01176         }
01177     } else
01178         ps.mfimage = NULL;
01179 
01180 
01181     /* Create a ratio image. NB: the difference image routine copes if the 
01182        input mean image or the channel tables are null.  Thus if either or
01183        both are null because of a failure to load, then the routine will do
01184        as  much as it can and return, allowing you to fill in the rest with
01185        dummy products */
01186 
01187     vircam_twilight_flat_combine_config.flatratio_med = 0.0;
01188     vircam_twilight_flat_combine_config.flatratio_rms = 0.0;
01189     ncells = vircam_twilight_flat_combine_config.ncells;
01190     vircam_difference_image(vircam_fits_get_image(ps.mfimage),ps.outimage,bpm,
01191                             vircam_tfits_get_table(ps.ctable),ncells,2,
01192                             &gdiff,&grms,&(ps.ratioimg),
01193                             &(ps.ratioimstats));
01194     vircam_mask_clear(ps.master_mask);
01195     vircam_twilight_flat_combine_config.flatratio_med = gdiff;
01196     vircam_twilight_flat_combine_config.flatratio_rms = grms;
01197     if (ps.ratioimg != NULL)
01198         we_get |= RATIMG;
01199     if (ps.ratioimstats != NULL)
01200         we_get |= STATS_TAB;
01201     return;
01202 }
01203 
01204 /*---------------------------------------------------------------------------*/
01212 /*---------------------------------------------------------------------------*/
01213 
01214 
01215 static int vircam_twilight_flat_combine_lastbit(int jext, 
01216                                                 cpl_frameset *framelist,
01217                                                 cpl_parameterlist *parlist) {
01218     int retval;
01219     const char *fctid="vircam_twilight_flat_combine_lastbit";
01220 
01221     /* Make whatever dummy products you need */
01222 
01223     vircam_twilight_flat_combine_dummy_products();
01224 
01225     /* Save everything */
01226 
01227     cpl_msg_info(fctid,"Saving products for extension %d",jext);
01228     retval = vircam_twilight_flat_combine_save(framelist,parlist);
01229     if (retval != 0) {
01230         vircam_twilight_flat_combine_tidy(2);
01231         return(-1);
01232     }
01233 
01234     /* Free some stuff up */
01235 
01236     vircam_twilight_flat_combine_tidy(1);
01237     return(0);
01238 }
01239 
01240 /*---------------------------------------------------------------------------*/
01244 /*---------------------------------------------------------------------------*/
01245 
01246 static void vircam_twilight_flat_combine_init(void) {
01247     ps.labels = NULL;
01248     ps.twilightlist = NULL;
01249     ps.twilights = NULL;
01250     ps.good = NULL;
01251     ps.master_dark = NULL;
01252     ps.master_twilight_flat = NULL;
01253     ps.master_mask = NULL;
01254     ps.chantab = NULL;
01255     ps.ctable = NULL;
01256     ps.outimage = NULL;
01257     ps.outconf = NULL;
01258     ps.drs = NULL;
01259     ps.drs2 = NULL;
01260     ps.rejmask = NULL;
01261     ps.rejplus = NULL;
01262     ps.mfimage = NULL;
01263     ps.ratioimg = NULL;
01264     ps.ratioimstats = NULL;
01265     ps.phupaf = NULL;
01266 }
01267 
01268 /*---------------------------------------------------------------------------*/
01272 /*---------------------------------------------------------------------------*/
01273 
01274 static void vircam_twilight_flat_combine_tidy(int level) {
01275     freeimage(ps.outimage);
01276     freeimage(ps.outconf);
01277     freefitslist(ps.twilights,ps.ntwilights);
01278     freepropertylist(ps.drs);
01279     freepropertylist(ps.drs2);
01280     freespace(ps.rejmask);
01281     freespace(ps.rejplus);
01282     freefits(ps.mfimage);
01283     freeimage(ps.ratioimg);
01284     freetable(ps.ratioimstats);
01285     freetfits(ps.ctable);
01286     freefits(ps.mdark);
01287     if (level == 1)
01288         return;
01289 
01290     freespace(ps.good);
01291     freespace(ps.labels);
01292     freeframeset(ps.twilightlist);
01293     freeframe(ps.master_dark);
01294     freeframe(ps.master_twilight_flat);
01295     freemask(ps.master_mask);
01296     freeframe(ps.chantab);
01297     freepropertylist(ps.phupaf);
01298 }
01299 
01302 /*
01303 
01304 $Log: vircam_twilight_flat_combine.c,v $
01305 Revision 1.40  2007/11/26 09:59:06  jim
01306 Recipe now takes ndit into account when doing linearity correction
01307 
01308 Revision 1.39  2007/10/19 09:25:09  jim
01309 Fixed problems with missing includes
01310 
01311 Revision 1.38  2007/10/15 12:53:26  jim
01312 Modified for compatibiliity with cpl_4.0
01313 
01314 Revision 1.37  2007/07/18 15:35:42  jim
01315 Added better error handling for missing or corrupt mask extensions
01316 
01317 Revision 1.36  2007/07/09 13:21:56  jim
01318 Modified to use new version of vircam_exten_range
01319 
01320 Revision 1.35  2007/06/13 08:11:27  jim
01321 Modified docs to reflect changes in DFS tags
01322 
01323 Revision 1.34  2007/05/08 10:42:33  jim
01324 Added DRS MEDFLAT keyword
01325 
01326 Revision 1.33  2007/04/30 09:40:17  jim
01327 Added more stuff to paf files
01328 
01329 Revision 1.32  2007/04/04 10:36:18  jim
01330 Modified to use new dfs tags
01331 
01332 Revision 1.31  2007/03/29 12:19:39  jim
01333 Little changes to improve documentation
01334 
01335 Revision 1.30  2007/03/02 12:37:16  jim
01336 Removed WCS stuff from table headers
01337 
01338 Revision 1.29  2007/03/01 12:41:49  jim
01339 Modified slightly after code checking
01340 
01341 Revision 1.28  2007/02/25 06:27:41  jim
01342 plugged a few memory leaks
01343 
01344 Revision 1.27  2007/02/15 11:54:09  jim
01345 Modified to make a distinction between initial channel table and one that
01346 has the proper linearity information
01347 
01348 Revision 1.26  2007/02/15 06:59:38  jim
01349 Added ability to write QC paf files
01350 
01351 Revision 1.25  2007/02/07 10:12:40  jim
01352 Removed calls to vircam_ndit_correct as this is now no longer necessary
01353 
01354 Revision 1.24  2007/02/06 13:11:12  jim
01355 Fixed entry for PRO dictionary in cpl_dfs_set_product_header
01356 
01357 Revision 1.23  2007/02/05 14:14:05  jim
01358 Input master frame is now tagged as REFERENCE. QC removed from stats table
01359 headers
01360 
01361 Revision 1.22  2007/01/08 19:09:11  jim
01362 Fixed memory leak
01363 
01364 Revision 1.21  2006/12/13 13:26:09  jim
01365 Fxied bad sigma estimate
01366 
01367 Revision 1.20  2006/11/27 12:15:08  jim
01368 changed calls to cpl_propertylist_append to cpl_propertylist_update
01369 
01370 Revision 1.19  2006/11/10 09:24:49  jim
01371 Fixed bug in save routine where the wrong propertylist was being saved
01372 
01373 Revision 1.18  2006/09/29 11:19:31  jim
01374 changed aliases on parameter names
01375 
01376 Revision 1.17  2006/09/10 20:47:03  jim
01377 Small documentation fix
01378 
01379 Revision 1.16  2006/09/09 16:49:40  jim
01380 Header comment update
01381 
01382 Revision 1.15  2006/08/27 20:30:02  jim
01383 Major mods to structure of the main processing routine to deal with missing
01384 and dummy frames. Deals better with lower level failures too
01385 
01386 Revision 1.14  2006/07/11 14:55:12  jim
01387 Now checks for zeros in the output flat and replaces them
01388 
01389 Revision 1.13  2006/06/20 19:07:01  jim
01390 Corrects for ndit != 1
01391 
01392 Revision 1.12  2006/06/15 09:58:58  jim
01393 Minor changes to docs
01394 
01395 Revision 1.11  2006/06/09 11:26:25  jim
01396 Small changes to keep lint happy
01397 
01398 Revision 1.10  2006/06/06 13:01:40  jim
01399 Fixed so that the QC parameters go into the correct headers
01400 
01401 Revision 1.9  2006/05/26 19:34:18  jim
01402 Fixed recipe to normalise the flats
01403 
01404 Revision 1.8  2006/05/17 14:43:58  jim
01405 Fixed problem in save routine which messed up the PRO CATG keywords
01406 
01407 Revision 1.7  2006/05/16 13:58:47  jim
01408 Fixed memory leaks that occur from not closing images at the end of
01409 the image extension loop
01410 
01411 Revision 1.6  2006/05/09 08:54:40  jim
01412 Fixed _save routine so that the confidence map is saved as a signed 16 bit
01413 integer
01414 
01415 Revision 1.5  2006/05/08 14:54:03  jim
01416 Fixed little bug where the confidence map file name wasn't being declared to
01417 the header correctly
01418 
01419 Revision 1.4  2006/05/08 13:20:23  jim
01420 Fixed bug where the fitslist for the flats got deleted twice
01421 
01422 Revision 1.3  2006/05/04 11:53:15  jim
01423 Fixed the way the _save routine works to be more consistent with the
01424 standard CPL way of doing things
01425 
01426 Revision 1.2  2006/04/27 14:21:26  jim
01427 Renamed undefined tag
01428 
01429 Revision 1.1  2006/04/27 09:44:47  jim
01430 new file
01431 
01432 */

Generated on Wed Apr 10 04:01:57 2013 for VIRCAM Pipeline by  doxygen 1.5.1