26#include "../hdrl_cat_conf.h"
27#include "../hdrl_cat_table.h"
28#include "hdrl_types.h"
38void fill_plist(cpl_propertylist *pl)
40 cpl_propertylist_update_string(pl,
"CTYPE1",
"RA---TAN" );
41 cpl_propertylist_update_string(pl,
"CTYPE2",
"DEC--TAN" );
42 cpl_propertylist_update_double(pl,
"CRVAL1", 30. );
43 cpl_propertylist_update_double(pl,
"CRVAL2", 12. );
44 cpl_propertylist_update_double(pl,
"CRPIX1", 512. );
45 cpl_propertylist_update_double(pl,
"CRPIX2", 512. );
46 cpl_propertylist_update_double(pl,
"CD1_1", -1. / 3600.);
47 cpl_propertylist_update_double(pl,
"CD1_2", 0. );
48 cpl_propertylist_update_double(pl,
"CD2_1", 0. );
49 cpl_propertylist_update_double(pl,
"CD2_2", 1. / 3600.);
59cpl_image * create_gauss(
double dx,
double dy,
double fwhm)
63 cpl_size nx = fwhm * 20;
64 cpl_size ny = fwhm * 20;
65 cpl_size nnx = nx * factor;
66 cpl_size nny = ny * factor;
67 double sigma = fwhm * factor / (2 * sqrt(2 * log(2)));
68 cpl_image *g = cpl_image_new(nnx, nny, CPL_TYPE_DOUBLE);
73 cpl_image_fill_gaussian( g,
76 2. * CPL_MATH_PI * sigma * sigma,
80 cpl_image *r = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
81 double *dg = cpl_image_get_data_double(g);
82 double *dr = cpl_image_get_data_double(r);
84 for (cpl_size y = 0; y < ny; y++) {
85 for (cpl_size x = 0; x < nx; x++) {
86 for (cpl_size i = y * factor; i < y * factor + factor; i++) {
87 for (cpl_size j = x * factor; j < x * factor + factor; j++) {
88 dr[y * nx + x] += dg[i * nnx + j];
94 for (cpl_size y = 0; y < nny; y++) {
95 for (cpl_size x = 0; x < nnx; x++) {
96 dr[y / factor * nx + x / factor] += dg[y * nx + x];
100 cpl_image_divide_scalar(r, factor * factor);
103 cpl_image * noise_bkg = cpl_image_duplicate(r);
104 cpl_image_fill_noise_uniform(noise_bkg, -HDRL_EPS_DATA, +HDRL_EPS_DATA);
105 cpl_image_add(r, noise_bkg);
106 cpl_image_delete(noise_bkg);
120cpl_error_code hdrl_catalogue_hdrl_catalogue_conf_basic(
void)
123 double xpos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
124 double ypos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
125 double norm[] = {1000., 100., 200., 500., 550., 600., 650., 700., 750., 800.};
128 cpl_image *bkg = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE);
129 cpl_image *im = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE);
130 cpl_image *cnf = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE);
132 cpl_image_fill_noise_uniform(bkg, -10., 10. );
133 cpl_image_fill_noise_uniform(cnf, 99.9, 100.1);
136 double norm2 = 2. * CPL_MATH_PI * sigma * sigma;
139 cpl_image_add_scalar(bkg, sky);
142 for (cpl_size i = 0; i < NTEST; i++) {
143 cpl_image_fill_gaussian(im, xpos[i], ypos[i], norm[i] * norm2, sigma, sigma);
144 tot[i] = cpl_image_get_flux(im);
145 cpl_image_add(bkg, im);
147 cpl_image_delete(im);
156 hdrl_casu_result *res = cpl_calloc(1,
sizeof(hdrl_casu_result));
157 cpl_test_eq(
hdrl_catalogue_conf(inf, inconf, 5, 1.5, 0, 5., 1, 64, 6, 3., 1.,
158 HDRL_SATURATION_INIT,res), CPL_ERROR_NONE);
159 cpl_test_nonnull(res->catalogue);
160 cpl_image_delete(res->segmentation_map);
161 cpl_image_delete(res->background);
165 cpl_test_nonnull(tab);
166 cpl_test_eq(cpl_table_get_ncol(tab), NCOLS);
167 cpl_test_eq(cpl_table_get_nrow(tab), NTEST);
169 cpl_propertylist *pl = cpl_propertylist_new();
170 cpl_propertylist_append_bool(pl,
"X_coordinate", 0);
171 cpl_table_sort(tab, pl);
172 cpl_propertylist_delete(pl);
176 for (cpl_size i = 0; i < NTEST; i++) {
178 cpl_test_abs(xpos[i], cpl_table_get_double(tab,
"X_coordinate", i, &nl), 0.2);
179 cpl_test_abs(ypos[i], cpl_table_get_double(tab,
"Y_coordinate", i, &nl), 0.2);
181 double diff = fabs(cpl_table_get_double(tab,
"Aper_flux_5", i, &nl) - tot[i])
182 / cpl_table_get_double(tab,
"Aper_flux_5_err", i, &nl);
183 cpl_test_lt(diff, 1.6);
193 return cpl_error_get_code();
203cpl_error_code hdrl_catalogue_hdrl_catalogue_conf_backsub(
void)
205 cpl_image *cnf = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE);
206 cpl_image_add_scalar(cnf, 100.);
208 cpl_image *im = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE);
209 cpl_image_fill_noise_uniform(im, -10., 10. );
212 for (cpl_size x = 400; x < 600; x++) {
213 for (cpl_size y = 400; y < 600; y++) {
214 cpl_image_set(im, x, y, 0.);
219 for (cpl_size x = 500; x < 505; x++) {
220 for (cpl_size y = 500; y < 505; y++) {
221 cpl_image_set(im, x, y, 4990.);
225 cpl_image_add_scalar(im, 10.);
230 hdrl_casu_result *res = cpl_calloc(1,
sizeof(hdrl_casu_result));
231 cpl_test_eq(
hdrl_catalogue_conf(inf, inconf, 5, 3., 0, 1., 0, 16, 7, 3., 1.,
232 HDRL_SATURATION_INIT,res), CPL_ERROR_NONE);
234 cpl_test_nonnull(tab);
237 cpl_test_eq(cpl_table_get_nrow(tab), 1);
241 cpl_test_abs(5000., cpl_table_get_double(tab,
"Aper_flux_1", 0, &nl), 0.2);
247 cpl_image_delete( res->segmentation_map);
248 cpl_image_delete( res->background);
252 return cpl_error_get_code();
255cpl_error_code test_gaussians(
double dx,
double dy,
double fwhm)
258 cpl_image *im = create_gauss(dx, dy, fwhm);
265 hdrl_casu_result *res = cpl_calloc(1,
sizeof(hdrl_casu_result));
266 cpl_test_eq(
hdrl_catalogue_conf(inf, NULL, 5, 2.5, 0, fwhm, 1, fwhm * 3, 6, 3., 1.,
267 HDRL_SATURATION_INIT, res), CPL_ERROR_NONE);
268 cpl_test_nonnull(res->catalogue);
269 cpl_image_delete(res->segmentation_map);
270 cpl_image_delete(res->background);
274 cpl_test_nonnull(tab);
275 cpl_test_eq(cpl_table_get_ncol(tab), NCOLS);
276 cpl_test_eq(cpl_table_get_nrow(tab), 1 );
280 cpl_test_abs(fwhm, cpl_table_get_double(tab,
"FWHM", 0, &nl), 0.006);
288 return cpl_error_get_code();
298 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
300 hdrl_catalogue_hdrl_catalogue_conf_basic();
301 hdrl_catalogue_hdrl_catalogue_conf_backsub();
303 test_gaussians(.5, .5, 3.);
304 test_gaussians(.0, .5, 4.);
305 test_gaussians(.5, .5, 5.);
306 test_gaussians(.8, .5, 6.);
307 test_gaussians(.1, .2, 7.);
309 cpl_test_error(CPL_ERROR_NONE);
311 return cpl_test_end(0);
cpl_error_code hdrl_catalogue_conf(hdrl_casu_fits *infile, hdrl_casu_fits *conf, cpl_size ipix, double threshold, cpl_size icrowd, double rcore, cpl_size bkg_subtr, cpl_size nbsize, cpl_size cattype, double filtfwhm, double gain, double saturation, hdrl_casu_result *res)
Do source extraction.
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.