vircam_mkconf.c

00001 /* $Id: vircam_mkconf.c,v 1.11 2007/03/29 12:19:39 jim Exp $
00002  *
00003  * This file is part of the VIRCAM Pipeline
00004  * Copyright (C) 2005 Cambridge Astronomy Survey Unit
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: jim $
00023  * $Date: 2007/03/29 12:19:39 $
00024  * $Revision: 1.11 $
00025  * $Name:  $
00026  */
00027 
00028 /* Includes */
00029 
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033 
00034 #include "vircam_mods.h"
00035 #include "vircam_utils.h"
00036 #include "vircam_mask.h"
00037 #include "vircam_stats.h"
00038 #include "vircam_fits.h"
00039 
00042 /*---------------------------------------------------------------------------*/
00085 /*---------------------------------------------------------------------------*/
00086 
00087 extern int vircam_mkconf(cpl_image *flat, char *flatfile, vir_mask *bpm, 
00088                          cpl_image **outconf, cpl_propertylist **drs, 
00089                          int *status) {
00090     int i,*odata,nx,ny;
00091     long npts;
00092     unsigned char *bdata;
00093     float *fdata,mean;
00094     const char *fctid = "vircam_mkconf";
00095 
00096     /* Inherited status */
00097 
00098     if (*status != VIR_OK)
00099         return(*status);
00100 
00101     /* Check the sizes of the input images to make sure they match */
00102 
00103     nx = cpl_image_get_size_x(flat);
00104     ny = cpl_image_get_size_y(flat);
00105     npts = nx*ny;
00106     if (vircam_mask_get_size_x(bpm)*vircam_mask_get_size_y(bpm) != npts) {
00107         cpl_msg_error(fctid,"Input image sizes don't match!");
00108         FATAL_ERROR
00109     }
00110 
00111     /* Get input the data arrays */
00112 
00113     if ((fdata = cpl_image_get_data_float(flat)) == NULL) {
00114         cpl_msg_error(fctid,"Unable to map flat data!");
00115         FATAL_ERROR
00116     }
00117     bdata = vircam_mask_get_data(bpm);
00118 
00119     /* Get a data array for the output */
00120 
00121     odata = cpl_malloc(npts*sizeof(*odata));
00122 
00123     /* Work out the mean of the flat field. It should already be 1, but you
00124        never know... */
00125 
00126     mean = vircam_mean(fdata,bdata,npts);
00127 
00128     /* Now create the output array */
00129 
00130     for (i = 0; i < npts; i++) {
00131         if (bdata[i] != 1)
00132             odata[i] = min(110,(int)(100.0*fdata[i]/mean + 0.5));
00133         else
00134             odata[i] = 0;
00135     }
00136 
00137     /* Wrap the data into an output image */
00138 
00139     *outconf = cpl_image_wrap_int(nx,ny,odata);
00140 
00141     /* Create some properties */
00142 
00143     *drs = cpl_propertylist_new();
00144     cpl_propertylist_update_string(*drs,"ESO DRS FLATIN",flatfile);
00145     cpl_propertylist_set_comment(*drs,"ESO DRS FLATIN",
00146                                  "Flat used to create this conf map");
00147     if (vircam_mask_get_type(bpm) != MASK_NONE) 
00148         cpl_propertylist_update_string(*drs,"ESO DRS BPMIN",
00149                                        vircam_fits_get_fullname(vircam_mask_get_fits(bpm)));
00150     else
00151         cpl_propertylist_update_string(*drs,"ESO DRS BPMIN","None available");
00152     cpl_propertylist_set_comment(*drs,"ESO DRS BPMIN",
00153                                  "BPM used to create this conf map");
00154 
00155     /* Tidy up */
00156 
00157     GOOD_STATUS
00158 }
00159 
00162 /*
00163 
00164 $Log: vircam_mkconf.c,v $
00165 Revision 1.11  2007/03/29 12:19:39  jim
00166 Little changes to improve documentation
00167 
00168 Revision 1.10  2007/03/01 12:42:42  jim
00169 Modified slightly after code checking
00170 
00171 Revision 1.9  2006/04/20 11:27:28  jim
00172 Error messages now print an extension name rather than an extension number
00173 
00174 Revision 1.8  2006/03/23 21:18:52  jim
00175 Minor changes mainly to comment headers
00176 
00177 Revision 1.7  2006/03/22 13:58:32  jim
00178 Cosmetic fixes to keep lint happy
00179 
00180 Revision 1.6  2006/03/22 13:19:19  jim
00181 Altered calling sequence slightly
00182 
00183 Revision 1.5  2006/03/22 12:02:40  jim
00184 bpm is accessed using vircam_mask interface
00185 
00186 Revision 1.4  2006/03/15 10:43:41  jim
00187 Fixed a few things
00188 
00189 Revision 1.3  2006/03/01 10:31:29  jim
00190 Now uses new vir_fits objects
00191 
00192 Revision 1.2  2006/02/22 14:08:07  jim
00193 Fixed silly doc error
00194 
00195 Revision 1.1  2006/02/18 11:46:36  jim
00196 new file
00197 
00198 
00199 */

Generated on Wed Apr 10 04:01:56 2013 for VIRCAM Pipeline by  doxygen 1.5.1