diff options
| author | Yuval Adam <_@yuv.al> | 2020-09-23 17:54:52 +0300 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2020-09-23 17:54:52 +0300 |
| commit | e9942559847d46face3ee0763c875a625abb4c2a (patch) | |
| tree | 5c7b59175a839c232adaf2531edff3dcc2f47d3c | |
| parent | 081abd6b2362a1ee9da9655428e625b96ad46251 (diff) | |
Implement get_next_days_timescale
| -rw-r--r-- | iss/predictions.py | 44 | ||||
| -rw-r--r-- | iss/tests/test_predictions.py | 11 |
2 files changed, 38 insertions, 17 deletions
diff --git a/iss/predictions.py b/iss/predictions.py index fa4aeff..37e23e6 100644 --- a/iss/predictions.py +++ b/iss/predictions.py @@ -3,21 +3,35 @@ from skyfield.api import Topos, load TEL_AVIV = Topos('32.0853 N', '34.7817 E') ISS = "ISS (ZARYA)" -def init_stations(): - stations_url = 'http://celestrak.com/NORAD/elements/stations.txt' - return load.tle_file(stations_url) -def get_predictions(location=TEL_AVIV, satellite_name=ISS): - satellites = init_stations() - by_name = {sat.name: sat for sat in satellites} - satellite = by_name[satellite_name] +class Predictions(object): - ts = load.timescale() - t0 = ts.now() - t1 = ts.utc(2020, 9, 30) + def __init__(self, lat, lng, tz="UTC", satellite=ISS): + self.lat = lat + self.lng = lng + self.tz = tz + self.satellite = satellite - t, events = satellite.find_events(location, t0, t1, altitude_degrees=60.0) - for ti, event in zip(t, events): - name = ('rise above 30°', 'culminate', 'set below 30°')[event] - print(ti) - print(ti.utc_strftime('%Y %b %d %H:%M:%S'), name) + def init_stations(self): + stations_url = 'http://celestrak.com/NORAD/elements/stations.txt' + return load.tle_file(stations_url) + + def get_next_days_timescale(self, days=10): + ts = load.timescale() + t0 = ts.now() + t1 = ts.ut1_jd(t0.ut1 + days) + return t0, t1 + + def get_predictions(self, location=TEL_AVIV, satellite_name=ISS): + satellites = self.init_stations() + by_name = {sat.name: sat for sat in satellites} + satellite = by_name[satellite_name] + + t0, t1 = self.get_next_days_timescale() + + t, events = satellite.find_events(location, t0, t1, altitude_degrees=30.0) + print(t) + print(events) + for ti, event in zip(t, events): + name = ('rise above 30°', 'culminate', 'set below 30°')[event] + print(ti.utc_strftime('%Y %b %d %H:%M:%S'), name) diff --git a/iss/tests/test_predictions.py b/iss/tests/test_predictions.py index 43dad05..541b2d8 100644 --- a/iss/tests/test_predictions.py +++ b/iss/tests/test_predictions.py @@ -1,2 +1,9 @@ -def test_foo(): - assert 1 == 1 +from ..predictions import Predictions + + +def test_get_timescales(): + p = Predictions(lat=32.0853, lng=34.7817, tz="Asia/Jerusalem") + days = 5 + t0, t1 = p.get_next_days_timescale(days=days) + delta = t1.ut1 - t0.ut1 + assert delta == days |
