Esempio n. 1
0
def interpolate_delta_t(cache, tt):
    """Given TT, return interpolated Delta T, falling back to a formula."""
    def delta_t():  # TODO
        "Fake placeholder function, until I rewrite how the cache works."
    x, y = cache.run(delta_t)
    delta_t = interp(tt, x, y, nan, nan)
    missing = isnan(delta_t)
    if missing.any():
        tt = tt[missing]
        delta_t[missing] = delta_t_formula_morrison_and_stephenson_2004(tt)
    return delta_t
Esempio n. 2
0
    def __init__(self, utc=None, tai=None, tt=None, tdb=None,
                 delta_t=None, cache=None):

        if cache is None:
            from skyfield.data.cachelib import cache
        self.cache = cache

        if tai is None and utc is not None:
            leap_dates, leap_offsets = cache.run(usno_leapseconds)
            if isinstance(utc, datetime):
                tai = _utc_datetime_to_tai(leap_dates, leap_offsets, utc)
            elif isinstance(utc, date):
                tai = _utc_date_to_tai(leap_dates, leap_offsets, utc)
            elif isinstance(utc, tuple):
                values = [_to_array(value) for value in utc]
                tai = _utc_to_tai(leap_dates, leap_offsets, *values)
            else:
                tai = array([
                    _utc_datetime_to_tai(leap_dates, leap_offsets, dt)
                    for dt in utc])

        if tai is not None:
            if isinstance(tai, tuple):
                tai = julian_date(*tai)
            self.tai = _to_array(tai)
            if tt is None:
                tt = tai + tt_minus_tai

        if tdb is not None:
            if isinstance(tdb, tuple):
                tdb = julian_date(*tdb)
            self.tdb = _to_array(tdb)
            if tt is None:
                tt = tdb - tdb_minus_tt(tdb) / DAY_S

        if tt is None:
            raise ValueError('You must supply either utc, tai, tt, or tdb'
                             ' when building a JulianDate')
        elif isinstance(tt, tuple):
            tt = julian_date(*tt)

        self.tt = tt = _to_array(tt)
        self.shape = getattr(tt, 'shape', ())

        if delta_t is not None:
            self.delta_t = _to_array(delta_t)