summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--iss/predictions.py30
-rw-r--r--iss/tests/test_predictions.py6
2 files changed, 20 insertions, 16 deletions
diff --git a/iss/predictions.py b/iss/predictions.py
index 04dcc88..37bf49e 100644
--- a/iss/predictions.py
+++ b/iss/predictions.py
@@ -23,28 +23,30 @@ class Predictions(object):
self.lng = lng
self.altitude = altitude
self.tz = tz
- self.satellite = satellite
self.start = start
self.days = days
self.tle_file = tle_file.resolve().as_posix() if tle_file else STATIONS_URL
+ self.satellite = self.init_satellite(satellite)
+ self.location = self.init_location()
+
def init_stations(self):
return load.tle_file(self.tle_file)
+ def init_satellite(self, satellite):
+ satellites = self.init_stations()
+ by_name = {sat.name: sat for sat in satellites}
+ return by_name[satellite]
+
+ def init_location(self):
+ return Topos(latitude_degrees=self.lat, longitude_degrees=self.lng)
+
def get_next_days(self):
ts = load.timescale()
t0 = ts.now() if not self.start else ts.ut1_jd(self.start)
t1 = ts.ut1_jd(t0.ut1 + self.days)
return t0, t1
- def get_location(self):
- return Topos(latitude_degrees=self.lat, longitude_degrees=self.lng)
-
- def get_satellite(self):
- satellites = self.init_stations()
- by_name = {sat.name: sat for sat in satellites}
- return by_name[self.satellite]
-
def get_prediction_details(self, rise, culminate, zet):
return {
"rise": {"iso": rise.utc_iso(), "ut1": rise.ut1},
@@ -52,13 +54,15 @@ class Predictions(object):
"set": {"iso": zet.utc_iso(), "ut1": zet.ut1},
}
+ def get_position_details(self, satellite, t):
+ geocentric = satellite.at(t)
+ return {"distance": geocentric.position.km}
+
def get_prediction_events(self):
- satellite = self.get_satellite()
t0, t1 = self.get_next_days()
- location = self.get_location()
- ts, _events = satellite.find_events(
- location, t0, t1, altitude_degrees=self.altitude
+ ts, _events = self.satellite.find_events(
+ self.location, t0, t1, altitude_degrees=self.altitude
)
# events are returned as 3-tuples of (rise, culminate, set)
diff --git a/iss/tests/test_predictions.py b/iss/tests/test_predictions.py
index b872d60..a88674d 100644
--- a/iss/tests/test_predictions.py
+++ b/iss/tests/test_predictions.py
@@ -25,9 +25,9 @@ def test_custom_start():
def test_get_location():
p = Predictions(lat=32.0853, lng=34.7817)
tlv = Topos("32.0853 N", "34.7817 E")
- topos = p.get_location()
- assert topos.latitude.degrees == tlv.latitude.degrees
- assert topos.longitude.degrees == tlv.longitude.degrees
+ location = p.location
+ assert location.latitude.degrees == tlv.latitude.degrees
+ assert location.longitude.degrees == tlv.longitude.degrees
def test_get_prediction_events():