Skip to content

Detector Layers¤

ApplyPixelResponse

dLux.layers.detector_layers.ApplyPixelResponse ¤

Bases: DetectorLayer

Applies a pixel response array to the input PSF via multiplication. This can be used to model inter- and intra-pixel sensitivity variations common to most detectors.

UML

UML

Attributes:

Name Type Description
pixel_response Array

The pixel_response to apply to the input PSF.

Source code in dLux/layers/detector_layers.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
class ApplyPixelResponse(DetectorLayer):
    """
    Applies a pixel response array to the input PSF via multiplication. This can be
    used to model inter- and intra-pixel sensitivity variations common
    to most detectors.

    ??? abstract "UML"
        ![UML](../../assets/uml/ApplyPixelResponse.png)

    Attributes
    ----------
    pixel_response : Array
        The pixel_response to apply to the input PSF.
    """

    pixel_response: Array

    def __init__(self: ApplyPixelResponse, pixel_response: Array):
        """
        Parameters
        ----------
        pixel_response : Array
            The pixel_response to apply to the input PSF. Must be a 2d array that
            matches the PSF shape at time of application.
        """
        super().__init__()
        self.pixel_response = np.asarray(pixel_response, dtype=float)
        if self.pixel_response.ndim != 2:
            raise ValueError("pixel_response must be a 2d array.")

    def __call__(self: ApplyPixelResponse, psf: PSF) -> PSF:
        return psf * self.pixel_response

__init__(pixel_response) ¤

Parameters:

Name Type Description Default
pixel_response Array

The pixel_response to apply to the input PSF. Must be a 2d array that matches the PSF shape at time of application.

required
Source code in dLux/layers/detector_layers.py
83
84
85
86
87
88
89
90
91
92
93
94
def __init__(self: ApplyPixelResponse, pixel_response: Array):
    """
    Parameters
    ----------
    pixel_response : Array
        The pixel_response to apply to the input PSF. Must be a 2d array that
        matches the PSF shape at time of application.
    """
    super().__init__()
    self.pixel_response = np.asarray(pixel_response, dtype=float)
    if self.pixel_response.ndim != 2:
        raise ValueError("pixel_response must be a 2d array.")
ApplyJitter

dLux.layers.detector_layers.ApplyJitter ¤

Bases: DetectorLayer

Convolves the PSF with a radially symmetric Gaussian kernel parameterised by its standard deviation (sigma).

UML

UML

Attributes:

Name Type Description
sigma (float, pixels)

The standard deviation of the Gaussian kernel, in units of pixels.

kernel_size int

The size of the convolution kernel to use.

oversample int

The oversampling factor to use when generating the kernel. This is used to mitigate aliasing when the kernel is small compared to the pixel size.

Source code in dLux/layers/detector_layers.py
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
class ApplyJitter(DetectorLayer):
    """
    Convolves the PSF with a radially symmetric Gaussian kernel parameterised by its
    standard deviation (sigma).

    ??? abstract "UML"
        ![UML](../../assets/uml/ApplyJitter.png)

    Attributes
    ----------
    sigma : float, pixels
        The standard deviation of the Gaussian kernel, in units of pixels.
    kernel_size : int
        The size of the convolution kernel to use.
    oversample : int
        The oversampling factor to use when generating the kernel. This is used to
        mitigate aliasing when the kernel is small compared to the pixel size.
    """

    sigma: float
    kernel_size: int
    oversample: int

    def __init__(
        self: ApplyJitter, sigma: float, kernel_size: int = 9, oversample: int = 3
    ):
        """
        Parameters
        ----------
        sigma : float, pixels
            The standard deviation of the Gaussian kernel, in units of pixels.
        kernel_size : int = 9
            The size of the convolution kernel to use.
        oversample : int = 3
            The oversampling factor to use when generating the kernel. This is used to
            mitigate aliasing when the kernel is small compared to the pixel size.
        """
        super().__init__()
        self.kernel_size = int(kernel_size)
        self.sigma = float(sigma)
        self.oversample = int(oversample)

        if self.kernel_size <= 0:
            raise ValueError("kernel_size must be greater than 0.")

    @property
    def kernel(self: ApplyJitter) -> Array:
        """
        Generates the normalised Gaussian kernel.

        Returns
        -------
        kernel : Array
            The Gaussian kernel.
        """
        kernel = dlu.gaussian(
            mean=np.array([0.0, 0.0]),
            std=np.array([self.sigma, self.sigma]),
            npixels=self.kernel_size * self.oversample,
        )
        return dlu.downsample(kernel, self.oversample, mean=False)

    def __call__(self: ApplyJitter, psf: PSF) -> PSF:
        return psf.convolve(self.kernel)

kernel property ¤

Generates the normalised Gaussian kernel.

Returns:

Name Type Description
kernel Array

The Gaussian kernel.

__init__(sigma, kernel_size=9, oversample=3) ¤

Parameters:

Name Type Description Default
sigma (float, pixels)

The standard deviation of the Gaussian kernel, in units of pixels.

required
kernel_size int = 9

The size of the convolution kernel to use.

9
oversample int = 3

The oversampling factor to use when generating the kernel. This is used to mitigate aliasing when the kernel is small compared to the pixel size.

