fors_dark-test.c

00001 /* $Id: fors_dark-test.c,v 1.3 2007/10/31 17:07:32 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/10/31 17:07:32 $
00024  * $Revision: 1.3 $
00025  * $Name: fors-4_8_6 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 #include <fors_dark_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_image_delete(&raw_dark); \
00053     fors_image_delete(&master_dark); \
00054     fors_image_delete(&master_bias); \
00055     fors_setting_delete(&setting); \
00056 } while(0)
00057 
00061 static void
00062 test_dark(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_dark  = NULL;
00070     fors_image *master_bias  = NULL;
00071     fors_image *raw_dark  = NULL;
00072 
00073     fors_setting *setting = NULL;
00074 
00075     /* Simulate data */
00076     const char *dark_filename[] = {"dark_1.fits",
00077                                    "dark_2.fits",
00078                                    "dark_3.fits"};
00079 
00080     {
00081         unsigned i;
00082         
00083         for (i = 0; i < sizeof(dark_filename)/sizeof(char *); i++) {
00084             cpl_frameset_insert(frames, 
00085                                 create_dark(dark_filename[i],
00086                                             DARK, CPL_FRAME_GROUP_RAW));
00087         }
00088     }
00089 
00090     setting = fors_setting_new(cpl_frameset_get_first(frames));
00091 
00092     cpl_frameset_insert(frames, 
00093                         create_bias("dark_master_bias.fits", 
00094                                     MASTER_BIAS, CPL_FRAME_GROUP_CALIB));
00095     
00096     fors_dark_define_parameters(parameters);
00097     assure( !cpl_error_get_code(), return, 
00098             "Create parameters failed");
00099     
00100     fors_parameterlist_set_defaults(parameters);
00101 
00102     /* Call recipe */
00103     fors_dark(frames, parameters);
00104     assure( !cpl_error_get_code(), return, 
00105             "Execution error");
00106 
00107     /* Test results */
00108     {
00109         /* New and previous frames */
00110         test( cpl_frameset_find(frames, MASTER_DARK) != NULL );
00111         test( cpl_frameset_find(frames, MASTER_BIAS) != NULL );
00112         test( cpl_frameset_find(frames, DARK) != NULL );
00113         
00114         master_dark = fors_image_load(
00115             cpl_frameset_find(frames, MASTER_DARK), NULL, setting, NULL);
00116         
00117         master_bias = fors_image_load(
00118             cpl_frameset_find(frames, MASTER_BIAS), NULL, setting, NULL);
00119         
00120         raw_dark    = fors_image_load(
00121             cpl_frameset_find(frames, DARK), NULL, setting, NULL);
00122         
00123         /* Verify relation
00124            master_dark = raw_dark - master_bias */
00125         test_rel( fors_image_get_mean(master_dark, NULL),
00126                   fors_image_get_mean(raw_dark, NULL) -
00127                   fors_image_get_mean(master_bias, NULL),
00128                   0.01);
00129 
00130         /* Verify that relative error decreased  */
00131         {
00132             test( fors_image_get_error_mean(master_dark, NULL) /
00133                   (fors_image_get_mean(master_dark, NULL) +
00134                    fors_image_get_mean(master_bias, NULL))
00135                   <
00136                   fors_image_get_error_mean(raw_dark, NULL) /
00137                   fors_image_get_mean(raw_dark, NULL));
00138         }
00139     }
00140 
00141     cleanup;
00142     return;
00143 }
00144 
00148 int main(void)
00149 {
00150     TEST_INIT;
00151     
00152     test_dark();
00153 
00154     TEST_END;
00155 }
00156 

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