예제 #1
0
def test_rotation_3d():
    """
    A sanity test - when V2_REF = 0 and V3_REF = 0,
    for V2, V3 close to the origin
    ROLL_REF should be approximately PA_V3 .

    (Test taken from JWST SIAF report.)
    """
    def _roll_angle_from_matrix(matrix, v2, v3):
        X = -(matrix[2, 0] * np.cos(v2) + matrix[2, 1] * np.sin(v2)) * \
            np.sin(v3) + matrix[2, 2] * np.cos(v3)
        Y = (matrix[0, 0] * matrix[1, 2] - matrix[1, 0] * matrix[0, 2]) * np.cos(v2) + \
            (matrix[0, 1] * matrix[1, 2] - matrix[1, 1] * matrix[0, 2]) * np.sin(v2)
        new_roll = np.rad2deg(np.arctan2(Y, X))
        if new_roll < 0:
            new_roll += 360
        return new_roll

    # reference points on sky and in a coordinate frame associated
    # with the telescope
    ra_ref = 165  # in deg
    dec_ref = 54  # in deg
    v2_ref = 0
    v3_ref = 0
    pa_v3 = 37  # in deg

    v2 = np.deg2rad(2.7e-6)  # in deg.01 # in arcsec
    v3 = np.deg2rad(2.7e-6)  # in deg .01 # in arcsec
    angles = [v2_ref, -v3_ref, pa_v3, dec_ref, -ra_ref]
    axes = "zyxyz"
    M = rotations._create_matrix(np.deg2rad(angles) * u.deg, axes)
    roll_angle = _roll_angle_from_matrix(M, v2, v3)
    assert_allclose(roll_angle, pa_v3, atol=1e-3)
예제 #2
0
def test_euler_angles(axes_order):
    """
    Tests against all Euler sequences.
    The rotation matrices definitions come from Wikipedia.
    """
    phi = np.deg2rad(23.4)
    theta = np.deg2rad(12.2)
    psi = np.deg2rad(34)
    c1 = cos(phi)
    c2 = cos(theta)
    c3 = cos(psi)
    s1 = sin(phi)
    s2 = sin(theta)
    s3 = sin(psi)

    matrices = {
        'zxz':
        np.array([[(c1 * c3 - c2 * s1 * s3), (-c1 * s3 - c2 * c3 * s1),
                   (s1 * s2)],
                  [(c3 * s1 + c1 * c2 * s3), (c1 * c2 * c3 - s1 * s3),
                   (-c1 * s2)], [(s2 * s3), (c3 * s2), (c2)]]),
        'zyz':
        np.array([[(c1 * c2 * c3 - s1 * s3), (-c3 * s1 - c1 * c2 * s3),
                   (c1 * s2)],
                  [(c1 * s3 + c2 * c3 * s1), (c1 * c3 - c2 * s1 * s3),
                   (s1 * s2)], [(-c3 * s2), (s2 * s3), (c2)]]),
        'yzy':
        np.array([[(c1 * c2 * c3 - s1 * s3), (-c1 * s2),
                   (c3 * s1 + c1 * c2 * s3)], [(c3 * s2), (c2), (s2 * s3)],
                  [(-c1 * s3 - c2 * c3 * s1), (s1 * s2),
                   (c1 * c3 - c2 * s1 * s3)]]),
        'yxy':
        np.array([[(c1 * c3 - c2 * s1 * s3), (s1 * s2),
                   (c1 * s3 + c2 * c3 * s1)], [(s2 * s3), (c2), (-c3 * s2)],
                  [(-c3 * s1 - c1 * c2 * s3), (c1 * s2),
                   (c1 * c2 * c3 - s1 * s3)]]),
        'xyx':
        np.array([[(c2), (s2 * s3), (c3 * s2)],
                  [(s1 * s2), (c1 * c3 - c2 * s1 * s3),
                   (-c1 * s3 - c2 * c3 * s1)],
                  [(-c1 * s2), (c3 * s1 + c1 * c2 * s3),
                   (c1 * c2 * c3 - s1 * s3)]]),
        'xzx':
        np.array([[(c2), (-c3 * s2), (s2 * s3)],
                  [(c1 * s2), (c1 * c2 * c3 - s1 * s3),
                   (-c3 * s1 - c1 * c2 * s3)],
                  [(s1 * s2), (c1 * s3 + c2 * c3 * s1),
                   (c1 * c3 - c2 * s1 * s3)]])
    }
    mat = rotations._create_matrix([phi, theta, psi], axes_order)

    assert_allclose(mat.T,
                    matrices[axes_order])  # get_rotation_matrix(axes_order))