From 25ecc980a5bb7d7a3e9d127faf5a06c5c9d1ba91 Mon Sep 17 00:00:00 2001 From: Andreas Trawoeger Date: Tue, 23 Jun 2020 12:43:18 +0200 Subject: [PATCH] fix Satellite import from sgp4 version > 2.11 --- pycraf/satellite/satellite.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/pycraf/satellite/satellite.py b/pycraf/satellite/satellite.py index 68bdb0838..1fe59fd43 100644 --- a/pycraf/satellite/satellite.py +++ b/pycraf/satellite/satellite.py @@ -44,13 +44,24 @@ def get_sat(tle_string): try: import sgp4 - from sgp4.earth_gravity import wgs72 - from sgp4.io import twoline2rv, Satellite except ImportError: raise ImportError( 'The "sgp4" package is necessary to use this function.' ) + try: + from sgp4.io import Satellite + except ImportError: + try: + from sgp4.model import Satellite + except ImportError: + raise ImportError( + "Can't import sgp4 Satellite object." + ) + + from sgp4.earth_gravity import wgs72 + from sgp4.io import twoline2rv + tle_string_list = tle_string.split('\n') satname = tle_string_list[0] if satname[0:2] == '0 ': # remove leading 0 if present @@ -267,15 +278,23 @@ def azel_from_sat(self, satellite_or_tle, obstime): assert isinstance(obstime, time.Time), ( 'obstime must be an astropy.time.Time object!' ) - try: import sgp4 - from sgp4.io import Satellite except ImportError: raise ImportError( 'The "sgp4" package is necessary to use this Class.' ) + try: + from sgp4.io import Satellite + except ImportError: + try: + from sgp4.model import Satellite + except ImportError: + raise ImportError( + "Can't import sgp4 Satellite object." + ) + if not isinstance(satellite_or_tle, Satellite): _, satellite = get_sat(satellite_or_tle) else: