Skip to content

Transformations

CoordTransform

Bases: Base

A simple class to handle the coordinate transformations applied dynamic aperture classes. Transformations are applied in the order: 1. Translation 2. Rotation 3. Compression 4. Shear

UML

UML

Attributes:

Name Type Description
translation Array

The (x, y) shift applied to the coords.

rotation Array

The clockwise rotation applied to the coords.

compression Array

The (x, y) compression applied to the coords.

shear Array

The (x, y) shear applied to the coords.

Source code in src/dLux/transformations.py
 12
 13
 14
 15
 16
 17
 18
 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
 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
 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
class CoordTransform(Base):
    """
    A simple class to handle the coordinate transformations applied dynamic
    aperture classes. Transformations are applied in the order:
        1. Translation
        2. Rotation
        3. Compression
        4. Shear

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

    Attributes
    ----------
    translation: Array
        The (x, y) shift applied to the coords.
    rotation: Array
        The clockwise rotation applied to the coords.
    compression: Array
        The (x, y) compression applied to the coords.
    shear: Array
        The (x, y) shear applied to the coords.
    """

    translation: Array
    rotation: float
    compression: Array
    shear: Array

    def __init__(
        self: CoordTransform,
        translation: Array = None,
        rotation: float = None,
        compression: Array = None,
        shear: Array = None,
    ):
        """
        Parameters
        ----------
        translation: Array
            The (x, y) shift applied to the coords.
        rotation: float, radians
            The clockwise rotation applied to the coords.
        compression: Array
            The (x, y) compression applied to the coords.
        shear: Array
            The (x, y) shear applied to the coords.
        """
        if translation is not None:
            self.translation = np.asarray(translation, dtype=float)
            if self.translation.shape != (2,):
                raise ValueError("center must be have shape (2,).")
        else:
            self.translation = None

        if rotation is not None:
            self.rotation = np.asarray(rotation, dtype=float)
            if self.rotation.shape != ():
                raise ValueError("rotation must have shaoe ().")
        else:
            self.rotation = None

        if compression is not None:
            self.compression = np.asarray(compression, dtype=float)
            if self.compression.shape != (2,):
                raise ValueError("compression must have shape (2,).")
        else:
            self.compression = None

        if shear is not None:
            self.shear = np.asarray(shear, dtype=float)
            if self.shear.shape != (2,):
                raise ValueError("shear must be have shape (2,).")
        else:
            self.shear = None

    def calculate(self: CoordTransform, npix: int, diam: float) -> Array:
        """
        Generate the transformed coords from diameter and npix.

        Parameters
        ----------
        npix : int
            The number of pixels in the output array.
        diam : float
            The diameter of the output array in metres.

        Returns
        -------
        coords : Array
            The transformed coordinates.
        """
        return self.apply(dlu.pixel_coords(npix, diam))

    def apply(self: CoordTransform, coords: Array) -> Array:
        """
        Apply the transformations to the input coordinates.

        Parameters
        ----------
        coords : Array
            The input coordinates to be transformed.

        Returns
        -------
        coords : Array
            The transformed coordinates.
        """
        if self.translation is not None:
            coords = dlu.translate_coords(coords, self.translation)
        if self.shear is not None:
            coords = dlu.shear_coords(coords, self.shear)
        if self.compression is not None:
            coords = dlu.compress_coords(coords, self.compression)
        if self.rotation is not None:
            coords = dlu.rotate_coords(coords, self.rotation)
        return coords

__init__(translation=None, rotation=None, compression=None, shear=None)

Parameters:

Name Type Description Default
translation Array

The (x, y) shift applied to the coords.

None
rotation float

The clockwise rotation applied to the coords.

None
compression Array

The (x, y) compression applied to the coords.

None
shear Array

The (x, y) shear applied to the coords.

None
Source code in src/dLux/transformations.py
41
42
43
44
45
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
def __init__(
    self: CoordTransform,
    translation: Array = None,
    rotation: float = None,
    compression: Array = None,
    shear: Array = None,
):
    """
    Parameters
    ----------
    translation: Array
        The (x, y) shift applied to the coords.
    rotation: float, radians
        The clockwise rotation applied to the coords.
    compression: Array
        The (x, y) compression applied to the coords.
    shear: Array
        The (x, y) shear applied to the coords.
    """
    if translation is not None:
        self.translation = np.asarray(translation, dtype=float)
        if self.translation.shape != (2,):
            raise ValueError("center must be have shape (2,).")
    else:
        self.translation = None

    if rotation is not None:
        self.rotation = np.asarray(rotation, dtype=float)
        if self.rotation.shape != ():
            raise ValueError("rotation must have shaoe ().")
    else:
        self.rotation = None

    if compression is not None:
        self.compression = np.asarray(compression, dtype=float)
        if self.compression.shape != (2,):
            raise ValueError("compression must have shape (2,).")
    else:
        self.compression = None

    if shear is not None:
        self.shear = np.asarray(shear, dtype=float)
        if self.shear.shape != (2,):
            raise ValueError("shear must be have shape (2,).")
    else:
        self.shear = None

apply(coords)

Apply the transformations to the input coordinates.

Parameters:

Name Type Description Default
coords Array

The input coordinates to be transformed.

required

Returns:

Name Type Description
coords Array

The transformed coordinates.

Source code in src/dLux/transformations.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
def apply(self: CoordTransform, coords: Array) -> Array:
    """
    Apply the transformations to the input coordinates.

    Parameters
    ----------
    coords : Array
        The input coordinates to be transformed.

    Returns
    -------
    coords : Array
        The transformed coordinates.
    """
    if self.translation is not None:
        coords = dlu.translate_coords(coords, self.translation)
    if self.shear is not None:
        coords = dlu.shear_coords(coords, self.shear)
    if self.compression is not None:
        coords = dlu.compress_coords(coords, self.compression)
    if self.rotation is not None:
        coords = dlu.rotate_coords(coords, self.rotation)
    return coords

calculate(npix, diam)

Generate the transformed coords from diameter and npix.

Parameters:

Name Type Description Default
npix int

The number of pixels in the output array.

required
diam float

The diameter of the output array in metres.

required

Returns:

Name Type Description
coords Array

The transformed coordinates.

Source code in src/dLux/transformations.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def calculate(self: CoordTransform, npix: int, diam: float) -> Array:
    """
    Generate the transformed coords from diameter and npix.

    Parameters
    ----------
    npix : int
        The number of pixels in the output array.
    diam : float
        The diameter of the output array in metres.

    Returns
    -------
    coords : Array
        The transformed coordinates.
    """
    return self.apply(dlu.pixel_coords(npix, diam))