コード例 #1
0
def test_iso_of_decimal_that_rounds_down():
    jd = JulianDate(utc=(2014, 12, 21, 6, 3, 1.234234))
    assert jd.utc_iso(places=0) == "2014-12-21T06:03:01Z"
    assert jd.utc_iso(places=1) == "2014-12-21T06:03:01.2Z"
    assert jd.utc_iso(places=2) == "2014-12-21T06:03:01.23Z"
    assert jd.utc_iso(places=3) == "2014-12-21T06:03:01.234Z"
    assert jd.utc_iso(places=4) == "2014-12-21T06:03:01.2342Z"
コード例 #2
0
def test_iso_of_leap_second_with_fraction():
    jd = JulianDate(utc=(1973, 12, 31, 23, 59, 60.12349))
    assert jd.utc_iso(places=0) == "1973-12-31T23:59:60Z"
    assert jd.utc_iso(places=1) == "1973-12-31T23:59:60.1Z"
    assert jd.utc_iso(places=2) == "1973-12-31T23:59:60.12Z"
    assert jd.utc_iso(places=3) == "1973-12-31T23:59:60.123Z"
    assert jd.utc_iso(places=4) == "1973-12-31T23:59:60.1235Z"
コード例 #3
0
def test_iso_of_leap_second_with_fraction():
    jd = JulianDate(utc=(1973, 12, 31, 23, 59, 60.12349))
    assert jd.utc_iso(places=0) == '1973-12-31T23:59:60Z'
    assert jd.utc_iso(places=1) == '1973-12-31T23:59:60.1Z'
    assert jd.utc_iso(places=2) == '1973-12-31T23:59:60.12Z'
    assert jd.utc_iso(places=3) == '1973-12-31T23:59:60.123Z'
    assert jd.utc_iso(places=4) == '1973-12-31T23:59:60.1235Z'
コード例 #4
0
def test_iso_of_decimal_that_rounds_down():
    jd = JulianDate(utc=(2014, 12, 21, 6, 3, 1.234234))
    assert jd.utc_iso(places=0) == '2014-12-21T06:03:01Z'
    assert jd.utc_iso(places=1) == '2014-12-21T06:03:01.2Z'
    assert jd.utc_iso(places=2) == '2014-12-21T06:03:01.23Z'
    assert jd.utc_iso(places=3) == '2014-12-21T06:03:01.234Z'
    assert jd.utc_iso(places=4) == '2014-12-21T06:03:01.2342Z'
コード例 #5
0
def test_iso_of_decimal_that_rounds_up():
    jd = JulianDate(utc=(1915, 12, 2, 3, 4, 5.6786786))
    assert jd.utc_iso(places=0) == '1915-12-02T03:04:06Z'
    assert jd.utc_iso(places=1) == '1915-12-02T03:04:05.7Z'
    assert jd.utc_iso(places=2) == '1915-12-02T03:04:05.68Z'
    assert jd.utc_iso(places=3) == '1915-12-02T03:04:05.679Z'
    assert jd.utc_iso(places=4) == '1915-12-02T03:04:05.6787Z'
コード例 #6
0
def test_iso_of_decimal_that_rounds_up():
    jd = JulianDate(utc=(1915, 12, 2, 3, 4, 5.6786786))
    assert jd.utc_iso(places=0) == "1915-12-02T03:04:06Z"
    assert jd.utc_iso(places=1) == "1915-12-02T03:04:05.7Z"
    assert jd.utc_iso(places=2) == "1915-12-02T03:04:05.68Z"
    assert jd.utc_iso(places=3) == "1915-12-02T03:04:05.679Z"
    assert jd.utc_iso(places=4) == "1915-12-02T03:04:05.6787Z"
コード例 #7
0
def test_stftime_of_date_array():
    jd = JulianDate(utc=(1973, 12, 31, 23, 59, np.arange(59.0, 61.1, 1.0)))
    assert jd.utc_strftime('%Y %m %d %H %M %S') == [
        '1973 12 31 23 59 59',
        '1973 12 31 23 59 60',
        '1974 01 01 00 00 00',
    ]
