예제 #1
0
def test_operations():
    t1 = Date(2015, 12, 6)

    t2 = t1 + timedelta(hours=2)
    assert t2.d == t1.d
    assert t2.s == t1.s + 2 * 3600

    with raises(TypeError):
        t2 = t1 + 1

    t2 = t1 - timedelta(hours=12)
    assert t2.d == t1.d - 1
    assert t2.s == 43200.

    t2 = t1 - datetime(2015, 12, 4)
    assert type(t2) is timedelta
    assert t2.days == 2

    t2 = t1 - Date(2015, 12, 4)
    assert type(t2) is timedelta
    assert t2.days == 2

    with raises(TypeError):
        t2 = t1 - 2.5

    # Test if Date is hashable
    d = {
        t1: "test",
        t2: "test2"
    }
    t1bis = t1.change_scale('UT1')
    assert d[t1bis] == "test"
예제 #2
0
def test_plot():
    # This test is ran only if matplotlib is installed

    import matplotlib.pyplot as plt

    dates = list(Date.range(Date.now(), timedelta(1), timedelta(minutes=10)))
    plt.plot(dates, np.random.rand(len(dates)))
    plt.draw()
예제 #3
0
def test_julian():

    with patch('beyond.dates.date.EopDb.get') as m:
        m.return_value = Eop(x=0, y=0, dx=0, dy=0, dpsi=0, deps=0, lod=0, ut1_utc=0.10362957986110499, tai_utc=36.0)

        t = Date(2015, 12, 18, 22, 25)
        assert t.mjd == 57374.93402777778
        assert t.jd == 2457375.434027778
        assert t.change_scale('TT').julian_century == 0.1596286055289367
예제 #4
0
def test_plot():
    # This test is ran only if matplotlib is installed

    import matplotlib.pyplot as plt

    fig = plt.figure()
    dates = list(Date.range(Date.now(), timedelta(1), timedelta(minutes=10)))
    plt.plot(dates, np.random.rand(len(dates)))
    plt.draw()  # draws the figure, but does not show it
    plt.close(fig)  # Delete the figure
예제 #5
0
def test_range():

    start = Date(2016, 11, 16, 22, 38)
    stop = timedelta(hours=1)
    step = timedelta(seconds=30)

    # classic range
    l1 = list(Date.range(start, stop, step))
    assert len(l1) == stop // step

    # Inclusive range
    l2 = list(Date.range(start, stop, step, inclusive=True))
    assert len(l2) == stop // step + 1

    # stop as a Date object
    stop = Date(2016, 11, 16, 22, 40)
    l3 = Date.range(start, stop, step)

    # Inverse order
    start = Date(2016, 11, 16, 22, 40)
    stop = -timedelta(minutes=2)
    step = -timedelta(seconds=30)

    l4 = list(Date.range(start, stop, step))
    assert len(l4) == stop // step

    # Error when the date range (start/stop) is not coherent with the step
    with raises(ValueError):
        list(Date.range(start, stop, -step))

    # Error when the step is null.
    with raises(ValueError):
        list(Date.range(start, stop, timedelta(0)))
예제 #6
0
def test_barycenter():
    with patch('beyond.dates.date.EopDb.get') as m:
        m.return_value = Eop(x=0, y=0, dx=0, dy=0, dpsi=0, deps=0, lod=0, ut1_utc=-0.463326, tai_utc=32.0)

        t = Date(2004, 5, 14, 16, 43)  # UTC

        t2 = t.change_scale('TT')
        assert str(t2) == "2004-05-14T16:44:04.184000 TT"

        t3 = t2.change_scale('TDB')
        assert str(t3) == "2004-05-14T16:44:04.185254 TDB"
예제 #7
0
def test_change_scale():

    with patch('beyond.dates.date.EopDb.get') as m:

        m.return_value = Eop(x=0,
                             y=0,
                             dx=0,
                             dy=0,
                             dpsi=0,
                             deps=0,
                             lod=0,
                             ut1_utc=0.1242558,
                             tai_utc=36.0)

        t = Date(2015, 12, 6)  # UTC object
        assert str(t.scale) == "UTC"

        t2 = t.change_scale('TT')
        assert str(t2) == "2015-12-06T00:01:08.184000 TT"

        t3 = t.change_scale('GPS')
        assert str(t3) == "2015-12-06T00:00:17 GPS"

        t4 = t.change_scale('UT1')
        assert str(t4) == "2015-12-06T00:00:00.124256 UT1"

        t5 = t.change_scale('TDB')
        assert str(t5) == "2015-12-06T00:01:08.183225 TDB"

        assert str(t5.change_scale('UTC')) == "2015-12-06T00:00:00 UTC"

        with raises(ValueError):
            t.change_scale('unknown')
