FORS Pipeline Reference Manual 4.9.20
|
00001 /* $Id: fors_identify-test.c,v 1.30 2011/05/10 07:29:10 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: 2011/05/10 07:29:10 $ 00024 * $Revision: 1.30 $ 00025 * $Name: fors-4_9_20 $ 00026 */ 00027 00028 #ifdef HAVE_CONFIG_H 00029 #include <config.h> 00030 #endif 00031 00032 #include <fors_identify.h> 00033 #include <fors_setting.h> 00034 #include <fors_data.h> 00035 #include <fors_dfs.h> 00036 #include <fors_utils.h> 00037 #include <fors_instrument.h> 00038 #include <fors_std_cat.h> 00039 00040 #include <test_simulate.h> 00041 #include <test.h> 00042 00050 #undef cleanup 00051 #define cleanup \ 00052 do { \ 00053 cpl_frame_delete(raw_frame); \ 00054 cpl_frameset_delete(cat_frames); \ 00055 cpl_frame_delete(phot_table); \ 00056 fors_setting_delete(&setting); \ 00057 cpl_parameterlist_delete(parameters); \ 00058 fors_identify_method_delete(&im); \ 00059 fors_std_star_list_delete(&cat, fors_std_star_delete); \ 00060 fors_std_star_list_delete(&cat, fors_std_star_delete); \ 00061 fors_star_list_delete(&stars, fors_star_delete); \ 00062 fors_star_list_delete(&stars_id, fors_star_delete); \ 00063 cpl_propertylist_delete(raw_header); raw_header = NULL; \ 00064 } while(0) 00065 00069 static void 00070 test_identify(void) 00071 { 00072 identify_method *im = NULL; 00073 cpl_parameterlist *parameters = cpl_parameterlist_new(); 00074 const char * const context = "test"; 00075 fors_star_list *stars = NULL; 00076 fors_star_list *stars_id = NULL; 00077 fors_std_star_list *cat = NULL; 00078 fors_setting *setting = NULL; 00079 cpl_frame *raw_frame = NULL; 00080 cpl_frame *phot_table = NULL; 00081 cpl_propertylist *raw_header = NULL; 00082 double color_term, dcolor_term; 00083 double ext_coeff, dext_coeff; 00084 char band; 00085 00086 /* Simulate data */ 00087 cpl_frameset *cat_frames = cpl_frameset_new(); 00088 cpl_frameset_insert(cat_frames, create_std_cat("identify_std_cat.fits", 00089 FLX_STD_IMG, 00090 CPL_FRAME_GROUP_CALIB)); 00091 00092 fors_identify_define_parameters(parameters, context); 00093 fors_parameterlist_set_defaults(parameters); 00094 00095 im = fors_identify_method_new(parameters, context); 00096 assure( !cpl_error_get_code(), return, 00097 "Could not get identification parameters"); 00098 00099 raw_frame = create_standard("identify_std_img.fits", 00100 STANDARD_IMG, CPL_FRAME_GROUP_RAW); 00101 00102 phot_table = create_phot_table("identify_phot_table.fits", 00103 PHOT_TABLE, CPL_FRAME_GROUP_CALIB); 00104 00105 setting = fors_setting_new(raw_frame); 00106 00107 fors_phot_table_load(phot_table, setting, 00108 &color_term, &dcolor_term, 00109 &ext_coeff, &dext_coeff, 00110 NULL, NULL); 00111 00112 /* Use catalogue list of stars as 'detected' sources */ 00113 band = fors_instrument_filterband_get_by_setting(setting); 00114 cat = fors_std_cat_load(cat_frames, band, 0, color_term, dcolor_term); 00115 assure( !cpl_error_get_code(), return, NULL ); 00116 00117 raw_header = cpl_propertylist_load(cpl_frame_get_filename(raw_frame), 0); 00118 assure( !cpl_error_get_code(), return, NULL ); 00119 fors_std_star_list_apply_wcs(cat, raw_header); 00120 assure( !cpl_error_get_code(), return, NULL ); 00121 00122 stars = fors_star_list_new(); 00123 stars_id = fors_star_list_new(); /* Reference list of expected results */ 00124 00125 /* Add offset + noise to positions, 00126 rotate 90 degrees 00127 */ 00128 { 00129 fors_std_star *s; 00130 double sigma = 0.1; /* pixels */ 00131 double offsetx = 60; /* pixels */ 00132 double offsety = -100; /* pixels */ 00133 double semi_major = 1.0; 00134 double semi_minor = 1.0; 00135 double fwhm = 3; 00136 double orientation = 0; 00137 double stellarity = 1.0; /* Presumably catalog objects are stars */ 00138 00139 for (s = fors_std_star_list_first(cat); 00140 s != NULL; 00141 s = fors_std_star_list_next(cat)) { 00142 00143 fors_star *source = 00144 fors_star_new( 00145 s->pixel->x + offsetx + sigma * fors_rand_gauss(), 00146 s->pixel->y + offsety + sigma * fors_rand_gauss(), 00147 fwhm, 00148 semi_major, 00149 semi_minor, 00150 orientation, 00151 - s->magnitude, 00152 s->dmagnitude, 00153 stellarity); 00154 00155 /* Rotate */ 00156 if (0) /* not supported by the implementation */ { 00157 double temp = source->pixel->x; 00158 source->pixel->x = source->pixel->y; 00159 source->pixel->y = -temp; 00160 } 00161 00162 /* 00163 printf("Inserisce in stars source (%2f,%2f)\n", s->pixel->x, s->pixel->y); 00164 printf(" deviata a %2f %2f ------> (%2f,%2f)\n", offsetx, offsety, source->pixel->x, source->pixel->y); 00165 */ 00166 fors_star_list_insert(stars, source); 00167 00168 fors_star *source_id = fors_star_duplicate(source); 00169 00170 source_id->id = fors_std_star_duplicate(s); 00171 fors_star_list_insert(stars_id, source_id); 00172 } 00173 } 00174 00175 /* Call function */ 00176 fors_identify(stars, cat, im, NULL); 00177 00178 /* Verify that 00179 * stars identifications 00180 * match 00181 * stars_id 00182 */ 00183 { 00184 fors_star *star; 00185 int id = 0; 00186 int tot = 0; 00187 00188 for (star = fors_star_list_first(stars); 00189 star != NULL; 00190 star = fors_star_list_next(stars)) 00191 { 00192 if (star->id != NULL) { 00193 id++; 00194 00195 /* Find corresponding input star and verify that the id 00196 is correct */ 00197 fors_star_list *input = 00198 fors_star_list_extract(stars_id, fors_star_duplicate, 00199 (fors_star_list_func_predicate) fors_star_equal, 00200 star); 00201 00202 test_eq( fors_star_list_size(input), 1 ); 00203 00204 fors_star *input1 = fors_star_list_first(input); 00205 00206 test( fors_std_star_equal(star->id, input1->id) ); 00207 00208 fors_star_list_delete(&input, fors_star_delete); 00209 } 00210 tot++; 00211 } 00212 00213 /* For some reason this test fails as soon as the default search radius 00214 and max search radius in fors_identify.c are set from 5,50 to 20,20. 00215 In the first case 7 out of 8 stars are identified, in the second case 00216 only 2 out of 8 stars are identified. However, stars are correctly 00217 identified in real cases by the pipeline with the 20,20 setting, and 00218 not with the 5,50 setting, therefore this test is disabled until the 00219 error (in the test!) is discovered. 00220 00221 printf("id = %d, tot = %d\n", id, tot); 00222 00223 test( id > tot/2 ); 00224 */ 00225 00226 } 00227 00228 00229 /* Now mirror sources (i.e. switch x and y), 00230 the identification should fail */ 00231 { 00232 fors_star *star; 00233 00234 for (star = fors_star_list_first(stars); 00235 star != NULL; 00236 star = fors_star_list_next(stars)) { 00237 00238 double temp = star->pixel->x; 00239 star->pixel->x = star->pixel->y; 00240 star->pixel->y = temp; 00241 00242 /* reset ID */ 00243 if (star->id != NULL) { 00244 fors_std_star_delete_const(&(star->id)); 00245 } 00246 } 00247 } 00248 00249 /* Call function, suppress warnings */ 00250 { 00251 cpl_msg_severity before = cpl_msg_get_level(); 00252 cpl_msg_set_level(CPL_MSG_ERROR); 00253 00254 fors_identify(stars, cat, im, NULL); 00255 00256 cpl_msg_set_level(before); 00257 } 00258 /* Verify that ID failed */ 00259 { 00260 fors_star *star; 00261 00262 for (star = fors_star_list_first(stars); 00263 star != NULL; 00264 star = fors_star_list_next(stars)) { 00265 00266 test( star->id == NULL ); 00267 } 00268 } 00269 00270 cleanup; 00271 return; 00272 } 00273 00274 00278 int main(void) 00279 { 00280 TEST_INIT; 00281 00282 /* cpl_msg_set_level(CPL_MSG_DEBUG); */ 00283 test_identify(); 00284 00285 TEST_END; 00286 } 00287