コード例 #1
0
def test_shorthand_attributes():
    # Check that attribute access works

    # for array data:
    n = 4
    icrs1 = ICRS(ra=np.random.uniform(0, 360, n) * u.deg,
                 dec=np.random.uniform(-90, 90, n) * u.deg,
                 distance=100 * u.pc,
                 pm_ra_cosdec=np.random.normal(0, 100, n) * u.mas / u.yr,
                 pm_dec=np.random.normal(0, 100, n) * u.mas / u.yr,
                 radial_velocity=np.random.normal(0, 100, n) * u.km / u.s)
    v = icrs1.velocity
    pm = icrs1.proper_motion
    assert quantity_allclose(pm[0], icrs1.pm_ra_cosdec)
    assert quantity_allclose(pm[1], icrs1.pm_dec)

    # for scalar data:
    icrs2 = ICRS(ra=37.4 * u.deg,
                 dec=-55.8 * u.deg,
                 distance=150 * u.pc,
                 pm_ra_cosdec=-21.2 * u.mas / u.yr,
                 pm_dec=17.1 * u.mas / u.yr,
                 radial_velocity=105.7 * u.km / u.s)
    v = icrs2.velocity
    pm = icrs2.proper_motion
    assert quantity_allclose(pm[0], icrs2.pm_ra_cosdec)
    assert quantity_allclose(pm[1], icrs2.pm_dec)

    # check that it fails where we expect:

    # no distance
    rv = 105.7 * u.km / u.s
    icrs3 = ICRS(ra=37.4 * u.deg,
                 dec=-55.8 * u.deg,
                 pm_ra_cosdec=-21.2 * u.mas / u.yr,
                 pm_dec=17.1 * u.mas / u.yr,
                 radial_velocity=rv)
    with pytest.raises(ValueError):
        icrs3.velocity

    icrs3.set_representation_cls('cartesian')
    assert hasattr(icrs3, 'radial_velocity')
    assert quantity_allclose(icrs3.radial_velocity, rv)

    icrs4 = ICRS(x=30 * u.pc,
                 y=20 * u.pc,
                 z=11 * u.pc,
                 v_x=10 * u.km / u.s,
                 v_y=10 * u.km / u.s,
                 v_z=10 * u.km / u.s,
                 representation_type=r.CartesianRepresentation,
                 differential_type=r.CartesianDifferential)
    icrs4.radial_velocity
コード例 #2
0
def test_differential_type_arg():
    """
    Test passing in an explicit differential class to the initializer or
    changing the differential class via set_representation_cls
    """
    from astropy.coordinates.builtin_frames import ICRS

    icrs = ICRS(ra=1 * u.deg,
                dec=60 * u.deg,
                pm_ra=10 * u.mas / u.yr,
                pm_dec=-11 * u.mas / u.yr,
                differential_type=r.UnitSphericalDifferential)
    assert icrs.pm_ra == 10 * u.mas / u.yr

    icrs = ICRS(ra=1 * u.deg,
                dec=60 * u.deg,
                pm_ra=10 * u.mas / u.yr,
                pm_dec=-11 * u.mas / u.yr,
                differential_type={'s': r.UnitSphericalDifferential})
    assert icrs.pm_ra == 10 * u.mas / u.yr

    icrs = ICRS(ra=1 * u.deg,
                dec=60 * u.deg,
                pm_ra_cosdec=10 * u.mas / u.yr,
                pm_dec=-11 * u.mas / u.yr)
    icrs.set_representation_cls(s=r.UnitSphericalDifferential)
    assert quantity_allclose(icrs.pm_ra, 20 * u.mas / u.yr)

    # incompatible representation and differential
    with pytest.raises(TypeError):
        ICRS(ra=1 * u.deg,
             dec=60 * u.deg,
             v_x=1 * u.km / u.s,
             v_y=-2 * u.km / u.s,
             v_z=-2 * u.km / u.s,
             differential_type=r.CartesianDifferential)

    # specify both
    icrs = ICRS(x=1 * u.pc,
                y=2 * u.pc,
                z=3 * u.pc,
                v_x=1 * u.km / u.s,
                v_y=2 * u.km / u.s,
                v_z=3 * u.km / u.s,
                representation_type=r.CartesianRepresentation,
                differential_type=r.CartesianDifferential)
    assert icrs.x == 1 * u.pc
    assert icrs.y == 2 * u.pc
    assert icrs.z == 3 * u.pc
    assert icrs.v_x == 1 * u.km / u.s
    assert icrs.v_y == 2 * u.km / u.s
    assert icrs.v_z == 3 * u.km / u.s
