Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def ut1_jd(self, jd):
"""Build a `Time` from a UT1 Julian date."""
ut1 = _to_array(jd)
# Estimate TT = UT1, to get a rough Delta T estimate.
tt_approx = ut1
delta_t_approx = interpolate_delta_t(self.delta_t_table, tt_approx)
# Use the rough Delta T to make a much better estimate of TT,
# then generate an even better Delta T.
tt_approx = ut1 + delta_t_approx / DAY_S
delta_t_approx = interpolate_delta_t(self.delta_t_table, tt_approx)
# We can now estimate TT with an error of < 1e-9 seconds within
# 10 centuries of either side of the present; for details, see:
# https://github.com/skyfielders/astronomy-notebooks
# and look for the notebook "error-in-timescale-ut1.ipynb".
delta_t_approx /= DAY_S
t = Time(self, ut1, delta_t_approx)
return value is a ``Time`` representing a whole array of times.
"""
# TODO: someday deprecate passing datetime objects here, as
# there are now separate constructors for them.
if isinstance(year, datetime):
return self.from_datetime(year)
if isinstance(year, date):
return self.from_datetime(datetime.combine(year, _time_zero))
if hasattr(year, '__len__') and isinstance(year[0], datetime):
return self.from_datetimes(year)
tai1, tai2 = _utc_to_tai(
self.leap_dates, self.leap_offsets, _to_array(year),
_to_array(month), _to_array(day), _to_array(hour),
_to_array(minute), _to_array(second),
)
t = Time(self, tai1, tai2 + tt_minus_tai)
t.tai_fraction = tai2
return t
"""Build a `Time` from a TDB calendar date.
Supply the Barycentric Dynamical Time (TDB) as a proleptic
Gregorian calendar date:
>>> t = ts.tdb(2014, 1, 18, 1, 35, 37.5)
>>> t.tdb
2456675.56640625
"""
if jd is not None:
tdb = jd
else:
tdb = julian_date(
_to_array(year), _to_array(month), _to_array(day),
_to_array(hour), _to_array(minute), _to_array(second),
)
tdb = _to_array(tdb)
t = Time(self, tdb, - tdb_minus_tt(tdb) / DAY_S)
return t
def tai_jd(self, jd, fraction=0.0):
"""Build a `Time` from a TAI Julian date."""
whole, fraction2 = divmod(_to_array(jd), 1.0)
fraction2 += fraction
t = Time(self, whole, fraction2 + tt_minus_tai)
t.tai_fraction = fraction2
return t
def calendar_tuple(jd_float, fraction=0.0):
"""Return a (year, month, day, hour, minute, second.fraction) tuple."""
jd_float = _to_array(jd_float)
whole1, fraction1 = divmod(jd_float, 1.0)
whole2, fraction = divmod(fraction1 + fraction + 0.5, 1.0)
whole = (whole1 + whole2).astype(int)
year, month, day = calendar_date(whole)
hour, hfrac = divmod(fraction * 24.0, 1.0) # TODO
minute, second = divmod(hfrac * 3600.0, 60.0)
return year, month, day, hour.astype(int), minute.astype(int), second
and second. Any argument may be an array in which case the
return value is a ``Time`` representing a whole array of times.
"""
# TODO: someday deprecate passing datetime objects here, as
# there are now separate constructors for them.
if isinstance(year, datetime):
return self.from_datetime(year)
if isinstance(year, date):
return self.from_datetime(datetime.combine(year, _time_zero))
if hasattr(year, '__len__') and isinstance(year[0], datetime):
return self.from_datetimes(year)
tai1, tai2 = _utc_to_tai(
self.leap_dates, self.leap_offsets, _to_array(year),
_to_array(month), _to_array(day), _to_array(hour),
_to_array(minute), _to_array(second),
)
t = Time(self, tai1, tai2 + tt_minus_tai)
t.tai_fraction = tai2
return t
def interpolate_delta_t(delta_t_table, tt):
"""Return interpolated Delta T values for the times in `tt`.
The 2xN table should provide TT values as element 0 and
corresponding Delta T values for element 1. For times outside the
range of the table, a long-term formula is used instead.
"""
tt_array, delta_t_array = delta_t_table
delta_t = _to_array(interp(tt, tt_array, delta_t_array, nan, nan))
missing = isnan(delta_t)
if missing.any():
# Test if we are dealing with an array and proceed appropriately
if missing.shape:
tt = tt[missing]
delta_t[missing] = delta_t_formula_morrison_and_stephenson_2004(tt)
else:
delta_t = delta_t_formula_morrison_and_stephenson_2004(tt)
return delta_t
def tt_jd(self, jd, fraction=0.0):
"""Build a `Time` from a TT Julian date."""
whole, fraction2 = divmod(_to_array(jd), 1.0)
fraction2 += fraction
return Time(self, whole, fraction2)