Пример #1
0
def test_exceptions():
    with pytest.raises(TypeError) as ei:
        QuantityTableCoordinate(u.Quantity([1, 2, 3], u.nm), [1, 2, 3])
    assert "All tables must be astropy Quantity objects" in str(ei)

    with pytest.raises(u.UnitsError) as ei:
        QuantityTableCoordinate(u.Quantity([1, 2, 3], u.nm), [1, 2, 3] * u.deg)
    assert "All tables must have equivalent units." in str(ei)

    with pytest.raises(ValueError) as ei:
        QuantityTableCoordinate(u.Quantity([1, 2, 3], u.nm), [1, 2, 3] * u.m,
                                names='x')
    assert "The number of names should match the number of world dimensions" in str(
        ei)

    with pytest.raises(ValueError) as ei:
        QuantityTableCoordinate(u.Quantity([1, 2, 3], u.nm), [1, 2, 3] * u.m,
                                physical_types='x')
    assert "The number of physical types should match the number of world dimensions" in str(
        ei)

    # Test two Time
    with pytest.raises(ValueError) as ei:
        TimeTableCoordinate(Time("2011-01-01"), Time("2011-01-01"))
    assert "single Time object" in str(ei)

    with pytest.raises(ValueError) as ei:
        TimeTableCoordinate(Time("2011-01-01"), names=['a', 'b'])
    assert "only have one name." in str(ei)

    with pytest.raises(ValueError) as ei:
        TimeTableCoordinate(Time("2011-01-01"), physical_types=['a', 'b'])
    assert "only have one physical type." in str(ei)

    # Test two SkyCoord
    with pytest.raises(ValueError) as ei:
        SkyCoordTableCoordinate(SkyCoord(10, 10, unit=u.deg),
                                SkyCoord(10, 10, unit=u.deg))
    assert "single SkyCoord object" in str(ei)

    with pytest.raises(ValueError) as ei:
        SkyCoordTableCoordinate(SkyCoord(10, 10, unit=u.deg), names='x')
    assert "names must equal two" in str(ei)

    with pytest.raises(ValueError) as ei:
        SkyCoordTableCoordinate(SkyCoord(10, 10, unit=u.deg),
                                physical_types='x')
    assert "physical types must equal two" in str(ei)

    with pytest.raises(TypeError) as ei:
        MultipleTableCoordinate(
            10, SkyCoordTableCoordinate(SkyCoord(10, 10, unit=u.deg)))
    assert "All arguments must be BaseTableCoordinate" in str(ei)

    with pytest.raises(TypeError) as ei:
        MultipleTableCoordinate(
            MultipleTableCoordinate(
                SkyCoordTableCoordinate(SkyCoord(10, 10, unit=u.deg))))
    assert "All arguments must be BaseTableCoordinate" in str(ei)
Пример #2
0
def test_slicing_quantity_table_coordinate():
    qtc = QuantityTableCoordinate(range(10) * u.m,
                                  mesh=False,
                                  names='x',
                                  physical_types='pos:x')

    assert u.allclose(qtc[2:8].table[0], range(2, 8) * u.m)
    assert u.allclose(qtc[2].table[0], 2 * u.m)
    assert qtc.names == ['x']
    assert qtc.physical_types == ['pos:x']

    qtc = QuantityTableCoordinate(range(10) * u.m, mesh=True)

    assert u.allclose(qtc[2:8].table[0], range(2, 8) * u.m)
    assert u.allclose(qtc[2].table[0], 2 * u.m)

    qtc = QuantityTableCoordinate(*np.mgrid[0:10, 0:10] * u.m,
                                  mesh=False,
                                  names=['x', 'y'],
                                  physical_types=['pos:x', 'pos:y'])

    assert u.allclose(qtc[2:8, 2:8].table[0], (np.mgrid[2:8, 2:8] * u.m)[0])
    assert u.allclose(qtc[2:8, 2:8].table[1], (np.mgrid[2:8, 2:8] * u.m)[1])
    assert qtc.names == ['x', 'y']
    assert qtc.physical_types == ['pos:x', 'pos:y']

    assert qtc.frame.axes_names == ('x', 'y')
    assert qtc.frame.axis_physical_types == ('custom:pos:x', 'custom:pos:y')

    assert u.allclose(qtc[2, 2:8].table[0], 2 * u.m)
    assert u.allclose(qtc[2, 2:8].table[1], (np.mgrid[2:8, 2:8] * u.m)[1])

    qtc = QuantityTableCoordinate(range(10) * u.m,
                                  range(10) * u.m,
                                  mesh=True,
                                  names=['x', 'y'],
                                  physical_types=['pos:x', 'pos:y'])
    assert u.allclose(qtc[2:8, 2:8].table[0], range(2, 8) * u.m)
    assert u.allclose(qtc[2:8, 2:8].table[1], range(2, 8) * u.m)

    # we have dropped one dimension
    assert len(qtc[2, 2:8].table) == 1
    assert u.allclose(qtc[2, 2:8].table[0], range(2, 8) * u.m)

    assert qtc.names == ['x', 'y']
    assert qtc.physical_types == ['pos:x', 'pos:y']

    assert qtc.frame.axes_names == ('x', 'y')
    assert qtc.frame.axis_physical_types == ('custom:pos:x', 'custom:pos:y')
