Skip to content

adjustments

Calculate adjustments needed to align LAT mirror panel

Author: Saianeesh Keshav Haridas

adjustment_fit_func(pars, can_points, points, adjustors)

Function to minimize when calculating adjustments.

Parameters:

Name Type Description Default
pars NDArray[float32]

The parameters to fit for:

  • dx: Translation in x
  • dy: Translation in y
  • dz: Translation in z
  • thetha_0: Angle to rotate about first adjustor axis
  • thetha_1: Angle to rotate about second adjustor axis
  • z_t: Additional translation to tension the center point
required
can_points NDArray[float32]

The cannonical positions of the points to align.

required
points NDArray[float32]

The measured positions of the points to align.

required
adjustors NDArray[float32]

The measured positions of the adjustors.

required

Returns:

Name Type Description
norm float32

The norm of \(cannonical_positions - transformed_positions\).

Source code in lat_alignment/adjustments.py
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
def adjustment_fit_func(
    pars: NDArray[np.float32],
    can_points: NDArray[np.float32],
    points: NDArray[np.float32],
    adjustors: NDArray[np.float32],
) -> np.float32:
    r"""
    Function to minimize when calculating adjustments.

    Parameters
    ----------
    pars : NDArray[np.float32]
        The parameters to fit for:

        * dx: Translation in x
        * dy: Translation in y
        * dz: Translation in z
        * thetha_0: Angle to rotate about first adjustor axis
        * thetha_1: Angle to rotate about second adjustor axis
        * z_t: Additional translation to tension the center point
    can_points : NDArray[np.float32]
        The cannonical positions of the points to align.
    points : NDArray[np.float32]
        The measured positions of the points to align.
    adjustors : NDArray[np.float32]
        The measured positions of the adjustors.

    Returns
    -------
    norm : np.float32
        The norm of $cannonical_positions - transformed_positions$.
    """
    dx, dy, dz, thetha_0, thetha_1, z_t = pars
    points, adjustors = translate_panel(points, adjustors, dx, dy, dz)
    points, adjustors = rotate_panel(points, adjustors, thetha_0, thetha_1)
    points[-1, -1] += z_t
    return np.linalg.norm(can_points - points)

calc_adjustments(can_points, points, adjustors, **kwargs)

Calculate adjustments needed to align panel.

Parameters:

Name Type Description Default
can_points NDArray[float32]

The cannonical position of the points to align.

required
points NDArray[float32]

The measured positions of the points to align.

required
adjustors NDArray[float32]

The measured positions of the adjustors.

required
**kwargs

Arguments to be passed to scipy.optimize.minimize.

{}
dx float32

The required translation of panel in x.

required
dy float32

The required translation of panel in y.

required
d_adj NDArray[float32]

The amount to move each adjustor.

required
dx_err float32

The error in the fit for dx.

required
dy_err float32

The error in the fit for dy.

required
d_adj_err NDArray[float32]

The error in the fit for d_adj.

required
Source code in lat_alignment/adjustments.py
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
def calc_adjustments(
    can_points: NDArray[np.float32],
    points: NDArray[np.float32],
    adjustors: NDArray[np.float32],
    **kwargs,
) -> Tuple[
    np.float32,
    np.float32,
    NDArray[np.float32],
    np.float32,
    np.float32,
    NDArray[np.float32],
]:
    """
    Calculate adjustments needed to align panel.

    Parameters
    ----------
    can_points : NDArray[np.float32]
        The cannonical position of the points to align.
    points : NDArray[np.float32]
        The measured positions of the points to align.
    adjustors : NDArray[np.float32]
        The measured positions of the adjustors.
    **kwargs
        Arguments to be passed to `scipy.optimize.minimize`.

    dx : np.float32
        The required translation of panel in x.
    dy : np.float32
        The required translation of panel in y.
    d_adj : NDArray[np.float32]
        The amount to move each adjustor.
    dx_err : np.float32
        The error in the fit for `dx`.
    dy_err : np.float32
        The error in the fit for `dy`.
    d_adj_err : NDArray[np.float32]
        The error in the fit for `d_adj`.
    """
    res = opt.minimize(
        adjustment_fit_func, np.zeros(6), (can_points, points, adjustors), **kwargs
    )

    dx, dy, dz, thetha_0, thetha_1, z_t = res.x
    _points, _adjustors = translate_panel(points, adjustors, dx, dy, dz)
    _points, _adjustors = rotate_panel(_points, _adjustors, thetha_0, thetha_1)
    _adjustors[-1, -1] += z_t
    d_adj = _adjustors - adjustors

    ftol = 2.220446049250313e-09
    if "ftol" in kwargs:
        ftol = kwargs["ftol"]
    perr = np.sqrt(ftol * np.diag(res.hess_inv))
    dx_err, dy_err, dz_err, thetha_0_err, thetha_1_err, z_t_err = perr
    _points, _adjustors = translate_panel(points, adjustors, dx_err, dy_err, dz_err)
    _points, _adjustors = rotate_panel(_points, _adjustors, thetha_0_err, thetha_1_err)
    _adjustors[-1, -1] += z_t_err
    d_adj_err = _adjustors - adjustors

    return dx, dy, d_adj[:, 2], dx_err, dy_err, d_adj_err[:, 2]