コード例 #8
0
def test_stftime_of_date_array():
    jd = JulianDate(utc=(1973, 12, 31, 23, 59, np.arange(59.0, 61.1, 1.0)))
    assert jd.utc_strftime('%Y %m %d %H %M %S') == [
        '1973 12 31 23 59 59',
        '1973 12 31 23 59 60',
        '1974 01 01 00 00 00',
        ]
コード例 #9
0
def test_jpl_format():
    jd = JulianDate(utc=(range(-300, 301, 100), 7, 1))
    assert jd.utc_jpl() == [
        "B.C. 0301-Jul-01 00:00:00.0000 UT",
        "B.C. 0201-Jul-01 00:00:00.0000 UT",
        "B.C. 0101-Jul-01 00:00:00.0000 UT",
        "B.C. 0001-Jul-01 00:00:00.0000 UT",
        "A.D. 0100-Jul-01 00:00:00.0000 UT",
        "A.D. 0200-Jul-01 00:00:00.0000 UT",
        "A.D. 0300-Jul-01 00:00:00.0000 UT",
    ]
コード例 #10
0
def test_jpl_format():
    jd = JulianDate(utc=(range(-300, 301, 100), 7, 1))
    assert jd.utc_jpl() == [
        'B.C. 0301-Jul-01 00:00:00.0000 UT',
        'B.C. 0201-Jul-01 00:00:00.0000 UT',
        'B.C. 0101-Jul-01 00:00:00.0000 UT',
        'B.C. 0001-Jul-01 00:00:00.0000 UT',
        'A.D. 0100-Jul-01 00:00:00.0000 UT',
        'A.D. 0200-Jul-01 00:00:00.0000 UT',
        'A.D. 0300-Jul-01 00:00:00.0000 UT',
    ]
コード例 #11
0
def test_iso_of_array_showing_whole_seconds():
    jd = JulianDate(utc=(1973, 12, 31, 23, 59, np.arange(58.75, 63.1, 0.5)))
    assert jd.utc_iso(places=0) == [
        '1973-12-31T23:59:59Z',
        '1973-12-31T23:59:59Z',
        '1973-12-31T23:59:60Z',
        '1973-12-31T23:59:60Z',
        '1974-01-01T00:00:00Z',
        '1974-01-01T00:00:00Z',
        '1974-01-01T00:00:01Z',
        '1974-01-01T00:00:01Z',
        '1974-01-01T00:00:02Z',
    ]
コード例 #12
0
def test_iso_of_array_showing_fractions():
    jd = JulianDate(utc=(1973, 12, 31, 23, 59, np.arange(58.75, 63.1, 0.5)))
    assert jd.utc_iso(places=2) == [
        '1973-12-31T23:59:58.75Z',
        '1973-12-31T23:59:59.25Z',
        '1973-12-31T23:59:59.75Z',
        '1973-12-31T23:59:60.25Z',
        '1973-12-31T23:59:60.75Z',
        '1974-01-01T00:00:00.25Z',
        '1974-01-01T00:00:00.75Z',
        '1974-01-01T00:00:01.25Z',
        '1974-01-01T00:00:01.75Z',
    ]
コード例 #13
0
def test_iso_of_array_showing_whole_seconds():
    jd = JulianDate(utc=(1973, 12, 31, 23, 59, np.arange(58.75, 63.1, 0.5)))
    assert jd.utc_iso(places=0) == [
        "1973-12-31T23:59:59Z",
        "1973-12-31T23:59:59Z",
        "1973-12-31T23:59:60Z",
        "1973-12-31T23:59:60Z",
        "1974-01-01T00:00:00Z",
        "1974-01-01T00:00:00Z",
        "1974-01-01T00:00:01Z",
        "1974-01-01T00:00:01Z",
        "1974-01-01T00:00:02Z",
    ]
