CR2RE Pipeline Reference Manual 1.6.7
hdrl_cat_background-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_background.h"
24
25
26int main(void)
27{
28 cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING);
29
30 /* Create an input apm structure */
31 ap_t ap;
32 ap.lsiz = 2048;
33 ap.csiz = 2048;
34 ap.inframe = cpl_image_new(2048, 2048, CPL_TYPE_DOUBLE);
35 ap.conframe = cpl_image_new(2048, 2048, CPL_TYPE_DOUBLE);
36
37 /* Initialize */
38 hdrl_apinit(&ap);
39
40 ap.indata = cpl_image_get_data_double(ap.inframe);
41 ap.confdata = cpl_image_get_data_double(ap.conframe);
42 ap.mflag = cpl_malloc(ap.lsiz * ap.csiz * sizeof(*ap.mflag));
43
44 double null_value = -100.;
45 for (cpl_size i = 0; i < ap.lsiz * ap.csiz; i++) {
46 ap.mflag[i] = null_value;
47 }
48
49 /* Create a background */
50 cpl_image_fill_noise_uniform(ap.inframe, -10., 10.);
51 cpl_image_add_scalar( ap.inframe, 5000.);
52 cpl_image_fill_noise_uniform(ap.conframe, 99, 101);
53
54 /* Get the background value */
55 double skymed;
56 double skysig;
57 cpl_test_eq(hdrl_backstats(&ap, &skymed, &skysig), CPL_ERROR_NONE);
58 cpl_test_rel(skymed, 5000., 0.01);
59 cpl_test_rel(skysig, 20 / sqrt(12), 0.1);
60
61 /* Create a background map */
62 hdrl_casu_result *res = cpl_malloc(sizeof(hdrl_casu_result));
63 res->background = cpl_image_new(ap.lsiz, ap.csiz, CPL_TYPE_DOUBLE);
64 cpl_test_eq(hdrl_background(&ap, 64, 1, res), CPL_ERROR_NONE);
65
66 for (cpl_size j = 0; j < ap.backmap.nby; j++) {
67 for (cpl_size i = 0; i < ap.backmap.nbx; i++) {
68 cpl_test_rel((ap.backmap.bvals)[i][j], 5000., 0.01);
69 }
70 }
71 cpl_test_rel(cpl_image_get_median(ap.inframe), 5000., 0.1);
72
73 /* TODO: Check results */
74 hdrl_backest(&ap, 1000., 1000., &skymed, &skysig);
75 cpl_test_rel(skymed, 5000., 0.01);
76 cpl_test_lt(0., skysig);
77 cpl_image_delete(res->background);
78 cpl_free(res);
79
80 /* Clean up */
81 hdrl_apclose(&ap);
82 cpl_free(ap.mflag);
83 cpl_image_delete(ap.inframe);
84 cpl_image_delete(ap.conframe);
85
86
87 return cpl_test_end(0);
88}
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_backest(ap_t *ap, double x, double y, double *skylev, double *skyrms)
Work out estimated sky for a pixel position.
cpl_error_code hdrl_background(ap_t *ap, cpl_size nbsize, cpl_size bkg_subtr, hdrl_casu_result *res)
Model and create background map.
cpl_error_code hdrl_backstats(ap_t *ap, double *skymed, double *skysig)
Work out robust background estimate over a whole input image.