summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2020-09-23 18:34:32 +0300
committerYuval Adam <_@yuv.al>2020-09-23 18:34:32 +0300
commit71da8e84d06e4ce7a0365db8ace3c6385c7a0bd4 (patch)
tree68cf28a20e102106d186a92d22bf5c98e1dd55ce
parent0ad888f42523a0a7bd89d65d6df91c490b166c11 (diff)
Cleanup code
-rw-r--r--iss/predictions.py28
-rw-r--r--iss/tests/test_predictions.py4
2 files changed, 18 insertions, 14 deletions
diff --git a/iss/predictions.py b/iss/predictions.py
index ac28cea..7febe62 100644
--- a/iss/predictions.py
+++ b/iss/predictions.py
@@ -1,13 +1,13 @@
from skyfield.api import Topos, load
-TEL_AVIV = Topos("32.0853 N", "34.7817 E")
-ISS = "ISS (ZARYA)"
-
class Predictions(object):
- def __init__(self, lat, lng, tz="UTC", satellite=ISS):
+ ISS = "ISS (ZARYA)"
+
+ def __init__(self, lat, lng, altitude=30.0, tz="UTC", satellite=ISS):
self.lat = lat
self.lng = lng
+ self.altitude = altitude
self.tz = tz
self.satellite = satellite
@@ -15,25 +15,29 @@ class Predictions(object):
stations_url = "http://celestrak.com/NORAD/elements/stations.txt"
return load.tle_file(stations_url)
- def get_next_days_timescale(self, days=10):
+ def get_next_days(self, days=10):
ts = load.timescale()
t0 = ts.now()
t1 = ts.ut1_jd(t0.ut1 + days)
return t0, t1
- def get_location_topos(self):
+ def get_location(self):
return Topos(latitude_degrees=self.lat, longitude_degrees=self.lng)
- def get_predictions(self, location=TEL_AVIV):
+ def get_satellite(self):
satellites = self.init_stations()
by_name = {sat.name: sat for sat in satellites}
- satellite = by_name[self.satellite]
+ return by_name[self.satellite]
+
+ def get_predictions(self):
+ satellite = self.get_satellite()
+ t0, t1 = self.get_next_days(days=10)
+ location = self.get_location()
- t0, t1 = self.get_next_days_timescale()
+ t, events = satellite.find_events(
+ location, t0, t1, altitude_degrees=self.altitude
+ )
- 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 daa2bf4..b809885 100644
--- a/iss/tests/test_predictions.py
+++ b/iss/tests/test_predictions.py
@@ -6,7 +6,7 @@ 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)
+ t0, t1 = p.get_next_days(days=days)
delta = t1.ut1 - t0.ut1
assert delta == days
@@ -14,6 +14,6 @@ def test_get_timescales():
def test_get_location():
p = Predictions(lat=32.0853, lng=34.7817)
tlv = Topos("32.0853 N", "34.7817 E")
- topos = p.get_location_topos()
+ topos = p.get_location()
assert topos.latitude.degrees == tlv.latitude.degrees
assert topos.longitude.degrees == tlv.longitude.degrees