コード例 #14
0
ファイル: views.py プロジェクト: triffids/SkyCalc
def Calculate(earth,planet,stri,lat,long):
    #boston = earth.topos('50.833639 N', '4.018829 E')
    boston = earth.topos(lat+' N', long+' E')
    startDate = datetime.datetime( 2015, 11, 1,22,00,00,0, pytz.UTC )
    endDate = datetime.datetime( 2016, 4, 1,22,00,00,0, pytz.UTC )
    dayDelta = datetime.timedelta( days=1 )
    momentList = []
    while startDate < endDate:
        startDate += dayDelta
        date =  JulianDate(startDate)
        position = boston.at(date).observe(planet)
        momentList.append(Print(position,stri,date.utc_datetime()))
    return momentList
コード例 #15
0
def test_iso_of_array_showing_fractions():
    jd = JulianDate(utc=(1973, 12, 31, 23, 59, np.arange(58.75, 63.1, 0.5)))
    assert jd.utc_iso(places=2) == [
        "1973-12-31T23:59:58.75Z",
        "1973-12-31T23:59:59.25Z",
        "1973-12-31T23:59:59.75Z",
        "1973-12-31T23:59:60.25Z",
        "1973-12-31T23:59:60.75Z",
        "1974-01-01T00:00:00.25Z",
        "1974-01-01T00:00:00.75Z",
        "1974-01-01T00:00:01.25Z",
        "1974-01-01T00:00:01.75Z",
    ]
コード例 #16
0
def test_indexing_julian_date():
    jd = JulianDate(utc=(1974, 10, range(1, 6)))
    assert jd.shape == (5, )
    jd0 = jd[0]
    assert jd.tai[0] == jd0.tai
    assert jd.tt[0] == jd0.tt
    assert jd.tdb[0] == jd0.tdb
    assert jd.ut1[0] == jd0.ut1
    assert jd.delta_t == jd0.delta_t
コード例 #17
0
def test_slicing_julian_date():
    jd = JulianDate(utc=(1974, 10, range(1, 6)))
    assert jd.shape == (5, )
    jd24 = jd[2:4]
    assert jd24.shape == (2, )
    assert (jd.tai[2:4] == jd24.tai).all()
    assert (jd.tt[2:4] == jd24.tt).all()
    assert (jd.tdb[2:4] == jd24.tdb).all()
    assert (jd.ut1[2:4] == jd24.ut1).all()
    assert jd.delta_t == jd24.delta_t
コード例 #18
0
def test_appendix_c_satellite():
    lines = appendix_c_example.splitlines()
    sat = EarthSatellite(lines, earth)

    jd_epoch = sat._sgp4_satellite.jdsatepoch
    three_days_later = jd_epoch + 3.0
    jd = JulianDate(tt=three_days_later)
    jd.ut1 = array(three_days_later)

    # First, a crucial sanity check (which is, technically, a test of
    # the `sgp4` package and not of Skyfield): are the right coordinates
    # being produced by our Python SGP4 propagator for this satellite?

    rTEME, vTEME = sat._position_and_velocity_TEME_km(jd)

    assert abs(-9060.47373569 - rTEME[0]) < 1e-8
    assert abs(4658.70952502 - rTEME[1]) < 1e-8
    assert abs(813.68673153 - rTEME[2]) < 1e-8

    assert abs(-2.232832783 - vTEME[0]) < 1e-9
    assert abs(-4.110453490 - vTEME[1]) < 1e-9
    assert abs(-3.157345433 - vTEME[2]) < 1e-9
コード例 #19
0
def test_appendix_c_satellite():
    lines = appendix_c_example.splitlines()
    sat = EarthSatellite(lines, earth)

    jd_epoch = sat._sgp4_satellite.jdsatepoch
    three_days_later = jd_epoch + 3.0
    offset = JulianDate(tt=three_days_later)._utc_float() - three_days_later
    jd = JulianDate(tt=three_days_later - offset)

    # First, a crucial sanity check (which is, technically, a test of
    # the `sgp4` package and not of Skyfield): are the right coordinates
    # being produced by our Python SGP4 propagator for this satellite?

    rTEME, vTEME, error = sat._position_and_velocity_TEME_km(jd)

    assert abs(-9060.47373569 - rTEME[0]) < 1e-8
    assert abs(4658.70952502 - rTEME[1]) < 1e-8
    assert abs(813.68673153 - rTEME[2]) < 1e-8

    assert abs(-2.232832783 - vTEME[0]) < 1e-9
    assert abs(-4.110453490 - vTEME[1]) < 1e-9
    assert abs(-3.157345433 - vTEME[2]) < 1e-9
