CR2RE Pipeline Reference Manual 1.7.0
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include <cpl_test.h>
25
26#include "../hdrl_cat_apio.h"
27#include "../hdrl_cat_background.h"
28
29
30int main(void)
31{
32 cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING);
33
34 /* Create an input apm structure */
35 ap_t ap;
36 ap.lsiz = 2048;
37 ap.csiz = 2048;
38 ap.inframe = cpl_image_new(2048, 2048, CPL_TYPE_DOUBLE);
39 ap.conframe = cpl_image_new(2048, 2048, CPL_TYPE_DOUBLE);
40
41 /* Initialize */
42 hdrl_apinit(&ap);
43
44 ap.indata = cpl_image_get_data_double(ap.inframe);
45 ap.confdata = cpl_image_get_data_double(ap.conframe);
46 ap.mflag = cpl_malloc(ap.lsiz * ap.csiz * sizeof(*ap.mflag));
47
48 double null_value = -100.;
49 for (cpl_size i = 0; i < ap.lsiz * ap.csiz; i++) {
50 ap.mflag[i] = null_value;
51 }
52
53 /* Create a background */
54 cpl_image_fill_noise_uniform(ap.inframe, -10., 10.);
55 cpl_image_add_scalar( ap.inframe, 5000.);
56 cpl_image_fill_noise_uniform(ap.conframe, 99, 101);
57
58 /* Get the background value */
59 double skymed;
60 double skysig;
61 cpl_test_eq(hdrl_backstats(&ap, &skymed, &skysig), CPL_ERROR_NONE);
62 cpl_test_rel(skymed, 5000., 0.01);
63 cpl_test_rel(skysig, 20 / sqrt(12), 0.1);
64
65 /* Create a background map */
66 hdrl_casu_result *res = cpl_malloc(sizeof(hdrl_casu_result));
67 res->background = cpl_image_new(ap.lsiz, ap.csiz, CPL_TYPE_DOUBLE);
68 cpl_test_eq(hdrl_background(&ap, 64, 1, res), CPL_ERROR_NONE);
69
70 for (cpl_size j = 0; j < ap.backmap.nby; j++) {
71 for (cpl_size i = 0; i < ap.backmap.nbx; i++) {
72 cpl_test_rel((ap.backmap.bvals)[i][j], 5000., 0.01);
73 }
74 }
75 cpl_test_rel(cpl_image_get_median(ap.inframe), 5000., 0.1);
76
77 /* TODO: Check results */
78 hdrl_backest(&ap, 1000., 1000., &skymed, &skysig);
79 cpl_test_rel(skymed, 5000., 0.01);
80 cpl_test_lt(0., skysig);
81 cpl_image_delete(res->background);
82 cpl_free(res);
83
84 /* Clean up */
85 hdrl_apclose(&ap);
86 cpl_free(ap.mflag);
87 cpl_image_delete(ap.inframe);
88 cpl_image_delete(ap.conframe);
89
90
91 return cpl_test_end(0);
92}
void hdrl_apinit(ap_t *ap)
Initialize the ap structure.
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.