skyfielders / python-skyfield

Elegant astronomy for Python
MIT License
1.43k stars 213 forks source link

Leap Second Data Expired #96

Closed ysiahpoosh closed 8 years ago

ysiahpoosh commented 8 years ago

I've been using skyfield to work on a program to track satellites. However, now whenever I run my program it keeps loading a file called "Leap_Second.dat". This file has the leap seconds data for time calculations, but it says that it expires on June 30, 2016. Is there a way to fix this?

brandon-rhodes commented 8 years ago

It looks like the official, international source of leap second data is indeed expired!

Well, drat. I had not anticipated the international data source going out of date.

  1. I wonder if this is an exception, or if they often fail to keep the file from expiring?
  2. I wonder if there is another data file we could rely on that is less likely to go out of date?
  3. If this is a recurrent problem, I wonder if Skyfield should be a bit lax with the expiration — like, maybe not considering the file out of date until a month after the expiration or something?
davidmikolas commented 8 years ago

Did something change? I didn't see any error when I ran a small script in an empty folder (see below). If I run it again, it seems to load leap second again, and add more old files. I've never seen that happen before, however.

I'm using v0.8 with IDLE.

Personally, the behavior I'd expect would be to raise some exception or warning about an expiration, but keep going. But I can't anticipate all the potential implications, especially for embedded scripts out in the field somewhere someday.

image

image

import numpy as np
import matplotlib.pyplot as plt
from skyfield.api import load

pi, halfpi = np.pi, 0.5*np.pi

data = load('de421.bsp')

earth = data['earth']
moon  = data['moon']
sun   = data['sun']

# Timescale
ts   = load.timescale()
days = np.arange(366.)
t    = ts.utc(2016, 1, days)

# Positions
ep = earth.at(t).ecliptic_position().km
mp = moon.at(t).ecliptic_position().km
sp = sun.at(t).ecliptic_position().km

plt.figure()
for io, ob in enumerate([ep, mp, sp]):
    for i, q in enumerate(ob):
        plt.subplot(3, 3, 3*io + i + 1)
        plt.plot(q)
plt.show()
brandon-rhodes commented 8 years ago

I will try to release soon — meanwhile, check the diff just above this comment for a workaround that's working for me!

brandon-rhodes commented 8 years ago

I note that the leap second data file is now up to date again — and they have declared a new leap second!

https://hpiers.obspm.fr/iers/bul/bulc/Leap_Second.dat

#  Value of TAI-UTC in second valid beetween the initial value until
#  the epoch given on the next line. The last line reads that NO
#  leap second was introduced since the corresponding date 
#  Updated through IERS Bulletin C52 issued in July 2016
#  
#
#  File expires on 28 June  2017
#
#
#    MJD        Date        TAI-UTC (s)
#           day month year
#    ---    --------------   ------   
#
    41317.0    1  1 1972       10
    41499.0    1  7 1972       11
    ...
    56109.0    1  7 2012       35
    57204.0    1  7 2015       36
    57754.0    1  1 2017       37

So it looks like a 30-day grace period is more than enough to cover a brief delay in the publication of a new file once the old one goes out of date, while hopefully not threatening seriously the accuracy of future predictions people are making with Skyfield — so I am inclined to leave the grace period at 30 days until we learn more. Feel free to comment here in future months or years if new problems with the file's expiration date crop up, and thanks for reporting the issue!