HAWKI Pipeline Reference Manual  1.8.12
hawki_variance.c
1 /* $Id: hawki_variance.c,v 1.2 2009/03/13 11:52:06 cgarcia Exp $
2  *
3  * This file is part of the HAWKI Pipeline
4  * Copyright (C) 2002,2003 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: cgarcia $
23  * $Date: 2009/03/13 11:52:06 $
24  * $Revision: 1.2 $
25  * $Name: hawki-1_8_12 $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 /*-----------------------------------------------------------------------------
33  Includes
34  -----------------------------------------------------------------------------*/
35 
36 #include <float.h>
37 #include <string.h>
38 #include <math.h>
39 #include <cpl.h>
40 
41 #include "hawki_variance.h"
42 
43 /*----------------------------------------------------------------------------*/
47 /*----------------------------------------------------------------------------*/
48 
51 /*----------------------------------------------------------------------------*/
79 /*----------------------------------------------------------------------------*/
81 (const cpl_image * image,
82  double gain,
83  double ron,
84  int ndit,
85  int ndsamples)
86 {
87  cpl_image * variance;
88  float * variance_p;
89  const float * image_p;
90  int pix;
91  int npix;
92  double poisson_contrib;
93  double poisson_factor;
94  double ron_contrib;
95 
96 
97  /* Test entries */
98  if (image == NULL) return NULL;
99 
100  /* Create new image */
101  variance = cpl_image_duplicate(image);
102 
103  /* Loop on pixels */
104  variance_p = cpl_image_get_data(variance);
105  image_p = cpl_image_get_data_const(image);
106  npix = cpl_image_get_size_x(image) * cpl_image_get_size_y(image);
107  /* TODO: There is a Delta_t factor that appears in the Vacca article
108  * that is not reflexed here! */
109  ron_contrib = 12 * ron * ron / (gain * gain * ndsamples * ndit) *
110  (ndsamples - 1) / (ndsamples + 1);
111  poisson_factor = 6. / (5. * gain * ndsamples * ndit) *
112  (ndsamples * ndsamples + 1) / (ndsamples + 1);
113  for(pix = 0; pix < npix; ++pix)
114  {
115  /* TODO: Include the effect of saturation in the TLI mode used by HAWK-I */
116  poisson_contrib = poisson_factor * fabs(image_p[pix]);
117  variance_p[pix] = poisson_contrib + ron_contrib;
118  }
119 
120  /* Return */
121  return variance;
122 }
123 
124 /*----------------------------------------------------------------------------*/
157 /*----------------------------------------------------------------------------*/
159 (cpl_imagelist * imagelist_raw,
160  double gain,
161  double ron,
162  int ndit,
163  int ndsamples)
164 {
165  cpl_imagelist * variances;
166 
167  variances = cpl_imagelist_new();
168  /* Loop on the frames */
169  while(cpl_imagelist_get_size(imagelist_raw) > 0)
170  {
171  cpl_image * variance;
172 
173  variance = hawki_image_create_variance
174  (cpl_imagelist_get(imagelist_raw, 0), gain, ron, ndit, ndsamples);
175  cpl_imagelist_set(variances, variance,
176  cpl_imagelist_get_size(variances));
177  cpl_image_delete(cpl_imagelist_unset(imagelist_raw, 0));
178  }
179  return variances;
180 }
181 
182