FORS Pipeline Reference Manual 4.9.20
|
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: fors-4_9_20 $ 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_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), NULL, setting, NULL); 00153 master_bias = fors_image_load( 00154 cpl_frameset_find(frames, MASTER_BIAS), NULL, setting, NULL); 00155 00156 raw_sflat = fors_image_load( 00157 cpl_frameset_find(frames, SCREEN_FLAT_IMG), master_bias, setting, NULL); 00158 00159 /* Verify that relative error decreased */ 00160 test( fors_image_get_error_mean(master_sflat, NULL) / 00161 fors_image_get_mean(master_sflat, NULL) 00162 < 00163 fors_image_get_error_mean(raw_sflat, NULL) / 00164 fors_image_get_mean(raw_sflat, NULL)); 00165 00166 /* Verify normalization */ 00167 test_rel( fors_image_get_mean(master_sflat, NULL), 00168 1.0, 0.01); 00169 00170 /* Test QC values */ 00171 product_header = 00172 cpl_propertylist_load(cpl_frame_get_filename( 00173 cpl_frameset_find(frames, 00174 MASTER_NORM_FLAT_IMG)), 00175 0); 00176 assure( product_header != NULL, return, NULL ); 00177 00178 00179 test_rel( cpl_propertylist_get_double(product_header, 00180 "ESO QC FLAT EFF"), 00181 fors_image_get_median(raw_sflat, NULL) / setting->exposure_time, 00182 0.01 ); 00183 00184 /* QC.FLAT.PHN is the master flat photon noise in ADU. 00185 But the master flat is normalized to one, so 00186 multiply by the normalization factor */ 00187 /* %%% 00188 test_rel( cpl_propertylist_get_double(product_header, 00189 "ESO QC FLAT PHN"), 00190 fors_image_get_stdev(master_sflat, NULL) * 00191 fors_image_get_median(raw_sflat, NULL), 00192 0.1 ); 00193 %%% */ 00194 00195 00196 /* CONAD */ 00197 test_rel( cpl_propertylist_get_double(product_header, 00198 "ESO QC FLAT CONAD"), 00199 cpl_propertylist_get_double(product_header, 00200 FORS_PFITS_CONAD[0]), 00201 /* Compare with propagated CONAD value */ 00202 0.1); 00203 00204 test( cpl_propertylist_get_double(product_header, 00205 "ESO QC FLAT CONADERR") < 00206 0.1 * cpl_propertylist_get_double(product_header, 00207 "ESO QC FLAT CONAD") ); 00208 } 00209 00210 cleanup; 00211 return; 00212 } 00213 00217 int main(void) 00218 { 00219 TEST_INIT; 00220 00221 test_img_screen_flat(); 00222 00223 TEST_END; 00224 } 00225