Skip to content

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.

order int

The order of the interpolation to use. Must be 0 or 1.

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 src/dLux/layers/unified_layers.py
 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
 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
132
133
134
135
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.
    order : int
        The order of the interpolation to use. Must be 0 or 1.
    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
    order: int
    complex: bool

    def __init__(
        self: UnifiedLayer,
        angle: float,
        order: int = 1,
        complex: bool = False,
    ):
        """
        Parameters
        ----------
        angle : float, radians
            The angle by which to rotate the input in the clockwise direction.
        order : int = 1
            The order of the interpolation to use. Must be 0 or 1.
        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.order = int(order)
        self.complex = bool(complex)

        if self.order not in (0, 1):
            raise ValueError("Order must be 0, 1")

    def apply(
        self: UnifiedLayer, input: Union[Wavefront, PSF]
    ) -> Union[Wavefront, PSF]:
        """
        Applies the rotation to the input.

        Parameters
        ----------
        input : Union[Wavefront, PSF]
            The input to rotate.

        Returns
        -------
        input : Union[Wavefront, PSF]
            The rotated input.
        """
        if isinstance(input, PSF):
            return input.rotate(self.angle, self.order)
        else:
            return input.rotate(self.angle, self.order, self.complex)

__init__(angle, order=1, complex=False)

Parameters:

Name Type Description Default
angle (float, radians)

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

required
order int = 1

The order of the interpolation to use. Must be 0 or 1.

1
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 src/dLux/layers/unified_layers.py
 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
def __init__(
    self: UnifiedLayer,
    angle: float,
    order: int = 1,
    complex: bool = False,
):
    """
    Parameters
    ----------
    angle : float, radians
        The angle by which to rotate the input in the clockwise direction.
    order : int = 1
        The order of the interpolation to use. Must be 0 or 1.
    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.order = int(order)
    self.complex = bool(complex)

    if self.order not in (0, 1):
        raise ValueError("Order must be 0, 1")

apply(input)

Applies the rotation to the input.

Parameters:

Name Type Description Default
input Union[Wavefront, PSF]

The input to rotate.

required

Returns:

Name Type Description
input Union[Wavefront, PSF]

The rotated input.

Source code in src/dLux/layers/unified_layers.py
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
def apply(
    self: UnifiedLayer, input: Union[Wavefront, PSF]
) -> Union[Wavefront, PSF]:
    """
    Applies the rotation to the input.

    Parameters
    ----------
    input : Union[Wavefront, PSF]
        The input to rotate.

    Returns
    -------
    input : Union[Wavefront, PSF]
        The rotated input.
    """
    if isinstance(input, PSF):
        return input.rotate(self.angle, self.order)
    else:
        return input.rotate(self.angle, self.order, self.complex)

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, ie axis 0 is the y-axis, and axis 1 is the x-axis.

UML

UML

Attributes:

Name Type Description
axes Union[tuple, int]

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

Source code in src/dLux/layers/unified_layers.py
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
185
186
187
188
189
190
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, ie axis 0 is the
    y-axis, and axis 1 is the x-axis.

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

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

    axes: Union[tuple[int], int]

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

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

    def apply(
        self: UnifiedLayer, input: Union[Wavefront, PSF]
    ) -> Union[Wavefront, PSF]:
        """
        Flips the input about the input axes.

        Parameters
        ----------
        input : Union[Wavefront, PSF]
            The input to flip.

        Returns
        -------
        input : Union[Wavefront, PSF]
            The flipped input.
        """
        return input.flip(self.axes)

__init__(axes)

Parameters:

Name Type Description Default
axes Union[tuple, int]

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

required
Source code in src/dLux/layers/unified_layers.py
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
def __init__(self: UnifiedLayer, axes: Union[tuple[int], int]):
    """
    Parameters
    ----------
    axes : Union[tuple, int]
        The axes to flip the input about. This class uses the 'ij' indexing
        convention, ie axis 0 is the y-axis, and axis 1 is the x-axis.
    """
    super().__init__()
    self.axes = axes

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

apply(input)

Flips the input about the input axes.

Parameters:

Name Type Description Default
input Union[Wavefront, PSF]

The input to flip.

required

Returns:

Name Type Description
input Union[Wavefront, PSF]

The flipped input.

Source code in src/dLux/layers/unified_layers.py
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
def apply(
    self: UnifiedLayer, input: Union[Wavefront, PSF]
) -> Union[Wavefront, PSF]:
    """
    Flips the input about the input axes.

    Parameters
    ----------
    input : Union[Wavefront, PSF]
        The input to flip.

    Returns
    -------
    input : Union[Wavefront, PSF]
        The flipped input.
    """
    return input.flip(self.axes)

Resize

Bases: UnifiedLayer

Resizes either a wavefront or PSF by either 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 src/dLux/layers/unified_layers.py
19
20
21
22
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
class Resize(UnifiedLayer):
    """
    Resizes either a wavefront or PSF by either 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: UnifiedLayer, npixels: int):
        """
        Parameters
        ----------
        npixels : tuple
            The desired output size.
        """
        super().__init__()
        self.npixels = int(npixels)

    def apply(
        self: UnifiedLayer, input: Union[Wavefront, PSF]
    ) -> Union[Wavefront, PSF]:
        """
        Resizes the input.

        Parameters
        ----------
        input : Union[Wavefront, PSF]
            The input to resize.

        Returns
        -------
        input : Union[Wavefront, PSF]
            The resized input.
        """
        return input.resize(self.npixels)

__init__(npixels)

Parameters:

Name Type Description Default
npixels tuple

The desired output size.

required
Source code in src/dLux/layers/unified_layers.py
36
37
38
39
40
41
42
43
44
def __init__(self: UnifiedLayer, npixels: int):
    """
    Parameters
    ----------
    npixels : tuple
        The desired output size.
    """
    super().__init__()
    self.npixels = int(npixels)

apply(input)

Resizes the input.

Parameters:

Name Type Description Default
input Union[Wavefront, PSF]

The input to resize.

required

Returns:

Name Type Description
input Union[Wavefront, PSF]

The resized input.

Source code in src/dLux/layers/unified_layers.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def apply(
    self: UnifiedLayer, input: Union[Wavefront, PSF]
) -> Union[Wavefront, PSF]:
    """
    Resizes the input.

    Parameters
    ----------
    input : Union[Wavefront, PSF]
        The input to resize.

    Returns
    -------
    input : Union[Wavefront, PSF]
        The resized input.
    """
    return input.resize(self.npixels)