Noise Generators

GalSim has a number of different noise models one can use for adding noise to an Image:

  • GaussianNoise adds Gaussian noise with a specified \(\sigma\) (or variance) to each pixel.

  • PoissonNoise treats each pixel value as the expectation value for the number of incident photons in the pixel, and implements a Poisson process drawing a realization of the observed number of photons in each pixel.

  • CCDNoise combines the two above noise types to implement Poisson photon noise plus Gaussian read noise.

  • VariableGaussianNoise is like GaussianNoise, but allows for a different variance in each pixel.

  • DeviateNoise adds noise according to any of the various Random Deviates implemented in GalSim.

These are all subclasses of the base class BaseNoise, which mostly just defines the common API for all of these classes.

class galsim.BaseNoise(rng=None)[source]

Base class for all noise classes.

This class should not be constructed directly. Rather, you should instantiate one of the subclasses:

which define what kind of noise you want to implement. This base class mostly just serves as a way to check if an object is a valid noise object with:

>>> isinstance(noise, galsim.BaseNoise)
__mul__(variance_ratio)[source]

Multiply the variance of the noise by variance_ratio.

Parameters:

variance_ratio – The factor by which to scale the variance of the correlation function profile.

Returns:

a new Noise object whose variance has been scaled by the given amount.

__div__(variance_ratio)[source]

Equivalent to self * (1/variance_ratio)

applyTo(image)[source]

Add noise to an input Image.

e.g.:

>>> noise.applyTo(image)

On output the Image instance image will have been given additional noise according to the current noise model.

Note: This is equivalent to the alternate syntax:

>>> image.addNoise(noise)

which may be more convenient or clearer.

getVariance()[source]

Get variance in current noise model.

property rng

The BaseDeviate of this noise object.

withScaledVariance(variance_ratio)[source]

Return a new noise object with the variance scaled up by the specified factor.

This is equivalent to noise * variance_ratio.

Parameters:

variance_ratio – The factor by which to scale the variance of the correlation function profile.

Returns:

a new Noise object whose variance has been scaled by the given amount.

withVariance(variance)[source]

Return a new noise object (of the same type as the current one) with the specified variance.

Parameters:

variance – The desired variance in the noise.

Returns:

a new Noise object with the given variance.

class galsim.GaussianNoise(rng=None, sigma=1.0)[source]

Bases: BaseNoise

Class implementing simple Gaussian noise.

This is a simple noise model where each pixel in the image gets Gaussian noise with a given sigma.

Example:

The following will add Gaussian noise to every element of an image:

>>> gaussian_noise = galsim.GaussianNoise(rng, sigma=1.0)
>>> image.addNoise(gaussian_noise)
Parameters:
  • rng – A BaseDeviate instance to use for generating the random numbers.

  • sigma – The rms noise on each pixel. [default: 1.]

Attributes:
  • rng – The internal random number generator (read-only)

  • sigma – The value of the constructor parameter sigma (read-only)

copy(rng=None)[source]

Returns a copy of the Gaussian noise model.

By default, the copy will share the BaseDeviate random number generator with the parent instance. However, you can provide a new rng to use in the copy if you want with:

>>> noise_copy = noise.copy(rng=new_rng)
property sigma

The input sigma value.

class galsim.PoissonNoise(rng=None, sky_level=0.0)[source]

Bases: BaseNoise

Class implementing Poisson noise according to the flux (and sky level) present in the image.

The PoissonNoise class encapsulates a simple version of the noise model of a normal CCD image where each pixel has Poisson noise corresponding to the number of electrons in each pixel (including an optional extra sky level).

Note that if the image to which you are adding noise already has a sky level on it, then you should not provide the sky level here as well. The sky level here corresponds to a level that is taken to be already subtracted from the image, but that originally contributed to the addition of Poisson noise.

Example:

The following will add Poisson noise to every element of an image:

>>> poisson_noise = galsim.PoissonNoise(rng, sky_level=0.)
>>> image.addNoise(poisson_noise)
Parameters:
  • rng – A BaseDeviate instance to use for generating the random numbers.

  • sky_level – The sky level in electrons per pixel that was originally in the input image, but which is taken to have already been subtracted off. [default: 0.]

Attributes:
  • rng – The internal random number generator (read-only)

  • sky_level – The value of the constructor parameter sky_level (read-only)

copy(rng=None)[source]

Returns a copy of the Poisson noise model.

By default, the copy will share the BaseDeviate random number generator with the parent instance. However, you can provide a new rng to use in the copy if you want with:

>>> noise_copy = noise.copy(rng=new_rng)
property sky_level

The input sky_level.

class galsim.CCDNoise(rng=None, sky_level=0.0, gain=1.0, read_noise=0.0)[source]

