Enable computation of the expiration date of the BSP file(s)
This commit is contained in:
parent
dc8ed7ec1e
commit
8c63fefd4f
|
@ -2,3 +2,4 @@ dist/
|
|||
build/
|
||||
*.egg-info/
|
||||
__pycache__/
|
||||
venv/
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
5
Makefile
5
Makefile
|
@ -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]
|
||||
|
|
22
README.md
22
README.md
|
@ -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
|
||||
|
|
40
download.py
40
download.py
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue