fors_img_sky_flat-test.c

00001 /* $Id: fors_img_sky_flat-test.c,v 1.7 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.7 $
00025  * $Name: fors-4_8_6 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 #include <fors_img_sky_flat_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_sflat); \
00053     fors_image_delete(&master_sflat); \
00054     fors_image_delete(&master_bias); \
00055     fors_setting_delete(&setting); \
00056 } while(0)
00057 
00061 static void
00062 test_img_sky_flat(void)
00063 {
00064     /* Input */
00065     cpl_frameset *frames = cpl_frameset_new();
00066     cpl_parameterlist *parameters = cpl_parameterlist_new();
00067 
00068     /* Output */
00069     fors_image *raw_sflat = NULL;
00070     fors_image *master_sflat = NULL;
00071     fors_image *master_bias = NULL;
00072 
00073     fors_setting *setting = NULL;
00074 
00075     /* Simulate data */
00076     const char *sky_flat_filename[] = {"img_sky_flat_1.fits",
00077                                        "img_sky_flat_2.fits",
00078                                        "img_sky_flat_3.fits"};
00079 
00080     double sky_flat_exptime[] = {1, 2, 5};
00081     {
00082         unsigned i;
00083         
00084         for (i = 0; i < sizeof(sky_flat_filename)/sizeof(char *); i++) {
00085             cpl_frame *sflat = create_sky_flat(sky_flat_filename[i],
00086                                                SKY_FLAT_IMG, CPL_FRAME_GROUP_RAW,
00087                                                sky_flat_exptime[i]);
00088 
00089             cpl_frame_set_group(sflat, CPL_FRAME_GROUP_RAW);
00090             cpl_frameset_insert(frames, sflat);
00091         }
00092     }
00093     
00094     setting = fors_setting_new(cpl_frameset_get_first(frames));
00095     
00096     cpl_frameset_insert(frames, 
00097                         create_bias("img_sky_flat_master_bias.fits", 
00098                                     MASTER_BIAS, CPL_FRAME_GROUP_CALIB));
00099 
00100     fors_img_sky_flat_define_parameters(parameters);
00101     assure( !cpl_error_get_code(), return, 
00102             "Create parameters failed");
00103     
00104     fors_parameterlist_set_defaults(parameters);
00105 
00106     /* Call recipe */
00107     fors_img_sky_flat(frames, parameters);
00108     assure( !cpl_error_get_code(), return, 
00109             "Execution error");
00110 
00111     /* Test results */
00112 
00113     /* Existence */
00114     const char *const product_tags[] = {MASTER_SKY_FLAT_IMG};
00115     const char *const qc[] = {"QC OVEREXPO"};
00116     test_recipe_output(frames,
00117                        product_tags, sizeof product_tags / sizeof *product_tags,
00118                MASTER_SKY_FLAT_IMG,
00119                        qc, sizeof qc / sizeof *qc);
00120     
00121     /* Numbers */
00122     {
00123         /* New and previous frames */
00124         test( cpl_frameset_find(frames, MASTER_BIAS) != NULL );
00125         test( cpl_frameset_find(frames, SKY_FLAT_IMG) != NULL );
00126         
00127         master_sflat = fors_image_load(
00128             cpl_frameset_find(frames, MASTER_SKY_FLAT_IMG), NULL, setting, NULL);
00129         
00130         master_bias  = fors_image_load(
00131             cpl_frameset_find(frames, MASTER_BIAS), NULL, setting, NULL);
00132         
00133         raw_sflat    = fors_image_load(
00134             cpl_frameset_find(frames, SKY_FLAT_IMG), NULL, setting, NULL);
00135         
00136         /* Verify that relative error decreased  */
00137         test( fors_image_get_error_mean(master_sflat, NULL) /
00138               fors_image_get_mean(master_sflat, NULL) 
00139               <
00140               fors_image_get_error_mean(raw_sflat, NULL) /
00141               fors_image_get_mean(raw_sflat, NULL));
00142 
00143         /* Verify normalization */
00144         test_rel( fors_image_get_mean(master_sflat, NULL),
00145                   1.0, 0.01);
00146     }
00147 
00148     cleanup;
00149     return;
00150 }
00151 
00155 int main(void)
00156 {
00157     TEST_INIT;
00158     
00159     test_img_sky_flat();
00160 
00161     TEST_END;
00162 }
00163 

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