CR2RE Pipeline Reference Manual 1.6.10
hdrl_cat_radii-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_apio.h"
23#include "../hdrl_cat_areals.h"
24#include "../hdrl_cat_moments.h"
25#include "../hdrl_cat_radii.h"
26
27#define NT 117
28#define SIZE_IMG 64
29
30
31static double radii[] = {2.5,3.53553,5.0,7.07107,10,14,20,25,30,35,40,50,60};
32
33static double fluxes[] = {13670.3, 19834.4, 23923.2, 25124.0, 25332.3, 25488.9,
34 25648.7, 25842.8, 25950.9, 25893.9, 25982,1, 25297.6, 24919.1};
35
36
37void flux_test(cpl_boolean execute_test)
38{
39 cpl_size x[] = {398,399,400,397,398,399,400,401,402,403,396,397,398,399,400,
40 401,402,403,404,395,396,397,398,399,400,401,402,403,404,405,
41 395,396,397,398,399,400,401,402,403,404,405,395,396,397,398,
42 399,400,401,402,403,404,405,395,396,397,398,399,400,401,402,
43 403,404,405,406,395,396,397,398,399,400,401,402,403,404,405,
44 395,396,397,398,399,400,401,402,403,404,405,395,396,397,398,
45 399,400,401,402,403,404,405,396,397,398,399,400,401,402,403,
46 404,397,398,399,400,401,402,403,398,399,400,401};
47
48 cpl_size y[] = {394,394,394,395,395,395,395,395,395,395,396,396,396,396,396,
49 396,396,396,396,397,397,397,397,397,397,397,397,397,397,397,
50 398,398,398,398,398,398,398,398,398,398,398,399,399,399,399,
51 399,399,399,399,399,399,399,400,400,400,400,400,400,400,400,
52 400,400,400,400,401,401,401,401,401,401,401,401,401,401,401,
53 402,402,402,402,402,402,402,402,402,402,402,403,403,403,403,
54 403,403,403,403,403,403,403,404,404,404,404,404,404,404,404,
55 404,405,405,405,405,405,405,405,406,406,406,406};
56
57 double z[] = {8.87152,12.515,7.69699,10.8527,22.2509,21.7368,13.0388,
58 12.1853,17.1976,7.43948,15.2245,29.1964,37.9117,57.9371,
59 71.5542,57.1288,34.7726,15.5934,11.5374,15.995,21.3606,
60 60.4006,103.46,147.55,168.274,147.476,98.9157,51.7186,20.188,
61 3.04248,5.77832,49.3103,98.2057,187.557,268.353,310.638,
62 274.295,183.969,94.6933,47.9889,20.245,26.3758,59.1781,
63 152.389,275.916,395.107,450.251,397.53,272.322,147.053,54.767,
64 11.8971,13.3888,73.3689,165.899,298.455,449.707,493.25,441.585,
65 299.31,157.474,70.1224,15.5313,8.76074,20.7188,54.5798,141.249,
66 264.87,382.736,435.452,393.871,268.175,138.485,65.9307,28.7812,
67 19.379,36.6449,93.5458,186.823,270.95,305.093,260.879,183.683,
68 100.676,32.6281,16.6497,5.94965,17.8105,57.256,106.32,145.264,
69 164.271,137.093,88.9384,60.7841,31.8582,10.0435,4.69162,
70 15.2187,32.5385,61.0381,74.5399,67.3727,43.3964,25.0956,
71 16.7595,-0.37323,21.3832,19.2497,18.5883,9.37448,19.6048,
72 11.5006,13.0159,14.5852,13.66,-1.04889};
73
74
75 /* Set up apm structure */
76 ap_t ap;
77 ap.lsiz = SIZE_IMG;
78 ap.csiz = SIZE_IMG;
79 ap.thresh = 11.0936;
80 ap.inframe = cpl_image_new(SIZE_IMG, SIZE_IMG, CPL_TYPE_DOUBLE);
81 ap.conframe = cpl_image_new(SIZE_IMG, SIZE_IMG, CPL_TYPE_DOUBLE);
82
83 /* Initialize */
84 hdrl_apinit(&ap);
85
86 ap.npl_pix = NT;
87 ap.plarray = cpl_realloc(ap.plarray, NT * sizeof(plstruct));
88 for (cpl_size i = 0; i < NT; i++) {
89 ap.plarray[i].x = x[i];
90 ap.plarray[i].y = y[i];
91 ap.plarray[i].z = z[i];
92 ap.plarray[i].zsm = z[i];
93 }
94
95 ap.xintmin = 0.;
96 ap.areal_offset = 3.47165;
97 ap.thresh = 11.0936;
98 ap.fconst = 1.4427;
99
100 /* Run the test */
101 cpl_size iareal[NAREAL];
102 hdrl_areals(&ap, iareal);
103
104 ap.indata = cpl_image_get_data_double(ap.inframe);
105 ap.confdata = cpl_image_get_data_double(ap.conframe);
106 ap.mflag = cpl_calloc(SIZE_IMG * SIZE_IMG, sizeof(*ap.mflag));
107
108 /* Create a background */
109 cpl_image_fill_noise_uniform(ap.inframe, -10., 10.);
110 cpl_image_add_scalar( ap.inframe, 5000.);
111 cpl_image_fill_noise_uniform(ap.conframe, 99, 101);
112
113 /* Do a basic moments analysis and work out the areal profiles*/
114 double momresults[8];
115 hdrl_moments(&ap, momresults);
116
117 /* Try and deblend the images if it is requested and justified */
118 double parmall[IMNUM][NPAR];
119 cpl_size nbit = 10;
120 for (cpl_size i = 0; i < IMNUM; i++) {
121 for (cpl_size j = 0; j < NPAR; j++) {
122 parmall[i][j] = 0.;
123 }
124 }
125
126 /* Get Kron radius for all images and get the flux */
127 double areal;
128 double kron_rad[IMNUM];
129 for (cpl_size k = 0; k < nbit; k++) {
130 areal = parmall[k][8];
131 kron_rad[k] = hdrl_kronrad(areal, radii, fluxes, NRADS);
132 }
133 if (execute_test) {
134 double kron_flux[IMNUM];
135 hdrl_flux(&ap, parmall, nbit, kron_rad, kron_flux, NRADS, radii, fluxes);
136 }
137
138 /* Get Petrosian radius for all images and get the flux */
139 double petr_rad[IMNUM];
140 for (cpl_size k = 0; k < nbit; k++) {
141 areal = parmall[k][8];
142 petr_rad[k] = hdrl_petrad(areal, radii, fluxes, NRADS);
143 }
144 if (execute_test) {
145 double petr_flux[IMNUM];
146 hdrl_flux(&ap, parmall, nbit, petr_rad, petr_flux, NRADS, radii, fluxes);
147 }
148
149 /* Clean up */
150 hdrl_apclose(&ap);
151 cpl_free(ap.mflag);
152 cpl_image_delete(ap.inframe);
153 cpl_image_delete(ap.conframe);
154}
155
156int main(void) {
157
158 /* Initialize */
159 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
160
161 double halfrad = 2.35;
162 double exprad = 6.18;
163 double kronrad = 6.18;
164 double petrrad = 12.45;
165 double peak = 1007.07;
166 double areal = 120.;
167
168 double halflight;
169 double thresh;
170 double rad;
171
172
173 /* Test halflight */
174 halflight = fluxes[4] / 2.;
175 rad = hdrl_halflight(radii, fluxes, halflight, peak, NRADS);
176 cpl_test_rel(rad, halfrad, 0.01);
177
178 /* Test exprad */
179 thresh = 4.;
180 rad = hdrl_exprad(thresh, peak, areal, radii, NRADS);
181 cpl_test_rel(rad, exprad, 0.01);
182
183 /* Test Kron */
184 rad = hdrl_kronrad(areal, radii, fluxes, NRADS);
185 cpl_test_rel(rad, kronrad, 0.01);
186
187 /* Test Petrosian */
188 rad = hdrl_petrad(areal, radii, fluxes, NRADS);
189 cpl_test_rel(rad, petrrad, 0.01);
190
191 /* Flux_test. TODO: Fail in Debian 6.0 [debug - i686] and Debian 7.0 [debug x86_64]
192 * Maybe for optiomization in the debug compiler mode for this machine.
193 * Activate the test when this will be solve */
194 flux_test(CPL_FALSE);
195
196 return cpl_test_end(0);
197}
void hdrl_apinit(ap_t *ap)
Initialize the ap structure.
Definition: hdrl_cat_apio.c:54
void hdrl_apclose(ap_t *ap)
Close ap structure.
void hdrl_areals(ap_t *ap, cpl_size iareal[NAREAL])
Work out the areal profiles for an object.
void hdrl_moments(ap_t *ap, double results[])
Do moments analysis on an object in a Plessey array.
void hdrl_flux(ap_t *ap, double parm[IMNUM][NPAR], cpl_size nbit, double apers[], double fluxes[], cpl_size nr, double rcores[], double rfluxes[])
Work out the fluxes for special radii.
double hdrl_exprad(double thresh, double peak, double areal0, double rcores[], cpl_size naper)
Work out the exponential radius for an object.
double hdrl_petrad(double areal0, double rcores[], double cflux[], cpl_size naper)
Work out the Petrosian radius for an object.
double hdrl_kronrad(double areal0, double rcores[], double cflux[], cpl_size naper)
Work out the Kron radius for an object.
double hdrl_halflight(double rcores[], double cflux[], double halflight, double peak, cpl_size naper)
Work out the half-light radius for an object.