Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions skyfield/sgp4lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ def __init__(self, line1, line2, name=None, ts=None):
else:
year = two_digit_year + 1900

self.epoch = ts.utc(year, 1, satrec.epochdays)
whole_days = int(satrec.epochdays)
seconds = (satrec.epochdays - whole_days) * DAY_S
self.epoch = ts.utc(year, 1, whole_days, 0, 0, seconds)

self._setup(satrec)

Expand Down Expand Up @@ -131,8 +133,8 @@ def from_satrec(cls, satrec, ts):
# be unified to always use epochyr and epochdays.
whole, fraction = divmod(satrec.jdsatepoch, 1.0)
year, month, day = compute_calendar_date(whole)
day += 0.5 # convert integer Julian day into Julian date float
self.epoch = ts.utc(year, month, day + fraction + satrec.jdsatepochF)
seconds = (0.5 + fraction + satrec.jdsatepochF) * DAY_S
self.epoch = ts.utc(year, month, day, 0, 0, seconds)

self._setup(satrec)
return self
Expand Down
17 changes: 17 additions & 0 deletions skyfield/tests/test_earth_satellites.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,20 @@ def _at(self, t):
True, True, True, False,
True, True, True, False, # Last two fake sats can see each other.
]

def test_tle_epoch_matches_sgp4_library():
from numpy import asarray
from sgp4.api import Satrec
from skyfield.constants import DAY_S
line1 = '1 55910U 23035C 23076.01808579 -.00000195 00000-0 00000+0 0 9994'
line2 = '2 55910 44.0037 312.8770 0004210 247.2472 260.1626 14.90311335 06'
ts = api.load.timescale(builtin=True)
satrec = Satrec.twoline2rv(line1, line2)
sat = EarthSatellite(line1, line2, ts=ts)
fraction = sat.epoch.tai_fraction - sat.epoch._leap_seconds() / DAY_S
offset_s = ((sat.epoch.whole - satrec.jdsatepoch)
+ (fraction - satrec.jdsatepochF)) * DAY_S
assert abs(offset_s) < 1e-9
_, r_library, _ = satrec.sgp4(satrec.jdsatepoch, satrec.jdsatepochF)
r_epoch, _, _ = sat._position_and_velocity_TEME_km(sat.epoch)
assert abs(asarray(r_epoch) - r_library).max() < 1e-12
Loading