00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00038 #include <test_simulate.h>
00039 #include <test.h>
00040
00048 #undef cleanup
00049 #define cleanup \
00050 do { \
00051 cpl_frame_delete(raw_frame); \
00052 cpl_frameset_delete(cat_frames); \
00053 cpl_frame_delete(phot_table); \
00054 fors_setting_delete(&setting); \
00055 cpl_parameterlist_delete(parameters); \
00056 fors_identify_method_delete(&im); \
00057 fors_std_star_list_delete(&cat, fors_std_star_delete); \
00058 fors_std_star_list_delete(&cat, fors_std_star_delete); \
00059 fors_star_list_delete(&stars, fors_star_delete); \
00060 fors_star_list_delete(&stars_id, fors_star_delete); \
00061 } while(0)
00062
00066 static void
00067 test_identify(void)
00068 {
00069 identify_method *im = NULL;
00070 cpl_parameterlist *parameters = cpl_parameterlist_new();
00071 const char * const context = "test";
00072 fors_star_list *stars = NULL;
00073 fors_star_list *stars_id = NULL;
00074 fors_std_star_list *cat = NULL;
00075 fors_setting *setting = NULL;
00076 cpl_frame *raw_frame = NULL;
00077 cpl_frame *phot_table = NULL;
00078 double color_term, dcolor_term;
00079 double ext_coeff, dext_coeff;
00080
00081
00082 cpl_frameset *cat_frames = cpl_frameset_new();
00083 cpl_frameset_insert(cat_frames, create_std_cat("identify_std_cat.fits",
00084 FLX_STD_IMG,
00085 CPL_FRAME_GROUP_CALIB));
00086
00087 fors_identify_define_parameters(parameters, context);
00088 fors_parameterlist_set_defaults(parameters);
00089
00090 im = fors_identify_method_new(parameters, context);
00091 assure( !cpl_error_get_code(), return,
00092 "Could not get identification parameters");
00093
00094 raw_frame = create_standard("identify_std_img.fits",
00095 STANDARD_IMG, CPL_FRAME_GROUP_RAW);
00096
00097 phot_table = create_phot_table("identify_phot_table.fits",
00098 PHOT_TABLE, CPL_FRAME_GROUP_CALIB);
00099
00100 setting = fors_setting_new(raw_frame);
00101
00102 fors_phot_table_load(phot_table, setting,
00103 &color_term, &dcolor_term,
00104 &ext_coeff, &dext_coeff,
00105 NULL, NULL);
00106
00107
00108 cat = fors_std_cat_load(cat_frames, raw_frame, setting, color_term, dcolor_term);
00109 assure( !cpl_error_get_code(), return, NULL );
00110
00111 stars = fors_star_list_new();
00112 stars_id = fors_star_list_new();
00113
00114
00115
00116
00117 {
00118 fors_std_star *s;
00119 double sigma = 0.1;
00120 double offsetx = 60;
00121 double offsety = -100;
00122 double semi_major = 1.0;
00123 double semi_minor = 1.0;
00124 double fwhm = 3;
00125 double orientation = 0;
00126 double stellarity = 1.0;
00127
00128 for (s = fors_std_star_list_first(cat);
00129 s != NULL;
00130 s = fors_std_star_list_next(cat)) {
00131
00132 fors_star *source =
00133 fors_star_new(
00134 s->pixel->x + offsetx + sigma * fors_rand_gauss(),
00135 s->pixel->y + offsety + sigma * fors_rand_gauss(),
00136 fwhm,
00137 semi_major,
00138 semi_minor,
00139 orientation,
00140 - s->magnitude,
00141 s->dmagnitude,
00142 stellarity);
00143
00144
00145 if (0) {
00146 double temp = source->pixel->x;
00147 source->pixel->x = source->pixel->y;
00148 source->pixel->y = -temp;
00149 }
00150
00151
00152
00153
00154
00155 fors_star_list_insert(stars, source);
00156
00157 fors_star *source_id = fors_star_duplicate(source);
00158
00159 source_id->id = fors_std_star_duplicate(s);
00160 fors_star_list_insert(stars_id, source_id);
00161 }
00162 }
00163
00164
00165 fors_identify(stars, cat, im);
00166
00167
00168
00169
00170
00171
00172 {
00173 fors_star *star;
00174 int id = 0;
00175 int tot = 0;
00176
00177 for (star = fors_star_list_first(stars);
00178 star != NULL;
00179 star = fors_star_list_next(stars))
00180 {
00181 if (star->id != NULL) {
00182 id++;
00183
00184
00185
00186 fors_star_list *input =
00187 fors_star_list_extract(stars_id, fors_star_duplicate,
00188 (fors_star_list_func_predicate) fors_star_equal,
00189 star);
00190
00191 test_eq( fors_star_list_size(input), 1 );
00192
00193 fors_star *input1 = fors_star_list_first(input);
00194
00195 test( fors_std_star_equal(star->id, input1->id) );
00196
00197 fors_star_list_delete(&input, fors_star_delete);
00198 }
00199 tot++;
00200 }
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 }
00216
00217
00218
00219
00220 {
00221 fors_star *star;
00222
00223 for (star = fors_star_list_first(stars);
00224 star != NULL;
00225 star = fors_star_list_next(stars)) {
00226
00227 double temp = star->pixel->x;
00228 star->pixel->x = star->pixel->y;
00229 star->pixel->y = temp;
00230
00231
00232 if (star->id != NULL) {
00233 fors_std_star_delete_const(&(star->id));
00234 }
00235 }
00236 }
00237
00238
00239 {
00240 cpl_msg_severity before = cpl_msg_get_level();
00241 cpl_msg_set_level(CPL_MSG_ERROR);
00242
00243 fors_identify(stars, cat, im);
00244
00245 cpl_msg_set_level(before);
00246 }
00247
00248 {
00249 fors_star *star;
00250
00251 for (star = fors_star_list_first(stars);
00252 star != NULL;
00253 star = fors_star_list_next(stars)) {
00254
00255 test( star->id == NULL );
00256 }
00257 }
00258
00259 cleanup;
00260 return;
00261 }
00262
00263
00267 int main(void)
00268 {
00269 TEST_INIT;
00270
00271
00272 test_identify();
00273
00274 TEST_END;
00275 }
00276