VIRCAM Pipeline 2.3.12
casu_imcombine-test.c
1/* $Id: casu_imcombine-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
37int main(void) {
38 int status,retval;
39 cpl_image *im,*outim,*outimv;
40 casu_fits *infits[10];
41 unsigned char *rejmask,*rejplus;
42 cpl_propertylist *drs,*phu,*ehu;
43 int i;
44 double val1,val2,ave;
45
46 /* Initialise */
47
48 cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING);
49
50 /* Check inherited status */
51
52 status = CASU_FATAL;
53 retval = casu_imcombine(NULL,NULL,100,2,1,0,100.0,"EXPTIME",&outim,
54 &outimv,&rejmask,&rejplus,&drs,&status);
55 cpl_test_eq(status,CASU_FATAL);
56 cpl_test_eq(status,retval);
57 cpl_test_null(outim);
58 cpl_test_null(outimv);
59 cpl_test_null(rejmask);
60 cpl_test_null(rejplus);
61 cpl_test_null(drs);
62 status = CASU_OK;
63
64 /* Create some images to stack */
65
66 for (i = 0; i < 10; i++) {
67 im = cpl_image_new(100,100,CPL_TYPE_FLOAT);
68 if (i % 2 == 0) {
69 ave = 100.0;
70 } else {
71 ave = 200.0;
72 }
73 val1 = ave - 10.0;
74 val2 = ave + 10.0;
75 cpl_image_fill_noise_uniform(im,val1,val2);
76 phu = cpl_propertylist_new();
77 ehu = cpl_propertylist_new();
78 cpl_propertylist_update_float(phu,"EXPTIME",ave);
79 infits[i] = casu_fits_wrap(im,NULL,phu,ehu);
80 cpl_propertylist_delete(phu);
81 cpl_propertylist_delete(ehu);
82 }
83
84 /* Test the routine with straight-forward averaging and additive
85 scaling */
86
87 retval = casu_imcombine(infits,NULL,10,2,1,0,100.0,"EXPTIME",&outim,
88 &outimv,&rejmask,&rejplus,&drs,&status);
89 cpl_test_eq(status,CASU_OK);
90 cpl_test_eq(status,retval);
91 cpl_test_nonnull(outim);
92 cpl_test_null(outimv);
93 cpl_test_nonnull(rejmask);
94 cpl_test_nonnull(rejplus);
95 cpl_test_nonnull(drs);
96 cpl_test_rel(cpl_image_get_mean(outim),150.0,0.001);
97 cpl_image_delete(outim);
98 cpl_free(rejmask);
99 cpl_free(rejplus);
100 cpl_propertylist_delete(drs);
101
102 /* Test the routine with straight-forward averaging and multiplicative
103 scaling */
104
105 retval = casu_imcombine(infits,NULL,10,2,2,0,100.0,"EXPTIME",&outim,
106 &outimv,&rejmask,&rejplus,&drs,&status);
107 cpl_test_eq(status,CASU_OK);
108 cpl_test_eq(status,retval);
109 cpl_test_nonnull(outim);
110 cpl_test_null(outimv);
111 cpl_test_nonnull(rejmask);
112 cpl_test_nonnull(rejplus);
113 cpl_test_nonnull(drs);
114 cpl_test_rel(cpl_image_get_mean(outim),150.0,0.001);
115 cpl_image_delete(outim);
116 cpl_free(rejmask);
117 cpl_free(rejplus);
118 cpl_propertylist_delete(drs);
119
120 /* Test the routine with straight-forward averaging and exposure time
121 scaling */
122
123 retval = casu_imcombine(infits,NULL,10,2,3,0,100.0,"EXPTIME",&outim,
124 &outimv,&rejmask,&rejplus,&drs,&status);
125 cpl_test_eq(status,CASU_OK);
126 cpl_test_eq(status,retval);
127 cpl_test_nonnull(outim);
128 cpl_test_null(outimv);
129 cpl_test_nonnull(rejmask);
130 cpl_test_nonnull(rejplus);
131 cpl_test_nonnull(drs);
132 cpl_test_rel(cpl_image_get_mean(outim),100.0,0.001);
133 cpl_image_delete(outim);
134 cpl_free(rejmask);
135 cpl_free(rejplus);
136 cpl_propertylist_delete(drs);
137
138 /* Tidy and exit */
139
140 for (i = 0; i < 10; i++)
141 casu_fits_delete(infits[i]);
142 return(cpl_test_end(0));
143}
144
145/*
146
147$Log: casu_imcombine-test.c,v $
148Revision 1.2 2015/08/07 13:06:54 jim
149Fixed copyright to ESO
150
151Revision 1.1.1.1 2015/06/12 10:44:32 jim
152Initial import
153
154Revision 1.1 2015/01/09 11:39:55 jim
155new entry
156
157
158*/
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_delete(casu_fits *p)
Definition: casu_fits.c:364
int casu_imcombine(casu_fits **fset, casu_fits **fsetv, int nfits, int combtype, int scaletype, int xrej, float thresh, const char *expkey, cpl_image **outimage, cpl_image **outvimage, unsigned char **rejmask, unsigned char **rejplus, cpl_propertylist **drs, int *status)
Stack images into a mean or median image with rejection.