fors_stack-test.c

00001 /* $Id: fors_stack-test.c,v 1.9 2008/02/28 15:06:54 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/02/28 15:06:54 $
00024  * $Revision: 1.9 $
00025  * $Name: fors-4_8_6 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 #include <fors_image.h>
00033 #include <fors_stack.h>
00034 #include <fors_dfs.h>
00035 #include <fors_utils.h>
00036 
00037 #include <test_simulate.h>
00038 #include <test.h>
00039 
00046 #undef cleanup
00047 #define cleanup \
00048 do { \
00049     cpl_frameset_delete(raw); \
00050     fors_stack_method_delete(&sm); \
00051     fors_setting_delete(&setting); \
00052     cpl_parameterlist_delete(parameters); \
00053     fors_image_list_delete_const(&ilist, fors_image_delete); \
00054 } while(0)
00055 
00059 static void
00060 test_stack(void)
00061 {
00062     const unsigned N = 3;
00063     const fors_image_list *ilist = NULL;
00064     cpl_frameset *raw = cpl_frameset_new();
00065     fors_setting *setting = NULL;
00066     stack_method *sm = NULL;
00067     fors_image *master = NULL;
00068     const char *master_filename = NULL;
00069     cpl_parameterlist *parameters = NULL;
00070     const char *filename[] = {"stack_bias_1.fits",
00071                               "stack_bias_2.fits",
00072                               "stack_bias_3.fits"};
00073 
00074     const char *method[] = {"average",
00075                             "median",
00076                             "minmax",
00077                             "ksigma"};
00078     unsigned i;
00079 
00080     /* Simulate raw bias */
00081     for (i = 0; i < N; i++) {
00082         cpl_frame *bias;
00083 
00084         bias = create_bias(filename[i], BIAS, CPL_FRAME_GROUP_RAW);
00085 
00086         assure( !cpl_error_get_code(), return, 
00087                 "Create bias %s failed", filename[i] );
00088     
00089         cpl_frameset_insert(raw, bias);
00090     }
00091 
00092     setting = fors_setting_new(cpl_frameset_get_first(raw));
00093 
00094     ilist = fors_image_load_list(raw, NULL, setting, NULL);
00095     assure( ilist != NULL, return, "Loading list failed" );
00096     
00097     test_eq( fors_image_list_size(ilist), 3 );
00098     
00099     /* For each stack method */
00100     for (i = 0; i < 2; i++) {
00101 //fixme: enable these tests    for (i = 0; i < sizeof(method)/sizeof(char *); i++) {
00102         const char *const context = "test";
00103         
00104         parameters = cpl_parameterlist_new();
00105         
00106         fors_stack_define_parameters(parameters, context, "median");
00107         assure( !cpl_error_get_code(), return, 
00108                 "Define parameters" );
00109         
00110         cpl_parameter_set_string(cpl_parameterlist_find(
00111                                      parameters, "test.stack_method"),
00112                                  method[i]);
00113         
00114 
00115         sm = fors_stack_method_new(parameters, context);
00116         
00117         /* Call function */
00118         master = fors_stack_const(ilist, sm);
00119         assure( !cpl_error_get_code(), return, 
00120                 "Could not stack images using method %s", method[i]);
00121 
00122         /* Compare results */
00123         
00124         /* Same level */
00125         test_abs( fors_image_get_mean(master, NULL), 
00126                   fors_image_get_mean(fors_image_list_first_const(ilist), NULL), 1.0);
00127 
00128         /* Test that avg(sigma_i) is consistent with empirical stdev */
00129         test_rel( fors_image_get_stdev(master, NULL), 
00130                   fors_image_get_error_mean(master, NULL), 
00131                   i == 0 ? 0.01 :
00132                   i == 1 ? 0.1 : 0.01);
00133 
00134 
00135         /* Save */
00136         master_filename = cpl_sprintf("stack_master_bias_%s.fits", method[i]);
00137         
00138         fors_image_save(master, NULL, master_filename);
00139         assure( !cpl_error_get_code(), return, 
00140                 "Error saving stacked image to %s", master_filename);
00141 
00142 
00143         fors_stack_method_delete(&sm);
00144         cpl_parameterlist_delete(parameters); parameters = NULL;        
00145         fors_image_delete(&master);                        
00146         cpl_free((void *)master_filename); master_filename = NULL;
00147     }
00148 
00149     cleanup;
00150     return;
00151 }
00152 
00156 int main(void)
00157 {
00158     TEST_INIT;
00159 
00160     /* cpl_msg_set_level(CPL_MSG_DEBUG); */
00161     test_stack();
00162 
00163     TEST_END;
00164 }
00165 

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