22#include "../hdrl_cat_casu.h"
25#define COMP_TOL_REL 1e-4
26#define COMP_TOL_ABS 1e-2
27#define IMG_XSIZE 110 * 2
28#define IMG_YSIZE 150 * 2
30#define APER_FLUX_NUM "Aper_flux_3"
33#define BIASES {2., 100., 5000., 5.e4, 5.e5}
34#define FACTORS {2., 10., 100., 1.e4, 1.e6}
49cpl_error_code hdrl_casumul_compute(
double factor)
52 hdrl_casu_result *res1 = cpl_calloc(1,
sizeof(hdrl_casu_result));
53 hdrl_casu_result *res_p2 = cpl_calloc(1,
sizeof(hdrl_casu_result));
55 CELL_SIZE, 6, 1.0, 2.0, HDRL_SATURATION_INIT, res1), CPL_ERROR_NULL_INPUT);
56 cpl_test_error(CPL_ERROR_NULL_INPUT);
57 cpl_test_null( res1->catalogue);
59 cpl_image_delete( res1->segmentation_map);
60 cpl_image_delete( res1->background);
64 cpl_image *bkg = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
65 cpl_image *im = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
66 cpl_image *cnf = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
69 double norm2 = 2. * CPL_MATH_PI * sigma * sigma;
70 cpl_image_fill_noise_uniform(bkg, -10., 10.);
73 cpl_image_add_scalar(bkg, sky);
74 cpl_image_fill_noise_uniform(cnf, 99.9, 100.1);
79 cpl_image_fill_gaussian(im, xpos, ypos, norm * norm2, sigma, sigma);
80 cpl_image_add(bkg, im);
84 cpl_image *bkg2 = cpl_image_duplicate(bkg);
85 cpl_image_multiply_scalar(bkg2, factor);
93 cpl_propertylist_update_string(pl,
"CTYPE1",
"RA---TAN" );
94 cpl_propertylist_update_string(pl,
"CTYPE2",
"DEC--TAN" );
95 cpl_propertylist_update_double(pl,
"CRVAL1", 30. );
96 cpl_propertylist_update_double(pl,
"CRVAL2", 12. );
97 cpl_propertylist_update_double(pl,
"CRPIX1", 512. );
98 cpl_propertylist_update_double(pl,
"CRPIX2", 512. );
99 cpl_propertylist_update_double(pl,
"CD1_1", -1. / 3600.);
100 cpl_propertylist_update_double(pl,
"CD1_2", 0. );
101 cpl_propertylist_update_double(pl,
"CD2_1", 0. );
102 cpl_propertylist_update_double(pl,
"CD2_2", 1. / 3600.);
103 cpl_propertylist_update_int( pl,
"NAXIS1", IMG_XSIZE );
104 cpl_propertylist_update_int( pl,
"NAXIS2", IMG_YSIZE );
105 cpl_wcs *wcs = cpl_wcs_new_from_propertylist(pl);
108 hdrl_casu_result * res2 = cpl_calloc(1,
sizeof(hdrl_casu_result));
110 CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res2), CPL_ERROR_NONE);
111 cpl_test_nonnull(res2->catalogue);
116 CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res_p2), CPL_ERROR_NONE);
117 cpl_test_nonnull(res_p2->catalogue);
125 cpl_test_image_rel(res2->segmentation_map, res_p2->segmentation_map, COMP_TOL_REL);
128 cpl_test_nonnull(tab);
131 cpl_test_nonnull(tab_p2);
134 cpl_test_rel( cpl_table_get_double(tab, APER_FLUX_NUM, 0, &nl),
135 cpl_table_get_double(tab_p2, APER_FLUX_NUM, 0, &nl) / factor, COMP_TOL_REL );
136 cpl_test_rel( cpl_table_get_double(tab,
"Isophotal_flux", 0, &nl),
137 cpl_table_get_double(tab_p2,
"Isophotal_flux", 0, &nl) / factor, COMP_TOL_REL );
138 cpl_test_rel( cpl_table_get_double(tab,
"FWHM", 0, &nl),
139 cpl_table_get_double(tab_p2,
"FWHM", 0, &nl), COMP_TOL_REL );
140 cpl_test_rel( cpl_table_get_double(tab,
"Kron_radius", 0, &nl),
141 cpl_table_get_double(tab_p2,
"Kron_radius", 0, &nl), COMP_TOL_REL );
142 cpl_test_eq ( cpl_table_get_double(tab,
"Classification", 0, &nl),
143 cpl_table_get_double(tab_p2,
"Classification", 0, &nl) );
144 cpl_test_rel( cpl_table_get_double(tab,
"X_coordinate", 0, &nl),
145 cpl_table_get_double(tab_p2,
"X_coordinate", 0, &nl), COMP_TOL_REL );
146 cpl_test_abs( cpl_table_get_double(tab,
"X_coordinate_err", 0, &nl),
147 cpl_table_get_double(tab_p2,
"X_coordinate_err", 0, &nl), COMP_TOL_ABS );
148 cpl_test_rel( cpl_table_get_double(tab,
"Y_coordinate", 0, &nl),
149 cpl_table_get_double(tab_p2,
"Y_coordinate", 0, &nl), COMP_TOL_REL );
150 cpl_test_abs( cpl_table_get_double(tab,
"Y_coordinate_err", 0, &nl),
151 cpl_table_get_double(tab_p2,
"Y_coordinate_err", 0, &nl), COMP_TOL_ABS );
154 cpl_image_delete( res2->segmentation_map);
155 cpl_image_delete( res2->background);
159 cpl_image_delete( res_p2->segmentation_map);
160 cpl_image_delete( res_p2->background);
165 return cpl_error_get_code();
177cpl_error_code hdrl_casuadd_compute(
double bias)
180 hdrl_casu_result *res1 = cpl_calloc(1,
sizeof(hdrl_casu_result));
181 hdrl_casu_result *res_p2 = cpl_calloc(1,
sizeof(hdrl_casu_result));
183 CELL_SIZE, 6, 1., 2., HDRL_SATURATION_INIT, res1), CPL_ERROR_NULL_INPUT);
184 cpl_test_error(CPL_ERROR_NULL_INPUT);
185 cpl_test_null(res1->catalogue);
187 cpl_image_delete( res1->segmentation_map);
188 cpl_image_delete( res1->background);
192 cpl_image *bkg = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
193 cpl_image *im = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
194 cpl_image *cnf = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
197 double norm2 = 2. * CPL_MATH_PI * sigma * sigma;
198 cpl_image_fill_noise_uniform(bkg, -10., 10.);
201 cpl_image_add_scalar(bkg, sky);
203 cpl_image_fill_noise_uniform(cnf, 99.9, 100.1);
208 cpl_image_fill_gaussian(im, xpos, ypos, norm * norm2, sigma, sigma);
209 cpl_image_add(bkg, im);
210 cpl_image_delete(im);
213 cpl_image *bkg2 = cpl_image_duplicate(bkg);
214 cpl_image_add_scalar(bkg2, bias);
222 cpl_propertylist_update_string(pl,
"CTYPE1",
"RA---TAN" );
223 cpl_propertylist_update_string(pl,
"CTYPE2",
"DEC--TAN" );
224 cpl_propertylist_update_double(pl,
"CRVAL1", 30. );
225 cpl_propertylist_update_double(pl,
"CRVAL2", 12. );
226 cpl_propertylist_update_double(pl,
"CRPIX1", 512. );
227 cpl_propertylist_update_double(pl,
"CRPIX2", 512. );
228 cpl_propertylist_update_double(pl,
"CD1_1", -1. / 3600.);
229 cpl_propertylist_update_double(pl,
"CD1_2", 0. );
230 cpl_propertylist_update_double(pl,
"CD2_1", 0. );
231 cpl_propertylist_update_double(pl,
"CD2_2", 1. / 3600.);
232 cpl_propertylist_update_int( pl,
"NAXIS1", IMG_XSIZE );
233 cpl_propertylist_update_int( pl,
"NAXIS2", IMG_YSIZE );
234 cpl_wcs *wcs = cpl_wcs_new_from_propertylist(pl);
237 hdrl_casu_result *res2 = cpl_calloc(1,
sizeof(hdrl_casu_result));
239 CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res2), CPL_ERROR_NONE);
240 cpl_test_nonnull(res2->catalogue);
245 CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res_p2), CPL_ERROR_NONE);
246 cpl_test_nonnull(res_p2->catalogue);
254 cpl_test_image_rel(res2->segmentation_map, res_p2->segmentation_map, COMP_TOL_REL);
257 cpl_test_nonnull(tab);
260 cpl_test_nonnull(tab_p2);
262 cpl_test_rel( cpl_table_get_double(tab, APER_FLUX_NUM, 0, &nl),
263 cpl_table_get_double(tab_p2, APER_FLUX_NUM, 0, &nl), COMP_TOL_REL );
264 cpl_test_rel( cpl_table_get_double(tab,
"Isophotal_flux", 0, &nl),
265 cpl_table_get_double(tab_p2,
"Isophotal_flux", 0, &nl), COMP_TOL_REL );
266 cpl_test_rel( cpl_table_get_double(tab,
"FWHM", 0, &nl),
267 cpl_table_get_double(tab_p2,
"FWHM", 0, &nl), COMP_TOL_REL );
268 cpl_test_rel( cpl_table_get_double(tab,
"Kron_radius", 0, &nl),
269 cpl_table_get_double(tab_p2,
"Kron_radius", 0, &nl), COMP_TOL_REL );
270 cpl_test_eq ( cpl_table_get_double(tab,
"Classification", 0, &nl),
271 cpl_table_get_double(tab_p2,
"Classification", 0, &nl) );
272 cpl_test_rel( cpl_table_get_double(tab,
"X_coordinate", 0, &nl),
273 cpl_table_get_double(tab_p2,
"X_coordinate", 0, &nl), COMP_TOL_REL );
274 cpl_test_abs( cpl_table_get_double(tab,
"X_coordinate_err", 0, &nl),
275 cpl_table_get_double(tab_p2,
"X_coordinate_err", 0, &nl), COMP_TOL_ABS );
276 cpl_test_rel( cpl_table_get_double(tab,
"Y_coordinate", 0, &nl),
277 cpl_table_get_double(tab_p2,
"Y_coordinate", 0, &nl), COMP_TOL_REL );
278 cpl_test_abs( cpl_table_get_double(tab,
"Y_coordinate_err", 0, &nl),
279 cpl_table_get_double(tab_p2,
"Y_coordinate_err", 0, &nl), COMP_TOL_ABS );
282 cpl_image_delete( res2->segmentation_map);
283 cpl_image_delete( res2->background);
287 cpl_image_delete( res_p2->segmentation_map);
288 cpl_image_delete( res_p2->background);
293 return cpl_error_get_code();
304 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
306 double bias[] = BIASES;
307 for (cpl_size i = 0; i < NUM_BIASES; i++) {
308 hdrl_casuadd_compute(bias[i]);
311 double factor[] = FACTORS;
312 for (cpl_size i = 0; i < NUM_FACTORS; i++) {
313 hdrl_casumul_compute(factor[i]);
316 cpl_test_error(CPL_ERROR_NONE);
318 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.