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