RandomNoisePixelDefect#
- class cabaret.camera.RandomNoisePixelDefect(name: str = 'defect', rate: float = 0.0, seed: int = 0, apply_before_base: bool = False, _rng: Generator | None = None, _pixels: ndarray | None = None, noise_level: float = 10.0, distribution: Literal['normal', 'poisson'] = 'normal')[source]#
A pixel defect that introduces random noise to selected pixels.
This is different from read noise, which is applied to all pixels and represents the electronic noise of the sensor. RandomNoisePixelDefect simulates pixels that are abnormally noisy (e.g., “noisy” or “unstable” pixels), and the noise is added only to those selected pixels.
Examples
>>> from cabaret import Observatory, Sources >>> pixel_defects = {"noise": {"type": "noise", "rate": 0.1, "noise_level": 5e3}} >>> observatory = Observatory(camera={"pixel_defects": pixel_defects}) >>> sources = Sources.get_test_sources() >>> ra, dec = sources.center >>> _, clean_image, image = observatory.generate_image_stack( ... exp_time=3, ra=ra, dec=dec, sources=sources, convert_all_to_adu=True ... )
To plot the images, you can use the plot_image function from cabaret.plot:
>>> from cabaret.plot import plot_image >>> import matplotlib.pyplot as plt >>> fig, axes = plt.subplots(1, 2, figsize=(7, 5), sharex=True, sharey=True) >>> _ = plot_image(clean_image, ax=axes[0], title="Image without defects") >>> _ = plot_image(image, ax=axes[1], title="Image with random noise defects") >>> plt.subplots_adjust(wspace=0.1) >>> plt.show()
Methods
__init__([name, rate, seed, ...])generate_noise(size)Generate noise for the defect pixels.
introduce_pixel_defect(image, camera[, seed])Introduce the defect into the image.
number_of_defect_pixels(camera)Calculate the number of pixels affected by the defect.
set_pixels(pixels, camera)Set the pixels for the defect.
Attributes
apply_before_baseIf True, this defect is applied before the base image (bias, dark, read noise) is added.
distributionDistribution type for the noise ('normal' or 'poisson').
nameName of the defect.
noise_levelStandard deviation or scale for the noise.
pixelsPixel coordinates affected by the defect.
rateFraction of pixels affected by the defect.
rngRandom number generator instance.
seedRandom seed for reproducibility.