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 #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
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
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();
00124
00125
00126
00127
00128 {
00129 fors_std_star *s;
00130 double sigma = 0.1;
00131 double offsetx = 60;
00132 double offsety = -100;
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;
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
00156 if (0) {
00157 double temp = source->pixel->x;
00158 source->pixel->x = source->pixel->y;
00159 source->pixel->y = -temp;
00160 }
00161
00162
00163
00164
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
00176 fors_identify(stars, cat, im);
00177
00178
00179
00180
00181
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
00196
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
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 }
00227
00228
00229
00230
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
00243 if (star->id != NULL) {
00244 fors_std_star_delete_const(&(star->id));
00245 }
00246 }
00247 }
00248
00249
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);
00255
00256 cpl_msg_set_level(before);
00257 }
00258
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
00283 test_identify();
00284
00285 TEST_END;
00286 }
00287