Skip to content

Detector Layers

ApplyPixelResponse

Bases: DetectorLayer

Applies a pixel response array to the input psf, via a multiplication. This can be used to model variations in the 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 src/dLux/layers/detector_layers.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
class ApplyPixelResponse(DetectorLayer):
    """
    Applies a pixel response array to the input psf, via a multiplication. This can be
    used to model variations in the 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: DetectorLayer, pixel_response: Array):
        """
        Parameters
        ----------
        pixel_response : Array
            The pixel_response to apply to the input psf. Must be a 2-dimensional array
            equal to size of the psf 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 2 dimensional array.")

    def apply(self: DetectorLayer, psf: PSF) -> PSF:
        """
        Applies the layer to the PSF.

        Parameters
        ----------
        psf : PSF
            The psf to operate on.

        Returns
        -------
        psf : PSF
            The transformed 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 2-dimensional array equal to size of the psf at time of application.

required
Source code in src/dLux/layers/detector_layers.py
63
64
65
66
67
68
69
70
71
72
73
74
def __init__(self: DetectorLayer, pixel_response: Array):
    """
    Parameters
    ----------
    pixel_response : Array
        The pixel_response to apply to the input psf. Must be a 2-dimensional array
        equal to size of the psf 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 2 dimensional array.")

apply(psf)

Applies the layer to the PSF.

Parameters:

Name Type Description Default
psf PSF

The psf to operate on.

required

Returns:

Name Type Description
psf PSF

The transformed psf.

Source code in src/dLux/layers/detector_layers.py
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def apply(self: DetectorLayer, psf: PSF) -> PSF:
    """
    Applies the layer to the PSF.

    Parameters
    ----------
    psf : PSF
        The psf to operate on.

    Returns
    -------
    psf : PSF
        The transformed psf.
    """
    return psf * self.pixel_response

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.

Source code in src/dLux/layers/detector_layers.py
 93
 94
 95
 96
 97
 98
 99
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
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.
    """

    kernel_size: int
    sigma: float

    def __init__(self: DetectorLayer, sigma: float, kernel_size: int = 10):
        """
        Parameters
        ----------
        sigma : float, pixels
            The standard deviation of the Gaussian kernel, in units of pixels.
        kernel_size : int = 10
            The size of the convolution kernel to use.
        """
        super().__init__()
        self.kernel_size = int(kernel_size)
        self.sigma = float(sigma)

    def generate_kernel(self: DetectorLayer, pixel_scale: float) -> Array:
        """
        Generates the normalised Gaussian kernel.

        Returns
        -------
        kernel : Array
            The Gaussian kernel.
        """
        # TODO: Move to utils?
        # Generate distribution
        sigma = self.sigma * pixel_scale
        x = np.linspace(-10, 10, self.kernel_size) * pixel_scale
        kernel = norm.pdf(x, scale=sigma) * norm.pdf(x[:, None], scale=sigma)
        return kernel / np.sum(kernel)

    def apply(self: DetectorLayer, psf: PSF) -> PSF:
        """
        Applies the layer to the PSF.

        Parameters
        ----------
        psf : PSF
            The psf to operate on.

        Returns
        -------
        psf : PSF
            The transformed psf.
        """
        kernel = self.generate_kernel(psf.pixel_scale)
        return psf.convolve(kernel)

__init__(sigma, kernel_size=10)

Parameters:

Name Type Description Default
sigma (float, pixels)

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

required
kernel_size int = 10

The size of the convolution kernel to use.

10
Source code in src/dLux/layers/detector_layers.py
112
113
114
115
116
117
118
119
120
121
122
123
def __init__(self: DetectorLayer, sigma: float, kernel_size: int = 10):
    """
    Parameters
    ----------
    sigma : float, pixels
        The standard deviation of the Gaussian kernel, in units of pixels.
    kernel_size : int = 10
        The size of the convolution kernel to use.
    """
    super().__init__()
    self.kernel_size = int(kernel_size)
    self.sigma = float(sigma)

apply(psf)

Applies the layer to the PSF.

Parameters:

Name Type Description Default
psf PSF

The psf to operate on.

required

Returns:

Name Type Description
psf PSF

The transformed psf.

Source code in src/dLux/layers/detector_layers.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
def apply(self: DetectorLayer, psf: PSF) -> PSF:
    """
    Applies the layer to the PSF.

    Parameters
    ----------
    psf : PSF
        The psf to operate on.

    Returns
    -------
    psf : PSF
        The transformed psf.
    """
    kernel = self.generate_kernel(psf.pixel_scale)
    return psf.convolve(kernel)

generate_kernel(pixel_scale)

Generates the normalised Gaussian kernel.

Returns:

Name Type Description
kernel Array

The Gaussian kernel.

Source code in src/dLux/layers/detector_layers.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
def generate_kernel(self: DetectorLayer, pixel_scale: float) -> Array:
    """
    Generates the normalised Gaussian kernel.

    Returns
    -------
    kernel : Array
        The Gaussian kernel.
    """
    # TODO: Move to utils?
    # Generate distribution
    sigma = self.sigma * pixel_scale
    x = np.linspace(-10, 10, self.kernel_size) * pixel_scale
    kernel = norm.pdf(x, scale=sigma) * norm.pdf(x[:, None], scale=sigma)
    return kernel / np.sum(kernel)

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 src/dLux/layers/detector_layers.py
159
160
161
162
163
164
165
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
194
195
196
197
198
199
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: DetectorLayer, threshold: float):
        """
        Parameters
        ----------
        threshold : float
            The threshold at which the saturation is applied.
        """
        super().__init__()
        self.threshold = float(threshold)

    def apply(self: DetectorLayer, psf: PSF) -> PSF:
        """
        Applies the layer to the PSF.

        Parameters
        ----------
        psf : PSF
            The psf to operate on.

        Returns
        -------
        psf : PSF
            The transformed 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 src/dLux/layers/detector_layers.py