コード例 #20
0
def test_iss_altitude_computed_with_gcrs(iss_transit):
    dt, their_altitude = iss_transit

    cst = timedelta(hours=-6)  #, minutes=1)
    dt = dt - cst
    jd = JulianDate(utc=dt, delta_t=67.2091)

    lines = iss_tle.splitlines()
    s = EarthSatellite(lines, earth)
    lake_zurich = earth.topos(latitude_degrees=42.2, longitude_degrees=-88.1)

    alt, az, d = lake_zurich.gcrs(jd).observe(s).altaz()
    print(dt, their_altitude, alt.degrees, their_altitude - alt.degrees)
    assert abs(alt.degrees - their_altitude) < 2.5  # TODO: tighten this up?
コード例 #21
0
def test_building_JulianDate_from_list_of_utc_datetimes():
    jd = JulianDate(utc=[
        datetime(1973, 12, 29, 23, 59, 48, tzinfo=utc),
        datetime(1973, 12, 30, 23, 59, 48, tzinfo=utc),
        datetime(1973, 12, 31, 23, 59, 48, tzinfo=utc),
        datetime(1974, 1, 1, 23, 59, 47, tzinfo=utc),
        datetime(1974, 1, 2, 23, 59, 47, tzinfo=utc),
        datetime(1974, 1, 3, 23, 59, 47, tzinfo=utc),
    ])
    assert (jd.tai == [
        2442046.5,
        2442047.5,
        2442048.5,
        2442049.5,
        2442050.5,
        2442051.5,
    ]).all()
コード例 #22
0
def test_appendix_c_conversion_from_TEME_to_ITRF():
    rTEME = array([5094.18016210, 6127.64465950, 6380.34453270])
    vTEME = array([-4.746131487, 0.785818041, 5.531931288])
    vTEME = vTEME * 24.0 * 60.0 * 60.0  # km/s to km/day

    jd_ut1 = JulianDate(tt=(2004, 4, 6, 7, 51, 28.386 - 0.439961)).tt

    xp = -0.140682 * arcsecond
    yp = 0.333309 * arcsecond

    rITRF, vITRF = TEME_to_ITRF(jd_ut1, rTEME, vTEME, xp, yp)

    meter = 1e-3

    assert abs(-1033.47938300 - rITRF[0]) < 0.1 * meter
    assert abs(+7901.29527540 - rITRF[1]) < 0.1 * meter
    assert abs(+6380.35659580 - rITRF[2]) < 0.1 * meter

    vITRF_per_second = vITRF * second

    assert abs(-3.225636520 - vITRF_per_second[0]) < 1e-4 * meter
    assert abs(-2.872451450 - vITRF_per_second[1]) < 1e-4 * meter
    assert abs(+5.531924446 - vITRF_per_second[2]) < 1e-4 * meter
