22#include "../hdrl_cat_conf.h"
23#include "../hdrl_cat_table.h"
24#include "hdrl_types.h"
34void fill_plist(cpl_propertylist *pl)
36 cpl_propertylist_update_string(pl,
"CTYPE1",
"RA---TAN" );
37 cpl_propertylist_update_string(pl,
"CTYPE2",
"DEC--TAN" );
38 cpl_propertylist_update_double(pl,
"CRVAL1", 30. );
39 cpl_propertylist_update_double(pl,
"CRVAL2", 12. );
40 cpl_propertylist_update_double(pl,
"CRPIX1", 512. );
41 cpl_propertylist_update_double(pl,
"CRPIX2", 512. );
42 cpl_propertylist_update_double(pl,
"CD1_1", -1. / 3600.);
43 cpl_propertylist_update_double(pl,
"CD1_2", 0. );
44 cpl_propertylist_update_double(pl,
"CD2_1", 0. );
45 cpl_propertylist_update_double(pl,
"CD2_2", 1. / 3600.);
55cpl_image * create_gauss(
double dx,
double dy,
double fwhm)
59 cpl_size nx = fwhm * 20;
60 cpl_size ny = fwhm * 20;
61 cpl_size nnx = nx * factor;
62 cpl_size nny = ny * factor;
63 double sigma = fwhm * factor / (2 * sqrt(2 * log(2)));
64 cpl_image *g = cpl_image_new(nnx, nny, CPL_TYPE_DOUBLE);
69 cpl_image_fill_gaussian( g,
72 2. * CPL_MATH_PI * sigma * sigma,
76 cpl_image *r = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
77 double *dg = cpl_image_get_data_double(g);
78 double *dr = cpl_image_get_data_double(r);
80 for (cpl_size y = 0; y < ny; y++) {
81 for (cpl_size x = 0; x < nx; x++) {
82 for (cpl_size i = y * factor; i < y * factor + factor; i++) {
83 for (cpl_size j = x * factor; j < x * factor + factor; j++) {
84 dr[y * nx + x] += dg[i * nnx + j];
90 for (cpl_size y = 0; y < nny; y++) {
91 for (cpl_size x = 0; x < nnx; x++) {
92 dr[y / factor * nx + x / factor] += dg[y * nx + x];
96 cpl_image_divide_scalar(r, factor * factor);
99 cpl_image * noise_bkg = cpl_image_duplicate(r);
100 cpl_image_fill_noise_uniform(noise_bkg, -HDRL_EPS_DATA, +HDRL_EPS_DATA);
101 cpl_image_add(r, noise_bkg);
102 cpl_image_delete(noise_bkg);
116cpl_error_code hdrl_catalogue_hdrl_catalogue_conf_basic(
void)
119 double xpos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
120 double ypos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
121 double norm[] = {1000., 100., 200., 500., 550., 600., 650., 700., 750., 800.};
124 cpl_image *bkg = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE);
125 cpl_image *im = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE);
126 cpl_image *cnf = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE);
128 cpl_image_fill_noise_uniform(bkg, -10., 10. );
129 cpl_image_fill_noise_uniform(cnf, 99.9, 100.1);
132 double norm2 = 2. * CPL_MATH_PI * sigma * sigma;
135 cpl_image_add_scalar(bkg, sky);
138 for (cpl_size i = 0; i < NTEST; i++) {
139 cpl_image_fill_gaussian(im, xpos[i], ypos[i], norm[i] * norm2, sigma, sigma);
140 tot[i] = cpl_image_get_flux(im);
141 cpl_image_add(bkg, im);
143 cpl_image_delete(im);
152 hdrl_casu_result *res = cpl_calloc(1,
sizeof(hdrl_casu_result));
153 cpl_test_eq(
hdrl_catalogue_conf(inf, inconf, 5, 1.5, 0, 5., 1, 64, 6, 3., 1.,
154 HDRL_SATURATION_INIT,res), CPL_ERROR_NONE);
155 cpl_test_nonnull(res->catalogue);
156 cpl_image_delete(res->segmentation_map);
157 cpl_image_delete(res->background);
161 cpl_test_nonnull(tab);
162 cpl_test_eq(cpl_table_get_ncol(tab), NCOLS);
163 cpl_test_eq(cpl_table_get_nrow(tab), NTEST);
165 cpl_propertylist *pl = cpl_propertylist_new();
166 cpl_propertylist_append_bool(pl,
"X_coordinate", 0);
167 cpl_table_sort(tab, pl);
168 cpl_propertylist_delete(pl);
172 for (cpl_size i = 0; i < NTEST; i++) {
174 cpl_test_abs(xpos[i], cpl_table_get_double(tab,
"X_coordinate", i, &nl), 0.2);
175 cpl_test_abs(ypos[i], cpl_table_get_double(tab,
"Y_coordinate", i, &nl), 0.2);
177 double diff = fabs(cpl_table_get_double(tab,
"Aper_flux_5", i, &nl) - tot[i])
178 / cpl_table_get_double(tab,
"Aper_flux_5_err", i, &nl);
179 cpl_test_lt(diff, 1.6);
189 return cpl_error_get_code();
199cpl_error_code hdrl_catalogue_hdrl_catalogue_conf_backsub(
void)
201 cpl_image *cnf = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE);
202 cpl_image_add_scalar(cnf, 100.);
204 cpl_image *im = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE);
205 cpl_image_fill_noise_uniform(im, -10., 10. );
208 for (cpl_size x = 400; x < 600; x++) {
209 for (cpl_size y = 400; y < 600; y++) {
210 cpl_image_set(im, x, y, 0.);
215 for (cpl_size x = 500; x < 505; x++) {
216 for (cpl_size y = 500; y < 505; y++) {
217 cpl_image_set(im, x, y, 4990.);
221 cpl_image_add_scalar(im, 10.);
226 hdrl_casu_result *res = cpl_calloc(1,
sizeof(hdrl_casu_result));
227 cpl_test_eq(
hdrl_catalogue_conf(inf, inconf, 5, 3., 0, 1., 0, 16, 7, 3., 1.,
228 HDRL_SATURATION_INIT,res), CPL_ERROR_NONE);
230 cpl_test_nonnull(tab);
233 cpl_test_eq(cpl_table_get_nrow(tab), 1);
237 cpl_test_abs(5000., cpl_table_get_double(tab,
"Aper_flux_1", 0, &nl), 0.2);
243 cpl_image_delete( res->segmentation_map);
244 cpl_image_delete( res->background);
248 return cpl_error_get_code();
251cpl_error_code test_gaussians(
double dx,
double dy,
double fwhm)
254 cpl_image *im = create_gauss(dx, dy, fwhm);
261 hdrl_casu_result *res = cpl_calloc(1,
sizeof(hdrl_casu_result));
262 cpl_test_eq(
hdrl_catalogue_conf(inf, NULL, 5, 2.5, 0, fwhm, 1, fwhm * 3, 6, 3., 1.,
263 HDRL_SATURATION_INIT, res), CPL_ERROR_NONE);
264 cpl_test_nonnull(res->catalogue);
265 cpl_image_delete(res->segmentation_map);
266 cpl_image_delete(res->background);
270 cpl_test_nonnull(tab);
271 cpl_test_eq(cpl_table_get_ncol(tab), NCOLS);
272 cpl_test_eq(cpl_table_get_nrow(tab), 1 );
276 cpl_test_abs(fwhm, cpl_table_get_double(tab,
"FWHM", 0, &nl), 0.006);
284 return cpl_error_get_code();
294 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
296 hdrl_catalogue_hdrl_catalogue_conf_basic();
297 hdrl_catalogue_hdrl_catalogue_conf_backsub();
299 test_gaussians(.5, .5, 3.);
300 test_gaussians(.0, .5, 4.);
301 test_gaussians(.5, .5, 5.);
302 test_gaussians(.8, .5, 6.);
303 test_gaussians(.1, .2, 7.);
305 cpl_test_error(CPL_ERROR_NONE);
307 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.