VIRCAM Pipeline  2.3.12
casu_flatcor-test.c
1 /* $Id: casu_flatcor-test.c,v 1.2 2015/08/07 13:06: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/08/07 13:06: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_fits.h>
34 #include <casu_utils.h>
35 #include <casu_mods.h>
36 
37 int main(void) {
38  int status,retval;
39  casu_fits *in,*flat;
40  cpl_image *inim,*flatim;
41  cpl_propertylist *ehu;
42  double mean,stdev;
43 
44  /* Initialise */
45 
46  cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING);
47 
48  /* Check inherited status */
49 
50  status = CASU_FATAL;
51  in = NULL;
52  flat = NULL;
53  retval = casu_flatcor(in,flat,&status);
54  cpl_test_eq(status,CASU_FATAL);
55  cpl_test_eq(status,retval);
56 
57  /* Create some images. Create them a different sizes */
58 
59  inim = cpl_image_new(10,10,CPL_TYPE_FLOAT);
60  flatim = cpl_image_new(11,11,CPL_TYPE_FLOAT);
61  ehu = cpl_propertylist_new();
62  cpl_propertylist_update_string(ehu,"ESO DRS FLATCOR","testfile");
63  in = casu_fits_wrap(inim,NULL,NULL,ehu);
64  cpl_propertylist_delete(ehu);
65  ehu = casu_fits_get_ehu(in);
66  flat = casu_fits_wrap(flatim,NULL,NULL,NULL);
67  status = CASU_OK;
68 
69  /* Status should be OK if it thinks it's already corrected the image */
70 
71  retval = casu_flatcor(in,flat,&status);
72  cpl_test_eq(status,CASU_OK);
73  cpl_test_eq(status,retval);
74 
75  /* Check to make sure it fails because of difference in image dimensions */
76 
77  cpl_propertylist_erase(ehu,"ESO DRS FLATCOR");
78  retval = casu_flatcor(in,flat,&status);
79  cpl_test_eq(status,CASU_FATAL);
80  cpl_test_eq(status,retval);
81 
82  /* Set up the images to have some data in them and they are the same
83  dimensionality */
84 
85  cpl_image_add_scalar(inim,10.0);
86  casu_fits_unwrap(flat);
87  cpl_image_delete(flatim);
88  flatim = cpl_image_new(10,10,CPL_TYPE_FLOAT);
89  cpl_image_multiply_scalar(flatim,0.0);
90  flat = casu_fits_wrap(flatim,NULL,NULL,NULL);
91  status = CASU_OK;
92 
93  /* See if we get a warning for the zero divide */
94 
95  retval = casu_flatcor(in,flat,&status);
96  cpl_test_eq(status,CASU_WARN);
97  cpl_test_eq(status,retval);
98  cpl_propertylist_erase(ehu,"ESO DRS FLATCOR");
99 
100  /* Now give the flat non-zero values */
101 
102  cpl_image_add_scalar(flatim,2.0);
103 
104  /* Test to see if you get the right answer */
105 
106  status = CASU_OK;
107  retval = casu_flatcor(in,flat,&status);
108  cpl_test_eq(status,CASU_OK);
109  cpl_test_eq(status,retval);
110  mean = cpl_image_get_mean((const cpl_image *)inim);
111  stdev = cpl_image_get_stdev((const cpl_image *)inim);
112  cpl_test_rel(mean,5.0,1.0e-6);
113  cpl_test_rel(stdev,0.0,1.0e-6);
114  cpl_test_eq_string("Memory File",
115  cpl_propertylist_get_string(ehu,"ESO DRS FLATCOR"));
116 
117  /* Tidy up and get out of here */
118 
119  casu_fits_unwrap(in);
120  casu_fits_unwrap(flat);
121  cpl_image_delete(inim);
122  cpl_image_delete(flatim);
123 
124  return(cpl_test_end(0));
125 }
126 
127 /*
128 
129 $Log: casu_flatcor-test.c,v $
130 Revision 1.2 2015/08/07 13:06:54 jim
131 Fixed copyright to ESO
132 
133 Revision 1.1.1.1 2015/06/12 10:44:32 jim
134 Initial import
135 
136 Revision 1.1 2014/03/26 15:31:29 jim
137 New Entry
138 
139 
140 */
casu_fits * casu_fits_wrap(cpl_image *im, casu_fits *model, cpl_propertylist *phu, cpl_propertylist *ehu)
Definition: casu_fits.c:883
void casu_fits_unwrap(casu_fits *p)
Definition: casu_fits.c:945
cpl_propertylist * casu_fits_get_ehu(casu_fits *p)
Definition: casu_fits.c:576
int casu_flatcor(casu_fits *infile, casu_fits *flatsrc, int *status)
Correct input data for flat field response.
Definition: casu_flatcor.c:79