26#include "../hdrl_cat_casu.h"
29#define COMP_TOL_REL 1e-4
30#define COMP_TOL_ABS 1e-2
31#define IMG_XSIZE 110 * 2
32#define IMG_YSIZE 150 * 2
34#define APER_FLUX_NUM "Aper_flux_3"
37#define BIASES {2., 100., 5000., 5.e4, 5.e5}
38#define FACTORS {2., 10., 100., 1.e4, 1.e6}
53cpl_error_code hdrl_casumul_compute(
double factor)
56 hdrl_casu_result *res1 = cpl_calloc(1,
sizeof(hdrl_casu_result));
57 hdrl_casu_result *res_p2 = cpl_calloc(1,
sizeof(hdrl_casu_result));
59 CELL_SIZE, 6, 1.0, 2.0, HDRL_SATURATION_INIT, res1), CPL_ERROR_NULL_INPUT);
60 cpl_test_error(CPL_ERROR_NULL_INPUT);
61 cpl_test_null( res1->catalogue);
63 cpl_image_delete( res1->segmentation_map);
64 cpl_image_delete( res1->background);
68 cpl_image *bkg = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
69 cpl_image *im = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
70 cpl_image *cnf = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
73 double norm2 = 2. * CPL_MATH_PI * sigma * sigma;
74 cpl_image_fill_noise_uniform(bkg, -10., 10.);
77 cpl_image_add_scalar(bkg, sky);
78 cpl_image_fill_noise_uniform(cnf, 99.9, 100.1);
83 cpl_image_fill_gaussian(im, xpos, ypos, norm * norm2, sigma, sigma);
84 cpl_image_add(bkg, im);
88 cpl_image *bkg2 = cpl_image_duplicate(bkg);
89 cpl_image_multiply_scalar(bkg2, factor);
97 cpl_propertylist_update_string(pl,
"CTYPE1",
"RA---TAN" );
98 cpl_propertylist_update_string(pl,
"CTYPE2",
"DEC--TAN" );
99 cpl_propertylist_update_double(pl,
"CRVAL1", 30. );
100 cpl_propertylist_update_double(pl,
"CRVAL2", 12. );
101 cpl_propertylist_update_double(pl,
"CRPIX1", 512. );
102 cpl_propertylist_update_double(pl,
"CRPIX2", 512. );
103 cpl_propertylist_update_double(pl,
"CD1_1", -1. / 3600.);
104 cpl_propertylist_update_double(pl,
"CD1_2", 0. );
105 cpl_propertylist_update_double(pl,
"CD2_1", 0. );
106 cpl_propertylist_update_double(pl,
"CD2_2", 1. / 3600.);
107 cpl_propertylist_update_int( pl,
"NAXIS1", IMG_XSIZE );
108 cpl_propertylist_update_int( pl,
"NAXIS2", IMG_YSIZE );
109 cpl_wcs *wcs = cpl_wcs_new_from_propertylist(pl);
112 hdrl_casu_result * res2 = cpl_calloc(1,
sizeof(hdrl_casu_result));
114 CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res2), CPL_ERROR_NONE);
115 cpl_test_nonnull(res2->catalogue);
120 CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res_p2), CPL_ERROR_NONE);
121 cpl_test_nonnull(res_p2->catalogue);
129 cpl_test_image_rel(res2->segmentation_map, res_p2->segmentation_map, COMP_TOL_REL);
132 cpl_test_nonnull(tab);
135 cpl_test_nonnull(tab_p2);
138 cpl_test_rel( cpl_table_get_double(tab, APER_FLUX_NUM, 0, &nl),
139 cpl_table_get_double(tab_p2, APER_FLUX_NUM, 0, &nl) / factor, COMP_TOL_REL );
140 cpl_test_rel( cpl_table_get_double(tab,
"Isophotal_flux", 0, &nl),
141 cpl_table_get_double(tab_p2,
"Isophotal_flux", 0, &nl) / factor, COMP_TOL_REL );
142 cpl_test_rel( cpl_table_get_double(tab,
"FWHM", 0, &nl),
143 cpl_table_get_double(tab_p2,
"FWHM", 0, &nl), COMP_TOL_REL );
144 cpl_test_rel( cpl_table_get_double(tab,
"Kron_radius", 0, &nl),
145 cpl_table_get_double(tab_p2,
"Kron_radius", 0, &nl), COMP_TOL_REL );
146 cpl_test_eq ( cpl_table_get_double(tab,
"Classification", 0, &nl),
147 cpl_table_get_double(tab_p2,
"Classification", 0, &nl) );
148 cpl_test_rel( cpl_table_get_double(tab,
"X_coordinate", 0, &nl),
149 cpl_table_get_double(tab_p2,
"X_coordinate", 0, &nl), COMP_TOL_REL );
150 cpl_test_abs( cpl_table_get_double(tab,
"X_coordinate_err", 0, &nl),
151 cpl_table_get_double(tab_p2,
"X_coordinate_err", 0, &nl), COMP_TOL_ABS );
152 cpl_test_rel( cpl_table_get_double(tab,
"Y_coordinate", 0, &nl),
153 cpl_table_get_double(tab_p2,
"Y_coordinate", 0, &nl), COMP_TOL_REL );
154 cpl_test_abs( cpl_table_get_double(tab,
"Y_coordinate_err", 0, &nl),
155 cpl_table_get_double(tab_p2,
"Y_coordinate_err", 0, &nl), COMP_TOL_ABS );
158 cpl_image_delete( res2->segmentation_map);
159 cpl_image_delete( res2->background);
163 cpl_image_delete( res_p2->segmentation_map);
164 cpl_image_delete( res_p2->background);
169 return cpl_error_get_code();
181cpl_error_code hdrl_casuadd_compute(
double bias)
184 hdrl_casu_result *res1 = cpl_calloc(1,
sizeof(hdrl_casu_result));
185 hdrl_casu_result *res_p2 = cpl_calloc(1,
sizeof(hdrl_casu_result));
187 CELL_SIZE, 6, 1., 2., HDRL_SATURATION_INIT, res1), CPL_ERROR_NULL_INPUT);
188 cpl_test_error(CPL_ERROR_NULL_INPUT);
189 cpl_test_null(res1->catalogue);
191 cpl_image_delete( res1->segmentation_map);
192 cpl_image_delete( res1->background);
196 cpl_image *bkg = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
197 cpl_image *im = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
198 cpl_image *cnf = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
201 double norm2 = 2. * CPL_MATH_PI * sigma * sigma;
202 cpl_image_fill_noise_uniform(bkg, -10., 10.);
205 cpl_image_add_scalar(bkg, sky);
207 cpl_image_fill_noise_uniform(cnf, 99.9, 100.1);
212 cpl_image_fill_gaussian(im, xpos, ypos, norm * norm2, sigma, sigma);
213 cpl_image_add(bkg, im);
214 cpl_image_delete(im);
217 cpl_image *bkg2 = cpl_image_duplicate(bkg);
218 cpl_image_add_scalar(bkg2, bias);
226 cpl_propertylist_update_string(pl,
"CTYPE1",
"RA---TAN" );
227 cpl_propertylist_update_string(pl,
"CTYPE2",
"DEC--TAN" );
228 cpl_propertylist_update_double(pl,
"CRVAL1", 30. );
229 cpl_propertylist_update_double(pl,
"CRVAL2", 12. );
230 cpl_propertylist_update_double(pl,
"CRPIX1", 512. );
231 cpl_propertylist_update_double(pl,
"CRPIX2", 512. );
232 cpl_propertylist_update_double(pl,
"CD1_1", -1. / 3600.);
233 cpl_propertylist_update_double(pl,
"CD1_2", 0. );
234 cpl_propertylist_update_double(pl,
"CD2_1", 0. );
235 cpl_propertylist_update_double(pl,
"CD2_2", 1. / 3600.);
236 cpl_propertylist_update_int( pl,
"NAXIS1", IMG_XSIZE );
237 cpl_propertylist_update_int( pl,
"NAXIS2", IMG_YSIZE );
238 cpl_wcs *wcs = cpl_wcs_new_from_propertylist(pl);
241 hdrl_casu_result *res2 = cpl_calloc(1,
sizeof(hdrl_casu_result));
243 CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res2), CPL_ERROR_NONE);
244 cpl_test_nonnull(res2->catalogue);
249 CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res_p2), CPL_ERROR_NONE);
250 cpl_test_nonnull(res_p2->catalogue);
258 cpl_test_image_rel(res2->segmentation_map, res_p2->segmentation_map, COMP_TOL_REL);
261 cpl_test_nonnull(tab);
264 cpl_test_nonnull(tab_p2);
266 cpl_test_rel( cpl_table_get_double(tab, APER_FLUX_NUM, 0, &nl),
267 cpl_table_get_double(tab_p2, APER_FLUX_NUM, 0, &nl), COMP_TOL_REL );
268 cpl_test_rel( cpl_table_get_double(tab,
"Isophotal_flux", 0, &nl),
269 cpl_table_get_double(tab_p2,
"Isophotal_flux", 0, &nl), COMP_TOL_REL );
270 cpl_test_rel( cpl_table_get_double(tab,
"FWHM", 0, &nl),
271 cpl_table_get_double(tab_p2,
"FWHM", 0, &nl), COMP_TOL_REL );
272 cpl_test_rel( cpl_table_get_double(tab,
"Kron_radius", 0, &nl),
273 cpl_table_get_double(tab_p2,
"Kron_radius", 0, &nl), COMP_TOL_REL );
274 cpl_test_eq ( cpl_table_get_double(tab,
"Classification", 0, &nl),
275 cpl_table_get_double(tab_p2,
"Classification", 0, &nl) );
276 cpl_test_rel( cpl_table_get_double(tab,
"X_coordinate", 0, &nl),
277 cpl_table_get_double(tab_p2,
"X_coordinate", 0, &nl), COMP_TOL_REL );
278 cpl_test_abs( cpl_table_get_double(tab,
"X_coordinate_err", 0, &nl),
279 cpl_table_get_double(tab_p2,
"X_coordinate_err", 0, &nl), COMP_TOL_ABS );
280 cpl_test_rel( cpl_table_get_double(tab,
"Y_coordinate", 0, &nl),
281 cpl_table_get_double(tab_p2,
"Y_coordinate", 0, &nl), COMP_TOL_REL );
282 cpl_test_abs( cpl_table_get_double(tab,
"Y_coordinate_err", 0, &nl),
283 cpl_table_get_double(tab_p2,
"Y_coordinate_err", 0, &nl), COMP_TOL_ABS );
286 cpl_image_delete( res2->segmentation_map);
287 cpl_image_delete( res2->background);
291 cpl_image_delete( res_p2->segmentation_map);
292 cpl_image_delete( res_p2->background);
297 return cpl_error_get_code();
308 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
310 double bias[] = BIASES;
311 for (cpl_size i = 0; i < NUM_BIASES; i++) {
312 hdrl_casuadd_compute(bias[i]);
315 double factor[] = FACTORS;
316 for (cpl_size i = 0; i < NUM_FACTORS; i++) {
317 hdrl_casumul_compute(factor[i]);
320 cpl_test_error(CPL_ERROR_NONE);
322 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.