VIRCAM Pipeline  1.3.4
vircam/vircam_mkconf.c
1 /* $Id: vircam_mkconf.c,v 1.14 2012-01-27 12:25:10 jim Exp $
2  *
3  * This file is part of the VIRCAM Pipeline
4  * Copyright (C) 2005 Cambridge Astronomy Survey Unit
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: 2012-01-27 12:25:10 $
24  * $Revision: 1.14 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 /* Includes */
29 
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 
34 #include "vircam_mods.h"
35 #include "vircam_utils.h"
36 #include "vircam_mask.h"
37 #include "vircam_stats.h"
38 #include "vircam_fits.h"
39 
42 /*---------------------------------------------------------------------------*/
85 /*---------------------------------------------------------------------------*/
86 
87 extern int vircam_mkconf(cpl_image *flat, char *flatfile, vir_mask *bpm,
88  cpl_image **outconf, cpl_propertylist **drs,
89  int *status) {
90  int i,*odata,nx,ny;
91  long npts;
92  unsigned char *bdata;
93  float *fdata,mean;
94  const char *fctid = "vircam_mkconf";
95 
96  /* Inherited status */
97 
98  if (*status != VIR_OK)
99  return(*status);
100 
101  /* Check the sizes of the input images to make sure they match */
102 
103  nx = (int)cpl_image_get_size_x(flat);
104  ny = (int)cpl_image_get_size_y(flat);
105  npts = nx*ny;
106  if (vircam_mask_get_size_x(bpm)*vircam_mask_get_size_y(bpm) != npts) {
107  cpl_msg_error(fctid,"Input image sizes don't match!");
108  FATAL_ERROR
109  }
110 
111  /* Get input the data arrays */
112 
113  if ((fdata = cpl_image_get_data_float(flat)) == NULL) {
114  cpl_msg_error(fctid,"Unable to map flat data!");
115  FATAL_ERROR
116  }
117  bdata = vircam_mask_get_data(bpm);
118 
119  /* Get a data array for the output */
120 
121  odata = cpl_malloc(npts*sizeof(*odata));
122 
123  /* Work out the mean of the flat field. It should already be 1, but you
124  never know... */
125 
126  mean = vircam_mean(fdata,bdata,npts);
127 
128  /* Now create the output array */
129 
130  for (i = 0; i < npts; i++) {
131  if (bdata[i] != 1)
132  odata[i] = max(0,min(110,(int)(100.0*fdata[i]/mean + 0.5)));
133  else
134  odata[i] = 0;
135  }
136 
137  /* Wrap the data into an output image */
138 
139  *outconf = cpl_image_wrap_int((cpl_size)nx,(cpl_size)ny,odata);
140 
141  /* Create some properties */
142 
143  *drs = cpl_propertylist_new();
144  cpl_propertylist_update_string(*drs,"ESO DRS FLATIN",flatfile);
145  cpl_propertylist_set_comment(*drs,"ESO DRS FLATIN",
146  "Flat used to create this conf map");
147  if (vircam_mask_get_type(bpm) != MASK_NONE)
148  cpl_propertylist_update_string(*drs,"ESO DRS BPMIN",
150  else
151  cpl_propertylist_update_string(*drs,"ESO DRS BPMIN","None available");
152  cpl_propertylist_set_comment(*drs,"ESO DRS BPMIN",
153  "BPM used to create this conf map");
154 
155  /* Tidy up */
156 
157  GOOD_STATUS
158 }
159 
162 /*
163 
164 $Log: not supported by cvs2svn $
165 Revision 1.13 2012/01/15 17:40:09 jim
166 Minor modifications to take into accout the changes in cpl API for v6
167 
168 Revision 1.12 2008/09/29 11:30:48 jim
169 Modified to set a lower limit of 0 confidence
170 
171 Revision 1.11 2007/03/29 12:19:39 jim
172 Little changes to improve documentation
173 
174 Revision 1.10 2007/03/01 12:42:42 jim
175 Modified slightly after code checking
176 
177 Revision 1.9 2006/04/20 11:27:28 jim
178 Error messages now print an extension name rather than an extension number
179 
180 Revision 1.8 2006/03/23 21:18:52 jim
181 Minor changes mainly to comment headers
182 
183 Revision 1.7 2006/03/22 13:58:32 jim
184 Cosmetic fixes to keep lint happy
185 
186 Revision 1.6 2006/03/22 13:19:19 jim
187 Altered calling sequence slightly
188 
189 Revision 1.5 2006/03/22 12:02:40 jim
190 bpm is accessed using vircam_mask interface
191 
192 Revision 1.4 2006/03/15 10:43:41 jim
193 Fixed a few things
194 
195 Revision 1.3 2006/03/01 10:31:29 jim
196 Now uses new vir_fits objects
197 
198 Revision 1.2 2006/02/22 14:08:07 jim
199 Fixed silly doc error
200 
201 Revision 1.1 2006/02/18 11:46:36 jim
202 new file
203 
204 
205 */
vir_fits * vircam_mask_get_fits(vir_mask *m)
Definition: vircam_mask.c:415
float vircam_mean(float *data, unsigned char *bpm, long npts)
Definition: vircam_stats.c:246
int vircam_mkconf(cpl_image *flat, char *flatfile, vir_mask *bpm, cpl_image **outconf, cpl_propertylist **drs, int *status)
Create a confidence map.
char * vircam_fits_get_fullname(vir_fits *p)
Definition: vircam_fits.c:560
unsigned char * vircam_mask_get_data(vir_mask *m)
Definition: vircam_mask.c:535
int vircam_mask_get_size_x(vir_mask *m)
Definition: vircam_mask.c:466
int vircam_mask_get_type(vir_mask *m)
Definition: vircam_mask.c:512
int vircam_mask_get_size_y(vir_mask *m)
Definition: vircam_mask.c:489