Enable computation of the expiration date of the BSP file(s)

This commit is contained in:
Bruno Bord 2019-09-20 16:26:48 +02:00
parent dc8ed7ec1e
commit 8c63fefd4f
No known key found for this signature in database
GPG Key ID: 9499EA6788BF80A1
6 changed files with 65 additions and 9 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ dist/
build/
*.egg-info/
__pycache__/
venv/

View File

@ -3,6 +3,7 @@
## master (unreleased)
* Added a ``--check-only`` argument to ``download.py`` to display the expiration dates of the files currently on disk.
* Enable computation of the expiration date of the BSP file(s) on disk (requires to install the local repository using the [dev] option / See README for more information).
## 0.0.2 (2019-08-23)

View File

@ -5,6 +5,8 @@ help:
@echo " (see \`python download.py --help\` for options)"
@echo " * clean: remove all skyfield data from data directory."
@echo " * package: build python source package."
@echo ""
@echo " * install-dev: Install the requirements to execute download.py"
download:
python3 download.py
@ -14,3 +16,6 @@ clean:
package:
python3 setup.py sdist bdist_wheel
install-dev:
pip install -e .[dev]

View File

@ -11,16 +11,15 @@ Several issues are raised by these data files:
* In some countries, or behind some filtering proxies, the USNO is considered as a military website, and thus is **blocked**.
* These files have **an expiration date** (in a more or less distant future). As a consequence, even if the files are already downloaded in the right path, at each runtime you could possibly have to download one or more files before making any computation using them.
## Currently known expiration dates
### Currently known expiration dates
| File | Date |
|:---------------:|:-------------:|
| deltat.data | 2020-06-01 |
| Leap_Second.dat | 2020-07-28 |
| deltat.preds | 2021-01-01 |
| de421.bsp | *unknown*(\*) |
| File | Date |
|:---------------:|:----------:|
| deltat.data | 2020-06-01 |
| Leap_Second.dat | 2020-07-28 |
| deltat.preds | 2021-01-01 |
| de421.bsp | 2053-10-08 |
(\*) Even though its expiration date has not been extracted through a convenient script, we can state that it should expire in the year 2053.
## Goal for this project
@ -60,8 +59,15 @@ load = Loader(get_skyfield_data_path(), expire=False)
We're providing a ``Makefile`` with basic targets to play around with the toolkit. use ``make help`` to get more details.
In order to be able to run the `download.py` script, we recommend to run it **from a virtualenv** where you'd have installed the "dev" dependencies, using:
```sh
make install-dev
```
*Note:* This project is, and should be compatible with Python 2.6/2.7 and Python 3.3+, to be kept the same Python compatiblity that `skyfield` has.
## Copyright
### Data files

View File

@ -5,6 +5,7 @@ from datetime import datetime, timedelta
from os.path import join, exists
import shutil
from urllib.request import urlopen
from jplephem.spk import DAF, SPK
from skyfield_data import get_skyfield_data_path
@ -13,6 +14,37 @@ USNO = "http://maia.usno.navy.mil/ser7"
IERS = "https://hpiers.obspm.fr/iers/bul/bulc"
def calendar_date(jd_integer):
"""Convert Julian Day `jd_integer` into a Gregorian (year, month, day)."""
k = jd_integer + 68569
n = 4 * k // 146097
k = k - (146097 * n + 3) // 4
m = 4000 * (k + 1) // 1461001
k = k - 1461 * m // 4 + 31
month = 80 * k // 2447
day = k - 2447 * month // 80
k = month // 11
month = month + 2 - 12 * k
year = 100 * (n - 49) + m + k
return date(int(year), int(month), int(day))
def bsp_expiration(fileobj):
"""
Return the expiration date for a .bsp file.
"""
daf_object = DAF(fileobj)
spk_object = SPK(daf_object)
dates = [segment.end_jd for segment in spk_object.segments]
# We take the closest end date, to expire the file as soon as it's obsolete
end_jd = min(dates)
return calendar_date(end_jd)
def deltat_data_expiration(fileobj):
"""Return the expiration date for the USNO ``deltat.data`` file.
@ -100,6 +132,9 @@ def download(url, target):
def get_expiration_date(target, params):
"""
Return expiration date for the given ``target``.
"""
expiration_date = None
if exists(target):
expiration_func = params.get("expiration_func")
@ -136,7 +171,10 @@ def check_should_i_download(target, params):
def main(args):
items = {
"de421.bsp": {"server": JPL},
"de421.bsp": {
"server": JPL,
"expiration_func": bsp_expiration,
},
"deltat.data": {
"server": USNO,
"expiration_func": deltat_data_expiration

View File

@ -32,5 +32,10 @@ packages = skyfield_data
setup_requires =
setuptools
[options.extras_require]
dev =
jplephem
numpy
[bdist_wheel]
universal = 1