コード例 #23
0
ファイル: test_timelib.py プロジェクト: silky/python-skyfield
def test_leap_second(ts):

    # During 1973 the offset between UTC and TAI was 12.0 seconds, so
    # TAI should reach the first moment of 1974 while the UTC clock is
    # still reading 12s before midnight (60 - 12 = 48).  Happily, the
    # fraction 0.5 can be precisely represented in floating point, so we
    # can use a bare `==` in this assert:

    t0 = ts.utc((1973, 12, 31, 23, 59, 48.0)).tai
    assert t0 == 2442048.5

    # Here are some more interesting values:

    t1 = ts.utc((1973, 12, 31, 23, 59, 58.0)).tai
    t2 = ts.utc((1973, 12, 31, 23, 59, 59.0)).tai
    t3 = ts.utc((1973, 12, 31, 23, 59, 60.0)).tai
    t4 = ts.utc((1974, 1, 1, 0, 0, 0.0)).tai
    t5 = ts.utc((1974, 1, 1, 0, 0, 1.0)).tai

    # The step from 23:59:59 to 0:00:00 is here a two-second step,
    # because of the leap second 23:59:60 that falls in between:

    assert abs(t4 - t2 - 2.0 * one_second) < epsilon

    # Thus, the five dates given above are all one second apart:

    assert abs(t2 - t1 - one_second) < epsilon
    assert abs(t3 - t2 - one_second) < epsilon
    assert abs(t4 - t3 - one_second) < epsilon
    assert abs(t5 - t4 - one_second) < epsilon

    # And all these dates can be converted back to UTC.

    assert JulianDate(tai=t0).utc_iso() == '1973-12-31T23:59:48Z'
    assert JulianDate(tai=t1).utc_iso() == '1973-12-31T23:59:58Z'
    assert JulianDate(tai=t2).utc_iso() == '1973-12-31T23:59:59Z'
    assert JulianDate(tai=t3).utc_iso() == '1973-12-31T23:59:60Z'
    assert JulianDate(tai=t4).utc_iso() == '1974-01-01T00:00:00Z'
    assert JulianDate(tai=t5).utc_iso() == '1974-01-01T00:00:01Z'
コード例 #24
0
def test_astimezone():
    jd = JulianDate(utc=(1969, 7, 20, 20, 18))
    tz = timezone("US/Eastern")
    dt = jd.astimezone(tz)
    assert dt == tz.localize(datetime(1969, 7, 20, 16, 18, 0, 0))
コード例 #25
0
def test_early_utc():
    jd = JulianDate(utc=(1915, 12, 2, 3, 4, 5.6786786))
    assert abs(jd.tt - 2420833.6283317441) < epsilon
    assert jd.utc_iso() == "1915-12-02T03:04:06Z"
コード例 #26
0
def test_stftime_of_single_date():
    jd = JulianDate(utc=(1973, 12, 31, 23, 59, 60))
    assert jd.utc_strftime("%Y %m %d %H %M %S") == "1973 12 31 23 59 60"
コード例 #27
0
def test_JulianDate_init(time_parameter, time_value):
    kw = {time_parameter: time_value}
    jd = JulianDate(**kw)
    assert getattr(jd, time_parameter) == 2441700.56640625
コード例 #28
0
def test_stftime_of_single_date():
    jd = JulianDate(utc=(1973, 12, 31, 23, 59, 60))
    assert jd.utc_strftime('%Y %m %d %H %M %S') == '1973 12 31 23 59 60'
コード例 #29
0
def test_building_JulianDate_from_utc_tuple_with_array_inside():
    seconds = np.arange(48.0, 58.0, 1.0)
    jd = JulianDate(utc=(1973, 12, 29, 23, 59, seconds))
    assert seconds.shape == jd.shape
    for i, second in enumerate(seconds):
        assert jd.tai[i] == JulianDate(utc=(1973, 12, 29, 23, 59, second)).tai
コード例 #30
0
def test_building_JulianDate_from_single_utc_datetime():
    jd = JulianDate(utc=datetime(1973, 12, 29, 23, 59, 48, tzinfo=utc))
    assert jd.tai == 2442046.5
コード例 #31
0
def test_utc_datetime_and_leap_second():
    jd = JulianDate(utc=(1969, 7, 20, 20, 18))
    dt, leap_second = jd.utc_datetime_and_leap_second()
    assert dt == datetime(1969, 7, 20, 20, 18, 0, 0, utc)
    assert leap_second == 0
コード例 #32
0
def test_utc_datetime():
    jd = JulianDate(utc=(1969, 7, 20, 20, 18))
    dt = jd.utc_datetime()
    assert dt == datetime(1969, 7, 20, 20, 18, 0, 0, utc)