예제 #8
0
def test_sun(helper):

    with patch('beyond.dates.date.EopDb.get') as m:
        m.return_value = Eop(x=0,
                             y=0,
                             dx=0,
                             dy=0,
                             deps=0,
                             dpsi=0,
                             lod=0,
                             ut1_utc=0.2653703,
                             tai_utc=33.0)
        sun = get_body('Sun')
        sun_orb = sun.propagate(Date(2006, 4, 2))

    assert str(sun_orb.form) == 'cartesian'
    assert str(sun_orb.frame) == 'MOD'
    assert isinstance(sun_orb.propagator, SunPropagator)
    assert sun_orb.date.scale.name == "UT1"
    assert abs(32.734629699999999274950823746622 -
               sun_orb.date._offset) <= np.finfo(float).eps

    helper.assert_vector(
        sun_orb.base,
        np.array([
            146186235643.53641, 28789144480.499767, 12481136552.345926,
            -5757.901470756284, 26793.699110930935, 11616.03628136728
        ]))
예제 #9
0
def test_moon(helper):
    with patch('beyond.dates.date.EopDb.get') as m:
        m.return_value = Eop(x=0,
                             y=0,
                             dx=0,
                             dy=0,
                             deps=0,
                             dpsi=0,
                             lod=0,
                             ut1_utc=-0.0889898,
                             tai_utc=28.0)
        moon = get_body('Moon')
        moon_orb = moon.propagate(Date(1994, 4, 28))

    assert str(moon_orb.form) == 'cartesian'
    assert str(moon_orb.frame) == 'EME2000'
    assert isinstance(moon_orb.propagator, MoonPropagator)
    assert moon_orb.date.scale.name == "TDB"
    assert abs(32.185528758994394138426287099719 +
               moon_orb.date._offset) <= np.finfo(float).eps
    helper.assert_vector(
        moon_orb,
        np.array([
            -134181155.8063418, -311598172.21627569, -126699062.57176001,
            976.8878152910264, -438.8323937765414, -87.42035305682552
        ]))
예제 #10
0
def test_moon():
    with patch('beyond.dates.date.EopDb.get') as m:
        m.return_value = Eop(x=0,
                             y=0,
                             dx=0,
                             dy=0,
                             deps=0,
                             dpsi=0,
                             lod=0,
                             ut1_utc=-0.0889898,
                             tai_utc=28.0)
        moon = get_body('Moon')
        moon_orb = moon.propagate(Date(1994, 4, 28))

    assert str(moon_orb.form) == 'cartesian'
    assert str(moon_orb.frame) == 'EME2000'
    assert isinstance(moon_orb.propagator, MoonPropagator)
    assert moon_orb.date.scale.name == "TDB"
    assert abs(32.185528758994394138426287099719 +
               moon_orb.date._offset) <= np.finfo(float).eps
    np.testing.assert_array_equal(
        moon_orb.base,
        np.array([
            -134181155.8063418, -311598172.21627569, -126699062.57176001, 0.0,
            0.0, 0.0
        ]))
예제 #11
0
def test_julian():

    with patch('beyond.dates.date.EopDb.get') as m:
        m.return_value = Eop(x=0,
                             y=0,
                             dx=0,
                             dy=0,
                             dpsi=0,
                             deps=0,
                             lod=0,
                             ut1_utc=0.10362957986110499,
                             tai_utc=36.0)

        t = Date(2015, 12, 18, 22, 25)
        assert t.mjd == 57374.93402777778
        assert t.jd == 2457375.434027778
        assert t.change_scale('TT').julian_century == 0.1596286055289367
