22#include "../hdrl_cat_casu.h"
24#include "hdrl_random.h"
27#define COMP_TOL_REL 1. / 3.
28#define COMP_TOL_ABS 1e-2
36 cpl_image *bkg = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
37 cpl_image *im = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
38 cpl_image *cnf = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE);
41 cpl_image_add_scalar(cnf, 100.);
45 double norm2 = 2. * CPL_MATH_PI * sigma * sigma;
48 cpl_image_add_scalar(bkg, sky);
53 cpl_image_fill_gaussian(im, xpos, ypos, norm * norm2, sigma, sigma);
54 cpl_image_add(bkg, im);
61 cpl_propertylist_update_string(pl,
"CTYPE1",
"RA---TAN" );
62 cpl_propertylist_update_string(pl,
"CTYPE2",
"DEC--TAN" );
63 cpl_propertylist_update_double(pl,
"CRVAL1", 30. );
64 cpl_propertylist_update_double(pl,
"CRVAL2", 12. );
65 cpl_propertylist_update_double(pl,
"CRPIX1", 512. );
66 cpl_propertylist_update_double(pl,
"CRPIX2", 512. );
67 cpl_propertylist_update_double(pl,
"CD1_1", -1. / 3600.);
68 cpl_propertylist_update_double(pl,
"CD1_2", 0. );
69 cpl_propertylist_update_double(pl,
"CD2_1", 0. );
70 cpl_propertylist_update_double(pl,
"CD2_2", 1. / 3600.);
71 cpl_propertylist_update_int( pl,
"NAXIS1", IMG_XSIZE );
72 cpl_propertylist_update_int( pl,
"NAXIS2", IMG_YSIZE );
73 cpl_wcs *wcs = cpl_wcs_new_from_propertylist(pl);
76 hdrl_casu_result *res = cpl_calloc(1,
sizeof(hdrl_casu_result));
77 cpl_table *tabfinal = NULL;
78 for (cpl_size iterate = 0; iterate < 100; iterate++) {
81 hdrl_random_state * rng = hdrl_random_state_new(1, NULL);
82 cpl_size size = cpl_image_get_size_x(bkg) * cpl_image_get_size_y(bkg);
83 double *pim = cpl_image_get_data_double(im);
84 double *pbkg= cpl_image_get_data_double(bkg);
86 for (cpl_size i = 0; i < size; i++) {
87 pim[i] = hdrl_random_poisson(rng, pbkg[i]);
89 hdrl_random_state_delete(rng);
93 HDRL_CATALOGUE_ALL, 3.0, 1.0, HDRL_SATURATION_INIT, res);
98 tabfinal = cpl_table_duplicate(tab);
100 cpl_table_insert(tabfinal, tab, iterate);
103 cpl_image_delete( res->segmentation_map);
104 cpl_image_delete( res->background);
109 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"X_coordinate_err"),
110 cpl_table_get_column_stdev(tabfinal,
"X_coordinate" ), COMP_TOL_REL);
111 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Y_coordinate_err"),
112 cpl_table_get_column_stdev(tabfinal,
"Y_coordinate" ), COMP_TOL_REL);
113 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Peak_height_err" ),
114 cpl_table_get_column_stdev(tabfinal,
"Peak_height" ), COMP_TOL_REL);
115 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Aper_flux_1_err" ),
116 cpl_table_get_column_stdev(tabfinal,
"Aper_flux_1" ), COMP_TOL_REL);
117 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Aper_flux_2_err" ),
118 cpl_table_get_column_stdev(tabfinal,
"Aper_flux_2" ), COMP_TOL_REL);
119 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Aper_flux_3_err" ),
120 cpl_table_get_column_stdev(tabfinal,
"Aper_flux_3" ), COMP_TOL_REL);
121 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Aper_flux_4_err" ),
122 cpl_table_get_column_stdev(tabfinal,
"Aper_flux_4" ), COMP_TOL_REL);
123 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Aper_flux_5_err" ),
124 cpl_table_get_column_stdev(tabfinal,
"Aper_flux_5" ), COMP_TOL_REL);
125 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Aper_flux_6_err" ),
126 cpl_table_get_column_stdev(tabfinal,
"Aper_flux_6" ), COMP_TOL_REL);
127 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Aper_flux_7_err" ),
128 cpl_table_get_column_stdev(tabfinal,
"Aper_flux_7" ), COMP_TOL_REL);
129 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Aper_flux_8_err" ),
130 cpl_table_get_column_stdev(tabfinal,
"Aper_flux_8" ), COMP_TOL_REL);
131 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Aper_flux_9_err" ),
132 cpl_table_get_column_stdev(tabfinal,
"Aper_flux_9" ), COMP_TOL_REL);
133 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Aper_flux_10_err"),
134 cpl_table_get_column_stdev(tabfinal,
"Aper_flux_10" ), COMP_TOL_REL);
135 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Aper_flux_11_err"),
136 cpl_table_get_column_stdev(tabfinal,
"Aper_flux_11" ), COMP_TOL_REL);
137 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Aper_flux_12_err"),
138 cpl_table_get_column_stdev(tabfinal,
"Aper_flux_12" ), COMP_TOL_REL);
139 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Aper_flux_13_err"),
140 cpl_table_get_column_stdev(tabfinal,
"Aper_flux_13" ), COMP_TOL_REL);
141 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Petr_flux_err" ),
142 cpl_table_get_column_stdev(tabfinal,
"Petr_flux" ), COMP_TOL_REL);
143 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Kron_flux_err" ),
144 cpl_table_get_column_stdev(tabfinal,
"Kron_flux" ), COMP_TOL_REL);
145 cpl_test_rel(cpl_table_get_column_mean( tabfinal,
"Half_flux_err" ),
146 cpl_table_get_column_stdev(tabfinal,
"Half_flux" ), COMP_TOL_REL);
152 cpl_table_delete(tabfinal);
153 cpl_image_delete(bkg);
164 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
168 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.