synthesizer.instruments.photometric_noise¶
Photometric noise generation for synthesizer imaging.
This module contains tools for modelling and generating photometric noise
for imaging. Correlated noise is represented by the
CorrelatedNoiseModel class, which stores a source noise template and
derives reusable statistical quantities from it. These cached quantities are
then used to generate new noise realisations for images of arbitrary shape.
Classes
Model correlated image noise from a source template.
This class encapsulates the correlated-noise machinery used by imaging. A source noise template (i.e. existing noise field) is supplied at construction time and is used to estimate a correlation function (CF). The expensive CF estimation is cached on the model so that many target images can draw fresh correlated noise realisations from the same underlying template.
The observed/template noise map used to characterise the noise.
- Type:
np.ndarray or unyt_array
Units carried by the source template, if present.
- Type:
unyt.Unit or None
Cache of estimated correlation functions keyed by
(subtract_mean, correct_periodicity).- Type:
dict
Apply correlated noise to an Image.
The correlated-noise realisation is generated for the image’s pixel shape and then added via the image’s existing noise-array machinery.
- Parameters:
image (Image) – The image to which the correlated noise should be added.
correct_periodicity (bool) – If True the DFT periodicity correction is applied.
rng_seed (int, optional) – Seed for the random number generator.
inplace (bool) – If True, update the input image in place and return it. Otherwise return a new image. Default is False.
- Returns:
The noisy image.
- Return type:
- Raises:
InconsistentArguments – If the image has units but the noise model is dimensionless.
Estimate and cache the source correlation function.
Computes an unrolled correlation function (DFT convention, origin at
[0, 0]) from the power spectrum of the source array. The result is cached for the requested modelling options so later calls can reuse it without recomputing the FFT.- Parameters:
subtract_mean (bool) – If True the DC component of the power spectrum is zeroed, removing the mean offset from the noise model.
correct_periodicity (bool) – If True a correction factor is applied to compensate for the periodicity assumption of the DFT.
- Returns:
A 2D array of the same shape as the source template holding the unrolled CF with the origin at
[0, 0].- Return type:
np.ndarray
Generate a correlated noise realisation for a target shape.
A cached source CF is first fetched or computed, then resampled to the target dimensions before a fresh random realisation is drawn. The same source CF can therefore be used to generate many independent target noise fields.
- Parameters:
target_shape (tuple of int) – The
(ny, nx)pixel dimensions of the desired noise field.subtract_mean (bool) – Passed through to
estimate_correlation_function().correct_periodicity (bool) – Passed through to
estimate_correlation_function().rng_seed (int, optional) – Seed for the random number generator. Pass the same seed to reproduce an identical noise realisation.
- Returns:
A 2D array of shape
target_shapecontaining the generated correlated noise field. Units are attached if the source template carried them.- Return type:
np.ndarray or unyt_array
- Raises:
InconsistentArguments – If the source CF is too small to contribute any pixels to the target CF grid.
Return the source noise template without units.
- Returns:
The source noise template as a plain NumPy array.
- Return type:
np.ndarray