예제 #12
0
def test_change_scale():

    with patch('beyond.dates.date.EopDb.get') as m:

        m.return_value = Eop(x=0, y=0, dx=0, dy=0, dpsi=0, deps=0, lod=0, ut1_utc=0.1242558, tai_utc=36.0)

        t = Date(2015, 12, 6)  # UTC object
        assert str(t.scale) == "UTC"

        t2 = t.change_scale('TT')
        assert str(t2) == "2015-12-06T00:01:08.184000 TT"

        t3 = t.change_scale('GPS')
        assert str(t3) == "2015-12-06T00:00:17 GPS"

        t4 = t.change_scale('UT1')
        assert str(t4) == "2015-12-06T00:00:00.124256 UT1"

        t5 = t.change_scale('TDB')
        assert str(t5) == "2015-12-06T00:01:08.183225 TDB"

        assert str(t5.change_scale('UTC')) == "2015-12-06T00:00:00 UTC"

        with raises(ValueError):
            t.change_scale('unknown')
예제 #13
0
def test_barycenter():
    with patch('beyond.dates.date.EopDb.get') as m:
        m.return_value = Eop(x=0,
                             y=0,
                             dx=0,
                             dy=0,
                             dpsi=0,
                             deps=0,
                             lod=0,
                             ut1_utc=-0.463326,
                             tai_utc=32.0)

        t = Date(2004, 5, 14, 16, 43)  # UTC

        t2 = t.change_scale('TT')
        assert str(t2) == "2004-05-14T16:44:04.184000 TT"

        t3 = t2.change_scale('TDB')
        assert str(t3) == "2004-05-14T16:44:04.185254 TDB"
예제 #14
0
def test_daterange2():

    start = Date(2021, 2, 9, 22, 35)
    stop = timedelta(hours=1, seconds=37)
    step = timedelta(seconds=17)

    r = Date.range(start, stop, step)
    l = list(r)

    assert np.ceil((r.stop - r.start) / r.step) == len(l)
    assert len(r) == len(l)
    assert l[0] == r.start
    assert l[-1] < r.stop

    r = Date.range(start, stop, step, inclusive=True)
    l = list(r)

    assert len(r) == len(l)
    assert l[0] == r.start
    assert l[-1] < r.stop
예제 #15
0
def test_pickle():

    date1 = Date(2018, 5, 8, 15, 55, 52, 232)

    txt = dumps(date1)
    date2 = loads(txt)

    assert date1 == date2
    assert date1.scale.name == date2.scale.name

    assert date1.eop.x == date2.eop.x
    assert date1.eop.y == date2.eop.y
    assert date1.eop.dx == date2.eop.dx
    assert date1.eop.dy == date2.eop.dy
    assert date1.eop.deps == date2.eop.deps
    assert date1.eop.dpsi == date2.eop.dpsi
    assert date1.eop.lod == date2.eop.lod
    assert date1.eop.ut1_utc == date2.eop.ut1_utc
    assert date1.eop.tai_utc == date2.eop.tai_utc

    assert date1.change_scale('UT1') == date2.change_scale('UT1')
예제 #16
0
def test_pickle():

    date1 = Date(2018, 5, 8, 15, 55, 52, 232)

    txt = dumps(date1)
    date2 = loads(txt)

    assert date1 == date2
    assert date1.scale.name == date2.scale.name

    assert date1.eop.x == date2.eop.x
    assert date1.eop.y == date2.eop.y
    assert date1.eop.dx == date2.eop.dx
    assert date1.eop.dy == date2.eop.dy
    assert date1.eop.deps == date2.eop.deps
    assert date1.eop.dpsi == date2.eop.dpsi
    assert date1.eop.lod == date2.eop.lod
    assert date1.eop.ut1_utc == date2.eop.ut1_utc
    assert date1.eop.tai_utc == date2.eop.tai_utc

    assert date1.change_scale('UT1') == date2.change_scale('UT1')
예제 #17
0
def test_comparison():

    with patch('beyond.dates.date.EopDb.get') as m:
        m.return_value = Eop(x=0,
                             y=0,
                             dx=0,
                             dy=0,
                             dpsi=0,
                             deps=0,
                             lod=0,
                             ut1_utc=0.10362957986110499,
                             tai_utc=36.0)

        # Same scale
        t1 = Date(2016, 11, 14)
        t2 = Date(2016, 11, 14, 12)
        assert t2 > t1

        # Different scale
        t1 = Date(2016, 11, 14)  # 00:00:36 in TAI
        t2 = Date(2016, 11, 14, scale='TAI')

        assert t2 < t1
        assert t1 > t2

        t1 = Date(2016, 11, 14)
        t2 = Date(2016, 11, 14, 0, 0, 36, scale='TAI')
        assert t1 == t2
        assert t1 >= t2
        assert t1 <= t2
