Beispiel #1
0
def test_RotationSequence3D_errors():
    # Bad axes_order labels
    with pytest.raises(
            ValueError,
            match=r"Unrecognized axis label .* should be one of .*"):
        rotations.RotationSequence3D(mk.MagicMock(), axes_order="abc")

    # Bad number of angles
    with pytest.raises(ValueError) as err:
        rotations.RotationSequence3D([1, 2, 3, 4], axes_order="zyx")
    assert str(err.value) ==\
        "The number of angles 4 should match the number of axes 3."

    # Bad evaluation input shapes
    model = rotations.RotationSequence3D([1, 2, 3], axes_order="zyx")
    message = "Expected input arrays to have the same shape"
    with pytest.raises(ValueError) as err:
        model.evaluate(np.array([1, 2, 3]), np.array([1, 2]), np.array([1, 2]),
                       [1, 2, 3])
    assert str(err.value) == message
    with pytest.raises(ValueError) as err:
        model.evaluate(np.array([1, 2]), np.array([1, 2, 3]), np.array([1, 2]),
                       [1, 2, 3])
    assert str(err.value) == message
    with pytest.raises(ValueError) as err:
        model.evaluate(np.array([1, 2]), np.array([1, 2]), np.array([1, 2, 3]),
                       [1, 2, 3])
    assert str(err.value) == message
Beispiel #2
0
def test_spherical_rotation():
    """
    Test taken from JWST INS report - converts
    JWST telescope (V2, V3) coordinates to RA, DEC.
    """
    ra_ref = 165  # in deg
    dec_ref = 54  # in deg
    v2_ref = -503.654472 / 3600  # in deg
    v3_ref = -318.742464 / 3600  # in deg
    r0 = 37  # in deg

    v2 = 210  # in deg
    v3 = -75  # in deg
    expected_ra_dec = (107.12810484789563, -35.97940247128502)  # in deg
    angles = np.array([v2_ref, -v3_ref, r0, dec_ref, -ra_ref])
    axes = "zyxyz"
    v2s = rotations.RotationSequence3D(angles, axes_order=axes)
    x, y, z = rotations.spherical2cartesian(v2, v3)
    x1, y1, z1 = v2s(x, y, z)
    radec = rotations.cartesian2spherical(x1, y1, z1)
    assert_allclose(radec, expected_ra_dec, atol=1e-10)

    v2s = rotations.SphericalRotationSequence(angles, axes_order=axes)
    radec = v2s(v2, v3)
    assert_allclose(radec, expected_ra_dec, atol=1e-10)
Beispiel #3
0
 def from_tree_transform(self, node):
     angles = node['angles']
     axes_order = node['axes_order']
     rotation_type = node['rotation_type']
     if rotation_type == 'cartesian':
         return rotations.RotationSequence3D(angles, axes_order=axes_order)
     elif rotation_type == 'spherical':
         return rotations.SphericalRotationSequence(angles,
                                                    axes_order=axes_order)
     else:
         raise ValueError(f"Unrecognized rotation_type: {rotation_type}")
    def from_yaml_tree_transform(self, node, tag, ctx):
        from astropy.modeling import rotations

        angles = node["angles"]
        axes_order = node["axes_order"]
        rotation_type = node["rotation_type"]
        if rotation_type == "cartesian":
            return rotations.RotationSequence3D(angles, axes_order=axes_order)
        elif rotation_type == "spherical":
            return rotations.SphericalRotationSequence(angles,
                                                       axes_order=axes_order)
        else:
            raise ValueError(f"Unrecognized rotation_type: {rotation_type}")
Beispiel #5
0
def test_RotationSequence3D_inverse():
    model = rotations.RotationSequence3D([1, 2, 3], axes_order="zyx")

    assert_allclose(model.inverse.angles.value, [-3, -2, -1])
    assert model.inverse.axes_order == "xyz"