VIRCAM Pipeline  2.3.10
casu_imcore-test.c
1 /* $Id: casu_imcore-test.c,v 1.4 2015/11/18 20:04:26 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/11/18 20:04:26 $
24  * $Revision: 1.4 $
25  * $Name: $
26  */
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <math.h>
31 
32 #include <cpl_init.h>
33 #include <cpl_test.h>
34 #include <casu_tfits.h>
35 #include <casu_utils.h>
36 #include <casu_mods.h>
37 
38 #define NTEST 10
39 
40 int main(void) {
41  int status,retval,i,nrow,ncol,nl;
42  casu_tfits *outtab;
43  cpl_image *im,*bkg,*cnf;
44  cpl_table *tab;
45  double sigma=2.0,norm2,tot[NTEST],sky=500.0,diff;
46  double xpos[] = {100.0,200.0,300.0,400.0,500.0,600.0,700.0,800.0,900.0,
47  1000.0};
48  double ypos[] = {100.0,200.0,300.0,400.0,500.0,600.0,700.0,800.0,900.0,
49  1000.0};
50  double norm[] = {1000.0,100.0,200.0,500.0,550.0,600.0,650.0,700.0,
51  750.0,800.0};
52  casu_fits *inf,*inconf;
53  cpl_propertylist *pl;
54 
55  /* Initialise */
56 
57  cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING);
58 
59  /* Check inherited status */
60 
61  status = CASU_FATAL;
62  retval = casu_imcore(NULL,NULL,5,1.5,1,3.5,64,6,1.0,&outtab,2.0,
63  &status);
64  cpl_test_eq(status,CASU_FATAL);
65  cpl_test_eq(status,retval);
66  cpl_test_null(outtab);
67 
68  /* Generate a field with some stars and a confidence map */
69 
70  bkg = cpl_image_new(1024,1024,CPL_TYPE_FLOAT);
71  im = cpl_image_new(1024,1024,CPL_TYPE_FLOAT);
72  cnf = cpl_image_new(1024,1024,CPL_TYPE_INT);
73  norm2 = 2.0*CPL_MATH_PI*sigma*sigma;
74  cpl_image_fill_noise_uniform(bkg,-10.0,10.0);
75  cpl_image_add_scalar(bkg,sky);
76  cpl_image_fill_noise_uniform(cnf,99.9,100.1);
77  for (i = 0; i < NTEST; i++) {
78  cpl_image_fill_gaussian(im,xpos[i],ypos[i],norm[i]*norm2,sigma,sigma);
79  tot[i] = cpl_image_get_flux(im);
80  cpl_image_add(bkg,im);
81  }
82  pl = cpl_propertylist_new();
83  inf = casu_fits_wrap(bkg,NULL,NULL,pl);
84  inconf = casu_fits_wrap(cnf,NULL,NULL,NULL);
85  cpl_image_delete(im);
86  cpl_propertylist_delete(pl);
87 
88  /* Give it a WCS */
89 
90  pl = casu_fits_get_ehu(inf);
91  cpl_propertylist_update_string(pl,"CTYPE1","RA---TAN");
92  cpl_propertylist_update_string(pl,"CTYPE2","DEC--TAN");
93  cpl_propertylist_update_double(pl,"CRVAL1",30.0);
94  cpl_propertylist_update_double(pl,"CRVAL2",12.0);
95  cpl_propertylist_update_double(pl,"CRPIX1",512.0);
96  cpl_propertylist_update_double(pl,"CRPIX2",512.0);
97  cpl_propertylist_update_double(pl,"CD1_1",-1.0/3600);
98  cpl_propertylist_update_double(pl,"CD1_2",0.0);
99  cpl_propertylist_update_double(pl,"CD2_1",0.0);
100  cpl_propertylist_update_double(pl,"CD2_2",1.0/3600);
101 
102  /* Run imcore */
103 
104  status = CASU_OK;
105  retval = casu_imcore(inf,inconf,5,1.5,0,5.0,64,6,3.0,&outtab,1.0,&status);
106  cpl_test_eq(status,CASU_OK);
107  cpl_test_eq(status,retval);
108  cpl_test_nonnull(outtab);
109  casu_fits_delete(inf);
110  casu_fits_delete(inconf);
111 
112  /* Check the results. Start by checking the number of rows and columns.
113  Sort the table by X */
114 
115  tab = casu_tfits_get_table(outtab);
116  cpl_test_nonnull(tab);
117  ncol = cpl_table_get_ncol(tab);
118  cpl_test_eq(ncol,80);
119  nrow = cpl_table_get_nrow(tab);
120  cpl_test_eq(nrow,NTEST);
121  pl = cpl_propertylist_new();
122  cpl_propertylist_append_bool(pl,"X_coordinate",0);
123  cpl_table_sort(tab,pl);
124  cpl_propertylist_delete(pl);
125 
126  /* Test the column content of the table */
127 
128  for (i = 0; i < NTEST; i++) {
129  cpl_test_abs(xpos[i],cpl_table_get_float(tab,"X_coordinate",(cpl_size)i,
130  &nl),0.2);
131  cpl_test_abs(ypos[i],cpl_table_get_float(tab,"Y_coordinate",(cpl_size)i,
132  &nl),0.2);
133  diff = fabs(cpl_table_get_float(tab,"Aper_flux_5",(cpl_size)i,&nl) -
134  tot[i]);
135  diff /= cpl_table_get_float(tab,"Aper_flux_5_err",(cpl_size)i,&nl);
136  cpl_test_lt(diff,1.5);
137  cpl_test_eq(cpl_table_get_float(tab,"Classification",(cpl_size)i,&nl),
138  -1.0);
139  }
140 
141  /* Compare some header info */
142 
143  pl = casu_tfits_get_ehu(outtab);
144  cpl_test_rel(cpl_propertylist_get_float(pl,"ESO QC IMAGE_SIZE")/2.355,sigma,
145  0.1);
146 
147  /* Get out of here */
148 
149  casu_tfits_delete(outtab);
150  return(cpl_test_end(0));
151 }
152 
153 /*
154 
155 $Log: casu_imcore-test.c,v $
156 Revision 1.4 2015/11/18 20:04:26 jim
157 Fixed missing include
158 
159 Revision 1.3 2015/10/15 11:18:32 jim
160 More comprehensive
161 
162 Revision 1.2 2015/08/07 13:06:54 jim
163 Fixed copyright to ESO
164 
165 Revision 1.1.1.1 2015/06/12 10:44:32 jim
166 Initial import
167 
168 Revision 1.1 2015/01/09 11:39:55 jim
169 new entry
170 
171 
172 */
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
cpl_propertylist * casu_fits_get_ehu(casu_fits *p)
Definition: casu_fits.c:576
int casu_imcore(casu_fits *infile, casu_fits *conf, int ipix, float threshold, int icrowd, float rcore, int nbsize, int cattype, float filtfwhm, casu_tfits **outtab, float gainloc, int *status)
Generate object catalogues from input images.
Definition: casu_imcore.c:149
void casu_tfits_delete(casu_tfits *p)
Definition: casu_tfits.c:292
cpl_table * casu_tfits_get_table(casu_tfits *p)
Definition: casu_tfits.c:364
cpl_propertylist * casu_tfits_get_ehu(casu_tfits *p)
Definition: casu_tfits.c:473