예제 #18
0
def test_range():

    start = Date(2016, 11, 16, 22, 38)
    stop = timedelta(hours=1)
    step = timedelta(seconds=30)

    # classic range
    l1 = list(Date.range(start, stop, step))
    assert len(l1) == stop // step

    # Inclusive range
    l2 = list(Date.range(start, stop, step, inclusive=True))
    assert len(l2) == stop // step + 1

    # stop as a Date object
    stop = Date(2016, 11, 16, 22, 40)
    l3 = Date.range(start, stop, step)

    # Inverse order
    start = Date(2016, 11, 16, 22, 40)
    stop = - timedelta(minutes=2)
    step = - timedelta(seconds=30)

    l4 = list(Date.range(start, stop, step))
    assert len(l4) == stop // step

    # Error when the date range (start/stop) is not coherent with the step
    with raises(ValueError):
        list(Date.range(start, stop, -step))

    # Error when the step is null.
    with raises(ValueError):
        list(Date.range(start, stop, timedelta(0)))
예제 #19
0
def test_read(tle_txt):

    tle = Tle(tle_txt)

    assert tle.name == "ISS (ZARYA)"
    assert tle.norad_id == 25544
    assert tle.cospar_id == "1998-067A"
    assert tle.epoch == Date(2008, 9, 20, 12, 25, 40, 104192)
    assert tle.ndot == -2.182e-5 * 2
    assert tle.ndotdot == 0.
    assert tle.bstar == -0.11606e-4
    assert tle.i == np.deg2rad(51.6416)
    assert tle.Ω == np.deg2rad(247.4627)
    assert tle.e == 6.703e-4
    assert tle.ω == np.deg2rad(130.5360)
    assert tle.M == np.deg2rad(325.0288)
    assert tle.n == 15.72125391 * 2 * np.pi / 86400.

    tle = Tle(tle_txt.splitlines()[1:])

    assert tle.name == ""

    with raises(TleParseError):
        ref2 = tle_txt[:-1] + "8"
        Tle(ref2)

    orbs = list(Tle.from_string("# comment\n" + tle_txt))
    assert len(orbs) == 1
    assert (orbs[0].orbit() == tle.orbit()).all()

    tle3 = Tle("Name\n" + "\n".join(tle_txt.splitlines()[1:]))
    assert (tle3.orbit() == tle.orbit()).all()

    with raises(TleParseError) as eee:
        l = tle_txt.splitlines()
        l[1] = "3" + l[1][1:]
        Tle("\n".join(l))

    assert str(eee.value) == "Line number check failed"
예제 #20
0
def test_daterange():

    start = Date(2016, 11, 16, 22, 38)
    stop = timedelta(hours=1)
    step = timedelta(seconds=30)

    # classic range
    l1 = list(Date.range(start, stop, step))
    assert len(l1) == stop // step

    # Inclusive range
    l2 = list(Date.range(start, stop, step, inclusive=True))
    assert len(l2) == stop // step + 1

    r = Date.range(start, stop, step)
    rlist = list(r)
    assert isinstance(r, DateRange)
    assert rlist[0] == r.start
    assert rlist[-1] == r.stop - r.step

    r = Date.range(start, stop, step, inclusive=True)
    rlist = list(r)
    assert isinstance(r, DateRange)
    assert rlist[0] == r.start
    assert rlist[-1] == r.stop

    # Addition of ranges
    # r1 = Date.range(start, stop, step)
    # r2 = Date.range(start + stop, stop, step * 2)

    # r = r1 + r2
    # assert isinstance(r, DateRange)
    # assert r.start == start
    # assert r.stop == start + 2*stop
    # assert r.steps == {step, step*2}

    # l = list(r)
    # assert len(l) == stop // step + stop // (step * 2)

    # stop as a Date object
    stop = Date(2016, 11, 16, 22, 40)
    l3 = Date.range(start, stop, step)

    # Inverse order
    start = Date(2016, 11, 16, 22, 40)
    stop = -timedelta(minutes=2)
    step = -timedelta(seconds=30)

    l4 = list(Date.range(start, stop, step))
    assert len(l4) == stop // step

    # Error when the date range (start/stop) is not coherent with the step
    with raises(ValueError):
        list(Date.range(start, stop, -step))

    # Error when the step is null.
    with raises(ValueError):
        list(Date.range(start, stop, timedelta(0)))
