VIRCAM Pipeline 2.3.15
casu_mkconf.c
1/* $Id: casu_mkconf.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/* Includes */
29
30#ifdef HAVE_CONFIG_H
31#include <config.h>
32#endif
33
34#include "casu_mods.h"
35#include "catalogue/casu_utils.h"
36#include "casu_mask.h"
37#include "casu_stats.h"
38#include "catalogue/casu_fits.h"
39
42/*---------------------------------------------------------------------------*/
85/*---------------------------------------------------------------------------*/
86
87extern int casu_mkconf(cpl_image *flat, char *flatfile, casu_mask *bpm,
88 cpl_image **outconf, cpl_propertylist **drs,
89 int *status) {
90 int i,nx,ny;
91 long npts;
92 unsigned char *bdata;
93 float *fdata,mean;
94 int *odata;
95 const char *fctid = "casu_mkconf";
96
97 /* Inherited status */
98
99 *outconf = NULL;
100 *drs = NULL;
101 if (*status != CASU_OK)
102 return(*status);
103
104 /* Check the sizes of the input images to make sure they match */
105
106 nx = (int)cpl_image_get_size_x(flat);
107 ny = (int)cpl_image_get_size_y(flat);
108 npts = nx*ny;
109 if (casu_mask_get_size_x(bpm)*casu_mask_get_size_y(bpm) != npts) {
110 cpl_msg_error(fctid,"Input image sizes don't match!");
111 FATAL_ERROR
112 }
113
114 /* Get input the data arrays */
115
116 if ((fdata = cpl_image_get_data_float(flat)) == NULL) {
117 cpl_msg_error(fctid,"Unable to map flat data!");
118 FATAL_ERROR
119 }
120 bdata = casu_mask_get_data(bpm);
121
122 /* Get a data array for the output */
123
124 odata = cpl_malloc(npts*sizeof(*odata));
125
126 /* Work out the mean of the flat field. It should already be 1, but you
127 never know... */
128
129 mean = casu_mean(fdata,bdata,npts);
130
131 /* Now create the output array */
132
133 for (i = 0; i < npts; i++) {
134 if (bdata[i] != 1) {
135 odata[i] = max(0,min(110,(int)(100*fdata[i]/mean)));
136 if (odata[i] < 20)
137 odata[i] = 0;
138 } else {
139 odata[i] = 0;
140 }
141 }
142
143 /* Wrap the data into an output image */
144
145 *outconf = cpl_image_wrap_int((cpl_size)nx,(cpl_size)ny,odata);
146
147 /* Create some properties */
148
149 *drs = cpl_propertylist_new();
150 cpl_propertylist_update_string(*drs,"ESO DRS FLATIN",flatfile);
151 cpl_propertylist_set_comment(*drs,"ESO DRS FLATIN",
152 "Flat used to create this conf map");
153 if (casu_mask_get_type(bpm) != MASK_NONE &&
154 casu_mask_get_filename(bpm) != NULL)
155 cpl_propertylist_update_string(*drs,"ESO DRS BPMIN",
157 else
158 cpl_propertylist_update_string(*drs,"ESO DRS BPMIN","None available");
159 cpl_propertylist_set_comment(*drs,"ESO DRS BPMIN",
160 "BPM used to create this conf map");
161
162 /* Tidy up */
163
164 GOOD_STATUS
165}
166
169/*
170
171$Log: casu_mkconf.c,v $
172Revision 1.2 2015/08/07 13:06:54 jim
173Fixed copyright to ESO
174
175Revision 1.1.1.1 2015/06/12 10:44:32 jim
176Initial import
177
178Revision 1.6 2015/01/29 11:51:56 jim
179modified comments
180
181Revision 1.5 2015/01/09 12:13:15 jim
182*** empty log message ***
183
184Revision 1.4 2014/12/11 12:23:33 jim
185new version
186
187Revision 1.3 2014/03/26 15:51:53 jim
188Creates floating point confidence maps now
189
190Revision 1.2 2013/11/21 09:38:14 jim
191detabbed
192
193Revision 1.1.1.1 2013-08-27 12:07:48 jim
194Imported
195
196
197*/
unsigned char * casu_mask_get_data(casu_mask *m)
Definition: casu_mask.c:544
int casu_mask_get_size_y(casu_mask *m)
Definition: casu_mask.c:498
int casu_mask_get_type(casu_mask *m)
Definition: casu_mask.c:521
const char * casu_mask_get_filename(casu_mask *m)
Definition: casu_mask.c:447
int casu_mask_get_size_x(casu_mask *m)
Definition: casu_mask.c:475
int casu_mkconf(cpl_image *flat, char *flatfile, casu_mask *bpm, cpl_image **outconf, cpl_propertylist **drs, int *status)
Create a confidence map.
Definition: casu_mkconf.c:87
float casu_mean(float *data, unsigned char *bpm, long npts)
Definition: casu_stats.c:479