vircam_dome_flat_combine.c

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

Generated on 5 Mar 2013 for VIRCAM Pipeline by  doxygen 1.6.1