VIRCAM Pipeline  2.3.12
casu_imdither-test.c
1 /* $Id: casu_imdither-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,i;
39  cpl_propertylist *prop,*phu,*ehu;
40  cpl_image *out,*outc,*im;
41  casu_fits *infits[2],*inconfs[2];
42  double ave,val1,val2;
43  float off;
44 
45  /* Initialise */
46 
47  cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING);
48 
49  /* Check inherited status and the situation where you say there are
50  no input frames */
51 
52  status = CASU_FATAL;
53  retval = casu_imdither(NULL,NULL,10,10,100.0,100.0,&prop,"EXPTIME",
54  &out,&outc,&status);
55  cpl_test_eq(status,CASU_FATAL);
56  cpl_test_eq(status,retval);
57  cpl_test_null(prop);
58  cpl_test_null(out);
59  cpl_test_null(outc);
60  status = CASU_OK;
61  retval = casu_imdither(NULL,NULL,0,10,100.0,100.0,&prop,"EXPTIME",
62  &out,&outc,&status);
63  cpl_test_eq(status,CASU_FATAL);
64  cpl_test_eq(status,retval);
65  cpl_test_null(prop);
66  cpl_test_null(out);
67  cpl_test_null(outc);
68 
69  /* Make a couple of frames and some confidence maps */
70 
71  for (i = 0; i < 2; i++) {
72  ave = 100.0*(float)(i+1);
73  val1 = ave - 5.0;
74  val2 = ave + 5.0;
75  im = cpl_image_new(100,100,CPL_TYPE_FLOAT);
76  cpl_image_fill_noise_uniform(im,val1,val2);
77  phu = cpl_propertylist_new();
78  ehu = cpl_propertylist_new();
79  off = (i == 0 ? 0.0 : 50.0);
80  cpl_propertylist_update_float(ehu,"ESO DRS XOFFDITHER",off);
81  cpl_propertylist_update_float(ehu,"ESO DRS YOFFDITHER",0.0);
82  infits[i] = casu_fits_wrap(im,NULL,phu,ehu);
83  cpl_propertylist_delete(phu);
84  cpl_propertylist_delete(ehu);
85 
86  val1 = 99.0;
87  val2 = 101.0;
88  im = cpl_image_new(100,100,CPL_TYPE_INT);
89  cpl_image_fill_noise_uniform(im,val1,val2);
90  phu = cpl_propertylist_new();
91  ehu = cpl_propertylist_new();
92  inconfs[i] = casu_fits_wrap(im,NULL,phu,ehu);
93  cpl_propertylist_delete(phu);
94  cpl_propertylist_delete(ehu);
95  }
96 
97  /* Now test to see if we get a reasonable dither */
98 
99  status = CASU_OK;
100  retval = casu_imdither(infits,inconfs,2,2,100.0,100.0,&prop,"EXPTIME",
101  &out,&outc,&status);
102  cpl_test_eq(status,CASU_OK);
103  cpl_test_eq(status,retval);
104  cpl_test_nonnull(prop);
105  cpl_test_nonnull(out);
106  cpl_test_nonnull(outc);
107  cpl_test_eq(150,cpl_image_get_size_x(out));
108  cpl_test_eq(100,cpl_image_get_size_y(out));
109  cpl_test_rel(100.0,cpl_image_get_mean(out),0.001);
110 
111  /* Tidy and exit */
112 
113  cpl_propertylist_delete(prop);
114  cpl_image_delete(out);
115  cpl_image_delete(outc);
116  for (i = 0; i < 2; i++) {
117  casu_fits_delete(infits[i]);
118  casu_fits_delete(inconfs[i]);
119  }
120  return(cpl_test_end(0));
121 }
122 
123 /*
124 
125 $Log: casu_imdither-test.c,v $
126 Revision 1.2 2015/08/07 13:06:54 jim
127 Fixed copyright to ESO
128 
129 Revision 1.1.1.1 2015/06/12 10:44:32 jim
130 Initial import
131 
132 Revision 1.1 2015/01/09 11:39:55 jim
133 new entry
134 
135 
136 */
void casu_fits_delete(casu_fits *p)
Definition: casu_fits.c:364
casu_fits * casu_fits_wrap(cpl_image *im, casu_fits *model, cpl_propertylist *phu, cpl_propertylist *ehu)
Definition: casu_fits.c:883
int casu_imdither(casu_fits **inf, casu_fits **inconf, int nimages, int nconfs, float lthr, float hthr, cpl_propertylist **p, const char *expkey, cpl_image **out, cpl_image **outc, int *status)
Dither a set of jittered observations.