GalSim-developers/GalSim — pull request #116 by barnabytprowe (2012-04-22 23:44:35+00:00)
Title: CcdNoise class wrapped with regression tests

I've written a wrapper for Gary's CcdNoise class, which adds noise according to a Poisson + Gaussian read noise model. Here's the docstring for the class in Python:

```
Pseudo-random number generator with a basic CCD noise model.

A CcdNoise instance is initialized given a UniformDeviate, a gain level in Electrons
per ADU used for the Poisson noise term, and a Gaussian read noise in electrons (if
gain > 0.) or ADU (if gain < 0.). With these parameters set, the CcdNoise operates
on an Image, adding noise to each pixel following this model.

The class must be given a reference to a UniformDeviate when constructed, which will
be the source of random values for the noise implementation.

Initialization
--------------
>>> ccd_noise = CcdNoise(uniform, gain=1., readnoise=0.)

Initializes ccd_noise to be a CcdNoise instance.

Subsequent calls to ccd_noise(Image) with an Image instance as the first argument
add noise following this model to that Image.

Parameters:

uniform a UniformDeviate instance (seed set there).
gain the gain for each pixel; setting gain <=0 will shut off the Poisson noise,
and the Gaussian RMS will take the value RMS=readNoise [default=1.].
reanoise the read noise on each pixel; setting readNoise=0 will shut off the
Gaussian noise [default=0.].

Calling
-------
>>> ccd_noise(image)

Image instance image will have CCD noise added following the instantiated model.

```

...getting the class wrapped while accepting a template class Image was only possible after Jim showed the way in Issue #97, so thanks for all that correspondence.

There is also a basic regression test along the lines of Rachel's prexisting tests for the basic RNGs. All seems to work OK.

I also hope to incorporate this CcdNoise model into the proposed addition of noise being an Image method (Issue #84) as well as giving some useful extra knowledge going into the vectorization of all of the Uniform, Poisson, Gaussian and Binomial deviates (Issue #108).

The only thing I noticed along the way (writing the tests in fact) was that the `int` and `short` versions of the CcdNoise are simply the same values as the `float` and `double` function return values, but integer rounded down.

Is that standard integer rounding down what we want, or should we be rounding to the nearest whole number? Would welcome thoughts, I am not sure I can decide...!