Пример #3
0
def test_and_errors():
    data = Time([
        "2011-01-01T00:00:00", "2011-01-01T00:00:10", "2011-01-01T00:00:20",
        "2011-01-01T00:00:30"
    ],
                format="isot")

    ttc = TimeTableCoordinate(data)

    qtc = QuantityTableCoordinate(range(10) * u.m, mesh=False)

    with pytest.raises(TypeError) as ei:
        ttc & 5
    assert "unsupported operand type(s) for &: 'TimeTableCoordinate' and 'int'" in str(
        ei)

    join = ttc & qtc

    with pytest.raises(TypeError) as ei:
        join & 5
    assert "unsupported operand type(s) for &: 'MultipleTableCoordinate' and 'int'" in str(
        ei)

    with pytest.raises(TypeError) as ei:
        5 & join
    assert "unsupported operand type(s) for &: 'int' and 'MultipleTableCoordinate'" in str(
        ei)
Пример #4
0
def test_and_base_table_coordinate():
    data = Time([
        "2011-01-01T00:00:00", "2011-01-01T00:00:10", "2011-01-01T00:00:20",
        "2011-01-01T00:00:30"
    ],
                format="isot")

    ttc = TimeTableCoordinate(data)

    qtc = QuantityTableCoordinate(range(10) * u.m, mesh=False)

    join = ttc & ttc
    assert isinstance(join, MultipleTableCoordinate)

    join2 = join & qtc

    assert isinstance(join2, MultipleTableCoordinate)
    assert len(join2._table_coords) == 3
    assert join2._table_coords[2] is qtc

    join3 = qtc & join

    assert isinstance(join3, MultipleTableCoordinate)
    assert len(join3._table_coords) == 3
    assert join3._table_coords[0] is qtc

    join4 = ttc & qtc
    assert isinstance(join4, MultipleTableCoordinate)
    assert len(join4._table_coords) == 2
    assert join4._table_coords[0] is ttc
    assert join4._table_coords[1] is qtc

    join5 = join & join
    assert isinstance(join5, MultipleTableCoordinate)
    assert len(join5._table_coords) == 4
Пример #5
0
def lut_3d_distance_mesh():
    lookup_table = (u.Quantity(np.arange(10) * u.km),
                    u.Quantity(np.arange(10, 20) * u.km),
                    u.Quantity(np.arange(20, 30) * u.km))

    return QuantityTableCoordinate(*lookup_table,
                                   mesh=True,
                                   names=['x', 'y', 'z'])
Пример #6
0
def lut_1d_wave():
    # TODO: Make this into a SpectralCoord object
    return QuantityTableCoordinate(range(10) * u.nm)
Пример #7
0
def lut_2d_distance_no_mesh():
    lookup_table = np.arange(9).reshape(3, 3) * u.km, np.arange(9, 18).reshape(
        3, 3) * u.km
    return QuantityTableCoordinate(*lookup_table, mesh=False)
Пример #8
0
def test_2d_quantity():
    shape = (3, 3)
    data = np.arange(np.product(shape)).reshape(shape) * u.m / u.s

    ltc = QuantityTableCoordinate(data)
    assert u.allclose(ltc.wcs.pixel_to_world(0, 0), 0 * u.m / u.s)
Пример #9
0
def lut_1d_distance():
    lookup_table = u.Quantity(np.arange(10) * u.km)
    return QuantityTableCoordinate(lookup_table, names='x')