CR2RE Pipeline Reference Manual 1.6.8
hdrl_cat_casu-test.c
1/*
2 * This file is part of the HDRL
3 * Copyright (C) 2017 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <cpl_test.h>
21
22#include "../hdrl_cat_casu.h"
23#include "../hdrl_cat_table.h"
24
25
26#define NTEST 10
27
28
29int main(void)
30{
31 /* Initialise */
32 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
33
34 double xpos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
35 double ypos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
36 double norm[] = {1000., 100., 200., 500., 550., 600., 650., 700., 750., 800.};
37
38 /* Check inherited status */
39 hdrl_casu_result *res = cpl_calloc(1, sizeof(hdrl_casu_result));
40 cpl_test_eq(hdrl_casu_catalogue(NULL, NULL, NULL, 5, 1.5, 1, 3.5, 1, 64, 6, 1., 2.,
41 HDRL_SATURATION_INIT, res), CPL_ERROR_NULL_INPUT);
42 cpl_test_error(CPL_ERROR_NULL_INPUT);
43 cpl_test_null( res->catalogue);
44 cpl_image_delete( res->segmentation_map);
45 cpl_image_delete( res->background);
46 hdrl_casu_tfits_delete(res->catalogue);
47 cpl_free(res);
48
49 /* tests tfits */
50 cpl_table *test_table = NULL;
51 cpl_propertylist *test_ehu = NULL;
52 hdrl_casu_tfits *test_tinf = hdrl_casu_tfits_wrap(test_table, test_ehu);
53 cpl_test_null(test_tinf);
54 test_table = cpl_table_new(10);
55 test_tinf = hdrl_casu_tfits_wrap(test_table, test_ehu);
56 cpl_test_nonnull(test_tinf);
57 hdrl_casu_tfits_delete(test_tinf);
58 test_table = cpl_table_new(10);
59 test_ehu = cpl_propertylist_new();
60 test_tinf = hdrl_casu_tfits_wrap(test_table, test_ehu);
61 cpl_test_nonnull(test_tinf);
62 hdrl_casu_tfits_delete(test_tinf);
63
64
65 /* Generate a field with some stars and a confidence map */
66 cpl_image *bkg = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE);
67 cpl_image *im = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE);
68 cpl_image *cnf = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE);
69
70 double sigma = 2.;
71 double norm2 = 2. * CPL_MATH_PI * sigma * sigma;
72 cpl_image_fill_noise_uniform(bkg, -10., 10.);
73
74 double sky = 500.;
75 cpl_image_add_scalar(bkg, sky);
76
77 cpl_image_fill_noise_uniform(cnf, 99.9, 100.1);
78
79 double tot[NTEST];
80 for (cpl_size i = 0; i < NTEST; i++) {
81 cpl_image_fill_gaussian(im, xpos[i], ypos[i], norm[i] * norm2, sigma, sigma);
82 tot[i] = cpl_image_get_flux(im);
83 cpl_image_add(bkg, im);
84 }
85 cpl_image_delete(im);
86
87 hdrl_casu_fits *inf = hdrl_casu_fits_wrap(bkg);
88 hdrl_casu_fits *inconf = hdrl_casu_fits_wrap(cnf);
89
90 /* Give it a WCS */
91 cpl_propertylist *pl = hdrl_casu_fits_get_ehu(inf);
92 cpl_propertylist_update_string(pl, "CTYPE1", "RA---TAN" );
93 cpl_propertylist_update_string(pl, "CTYPE2", "DEC--TAN" );
94 cpl_propertylist_update_double(pl, "CRVAL1", 30. );
95 cpl_propertylist_update_double(pl, "CRVAL2", 12. );
96 cpl_propertylist_update_double(pl, "CRPIX1", 512. );
97 cpl_propertylist_update_double(pl, "CRPIX2", 512. );
98 cpl_propertylist_update_double(pl, "CD1_1", -1. / 3600.);
99 cpl_propertylist_update_double(pl, "CD1_2", 0. );
100 cpl_propertylist_update_double(pl, "CD2_1", 0. );
101 cpl_propertylist_update_double(pl, "CD2_2", 1. / 3600.);
102 cpl_propertylist_update_int( pl, "NAXIS1", 1024 );
103 cpl_propertylist_update_int( pl, "NAXIS2", 1024 );
104 cpl_wcs *wcs = cpl_wcs_new_from_propertylist(pl);
105
106 /* Run casu catalogue */
107 res = cpl_calloc(1, sizeof(*res));
108 cpl_test_eq(hdrl_casu_catalogue(inf, inconf, wcs, 5, 1.5, 0, 5., 1, 64, 6, 3., 1.,
109 HDRL_SATURATION_INIT, res), CPL_ERROR_NONE);
110 cpl_test_nonnull(res->catalogue);
112 hdrl_casu_fits_delete(inconf);
113
114 cpl_wcs_delete(wcs);
115 cpl_image_delete(res->segmentation_map);
116 cpl_image_delete(res->background);
117
118 /* Check the results. Start by checking the number of rows and columns. Sort the table by X */
119 cpl_table *tab = hdrl_casu_tfits_get_table(res->catalogue);
120 cpl_test_nonnull(tab);
121 cpl_test_eq(cpl_table_get_ncol(tab), NCOLS);
122 cpl_test_eq(cpl_table_get_nrow(tab), NTEST);
123
124 pl = cpl_propertylist_new();
125 cpl_propertylist_append_bool(pl, "X_coordinate", 0);
126 cpl_table_sort(tab, pl);
127 cpl_propertylist_delete(pl);
128
129 /* Test the column content of the table */
130 int nl;
131 for (cpl_size i = 0; i < NTEST; i++) {
132
133 cpl_test_abs(xpos[i], cpl_table_get_double(tab, "X_coordinate", i, &nl), 0.2);
134 cpl_test_abs(ypos[i], cpl_table_get_double(tab, "Y_coordinate", i, &nl), 0.2);
135
136 double diff = fabs( cpl_table_get_double(tab, "Aper_flux_5", i, &nl) - tot[i])
137 / cpl_table_get_double(tab, "Aper_flux_5_err", i, &nl);
138 cpl_test_lt(diff, 1.6);
139 cpl_test_eq( cpl_table_get_double(tab, "Classification", i, &nl), -1.);
140 }
141
142 /* Compare some header info */
143 pl = hdrl_casu_tfits_get_ehu(res->catalogue);
144 cpl_test_rel( cpl_propertylist_get_double(pl, "ESO QC IMAGE_SIZE") / 2.355, sigma, 0.1);
145
146 /* Clean up*/
147 hdrl_casu_tfits_delete(res->catalogue);
148 cpl_free(res);
149
150 return cpl_test_end(0);
151}
hdrl_casu_fits * hdrl_casu_fits_wrap(cpl_image *im)
Wrap an image in a hdrl_casu_fits wrapper.
cpl_propertylist * hdrl_casu_tfits_get_ehu(hdrl_casu_tfits *p)
Get the propertylist for the extension header for a given hdrl_casu_tfits image.
Definition: hdrl_cat_casu.c:98
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.
hdrl_casu_tfits * hdrl_casu_tfits_wrap(cpl_table *tab, cpl_propertylist *ehu)
Wrap an table in a hdrl_casu_tfits wrapper.
Definition: hdrl_cat_casu.c:59
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.