Beispiel #1
0
    def test_update_leap_seconds(self):
        assert erfa.dat(2018, 1, 1, 0.) == 37.0
        leap_seconds = erfa.leap_seconds.get()
        # Get old and new leap seconds
        old_leap_seconds = leap_seconds[leap_seconds['year'] < 2017]
        new_leap_seconds = leap_seconds[leap_seconds['year'] >= 2017]
        # Updating with either of these should do nothing.
        n_update = erfa.leap_seconds.update(new_leap_seconds)
        assert n_update == 0
        assert_array_equal(erfa.leap_seconds.get(), self.erfa_ls)
        n_update = erfa.leap_seconds.update(old_leap_seconds)
        assert n_update == 0
        assert_array_equal(erfa.leap_seconds.get(), self.erfa_ls)

        # But after setting to older part, update with newer should work.
        erfa.leap_seconds.set(old_leap_seconds)
        # Check the 2017 leap second is indeed missing.
        assert erfa.dat(2018, 1, 1, 0.) == 36.0
        # Update with missing leap seconds.
        n_update = erfa.leap_seconds.update(new_leap_seconds)
        assert n_update == len(new_leap_seconds)
        assert erfa.dat(2018, 1, 1, 0.) == 37.0

        # Also a final try with overlapping data.
        erfa.leap_seconds.set(old_leap_seconds)
        n_update = erfa.leap_seconds.update(leap_seconds)
        assert n_update == len(new_leap_seconds)
        assert erfa.dat(2018, 1, 1, 0.) == 37.0
Beispiel #2
0
def test_errwarn_reporting():
    """
    Test that the ERFA error reporting mechanism works as it should
    """

    # no warning
    erfa.dat(1990, 1, 1, 0.5)

    # check warning is raised for a scalar
    with catch_warnings() as w:
        erfa.dat(100, 1, 1, 0.5)
        assert len(w) == 1
        assert w[0].category == erfa.ErfaWarning
        assert '1 of "dubious year (Note 1)"' in str(w[0].message)

    # and that the count is right for a vector.
    with catch_warnings() as w:
        erfa.dat([100, 200, 1990], 1, 1, 0.5)
        assert len(w) == 1
        assert w[0].category == erfa.ErfaWarning
        assert '2 of "dubious year (Note 1)"' in str(w[0].message)

    try:
        erfa.dat(1990, [1, 34, 2], [1, 1, 43], 0.5)
    except erfa.ErfaError as e:
        if '1 of "bad day (Note 3)", 1 of "bad month"' not in e.args[0]:
            assert False, 'Raised the correct type of error, but wrong message: ' + e.args[
                0]

    try:
        erfa.dat(200, [1, 34, 2], [1, 1, 43], 0.5)
    except erfa.ErfaError as e:
        if 'warning' in e.args[0]:
            assert False, ('Raised the correct type of error, but there were '
                           'warnings mixed in: ' + e.args[0])
Beispiel #3
0
 def test_set_leap_seconds(self):
     assert erfa.dat(2018, 1, 1, 0.) == 37.0
     leap_seconds = erfa.leap_seconds.get()
     # Set to a table that misses the 2017 leap second.
     part_leap_seconds = leap_seconds[leap_seconds['year'] < 2017]
     erfa.leap_seconds.set(part_leap_seconds)
     new_leap_seconds = erfa.leap_seconds.get()
     assert_array_equal(new_leap_seconds, part_leap_seconds)
     # Check the 2017 leap second is indeed missing.
     assert erfa.dat(2018, 1, 1, 0.) == 36.0
     # And that this would be expected from the expiration date.
     assert erfa.leap_seconds.expires < datetime(2018, 1, 1)
     assert erfa.leap_seconds.expired
     # Reset and check it is back.
     erfa.leap_seconds.set()
     assert erfa.dat(2018, 1, 1, 0.) == 37.0
    def test_auto_update_leap_seconds(self):
        # Sanity check.
        assert erfa.dat(2018, 1, 1, 0.) == 37.0
        # Set expired leap seconds
        expired = self.erfa_ls[self.erfa_ls['year'] < 2017]
        expired.update_erfa_leap_seconds(initialize_erfa='empty')
        # Check the 2017 leap second is indeed missing.
        assert erfa.dat(2018, 1, 1, 0.) == 36.0

        # Update with missing leap seconds.
        n_update = update_leap_seconds([iers.IERS_LEAP_SECOND_FILE])
        assert n_update >= 1
        assert erfa.leap_seconds.expires == self.built_in.expires
        assert erfa.dat(2018, 1, 1, 0.) == 37.0

        # Doing it again does not change anything
        n_update2 = update_leap_seconds([iers.IERS_LEAP_SECOND_FILE])
        assert n_update2 == 0
        assert erfa.dat(2018, 1, 1, 0.) == 37.0
