VIRCAM Pipeline  2.3.12
imcore_background-test.c
1 /* $Id: imcore_background-test.c,v 1.2 2015/11/18 20:03:54 jim Exp $
2  *
3  * This file is part of the CASU Pipeline utilities
4  * Copyright (C) 2015 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: jim $
23  * $Date: 2015/11/18 20:03:54 $
24  * $Revision: 1.2 $
25  * $Name: $
26  */
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 
31 #include <cpl_init.h>
32 #include <cpl_test.h>
33 #include <casu_utils.h>
34 #include <casu_mods.h>
35 #include "../imcore.h"
36 
37 int main(void) {
38  ap_t ap;
39  float skymed,skysig,sat;
40  int retval,i,j;
41 
42  /* Initialise */
43 
44  cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING);
45 
46  /* Create an input apm structure */
47 
48  ap.lsiz = 2048;
49  ap.csiz = 2048;
50  ap.xtnum = 0;
51  ap.inframe = cpl_image_new(2048,2048,CPL_TYPE_FLOAT);
52  ap.conframe = cpl_image_new(2048,2048,CPL_TYPE_INT);
53  imcore_apinit(&ap);
54  ap.indata = cpl_image_get_data_float(ap.inframe);
55  ap.confdata = cpl_image_get_data_int(ap.conframe);
56  ap.mflag = cpl_calloc(2048*2048,sizeof(unsigned char));
57 
58  /* Create a background */
59 
60  cpl_image_fill_noise_uniform(ap.inframe,-10.0,10.0);
61  cpl_image_add_scalar(ap.inframe,5000.0);
62  cpl_image_fill_noise_uniform(ap.conframe,99,101);
63 
64  /* Get the background value */
65 
66  retval = imcore_backstats(&ap,-100.0,0,&skymed,&skysig,&sat);
67  cpl_test_eq(retval,CASU_OK);
68  cpl_test_rel(skymed,5000.0,0.01);
69  cpl_test_rel(sat,20000.0,0.001);
70  cpl_test_rel(skysig,7.4,0.1);
71 
72  /* Create a background map */
73 
74  retval = imcore_background(&ap,64,-100.0);
75  cpl_test_eq(retval,CASU_OK);
76  for (j = 0; j < ap.backmap.nby; j++)
77  for (i = 0; i < ap.backmap.nbx; i++)
78  cpl_test_rel((ap.backmap.bvals)[i][j],5000.0,0.01);
79  cpl_test_rel(cpl_image_get_median(ap.inframe),5000.0,0.1);
80  imcore_backest(&ap,1000.0,1000.0,&skymed,&skysig);
81  cpl_test_rel(skymed,5000.0,0.01);
82  cpl_test_abs(skysig,0.013,0.01);
83 
84  /* Get out of here */
85 
86  imcore_apclose(&ap);
87  cpl_free(ap.mflag);
88  cpl_image_delete(ap.inframe);
89  cpl_image_delete(ap.conframe);
90  return(cpl_test_end(0));
91 
92 }
93 
94 /*
95 
96 $Log: imcore_background-test.c,v $
97 Revision 1.2 2015/11/18 20:03:54 jim
98 Fixed a couple of tests
99 
100 Revision 1.1 2015/10/15 11:27:22 jim
101 new
102 
103 
104 */
int imcore_background(ap_t *ap, int nbsize, float nullval)
Model and create background map.
int imcore_backstats(ap_t *ap, float nullval, int satonly, float *skymed, float *skysig, float *sat)
Work out robust background estimate over a whole input image.
void imcore_apclose(ap_t *ap)
Close ap structure.
Definition: apinit.c:186
void imcore_backest(ap_t *ap, float x, float y, float *skylev, float *skyrms)
Work out estimated sky for a pixel position.
void imcore_apinit(ap_t *ap)
Initialise the ap structure.
Definition: apinit.c:65