UVES Pipeline Reference Manual  5.4.6
uves_corrbadpix-test.c
1 /* *
2  * This file is part of the ESO UVES Pipeline *
3  * Copyright (C) 2004,2005 European Southern Observatory *
4  * *
5  * This library 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, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
18  * */
19 
20 /*
21  * $Author: amodigli $
22  * $Date: 2010-09-24 09:31:49 $
23  * $Revision: 1.7 $
24  * $Name: not supported by cvs2svn $
25  * $Log: not supported by cvs2svn $
26  * Revision 1.5 2009/11/04 06:58:26 amodigli
27  * fixed API error
28  *
29  * Revision 1.4 2009/06/05 05:49:02 amodigli
30  * updated init/end to cpl5
31  *
32  * Revision 1.3 2007/05/23 06:43:23 jmlarsen
33  * Removed unused variables
34  *
35  * Revision 1.2 2007/04/24 12:50:29 jmlarsen
36  * Replaced cpl_propertylist -> uves_propertylist which is much faster
37  *
38  * Revision 1.1 2007/03/15 12:27:18 jmlarsen
39  * Moved unit tests to ./uves/tests and ./flames/tests
40  *
41  * Revision 1.3 2007/02/27 14:04:14 jmlarsen
42  * Move unit test infrastructure to IRPLIB
43  *
44  * Revision 1.2 2007/01/29 12:17:54 jmlarsen
45  * Support setting verbosity from command line
46  *
47  * Revision 1.1 2007/01/16 10:25:11 jmlarsen
48  * Added test of bad pixel correction
49  *
50  * Revision 1.1 2006/11/28 08:26:35 jmlarsen
51  * Added QC log unit test
52  *
53  */
54 
55 /*-----------------------------------------------------------------------------
56  Includes
57  -----------------------------------------------------------------------------*/
58 
59 #ifdef HAVE_CONFIG_H
60 # include <config.h>
61 #endif
62 
63 #include <uves_corrbadpix.h>
64 #include <uves_chip.h>
65 #include <uves_utils_wrappers.h>
66 #include <uves_error.h>
67 #include <cpl_test.h>
68 
69 #include <cpl.h>
70 /*-----------------------------------------------------------------------------
71  Defines
72  -----------------------------------------------------------------------------*/
73 
74 /*-----------------------------------------------------------------------------
75  Functions prototypes
76  -----------------------------------------------------------------------------*/
77 
78 
79 /*----------------------------------------------------------------------------*/
83 /*----------------------------------------------------------------------------*/
86 /*----------------------------------------------------------------------------*/
90 /*----------------------------------------------------------------------------*/
91 static void
93 {
94  cpl_image *master_bias = NULL;
96  int **map = NULL;
97  int mark_bad;
98  int blue, binx, biny;
99 
100  /* Empty map */
101  map = cpl_calloc(1, sizeof(int*));
102  map[0] = cpl_calloc(4, sizeof(int));
103  map[0][0] = -1;
104  map[0][1] = -1;
105  map[0][2] = -1;
106  map[0][3] = -1;
107  uves_badmap_free(&map);
108 
109  /* 2 row map */
110  map = cpl_calloc(3, sizeof(int*));
111  map[0] = cpl_calloc(4, sizeof(int));
112  map[0][0] = 1;
113  map[0][1] = 2;
114  map[0][2] = 3;
115  map[0][3] = 4;
116  map[1] = cpl_calloc(4, sizeof(int));
117  map[1][0] = 5;
118  map[1][1] = 6;
119  map[1][2] = 7;
120  map[1][3] = 8;
121  map[2] = cpl_calloc(4, sizeof(int));
122  map[2][0] = -1;
123  map[2][1] = -1;
124  map[2][2] = -1;
125  map[2][3] = -1;
126  uves_badmap_free(&map);
127 
128  for (blue = 0; blue <= 1; blue++)
129  for (binx = 1; binx <= 3; binx++)
130  for (biny = 1; biny <= 3; biny++)
131  if (!(
132  (binx == 1 && biny == 3) ||
133  (binx == 2 && biny == 1) ||
134  (binx == 3 && biny == 1) ||
135  (binx == 3 && biny == 2) ||
136  (binx == 3 && biny == 3)
137  )){
138  enum uves_chip chip;
139  for (chip = uves_chip_get_first(blue);
140  chip != UVES_CHIP_INVALID;
141  chip = uves_chip_get_next(chip))
142  {
143  uves_free_image(&master_bias);
144  master_bias = cpl_image_new(4096/biny, 2048/binx, CPL_TYPE_DOUBLE);
145  assure_mem( master_bias );
146 
147  for (mark_bad = 0; mark_bad <= 1; mark_bad++)
148  {
149  int expected_size;
150 
151  /* Call low level function */
152  check( map = uves_get_badpix(chip, binx, biny, mark_bad,0),
153  "Error getting bad pixel map");
154  uves_badmap_free(&map);
155 
156  /* Call higher level wrapper */
157  uves_propertylist_empty(header);
158  check( uves_correct_badpix_all(master_bias, header,
159  chip,
160  binx, biny, mark_bad,0),
161  "Error in bad pixel correction");
162 
163  /* Should write one key: correct = true (or something like that) */
164  if (chip == UVES_CHIP_BLUE)
165  {
166  expected_size = 0;
167  }
168  else
169  {
170  expected_size = 1;
171  }
172  assure( uves_propertylist_get_size(header) == expected_size,
173  CPL_ERROR_ILLEGAL_OUTPUT, "Wrong output header size: %ld "
174  "(%d expected)",
175  uves_propertylist_get_size(header), expected_size);
176  }
177 
178  }
179  }
180 
181  cleanup:
182  uves_badmap_free(&map);
183  uves_free_propertylist(&header);
184  uves_free_image(&master_bias);
185  return;
186 }
187 
188 
189 /*----------------------------------------------------------------------------*/
193 /*----------------------------------------------------------------------------*/
194 
195 int main(void)
196 {
197  /* Initialize CPL + UVES messaging */
198  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
199 
200  check( test_bad_corr(),
201  "Test failed");
202 
203  cleanup:
204  return cpl_test_end(0);
205 }
206 
207 
void uves_propertylist_empty(uves_propertylist *self)
Remove all properties from a property list.
void uves_badmap_free(int ***badmap)
Deallocate bpm position.
int ** uves_get_badpix(enum uves_chip chip, int binx, int biny, int mark_bad, bool red_ccd_new)
Get hard-coded bpm map.
uves_propertylist * uves_propertylist_new(void)
Create an empty property list.
long uves_propertylist_get_size(const uves_propertylist *self)
Get the current size of a property list.
static void test_bad_corr(void)
Call the functions which had many memory errors.
#define assure_mem(PTR)
Definition: uves_error.h:181
enum uves_chip uves_chip_get_first(bool blue)
Get first chip for blue or red arm.
Definition: uves_chip.c:92
enum uves_chip uves_chip_get_next(enum uves_chip chip)
Get next chip.
Definition: uves_chip.c:108
int uves_correct_badpix_all(cpl_image *master_bias, uves_propertylist *mbias_header, enum uves_chip chip, int binx, int biny, int mark_bad, bool red_ccd_new)
Correct all bad pixels on a chip.
int main(void)
Test of uves_corrbadpix.
#define check(CMD,...)
Definition: uves_error.h:198