コード例 #33
0
def test_astimezone_and_leap_second():
    jd = JulianDate(utc=(1969, 7, 20, 20, 18))
    tz = timezone("US/Eastern")
    dt, leap_second = jd.astimezone_and_leap_second(tz)
    assert dt == tz.localize(datetime(1969, 7, 20, 16, 18, 0, 0))
    assert leap_second == 0
コード例 #34
0
def test_early_utc():
    jd = JulianDate(utc=(1915, 12, 2, 3, 4, 5.6786786))
    assert abs(jd.tt - 2420833.6283317441) < epsilon
    assert jd.utc_iso() == '1915-12-02T03:04:06Z'
コード例 #35
0
def test_utc_datetime_and_leap_second():
    jd = JulianDate(utc=(1969, 7, 20, 20, 18))
    dt, leap_second = jd.utc_datetime_and_leap_second()
    assert dt == datetime(1969, 7, 20, 20, 18, 0, 0, utc)
    assert leap_second == 0
コード例 #36
0
def test_building_JulianDate_from_naive_datetime_raises_exception():
    with assert_raises(ValueError) as info:
        JulianDate(utc=datetime(1973, 12, 29, 23, 59, 48))
    assert 'import timezone' in str(info.exception)
コード例 #37
0
def test_astimezone():
    jd = JulianDate(utc=(1969, 7, 20, 20, 18))
    tz = timezone('US/Eastern')
    dt = jd.astimezone(tz)
    assert dt == tz.localize(datetime(1969, 7, 20, 16, 18, 0, 0))
コード例 #38
0
def test_utc_datetime():
    jd = JulianDate(utc=(1969, 7, 20, 20, 18))
    dt = jd.utc_datetime()
    assert dt == datetime(1969, 7, 20, 20, 18, 0, 0, utc)
コード例 #39
0
def test_astimezone_and_leap_second():
    jd = JulianDate(utc=(1969, 7, 20, 20, 18))
    tz = timezone('US/Eastern')
    dt, leap_second = jd.astimezone_and_leap_second(tz)
    assert dt == tz.localize(datetime(1969, 7, 20, 16, 18, 0, 0))
    assert leap_second == 0
コード例 #40
0
ファイル: benchmark.py プロジェクト: silky/python-skyfield

def bm_coordinate_to_apparent(times, t):
    coordinate = star.observe_from(earth(t))
    run_benchmark(times, coordinate.apparent)


def bm_coordinate_horizontal(times, t):
    ggr = earth.topos('75 W', '45 N', elevation_m=0.0)
    run_benchmark(times, ggr(t).observe(jupiter).apparent().horizontal)


BENCHMARKS = (
    BM(times=100, bm_fn=bm_earth_rotation_angle, t=array([T0, TA, TB])),

    BM(times=100, bm_fn=bm_star_observe_from, t=JulianDate(tt=T0)),
    BM(times=100, bm_fn=bm_star_observe_from, t=JulianDate(tt=TA)),
    BM(times=100, bm_fn=bm_star_observe_from, t=JulianDate(tt=TB)),

    BM(times=100, bm_fn=bm_planet_observe_from, t=JulianDate(tt=T0)),
    BM(times=100, bm_fn=bm_planet_observe_from, t=JulianDate(tt=TA)),
    BM(times=100, bm_fn=bm_planet_observe_from, t=JulianDate(tt=TB)),

    BM(times=100, bm_fn=bm_topo_planet_observe, t=JulianDate(tt=T0)),
    BM(times=100, bm_fn=bm_topo_planet_observe, t=JulianDate(tt=TA)),
    BM(times=100, bm_fn=bm_topo_planet_observe, t=JulianDate(tt=TB)),

    BM(times=100, bm_fn=bm_earth_tilt, t=JulianDate(tt=T0)),
    BM(times=100, bm_fn=bm_earth_tilt, t=JulianDate(tt=TA)),
    BM(times=100, bm_fn=bm_earth_tilt, t=JulianDate(tt=TB)),