rotate(point, end_point1, end_point2, theta)

Rotate a point about an axis

Parameters:

Name Type Description Default
point NDArray[float32]

The point to rotate

required
end_point1 NDArray[float32]

A point on the axis of rotation

required
end_point2 NDArray[float32]

Another point on the axis of rotation

required
theta float32

Angle in radians to rotate by

required

Returns:

Name Type Description
point NDArray[float32]

The rotated point

Source code in lat_alignment/adjustments.py
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
def rotate(
    point: NDArray[np.float32],
    end_point1: NDArray[np.float32],
    end_point2: NDArray[np.float32],
    theta: np.float32,
) -> NDArray[np.float32]:
    """
    Rotate a point about an axis

    Parameters
    ----------
    point : NDArray[np.float32]
        The point to rotate
    end_point1 : NDArray[np.float32]
        A point on the axis of rotation
    end_point2 : NDArray[np.float32]
        Another point on the axis of rotation
    theta: NDArray[np.float32]
        Angle in radians to rotate by

    Returns
    -------
    point : NDArray[np.float32]
        The rotated point
    """
    origin = np.mean((end_point1, end_point2))
    point_0 = point - origin
    ax = end_point2 - end_point1
    ax = rot.from_rotvec(theta * ax / np.linalg.norm(ax))
    point_0 = ax.apply(point_0)
    return point_0 + origin

rotate_panel(points, adjustors, thetha_0, thetha_1)

Rotate panel about axes created by adjustors.

Parameters:

Name Type Description Default
points NDArray[float32]

Points on panel to rotate.

required
adjustors NDArray[float32]

Adjustor positions.

required
thetha_0 float32

Angle to rotate about first adjustor axis

required
thetha_1 np.float32.

Angle to rotate about second adjustor axis

required

Returns:

Name Type Description
rot_points NDArray[float32]

The rotated points.

rot_adjustors NDArray[float32]

The rotated adjustors.

Source code in lat_alignment/adjustments.py
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
def rotate_panel(
    points: NDArray[np.float32],
    adjustors: NDArray[np.float32],
    thetha_0: np.float32,
    thetha_1: np.float32,
) -> Tuple[NDArray[np.float32], NDArray[np.float32]]:
    """
    Rotate panel about axes created by adjustors.

    Parameters
    ----------
    points : NDArray[np.float32]
        Points on panel to rotate.
    adjustors : NDArray[np.float32]
        Adjustor positions.
    thetha_0 : np.float32
        Angle to rotate about first adjustor axis
    thetha_1 : np.float32.
        Angle to rotate about second adjustor axis

    Returns
    -------
    rot_points : NDArray[np.float32]
        The rotated points.
    rot_adjustors : NDArray[np.float32]
        The rotated adjustors.
    """
    rot_points = np.zeros(points.shape, np.float32)
    rot_adjustors = np.zeros(adjustors.shape, np.float32)

    n_points = len(points)
    n_adjustors = len(adjustors)

    for i in range(n_points):
        rot_points[i] = rotate(points[i], adjustors[1], adjustors[2], thetha_0)
        rot_points[i] = rotate(rot_points[i], adjustors[0], adjustors[3], thetha_1)
    for i in range(n_adjustors):
        rot_adjustors[i] = rotate(adjustors[i], adjustors[1], adjustors[2], thetha_0)
        rot_adjustors[i] = rotate(
            rot_adjustors[i], adjustors[0], adjustors[3], thetha_1
        )
    return rot_points, rot_adjustors

translate_panel(points, adjustors, dx, dy, dz)

Translate a panel.

Parameters:

Name Type Description Default
points NDArray[float32]

The points on panel to translate.

required
adjustors NDArray[float32]

Adjustor positions.

required
dx float32

Translation in x.

required
dy float32

Translation in y.

required
dz float32

Translation in z.

required

Returns:

Name Type Description
points NDArray[float32]

The translated points.

adjustors NDArray[float32]

The translated adjustors.

Source code in lat_alignment/adjustments.py
 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
def translate_panel(
    points: NDArray[np.float32],
    adjustors: NDArray[np.float32],
    dx: np.float32,
    dy: np.float32,
    dz: np.float32,
) -> Tuple[NDArray[np.float32], NDArray[np.float32]]:
    """
    Translate a panel.

    Parameters
    ----------
    points : NDArray[np.float32]
        The points on panel to translate.
    adjustors : NDArray[np.float32]
        Adjustor positions.
    dx : np.float32
        Translation in x.
    dy : np.float32
        Translation in y.
    dz : np.float32
        Translation in z.

    Returns
    -------
    points : NDArray[np.float32]
        The translated points.
    adjustors : NDArray[np.float32]
        The translated adjustors.
    """
    translation = np.array((dx, dy, dz))
    return points + translation, adjustors + translation