예제 #21
0
def test_creation():

    t = Date(2015, 12, 5)
    assert t.d == 57361
    assert t.s == 0

    t = Date(2015, 12, 5, 12)
    assert t.d == 57361
    assert t.s == 43200

    assert str(t) == "2015-12-05T12:00:00 UTC"
    # to trigger the cache mechanism
    assert str(t) == "2015-12-05T12:00:00 UTC"

    # Datetime object
    t = Date(datetime(2015, 12, 6, 12, 20))
    assert t.d == 57362
    assert t.s == 44400

    # Timezone handling (this is supposend to be the same time as the one just above)
    tz = timezone(timedelta(hours=2))
    t = Date(datetime(2015, 12, 6, 14, 20, tzinfo=tz))
    assert t.d == 57362
    assert t.s == 44400

    # Date object
    t2 = Date(t)
    assert t2.d == t.d
    assert t2.s == t.s

    # Julian day
    t = Date(57388, 0)
    assert t.d == 57388
    assert t.s == 0
    assert t.datetime == datetime(2016, 1, 1)

    t = Date(57388)
    assert t.d == 57388
    assert t.s == 0.

    t = Date(57388.5)
    assert t.d == 57388
    assert t.s == 43200

    # Wrong number of arguments
    with raises(TypeError):
        t = Date((2015, 12, 6))

    with raises(TypeError):
        t = Date(2015, 12, 6, 16, 52, 37, 2156, 'utc')

    # Scale
    t = Date(2015, 12, 6, 16, 52, 37, 2156, scale='TAI')

    # Unknown scale
    with raises(UnknownScaleError):
        t = Date(2015, 12, 6, 16, 52, 37, 2156, scale='unknown')

    t = Date.now()
    assert t.d > 57373

    with raises(TypeError):
        t.d = 5
        t.s = 32.
예제 #22
0
def test_creation():

    t = Date(2015, 12, 5)
    assert t.d == 57361
    assert t.s == 0

    t = Date(2015, 12, 5, 12)
    assert t.d == 57361
    assert t.s == 43200

    assert str(t) == "2015-12-05T12:00:00 UTC"
    # to trigger the cache mechanism
    assert str(t) == "2015-12-05T12:00:00 UTC"

    # Datetime object
    t = Date(datetime(2015, 12, 6, 12, 20))
    assert t.d == 57362
    assert t.s == 44400

    # Timezone handling (this is supposend to be the same time as the one just above)
    tz = timezone(timedelta(hours=2))
    t = Date(datetime(2015, 12, 6, 14, 20, tzinfo=tz))
    assert t.d == 57362
    assert t.s == 44400

    # Date object
    t2 = Date(t)
    assert t2.d == t.d
    assert t2.s == t.s

    # Julian day
    t = Date(57388, 0)
    assert t.d == 57388
    assert t.s == 0
    assert t.datetime == datetime(2016, 1, 1)

    t = Date(57388)
    assert t.d == 57388
    assert t.s == 0.

    t = Date(57388.5)
    assert t.d == 57388
    assert t.s == 43200

    # Wrong number of arguments
    with raises(TypeError):
        t = Date((2015, 12, 6))

    with raises(TypeError):
        t = Date(2015, 12, 6, 16, 52, 37, 2156, 'utc')

    # Scale
    t = Date(2015, 12, 6, 16, 52, 37, 2156, scale='TAI')

    # Unknown scale
    with raises(UnknownScaleError):
        t = Date(2015, 12, 6, 16, 52, 37, 2156, scale='unknown')

    t = Date.now()
    assert t.d > 57373

    with raises(TypeError):
        t.d = 5
        t.s = 32.
예제 #23
0
def date(model_correction):
    return Date(2004, 4, 6, 7, 51, 28, 386009)
예제 #24
0
def ref_date():
    return Date(2015, 9, 21, 12)