Beispiel #5
0
DDP80 = -55.0655 * AS2R / 1000.
DDE80 = -6.3580 * AS2R / 1000.

# CIP offsets wrt IAU 2000A (mas->radians)
DX00 = 0.1725 * AS2R / 1000.
DY00 = -0.2650 * AS2R / 1000.

# CIP offsets wrt IAU 2006/2000A (mas->radians)
DX06 = 0.1750 * AS2R / 1000.
DY06 = -0.2259 * AS2R / 1000.

# TT (MJD)
DJMJD0, DATE = erfa.cal2jd(IY, IM, ID)
TIME = (60 * (60 * IH + MIN) + SEC) / 86400.
UTC = DATE + TIME
DAT = erfa.dat(IY, IM, ID, TIME)
TAI = UTC + DAT / 86400.
TT = TAI + 32.184 / 86400.

# UT1
TUT = TIME + DUT1 / 86400.
UT1 = DATE + TUT

print("UTC :%4d/%2.2d/%2.2d%3d:%2.2d:%2.2d.%3.3d" %
      erfa.d2dtf(3, *erfa.dtf2d(IY, IM, ID, IH, MIN, SEC)))
print("TT  = 2400000.5 + %.17f " % TT)
print("UT1 = 2400000.5 + %.17f " % UT1)

print('''
======================================
IAU 1976/1980/1982/1994, equinox based
Beispiel #6
0
 def test_validation(self, table, match):
     with pytest.raises(ValueError, match=match):
         erfa.leap_seconds.set(table)
     # Check leap-second table is not corrupted.
     assert_array_equal(erfa.leap_seconds.get(), self.erfa_ls)
     assert erfa.dat(2018, 1, 1, 0.) == 37.0
Beispiel #7
0
DDP80 = -55.0655 * AS2R/1000.
DDE80 = -6.3580 * AS2R/1000.

# CIP offsets wrt IAU 2000A (mas->radians)
DX00 = 0.1725 * AS2R/1000.
DY00 = -0.2650 * AS2R/1000.

# CIP offsets wrt IAU 2006/2000A (mas->radians)
DX06 = 0.1750 * AS2R/1000.
DY06 = -0.2259 * AS2R/1000.

# TT (MJD)
DJMJD0, DATE = erfa.cal2jd(IY, IM, ID)
TIME = ( 60*(60*IH + MIN) + SEC ) / 86400.
UTC = DATE + TIME
DAT = erfa.dat(IY, IM, ID, TIME)
TAI = UTC + DAT/86400.
TT = TAI + 32.184/86400.

# UT1
TUT = TIME + DUT1/86400.
UT1 = DATE + TUT

print("UTC :%4d/%2.2d/%2.2d%3d:%2.2d:%2.2d.%3.3d"%erfa.d2dtf(3, *erfa.dtf2d(IY, IM, ID, IH, MIN, SEC)))
print("TT  = 2400000.5 + %.17f "%TT)
print("UT1 = 2400000.5 + %.17f "%UT1)

print('''
======================================
IAU 1976/1980/1982/1994, equinox based
======================================