175
176
177
178
179
180
181
182
183
def __init__(self: DetectorLayer, threshold: float):
    """
    Parameters
    ----------
    threshold : float
        The threshold at which the saturation is applied.
    """
    super().__init__()
    self.threshold = float(threshold)

apply(psf)

Applies the layer to the PSF.

Parameters:

Name Type Description Default
psf PSF

The psf to operate on.

required

Returns:

Name Type Description
psf PSF

The transformed psf.

Source code in src/dLux/layers/detector_layers.py
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
def apply(self: DetectorLayer, psf: PSF) -> PSF:
    """
    Applies the layer to the PSF.

    Parameters
    ----------
    psf : PSF
        The psf to operate on.

    Returns
    -------
    psf : PSF
        The transformed psf.
    """
    return psf.min("data", self.threshold)

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 src/dLux/layers/detector_layers.py
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
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: DetectorLayer, value: float):
        """
        Parameters
        ----------
        value : float
            The value to add to the psf.
        """
        super().__init__()
        self.value = float(value)

    def apply(self: DetectorLayer, psf: PSF) -> PSF:
        """
        Applies the layer to the PSF.

        Parameters
        ----------
        psf : PSF
            The psf to operate on.

        Returns
        -------
        psf : PSF
            The transformed 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 src/dLux/layers/detector_layers.py
218
219
220
221
222
223
224
225
226
def __init__(self: DetectorLayer, value: float):
    """
    Parameters
    ----------
    value : float
        The value to add to the psf.
    """
    super().__init__()
    self.value = float(value)

apply(psf)

Applies the layer to the PSF.

Parameters:

Name Type Description Default
psf PSF

The psf to operate on.

required

Returns:

Name Type Description
psf PSF

The transformed psf.

Source code in src/dLux/layers/detector_layers.py
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
def apply(self: DetectorLayer, psf: PSF) -> PSF:
    """
    Applies the layer to the PSF.

    Parameters
    ----------
    psf : PSF
        The psf to operate on.

    Returns
    -------
    psf : PSF
        The transformed psf.
    """
    return psf + self.value

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 kernel_size must be an integer multiple of the input psf size.

UML

UML

Attributes:

Name Type Description
kernel_size int

The size of the downsampling kernel.

Source code in src/dLux/layers/detector_layers.py
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
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 kernel_size must be
    an integer multiple of the input psf size.

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

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

    kernel_size: int

    def __init__(self: DetectorLayer, kernel_size: int):
        """
        Parameters
        ----------
        kernel_size : int
            The size of the downsampling kernel.
        """
        super().__init__()
        self.kernel_size = int(kernel_size)

    def apply(self: DetectorLayer, psf: PSF) -> PSF:
        """
        Applies the layer to the PSF.

        Parameters
        ----------
        psf : PSF
            The psf to operate on.

        Returns
        -------
        psf : PSF
            The transformed psf.
        """
        return psf.downsample(self.kernel_size)

__init__(kernel_size)

Parameters:

Name Type Description Default
kernel_size int

The size of the downsampling kernel.

required
Source code in src/dLux/layers/detector_layers.py
262
263
264
265
266
267
268
269
270
def __init__(self: DetectorLayer, kernel_size: int):
    """
    Parameters
    ----------
    kernel_size : int
        The size of the downsampling kernel.
    """
    super().__init__()
    self.kernel_size = int(kernel_size)

apply(psf)

Applies the layer to the PSF.

Parameters:

Name Type Description Default
psf PSF

The psf to operate on.

required

Returns:

Name Type Description
psf PSF

The transformed psf.

Source code in src/dLux/layers/detector_layers.py
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
def apply(self: DetectorLayer, psf: PSF) -> PSF:
    """
    Applies the layer to the PSF.

    Parameters
    ----------
    psf : PSF
        The psf to operate on.

    Returns
    -------
    psf : PSF
        The transformed psf.
    """
    return psf.downsample(self.kernel_size)