コード例 #3
0
def test_shorthand_attributes():
    # Check that attribute access works

    # for array data:
    n = 4
    icrs1 = ICRS(ra=np.random.uniform(0, 360, n)*u.deg,
                 dec=np.random.uniform(-90, 90, n)*u.deg,
                 distance=100*u.pc,
                 pm_ra_cosdec=np.random.normal(0, 100, n)*u.mas/u.yr,
                 pm_dec=np.random.normal(0, 100, n)*u.mas/u.yr,
                 radial_velocity=np.random.normal(0, 100, n)*u.km/u.s)
    v = icrs1.velocity
    pm = icrs1.proper_motion
    assert quantity_allclose(pm[0], icrs1.pm_ra_cosdec)
    assert quantity_allclose(pm[1], icrs1.pm_dec)

    # for scalar data:
    icrs2 = ICRS(ra=37.4*u.deg, dec=-55.8*u.deg, distance=150*u.pc,
                 pm_ra_cosdec=-21.2*u.mas/u.yr, pm_dec=17.1*u.mas/u.yr,
                 radial_velocity=105.7*u.km/u.s)
    v = icrs2.velocity
    pm = icrs2.proper_motion
    assert quantity_allclose(pm[0], icrs2.pm_ra_cosdec)
    assert quantity_allclose(pm[1], icrs2.pm_dec)

    # check that it fails where we expect:

    # no distance
    rv = 105.7*u.km/u.s
    icrs3 = ICRS(ra=37.4*u.deg, dec=-55.8*u.deg,
                 pm_ra_cosdec=-21.2*u.mas/u.yr, pm_dec=17.1*u.mas/u.yr,
                 radial_velocity=rv)
    with pytest.raises(ValueError):
        icrs3.velocity

    icrs3.set_representation_cls('cartesian')
    assert hasattr(icrs3, 'radial_velocity')
    assert quantity_allclose(icrs3.radial_velocity, rv)

    icrs4 = ICRS(x=30*u.pc, y=20*u.pc, z=11*u.pc,
                 v_x=10*u.km/u.s, v_y=10*u.km/u.s, v_z=10*u.km/u.s,
                 representation_type=r.CartesianRepresentation,
                 differential_type=r.CartesianDifferential)
    icrs4.radial_velocity
コード例 #4
0
def test_differential_type_arg():
    """
    Test passing in an explicit differential class to the initializer or
    changing the differential class via set_representation_cls
    """
    from astropy.coordinates.builtin_frames import ICRS

    icrs = ICRS(ra=1*u.deg, dec=60*u.deg,
                pm_ra=10*u.mas/u.yr, pm_dec=-11*u.mas/u.yr,
                differential_type=r.UnitSphericalDifferential)
    assert icrs.pm_ra == 10*u.mas/u.yr

    icrs = ICRS(ra=1*u.deg, dec=60*u.deg,
                pm_ra=10*u.mas/u.yr, pm_dec=-11*u.mas/u.yr,
                differential_type={'s': r.UnitSphericalDifferential})
    assert icrs.pm_ra == 10*u.mas/u.yr

    icrs = ICRS(ra=1*u.deg, dec=60*u.deg,
                pm_ra_cosdec=10*u.mas/u.yr, pm_dec=-11*u.mas/u.yr)
    icrs.set_representation_cls(s=r.UnitSphericalDifferential)
    assert quantity_allclose(icrs.pm_ra, 20*u.mas/u.yr)

    # incompatible representation and differential
    with pytest.raises(TypeError):
        ICRS(ra=1*u.deg, dec=60*u.deg,
             v_x=1*u.km/u.s, v_y=-2*u.km/u.s, v_z=-2*u.km/u.s,
             differential_type=r.CartesianDifferential)

    # specify both
    icrs = ICRS(x=1*u.pc, y=2*u.pc, z=3*u.pc,
                v_x=1*u.km/u.s, v_y=2*u.km/u.s, v_z=3*u.km/u.s,
                representation_type=r.CartesianRepresentation,
                differential_type=r.CartesianDifferential)
    assert icrs.x == 1*u.pc
    assert icrs.y == 2*u.pc
    assert icrs.z == 3*u.pc
    assert icrs.v_x == 1*u.km/u.s
    assert icrs.v_y == 2*u.km/u.s
    assert icrs.v_z == 3*u.km/u.s