Bases: BaseNoise

Class implementing a basic CCD noise model.

The CCDNoise class encapsulates the noise model of a normal CCD image. The noise has two components: first, Poisson noise corresponding to the number of electrons in each pixel (including an optional extra sky level); second, Gaussian read noise.

Note that if the image to which you are adding noise already has a sky level on it, then you should not provide the sky level here as well. The sky level here corresponds to a level is taken to be already subtracted from the image, but which was present for the Poisson noise.

The units here are slightly confusing. We try to match the most common way that each of these quantities is usually reported. Note: ADU stands for Analog/Digital Units; they are the units of the numbers in the final image. Some places use the term “counts” for this.

  • sky_level is normally measured from the image itself, so it is normally quoted in ADU/pixel.

  • gain is a property of the detector and is normally measured in the laboratory. The units are normally e-/ADU. This is backwards what might be more intuitive, ADU/e-, but that’s how astronomers use the term gain, so we follow suit here.

  • read_noise is also a property of the detector and is usually quoted in e-/pixel.

If you are manually applying the quantum efficiency of the detector (e-/photon), then this would normally be applied before the noise. However, it is also fine to fold in the quantum efficiency into the gain to give units photons/ADU. Either way is acceptable. Just make sure you give the read noise in photons as well in this case.

Example:

The following will add CCD noise to every element of an image:

>>> ccd_noise = galsim.CCDNoise(rng, sky_level=0., gain=1., read_noise=0.)
>>> image.addNoise(ccd_noise)
Parameters:
  • rng – A BaseDeviate instance to use for generating the random numbers.

  • sky_level – The sky level in ADU per pixel that was originally in the input image, but which is taken to have already been subtracted off. [default: 0.]

  • gain – The gain for each pixel in electrons per ADU; setting gain<=0 will shut off the Poisson noise, and the Gaussian rms will take the value read_noise as being in units of ADU rather than electrons. [default: 1.]

  • read_noise – The read noise on each pixel in electrons (gain > 0.) or ADU (gain <= 0.). Setting read_noise=0. will shut off the Gaussian noise. [default: 0.]

Attributes:
  • rng – The internal random number generator (read-only)

  • sky_level – The value of the constructor parameter sky_level (read-only)

  • gain – The value of the constructor parameter gain (read-only)

  • read_noise – The value of the constructor parameter read_noise (read-only)

copy(rng=None)[source]

Returns a copy of the CCD noise model.

By default, the copy will share the BaseDeviate random number generator with the parent instance. However, you can provide a new rng to use in the copy if you want with:

>>> noise_copy = noise.copy(rng=new_rng)
property gain

The input gain.

property read_noise

The input read_noise.

property sky_level

The input sky_level.

class galsim.VariableGaussianNoise(rng, var_image)[source]

Bases: BaseNoise

Class implementing Gaussian noise that has a different variance in each pixel.

The following will add variable Gaussian noise to every element of an image:

>>> variable_noise = galsim.VariableGaussianNoise(rng, var_image)
>>> image.addNoise(variable_noise)
Parameters:
  • rng – A BaseDeviate instance to use for generating the random numbers.

  • var_image – The variance of the noise to apply to each pixel. This image must be the same shape as the image for which you eventually call addNoise().

Attributes:
  • rng – The internal random number generator (read-only)

  • var_image – The value of the constructor parameter var_image (read-only)

applyTo(image)[source]

Add noise to an input Image.

e.g.:

>>> noise.applyTo(image)

On output the Image instance image will have been given additional noise according to the current noise model.

Note: This is equivalent to the alternate syntax:

>>> image.addNoise(noise)

which may be more convenient or clearer.

copy(rng=None)[source]

Returns a copy of the variable Gaussian noise model.

By default, the copy will share the BaseDeviate random number generator with the parent instance. However, you can provide a new rng to use in the copy if you want with:

>>> noise_copy = noise.copy(rng=new_rng)
property var_image

The input var_image.

class galsim.DeviateNoise(dev)[source]

Bases: BaseNoise

Class implementing noise with an arbitrary BaseDeviate object.

The DeviateNoise class provides a way to treat an arbitrary deviate as the noise model for each pixel in an image.

The following will add noise according to a given random deviate to every element of an image:

>>> dev_noise = galsim.DeviateNoise(dev)
>>> image.addNoise(dev_noise)
Parameters:

dev – A BaseDeviate subclass to use as the noise deviate for each pixel.

Attributes:

rng – The internal random number generator (read-only)

copy(rng=None)[source]

Returns a copy of the DeviateNoise instance.

By default, the copy will share the BaseDeviate random number generator with the parent instance. However, you can provide a new rng to use in the copy if you want with:

>>> noise_copy = noise.copy(rng=new_rng)