22#include "../hdrl_cat_casu.h"
26#define COMP_TOLERANCE 1e-2
27#define CORNER_OFFSET 10
28#define CORNER_REL_TOL 1e-2
38#define APER_FLUX_NUM "Aper_flux_3"
50cpl_error_code hdrl_casubkg_badpatch_compute(
void)
52 double xpos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
53 double ypos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
54 double norm[] = {1000., 100., 200., 500., 550., 600., 650., 700., 750., 800.};
57 hdrl_casu_result *res = cpl_calloc(1,
sizeof(hdrl_casu_result));
58 hdrl_casu_result *res_p1 = cpl_calloc(1,
sizeof(hdrl_casu_result));
59 hdrl_casu_result *res_p2 = cpl_calloc(1,
sizeof(hdrl_casu_result));
61 6, 1.0, 2.0, HDRL_SATURATION_INIT, res), CPL_ERROR_NULL_INPUT);
62 cpl_test_error(CPL_ERROR_NULL_INPUT);
63 cpl_test_null(res->catalogue);
65 cpl_image_delete(res->segmentation_map);
66 cpl_image_delete(res->background);
71 cpl_image *bkg = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
72 cpl_image *im = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
73 cpl_image *cnf = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
74 cpl_image *aux = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
77 double norm2 = 2. * CPL_MATH_PI * sigma * sigma;
78 cpl_image_fill_noise_uniform(bkg, -10., 10.);
81 cpl_image_add_scalar(bkg, sky);
83 cpl_image_fill_noise_uniform(cnf, 99.9, 100.1);
84 cpl_image *cnf_p1 = cpl_image_duplicate(cnf);
85 cpl_image *cnf_p2 = cpl_image_duplicate(cnf);
88 for (cpl_size i = 0; i < NTEST; i++) {
89 cpl_image_fill_gaussian(im, xpos[i], ypos[i], norm[i] * norm2, sigma, sigma);
90 tot[i] = cpl_image_get_flux(im);
91 cpl_image_add(bkg, im);
96 double dlt_ramp = MAX_RAMP - MIN_RAMP;
97 for (cpl_size i = 1; i <= IMG_XSIZE; i++) {
98 for (cpl_size j = 1; j <= IMG_YSIZE; j++) {
99 cpl_image_set(aux, i, j, MIN_RAMP + dlt_ramp * (
double)i / IMG_XSIZE);
102 cpl_image_add(bkg, aux);
103 cpl_image_delete(aux);
108 cpl_size x_os = X_OS_P1;
109 for (cpl_size i = 0; i <= PATCH_SIZE; i++) {
110 for (cpl_size j = 0; j <= PATCH_SIZE; j++) {
111 cpl_image_set(cnf_p1, xpos[STAR]-(PATCH_SIZE/2)+i +x_os,
112 ypos[STAR]-(PATCH_SIZE/2)+j +y_os, 0);
118 for (cpl_size i = 0; i <= PATCH_SIZE; i++) {
119 for (cpl_size j = 0; j <= PATCH_SIZE; j++) {
120 cpl_image_set(cnf_p2, xpos[STAR]-(PATCH_SIZE/2)+i +x_os,
121 ypos[STAR]-(PATCH_SIZE/2)+j +y_os, 0);
132 cpl_propertylist_update_string(pl,
"CTYPE1",
"RA---TAN" );
133 cpl_propertylist_update_string(pl,
"CTYPE2",
"DEC--TAN" );
134 cpl_propertylist_update_double(pl,
"CRVAL1", 30. );
135 cpl_propertylist_update_double(pl,
"CRVAL2", 12. );
136 cpl_propertylist_update_double(pl,
"CRPIX1", 512. );
137 cpl_propertylist_update_double(pl,
"CRPIX2", 512. );
138 cpl_propertylist_update_double(pl,
"CD1_1", -1. / 3600.);
139 cpl_propertylist_update_double(pl,
"CD1_2", 0. );
140 cpl_propertylist_update_double(pl,
"CD2_1", 0. );
141 cpl_propertylist_update_double(pl,
"CD2_2", 1. / 3600.);
142 cpl_propertylist_update_int( pl,
"NAXIS1", IMG_XSIZE );
143 cpl_propertylist_update_int( pl,
"NAXIS2", IMG_YSIZE );
144 cpl_wcs *wcs = cpl_wcs_new_from_propertylist(pl);
147 res = cpl_calloc(1,
sizeof(hdrl_casu_result));
149 CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res), CPL_ERROR_NONE);
150 cpl_test_nonnull(res->catalogue);
155 CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res_p1), CPL_ERROR_NONE);
156 cpl_test_nonnull(res_p1->catalogue);
161 CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res_p2), CPL_ERROR_NONE);
162 cpl_test_nonnull(res_p2->catalogue);
169 cpl_test_image_rel(res->background, res_p1->background, COMP_TOLERANCE);
170 cpl_test_image_rel(res->background, res_p2->background, COMP_TOLERANCE);
172 cpl_size corner_x = cpl_image_get_size_x(res->background) -CORNER_OFFSET;
173 cpl_size corner_y = cpl_image_get_size_y(res->background) -CORNER_OFFSET;
176 cpl_test_abs(cpl_image_get(res ->background, corner_x, corner_y, &rej),
177 cpl_image_get(res_p1->background, corner_x, corner_y, &rej), CORNER_REL_TOL);
178 cpl_test_abs(cpl_image_get(res ->background, corner_x, corner_y, &rej),
179 cpl_image_get(res_p2->background, corner_x, corner_y, &rej), CORNER_REL_TOL);
181 cpl_test_image_rel(res->segmentation_map, res_p1->segmentation_map, COMP_TOLERANCE);
182 cpl_test_image_rel(res->segmentation_map, res_p2->segmentation_map, COMP_TOLERANCE);
189 cpl_test_nonnull(tab);
190 cpl_test_nonnull(tab_p1);
191 cpl_test_nonnull(tab_p2);
194 for (cpl_size i = 0; i < NTEST; i++) {
195 cpl_test_rel( cpl_table_get_double(tab, APER_FLUX_NUM, i, &nl),
196 cpl_table_get_double(tab_p1, APER_FLUX_NUM, i, &nl), COMP_TOLERANCE );
197 cpl_test_rel( cpl_table_get_double(tab, APER_FLUX_NUM, i, &nl),
198 cpl_table_get_double(tab_p2, APER_FLUX_NUM, i, &nl), COMP_TOLERANCE );
201 cpl_test_eq(cpl_table_get_ncol(tab), 63);
202 cpl_test_eq(cpl_table_get_nrow(tab), NTEST);
203 pl = cpl_propertylist_new();
204 cpl_propertylist_append_bool(pl,
"X_coordinate", 0);
205 cpl_table_sort(tab, pl);
206 cpl_propertylist_delete(pl);
209 for (cpl_size i = 0; i < NTEST; i++) {
210 cpl_test_abs(xpos[i], cpl_table_get_double(tab,
"X_coordinate", i, &nl), 0.2);
211 cpl_test_abs(ypos[i], cpl_table_get_double(tab,
"Y_coordinate", i, &nl), 0.2);
212 double diff = fabs( cpl_table_get_double(tab,
"Aper_flux_5", i, &nl) -tot[i])
213 / cpl_table_get_double(tab,
"Aper_flux_5_err", i, &nl);
214 cpl_test_lt(diff, 1.5);
215 cpl_test_eq( cpl_table_get_double(tab,
"Classification", i, &nl), -1.);
219 cpl_image_delete( res->segmentation_map);
220 cpl_image_delete( res->background);
224 cpl_image_delete( res_p1->segmentation_map);
225 cpl_image_delete( res_p1->background);
229 cpl_image_delete( res_p2->segmentation_map);
230 cpl_image_delete( res_p2->background);
235 return cpl_error_get_code();
245 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
247 hdrl_casubkg_badpatch_compute();
249 cpl_test_error(CPL_ERROR_NONE);
251 return cpl_test_end(0);
hdrl_casu_fits * hdrl_casu_fits_wrap(cpl_image *im)
Wrap an image in a hdrl_casu_fits wrapper.
void hdrl_casu_tfits_delete(hdrl_casu_tfits *p)
Free all the workspace associated with a hdrl_casu_fits object.
void hdrl_casu_fits_delete(hdrl_casu_fits *p)
Free all the workspace associated with a hdrl_casu_fits object.
cpl_table * hdrl_casu_tfits_get_table(hdrl_casu_tfits *p)
Get the CPL table from the hdrl_casu_tfits object.
cpl_propertylist * hdrl_casu_fits_get_ehu(hdrl_casu_fits *p)
Get the propertylist for the extension header for a given hdrl_casu_fits image.
cpl_error_code hdrl_casu_catalogue(hdrl_casu_fits *infile, hdrl_casu_fits *conf, const cpl_wcs *wcs, cpl_size ipix, double threshold, cpl_size icrowd, double rcore, cpl_size bkg_subtr, cpl_size nbsize, hdrl_catalogue_options cattype, double filtfwhm, double gainloc, double saturation, hdrl_casu_result *res)
Generate object catalogues from input images.