Skip to content

Unified Layers¤

UnifiedLayer

dLux.layers.unified_layers.UnifiedLayer ¤

Bases: OpticalLayer, DetectorLayer

Base class for unified layers that can be applied to either wavefronts or PSFs.

UML

UML

Source code in dLux/layers/unified_layers.py
14
15
16
17
18
19
20
class UnifiedLayer(OpticalLayer, DetectorLayer):
    """
    Base class for unified layers that can be applied to either wavefronts or PSFs.

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

dLux.layers.unified_layers.Rotate ¤

Bases: UnifiedLayer

Rotates either a wavefront or PSF by a given angle. This is done using interpolation methods. The 'complex' input only has an effect if the input is a wavefront.

UML

UML

Attributes:

Name Type Description
angle (float, radians)

The angle by which to rotate the input in the clockwise direction.

method str

The interpolation method.

complex bool

Should the rotation be performed on the 'complex' (real, imaginary), as opposed to the default 'phasor' (amplitude, phase) arrays. Only applies if the input is a wavefront.

Source code in dLux/layers/unified_layers.py
 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
 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
class Rotate(UnifiedLayer):
    """
    Rotates either a wavefront or PSF by a given angle. This is done using
    interpolation methods. The 'complex' input only has an effect if the input is a
    wavefront.

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

    Attributes
    ----------
    angle : float, radians
        The angle by which to rotate the input in the clockwise direction.
    method : str
        The interpolation method.
    complex : bool
        Should the rotation be performed on the 'complex' (real, imaginary), as opposed
        to the default 'phasor' (amplitude, phase) arrays. Only applies if the input is
        a wavefront.
    """

    angle: float
    method: str
    complex: bool

    def __init__(
        self: Rotate,
        angle: float,
        method: str = "linear",
        complex: bool = False,
    ):
        """
        Parameters
        ----------
        angle : float, radians
            The angle by which to rotate the input in the clockwise direction.
        method : str = "linear"
            The interpolation method.
        complex : bool = False
            Should the rotation be performed on the 'complex' (real, imaginary), as
            opposed to the default 'phasor' (amplitude, phase) arrays. Only applies if
            the input is a wavefront.
        """
        super().__init__()
        self.angle = float(angle)
        self.method = str(method)
        self.complex = bool(complex)

    def __call__(self: Rotate, target: Wavefront | PSF) -> Wavefront | PSF:
        """
        Applies the rotation to the input.

        Parameters
        ----------
        target : Wavefront | PSF
            The input to rotate.

        Returns
        -------
        target : Wavefront | PSF
            The rotated input.
        """
        if isinstance(target, PSF):
            return target.rotate(self.angle, self.method)
        return target.rotate(self.angle, self.method, self.complex)

__call__(target) ¤

Applies the rotation to the input.

Parameters:

Name Type Description Default
target Wavefront | PSF

The input to rotate.

required

Returns:

Name Type Description
target Wavefront | PSF

The rotated input.

Source code in dLux/layers/unified_layers.py
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
def __call__(self: Rotate, target: Wavefront | PSF) -> Wavefront | PSF:
    """
    Applies the rotation to the input.

    Parameters
    ----------
    target : Wavefront | PSF
        The input to rotate.

    Returns
    -------
    target : Wavefront | PSF
        The rotated input.
    """
    if isinstance(target, PSF):
        return target.rotate(self.angle, self.method)
    return target.rotate(self.angle, self.method, self.complex)

__init__(angle, method='linear', complex=False) ¤

Parameters:

Name Type Description Default
angle (float, radians)

The angle by which to rotate the input in the clockwise direction.

required
method str = "linear"

The interpolation method.

'linear'
complex bool = False

Should the rotation be performed on the 'complex' (real, imaginary), as opposed to the default 'phasor' (amplitude, phase) arrays. Only applies if the input is a wavefront.

False
Source code in dLux/layers/unified_layers.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
def __init__(
    self: Rotate,
    angle: float,
    method: str = "linear",
    complex: bool = False,
):
    """
    Parameters
    ----------
    angle : float, radians
        The angle by which to rotate the input in the clockwise direction.
    method : str = "linear"
        The interpolation method.
    complex : bool = False
        Should the rotation be performed on the 'complex' (real, imaginary), as
        opposed to the default 'phasor' (amplitude, phase) arrays. Only applies if
        the input is a wavefront.
    """
    super().__init__()
    self.angle = float(angle)
    self.method = str(method)
    self.complex = bool(complex)
Flip

dLux.layers.unified_layers.Flip ¤

Bases: UnifiedLayer

Flips either a wavefront or PSF about the input axes. Can be either an int or a tuple of ints. This class uses the 'ij' indexing convention, i.e. axis 0 is the y-axis, and axis 1 is the x-axis.

UML

UML

Attributes:

Name Type Description
axes tuple[int, ...] | int

The axes to flip the input about. This class uses the 'ij' indexing convention, i.e. axis 0 is the y-axis, and axis 1 is the x-axis.

Source code in dLux/layers/unified_layers.py
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
class Flip(UnifiedLayer):
    """
    Flips either a wavefront or PSF about the input axes. Can be either an int or a
    tuple of ints. This class uses the 'ij' indexing convention, i.e. axis 0 is the
    y-axis, and axis 1 is the x-axis.

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

    Attributes
    ----------
    axes : tuple[int, ...] | int
        The axes to flip the input about. This class uses the 'ij' indexing convention,
        i.e. axis 0 is the y-axis, and axis 1 is the x-axis.
    """

    axes: tuple[int, ...] | int

    def __init__(self: Flip, axes: tuple[int, ...] | int):
        """
        Parameters
        ----------
        axes : tuple[int, ...] | int
            The axes to flip the input about. This class uses the 'ij' indexing
            convention, i.e. axis 0 is the y-axis, and axis 1 is the x-axis.
        """
        super().__init__()
        self.axes = axes

        if isinstance(self.axes, tuple):
            for axis in self.axes:
                if not isinstance(axis, int):
                    raise ValueError("All axes must be integers.")
        elif not isinstance(self.axes, int):
            raise ValueError("axes must be an int or tuple of ints.")

    def __call__(self: Flip, target: Wavefront | PSF) -> Wavefront | PSF:
        """
        Flips the input about the specified axes.

        Parameters
        ----------
        target : Wavefront | PSF
            The input to flip.

        Returns
        -------
        target : Wavefront | PSF
            The flipped input.
        """
        return target.flip(self.axes)

__call__(target) ¤

Flips the input about the specified axes.

Parameters:

Name Type Description Default
target Wavefront | PSF

The input to flip.

required

Returns:

Name Type Description
target Wavefront | PSF

The flipped input.

Source code in dLux/layers/unified_layers.py
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
def __call__(self: Flip, target: Wavefront | PSF) -> Wavefront | PSF:
    """
    Flips the input about the specified axes.

    Parameters
    ----------
    target : Wavefront | PSF
        The input to flip.

    Returns
    -------
    target : Wavefront | PSF
        The flipped input.
    """
    return target.flip(self.axes)

__init__(axes) ¤

Parameters:

Name Type Description Default
axes tuple[int, ...] | int

The axes to flip the input about. This class uses the 'ij' indexing convention, i.e. axis 0 is the y-axis, and axis 1 is the x-axis.

required
Source code in dLux/layers/unified_layers.py
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
def __init__(self: Flip, axes: tuple[int, ...] | int):
    """
    Parameters
    ----------
    axes : tuple[int, ...] | int
        The axes to flip the input about. This class uses the 'ij' indexing
        convention, i.e. axis 0 is the y-axis, and axis 1 is the x-axis.
    """
    super().__init__()
    self.axes = axes

    if isinstance(self.axes, tuple):
        for axis in self.axes:
            if not isinstance(axis, int):
                raise ValueError("All axes must be integers.")
    elif not isinstance(self.axes, int):
        raise ValueError("axes must be an int or tuple of ints.")
Resize

dLux.layers.unified_layers.Resize ¤

Bases: UnifiedLayer

Resizes either a wavefront or PSF by padding or cropping. Note this class only supports padding and cropping of even sizes to even sizes, and odd sizes to odd sizes to ensure all operations are paraxial.

UML

UML

Attributes:

Name Type Description
npixels int

The desired output size.

Source code in dLux/layers/unified_layers.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class Resize(UnifiedLayer):
    """
    Resizes either a wavefront or PSF by padding or cropping. Note this class
    only supports padding and cropping of even sizes to even sizes, and odd sizes to
    odd sizes to ensure all operations are paraxial.

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

    Attributes
    ----------
    npixels : int
        The desired output size.
    """

    npixels: int

    def __init__(self: Resize, npixels: int):
        """
        Parameters
        ----------
        npixels : int
            The desired output size.
        """
        super().__init__()
        self.npixels = int(npixels)

    def __call__(self: Resize, target: Wavefront | PSF) -> Wavefront | PSF:
        """
        Resizes the input.

        Parameters
        ----------
        target : Wavefront | PSF
            The input to resize.

        Returns
        -------
        target : Wavefront | PSF
            The resized input.
        """
        return target.resize(self.npixels)

__call__(target) ¤

Resizes the input.

Parameters:

Name Type Description Default
target Wavefront | PSF

The input to resize.

required

Returns:

Name Type Description
target Wavefront | PSF

The resized input.

Source code in dLux/layers/unified_layers.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def __call__(self: Resize, target: Wavefront | PSF) -> Wavefront | PSF:
    """
    Resizes the input.

    Parameters
    ----------
    target : Wavefront | PSF
        The input to resize.

    Returns
    -------
    target : Wavefront | PSF
        The resized input.
    """
    return target.resize(self.npixels)

__init__(npixels) ¤

Parameters:

Name Type Description Default
npixels int

The desired output size.

required
Source code in dLux/layers/unified_layers.py
40
41
42
43
44
45
46
47
48
def __init__(self: Resize, npixels: int):
    """
    Parameters
    ----------
    npixels : int
        The desired output size.
    """
    super().__init__()
    self.npixels = int(npixels)
Lambda

dLux.layers.unified_layers.Lambda ¤

Bases: UnifiedLayer

A no-op layer that returns the input unchanged. This can be useful for debugging or as a placeholder in a pipeline.

UML

UML

Source code in dLux/layers/unified_layers.py
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
class Lambda(UnifiedLayer):
    """
    A no-op layer that returns the input unchanged. This can be useful for debugging or
    as a placeholder in a pipeline.

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

    def __call__(self: Lambda, target: Wavefront | PSF) -> Wavefront | PSF:
        """
        Returns the input unchanged.

        Parameters
        ----------
        target : Wavefront | PSF
            The input to return.

        Returns
        -------
        target : Wavefront | PSF
            The input, unchanged.
        """
        return target

__call__(target) ¤

Returns the input unchanged.

Parameters:

Name Type Description Default
target Wavefront | PSF

The input to return.

required

Returns:

Name Type Description
target Wavefront | PSF

The input, unchanged.

Source code in dLux/layers/unified_layers.py
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
def __call__(self: Lambda, target: Wavefront | PSF) -> Wavefront | PSF:
    """
    Returns the input unchanged.

    Parameters
    ----------
    target : Wavefront | PSF
        The input to return.

    Returns
    -------
    target : Wavefront | PSF
        The input, unchanged.
    """
    return target