3
Source code in dLux/layers/detector_layers.py
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
def __init__(
    self: ApplyJitter, sigma: float, kernel_size: int = 9, oversample: int = 3
):
    """
    Parameters
    ----------
    sigma : float, pixels
        The standard deviation of the Gaussian kernel, in units of pixels.
    kernel_size : int = 9
        The size of the convolution kernel to use.
    oversample : int = 3
        The oversampling factor to use when generating the kernel. This is used to
        mitigate aliasing when the kernel is small compared to the pixel size.
    """
    super().__init__()
    self.kernel_size = int(kernel_size)
    self.sigma = float(sigma)
    self.oversample = int(oversample)

    if self.kernel_size <= 0:
        raise ValueError("kernel_size must be greater than 0.")
ApplySaturation

dLux.layers.detector_layers.ApplySaturation ¤

Bases: DetectorLayer

Applies a simple saturation model to the input PSF by clipping any values above the threshold value.

UML

UML

Attributes:

Name Type Description
threshold float

The threshold at which the saturation is applied.

Source code in dLux/layers/detector_layers.py
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
class ApplySaturation(DetectorLayer):
    """
    Applies a simple saturation model to the input PSF by clipping any values above
    the threshold value.

    ??? abstract "UML"
        ![UML](../../assets/uml/ApplySaturation.png)

    Attributes
    ----------
    threshold : float
        The threshold at which the saturation is applied.
    """

    threshold: float

    def __init__(self: ApplySaturation, threshold: float):
        """
        Parameters
        ----------
        threshold : float
            The threshold at which the saturation is applied.
        """
        super().__init__()
        self.threshold = float(threshold)

    def __call__(self: ApplySaturation, psf: PSF) -> PSF:
        return psf.min("data", self.threshold)

__init__(threshold) ¤

Parameters:

Name Type Description Default
threshold float

The threshold at which the saturation is applied.

required
Source code in dLux/layers/detector_layers.py
182
183
184
185
186
187
188
189
190
def __init__(self: ApplySaturation, threshold: float):
    """
    Parameters
    ----------
    threshold : float
        The threshold at which the saturation is applied.
    """
    super().__init__()
    self.threshold = float(threshold)
AddConstant

dLux.layers.detector_layers.AddConstant ¤

Bases: DetectorLayer

Adds a constant to the output PSF. This is typically used to model the mean value of the detector noise.

UML

UML

Attributes:

Name Type Description
value float

The value to add to the PSF.

Source code in dLux/layers/detector_layers.py
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
class AddConstant(DetectorLayer):
    """
    Adds a constant to the output PSF. This is typically used to model the mean value of
    the detector noise.

    ??? abstract "UML"
        ![UML](../../assets/uml/AddConstant.png)

    Attributes
    ----------
    value : float
        The value to add to the PSF.
    """

    value: float

    def __init__(self: AddConstant, value: float):
        """
        Parameters
        ----------
        value : float
            The value to add to the PSF.
        """
        super().__init__()
        self.value = float(value)

    def __call__(self: AddConstant, psf: PSF) -> PSF:
        return psf + self.value

__init__(value) ¤

Parameters:

Name Type Description Default
value float

The value to add to the PSF.

required
Source code in dLux/layers/detector_layers.py
212
213
214
215
216
217
218
219
220
def __init__(self: AddConstant, value: float):
    """
    Parameters
    ----------
    value : float
        The value to add to the PSF.
    """
    super().__init__()
    self.value = float(value)
Downsample

dLux.layers.detector_layers.Downsample ¤

Bases: DetectorLayer

Downsamples an input PSF by an integer number of pixels via a sum. Typically used to downsample an oversampled PSF to the true pixel size. Note the input PSF size must be divisible by kernel_size.

UML

UML

Attributes:

Name Type Description
kernel_size int

The size of the downsampling kernel.

Source code in dLux/layers/detector_layers.py
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
class Downsample(DetectorLayer):
    """
    Downsamples an input PSF by an integer number of pixels via a sum. Typically used
    to downsample an oversampled PSF to the true pixel size. Note the input PSF size
    must be divisible by kernel_size.

    ??? abstract "UML"
        ![UML](../../assets/uml/Downsample.png)

    Attributes
    ----------
    kernel_size : int
        The size of the downsampling kernel.
    """

    kernel_size: int

    def __init__(self: Downsample, kernel_size: int):
        """
        Parameters
        ----------
        kernel_size : int
            The size of the downsampling kernel. Must be greater than 0.
        """
        super().__init__()
        self.kernel_size = int(kernel_size)

        if self.kernel_size <= 0:
            raise ValueError("kernel_size must be greater than 0.")

    def __call__(self: Downsample, psf: PSF) -> PSF:
        return psf.downsample(self.kernel_size)

__init__(kernel_size) ¤

Parameters:

Name Type Description Default
kernel_size int

The size of the downsampling kernel. Must be greater than 0.

required
Source code in dLux/layers/detector_layers.py
243
244
245
246
247
248
249
250
251
252
253
254
def __init__(self: Downsample, kernel_size: int):
    """
    Parameters
    ----------
    kernel_size : int
        The size of the downsampling kernel. Must be greater than 0.
    """
    super().__init__()
    self.kernel_size = int(kernel_size)

    if self.kernel_size <= 0:
        raise ValueError("kernel_size must be greater than 0.")