vircam_destripe.c

00001 /* $Id: vircam_destripe.c,v 1.7 2007/10/25 17:34:00 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/10/25 17:34:00 $
00024  * $Revision: 1.7 $
00025  * $Name:  $
00026  */
00027 
00028 /* Includes */
00029 
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033 
00034 #include <cpl.h>
00035 #include <cxtypes.h>
00036 #include <math.h>
00037 
00038 #include "vircam_mods.h"
00039 #include "vircam_utils.h"
00040 #include "vircam_stats.h"
00041 #include "vircam_mask.h"
00042 
00045 /*---------------------------------------------------------------------------*/
00082 /*---------------------------------------------------------------------------*/
00083 
00084 extern int vircam_destripe(vir_fits *in, vir_mask *inbpm, int *status) {
00085     float *data,*d,medprofile,profilerms,*wptr,val;
00086     unsigned char *bpm,*b,*rb;
00087     long i,j,nx,ny;
00088     cpl_propertylist *plist;
00089 
00090     /* Inherited status */
00091 
00092     if (*status != VIR_OK)
00093         return(*status);
00094 
00095     /* Get the data array for the input image and the bad pixel mask */
00096 
00097     data = cpl_image_get_data(vircam_fits_get_image(in));
00098     if (inbpm != NULL) 
00099         bpm = vircam_mask_get_data(inbpm);
00100     else
00101         bpm = NULL;
00102 
00103     /* Get the data array size */
00104 
00105     nx = (long)cpl_image_get_size_x(vircam_fits_get_image(in));
00106     ny = (long)cpl_image_get_size_y(vircam_fits_get_image(in));
00107 
00108     /* Get some workspace to hold the 1d profile */
00109 
00110     wptr = cpl_malloc(nx*sizeof(*wptr));
00111     rb = cpl_calloc(nx,sizeof(*rb));
00112 
00113     /* Loop for each row */
00114 
00115     d = data;
00116     b = bpm;
00117     for (i = 0; i < ny; i++) {
00118 
00119         /* Get the median for that row, ignoring any bad pixels */
00120 
00121         val = vircam_med(d,b,nx);
00122         if (val == CX_MAXFLOAT) {
00123             wptr[i] = 0.0;
00124             rb[i] = 1;
00125         } else {
00126             wptr[i] = val;
00127         }
00128         d += nx;
00129         if (b != NULL)
00130             b += nx;
00131     }
00132 
00133     /* Get the median of the profile and normalise the profile 
00134        to zero median */
00135 
00136     vircam_medsig(wptr,rb,ny,&medprofile,&profilerms);
00137     for (i = 0; i < ny; i++) {
00138         if (rb[i]) {
00139             wptr[i] = 0.0;
00140         } else {
00141             wptr[i] -= medprofile;
00142         }
00143     }
00144     cpl_free(rb);
00145 
00146     /* Now do the correction */
00147 
00148     d = data;
00149     for (i = 0; i < ny; i++) {
00150         for (j = 0; j < nx; j++) 
00151             d[j] -= wptr[i];
00152         d += nx;
00153     }
00154 
00155     /* Store the RMS of the profile away */
00156 
00157     plist = vircam_fits_get_ehu(in);
00158     cpl_propertylist_update_bool(plist,"ESO DRS STRIPECOR",TRUE);
00159     cpl_propertylist_set_comment(plist,"ESO DRS STRIPECOR",
00160                                  "Stripe correction done");
00161     cpl_propertylist_update_float(plist,"ESO DRS STRIPERMS",profilerms);
00162     cpl_propertylist_set_comment(plist,"ESO DRS STRIPERMS",
00163                                  "RMS of the removed stripe profile");
00164 
00165     /* Ditch the workspace and get out of here */
00166 
00167     freespace(wptr);
00168     GOOD_STATUS
00169 }
00170         
00171 
00175 /*
00176 
00177 $Log: vircam_destripe.c,v $
00178 Revision 1.7  2007/10/25 17:34:00  jim
00179 Modified to remove lint warnings
00180 
00181 Revision 1.6  2007/09/07 10:45:10  jrl
00182 Fixed bug which arises if an entire row is flagged bad
00183 
00184 Revision 1.5  2007/03/29 12:19:39  jim
00185 Little changes to improve documentation
00186 
00187 Revision 1.4  2007/03/01 12:42:41  jim
00188 Modified slightly after code checking
00189 
00190 Revision 1.3  2006/11/27 12:09:35  jim
00191 Tidied up some docs. Also modified definition of DRS STRIPECOR so that it's
00192 now a boolean
00193 
00194 Revision 1.2  2006/11/10 10:27:56  jim
00195 Added STRIPECOR header parameter
00196 
00197 Revision 1.1  2006/10/02 13:43:31  jim
00198 new file
00199 
00200 
00201 */

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