fors_bias-test.c

00001 /* $Id: fors_bias-test.c,v 1.8 2007/11/26 14:30:52 jmlarsen 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: jmlarsen $
00023  * $Date: 2007/11/26 14:30:52 $
00024  * $Revision: 1.8 $
00025  * $Name: fors-4_8_6 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 #include <fors_bias_impl.h>
00033 #include <fors_dfs.h>
00034 #include <fors_utils.h>
00035 
00036 #include <test_simulate.h>
00037 #include <test.h>
00038 
00039 #include <cpl.h>
00040 
00047 #undef cleanup
00048 #define cleanup \
00049 do { \
00050     cpl_frameset_delete(frames); \
00051     cpl_parameterlist_delete(parameters); \
00052     fors_setting_delete(&setting); \
00053     fors_image_delete(&raw_bias); \
00054     fors_image_delete(&master_bias); \
00055     cpl_propertylist_delete(product_header); \
00056 } while(0)
00057 
00061 static void
00062 test_bias(void)
00063 {
00064     /* Input */
00065     cpl_frameset *frames          = cpl_frameset_new();
00066     cpl_parameterlist *parameters = cpl_parameterlist_new();
00067 
00068     /* Output */
00069     fors_image *master_bias  = NULL;
00070     fors_image *raw_bias  = NULL;
00071     cpl_propertylist *product_header = NULL;
00072 
00073     fors_setting *setting = NULL;
00074 
00075     /* Simulate data */
00076     const char *bias_filename[] = {"bias_1.fits",
00077                                    "bias_2.fits",
00078                                    "bias_3.fits",
00079                                    "bias_4.fits",
00080                                    "bias_5.fits"};
00081     
00082     {
00083         unsigned i;
00084         
00085         for (i = 0; i < sizeof(bias_filename)/sizeof(char *); i++) {
00086             cpl_frameset_insert(frames, 
00087                                 create_bias(bias_filename[i],
00088                                             BIAS, CPL_FRAME_GROUP_RAW));
00089         }
00090     }
00091 
00092     setting = fors_setting_new(cpl_frameset_get_first(frames));
00093 
00094     fors_bias_define_parameters(parameters);
00095     assure( !cpl_error_get_code(), return, 
00096             "Create parameters failed");
00097     
00098     fors_parameterlist_set_defaults(parameters);
00099 
00100     /* Call recipe */
00101     fors_bias(frames, parameters);
00102     assure( !cpl_error_get_code(), return, 
00103             "Execution error");
00104 
00105     /* Test existence of QC + products */
00106     const char *const product_tags[] = {MASTER_BIAS};
00107     const char *const qc[] = 
00108         {"QC BIAS STRUCT", "QC BIAS LEVEL", "QC RON", "QC BIAS FPN",
00109          "QC MBIAS LEVEL",
00110          "QC MBIAS RONEXP", "QC MBIAS NOISE", "QC MBIAS NRATIO", "QC MBIAS STRUCT"};
00111     test_recipe_output(frames, 
00112                        product_tags, sizeof product_tags / sizeof *product_tags,
00113                MASTER_BIAS,
00114                        qc, sizeof qc / sizeof *qc);
00115     
00116     /* Test results */
00117     {
00118         /* New and previous frames */
00119         test( cpl_frameset_find(frames, BIAS) != NULL );
00120 
00121         master_bias = fors_image_load(
00122             cpl_frameset_find(frames, MASTER_BIAS), NULL, setting, NULL);
00123         
00124         raw_bias    = fors_image_load(
00125             cpl_frameset_find(frames, BIAS), NULL, setting, NULL);
00126         
00127         /* Verify that relative error decreased  */
00128         test( fors_image_get_error_mean(master_bias, NULL) /
00129               fors_image_get_mean(master_bias, NULL) 
00130               <
00131               fors_image_get_error_mean(raw_bias, NULL) /
00132               fors_image_get_mean(raw_bias, NULL));
00133 
00134 
00135         /* QC numbers */
00136         product_header = 
00137             cpl_propertylist_load(cpl_frame_get_filename(
00138                                       cpl_frameset_find(frames,
00139                                                         MASTER_BIAS)),
00140                                   0);
00141         assure( product_header != NULL, return, NULL );
00142 
00143         test_rel( cpl_propertylist_get_double(product_header,
00144                                               "ESO QC BIAS LEVEL"),
00145                   fors_image_get_median(master_bias, NULL), 0.01 );
00146         
00147         test_rel( cpl_propertylist_get_double(product_header,
00148                                               "ESO QC MBIAS LEVEL"),
00149                   fors_image_get_median(master_bias, NULL), 0.01 );
00150         
00151         test_rel( cpl_propertylist_get_double(product_header,
00152                                               "ESO QC RON"),
00153                   fors_image_get_stdev(raw_bias, NULL), 0.10 );
00154 
00155         /* fixed pattern and structure should be zero */
00156         test_abs( cpl_propertylist_get_double(product_header,
00157                                               "ESO QC BIAS FPN"),
00158                   0, 0.01*fors_image_get_median(master_bias, NULL));
00159 
00160         test_abs( cpl_propertylist_get_double(product_header,
00161                                               "ESO QC BIAS STRUCT"),
00162                   0, 0.01*fors_image_get_median(master_bias, NULL));
00163     }
00164 
00165     cleanup;
00166     return;
00167 }
00168 
00172 int main(void)
00173 {
00174     TEST_INIT;
00175     
00176     test_bias();
00177 
00178     TEST_END;
00179 }
00180 

Generated on Fri Mar 4 09:46:00 2011 for FORS Pipeline Reference Manual by  doxygen 1.4.7