fors_img_screen_flat-test.c

00001 /* $Id: fors_img_screen_flat-test.c,v 1.17 2008-08-07 09:38:01 cizzo Exp $
00002  *
00003  * This file is part of the FORS Library
00004  * Copyright (C) 2002-2006 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00019  */
00020 
00021 /*
00022  * $Author: cizzo $
00023  * $Date: 2008-08-07 09:38:01 $
00024  * $Revision: 1.17 $
00025  * $Name: not supported by cvs2svn $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 #include <fors_img_screen_flat_impl.h>
00033 #include <fors_dfs.h>
00034 #include <fors_pfits.h>
00035 #include <fors_utils.h>
00036 
00037 #include <test_simulate.h>
00038 #include <test.h>
00039 
00040 #include <cpl.h>
00041 #include <math.h>
00042 
00049 #undef cleanup
00050 #define cleanup \
00051 do { \
00052     cpl_frameset_delete(frames); \
00053     cpl_parameterlist_delete(parameters); \
00054     fors_image_delete(&raw_sflat); \
00055     fors_image_delete(&master_sflat); \
00056     fors_image_delete(&master_bias); \
00057     fors_setting_delete(&setting); \
00058     cpl_propertylist_delete(product_header); \
00059 } while(0)
00060 
00064 static void
00065 test_img_screen_flat(void)
00066 {
00067     /* Input */
00068     cpl_frameset *frames = cpl_frameset_new();
00069     cpl_parameterlist *parameters = cpl_parameterlist_new();
00070 
00071     /* Output */
00072     fors_image *raw_sflat = NULL;
00073     fors_image *master_sflat = NULL;
00074     fors_image *master_bias = NULL;
00075     fors_setting *setting = NULL;
00076     cpl_propertylist *product_header = NULL;
00077 
00078     /* Simulate data */
00079     const char *screen_flat_filename[] = {"img_screen_flat_1.fits",
00080                                           "img_screen_flat_2.fits",
00081                                           "img_screen_flat_3.fits"};
00082     const unsigned N =  sizeof(screen_flat_filename)/sizeof(char *);
00083 
00084     {
00085         unsigned i;
00086         
00087         for (i = 0; i < N; i++) {
00088             cpl_frameset_insert(
00089                 frames,
00090                 create_screen_flat(screen_flat_filename[i],
00091                                    SCREEN_FLAT_IMG, CPL_FRAME_GROUP_RAW));
00092         }
00093     }
00094     
00095     cpl_frameset_insert(frames, 
00096                         create_master_bias("img_screen_flat_master_bias.fits", 
00097                                     MASTER_BIAS, CPL_FRAME_GROUP_CALIB));
00098     
00099     /* Define parameters */
00100     fors_img_screen_flat_define_parameters(parameters);
00101 
00102     assure( !cpl_error_get_code(), return, 
00103             "Create parameters failed");
00104     
00105     fors_parameterlist_set_defaults(parameters);
00106 
00107     cpl_parameter_set_int(cpl_parameterlist_find(parameters, 
00108                           "fors.fors_img_screen_flat.xradius"),
00109                           1);
00110     cpl_parameter_set_int(cpl_parameterlist_find(parameters, 
00111                           "fors.fors_img_screen_flat.yradius"),
00112                           1);
00113 
00114     cpl_parameter_set_int(cpl_parameterlist_find(parameters,
00115                           "fors.fors_img_screen_flat.degree"),
00116                           -1);
00117 
00118     /* Call recipe */
00119     fors_img_screen_flat(frames, parameters);
00120     assure( !cpl_error_get_code(), return, 
00121             "Execution error");
00122     
00123     /* Test results */
00124 
00125     /* Existence */
00126     const char *const product_tags[] = {MASTER_SCREEN_FLAT_IMG,
00127                                         MASTER_NORM_FLAT_IMG};
00128     const char *const qc[] =  {"QC OVEREXPO",
00129                                "QC FLAT EFF",
00130                                "QC FLAT PHN",
00131                                "QC FLAT FPN",
00132                                "QC FLAT CONAD",
00133                                "QC FLAT CONADERR"};
00134     
00135     test_recipe_output(frames,
00136                        product_tags, sizeof product_tags / sizeof *product_tags,
00137                MASTER_NORM_FLAT_IMG,
00138                        qc, sizeof qc / sizeof *qc);    
00139 
00140 
00141     setting = fors_setting_new(cpl_frameset_find(frames,
00142                                                  SCREEN_FLAT_IMG));
00143     
00144     {
00145         /* New and previous frames */
00146         test( cpl_frameset_find(frames, MASTER_SCREEN_FLAT_IMG) != NULL );
00147         test( cpl_frameset_find(frames, MASTER_NORM_FLAT_IMG) != NULL );
00148         test( cpl_frameset_find(frames, MASTER_BIAS) != NULL );
00149         test( cpl_frameset_find(frames, SCREEN_FLAT_IMG) != NULL );
00150         
00151         master_sflat = fors_image_load(
00152             cpl_frameset_find(frames, MASTER_NORM_FLAT_IMG));
00153         master_bias  = fors_image_load(
00154             cpl_frameset_find(frames, MASTER_BIAS));
00155         
00156         raw_sflat    = fors_image_load(
00157             cpl_frameset_find(frames, SCREEN_FLAT_IMG));
00158         cpl_image_subtract_scalar(raw_sflat->data, 200); //Hard-coded bias level 
00159         //fors_subtract_bias(raw_sflat, master_bias); //Sizes are different now that trimming is done before
00160         
00161         /* Verify that relative error decreased  */
00162         test( fors_image_get_error_mean(master_sflat, NULL) /
00163               fors_image_get_mean(master_sflat, NULL) 
00164               <
00165               fors_image_get_error_mean(raw_sflat, NULL) /
00166               fors_image_get_mean(raw_sflat, NULL));
00167 
00168         /* Verify normalization */
00169         test_rel( fors_image_get_mean(master_sflat, NULL),
00170                   1.0, 0.01);
00171 
00172         /* Test QC values */
00173         product_header = 
00174             cpl_propertylist_load(cpl_frame_get_filename(
00175                                       cpl_frameset_find(frames,
00176                                                         MASTER_NORM_FLAT_IMG)),
00177                                   0);
00178         assure( product_header != NULL, return, NULL );
00179 
00180         
00181         test_rel( cpl_propertylist_get_double(product_header,
00182                                               "ESO QC FLAT EFF"),
00183                   fors_image_get_median(raw_sflat, NULL) / setting->exposure_time,
00184                   0.03 );
00185 
00186         /* QC.FLAT.PHN is the master flat photon noise in ADU.
00187            But the master flat is normalized to one, so
00188            multiply by the normalization factor */
00189 /*  %%%
00190         test_rel( cpl_propertylist_get_double(product_header,
00191                                               "ESO QC FLAT PHN"),
00192                   fors_image_get_stdev(master_sflat, NULL) *
00193                   fors_image_get_median(raw_sflat, NULL),
00194                   0.1 );
00195 %%% */
00196 
00197 
00198         /* CONAD */
00199         test_rel( cpl_propertylist_get_double(product_header,
00200                                               "ESO QC FLAT CONAD"),
00201                   cpl_propertylist_get_double(product_header,
00202                                               FORS_PFITS_CONAD[0]),
00203                   /* Compare with propagated CONAD value */
00204                   0.1);
00205 
00206         test( cpl_propertylist_get_double(product_header,
00207                                           "ESO QC FLAT CONADERR") <
00208               0.1 * cpl_propertylist_get_double(product_header,
00209                                                 "ESO QC FLAT CONAD") );
00210     }
00211     
00212     cleanup;
00213     return;
00214 }
00215 
00219 int main(void)
00220 {
00221     TEST_INIT;
00222     
00223     test_img_screen_flat();
00224 
00225     TEST_END;
00226 }
00227 

Generated on 12 Feb 2016 for FORS Pipeline Reference Manual by  doxygen 1.6.1