def sgp4init(self, whichconst, opsmode, satnum, epoch, bstar, ndot, nddot, ecco, argpo, inclo, mo, no_kozai, nodeo): whichconst = gravity_constants[whichconst] self.jdsatepoch, self.jdsatepochF = divmod(epoch, 1.0) self.jdsatepoch += 2433281.5 sgp4init(whichconst, opsmode, satnum, epoch, bstar, ndot, nddot, ecco, argpo, inclo, mo, no_kozai, nodeo, self)
def init_sgp4(self): xpdotp = 1440.0 / (2.0 * pi) self.sgp4 = sgp4model.Satellite() self.sgp4.error = 0 self.sgp4.whichconst = wgs84 self.sgp4.no = self.no / xpdotp self.sgp4.bstar = self.bstar * pow(10.0, self.ibexp) self.sgp4.a = pow(self.sgp4.no * wgs84.tumin, (-2.0 / 3.0)) self.sgp4.inclo = radians(self.inclo) self.sgp4.nodeo = radians(self.nodeo) self.sgp4.argpo = radians(self.argpo) self.sgp4.mo = radians(self.mo) self.sgp4.alta = self.sgp4.a * (1.0 + self.ecco) - 1.0 self.sgp4.altp = self.sgp4.a * (1.0 - self.ecco) - 1.0 self.sgp4.epochyr = self.date.year self.sgp4.jdsatepoch = self.jdate self.sgp4.epoch = self.date self.sgp4.ecco = self.ecco propagation.sgp4init( wgs84, 'i', self.norad, self.sgp4.jdsatepoch - 2433281.5, self.sgp4.bstar, self.sgp4.ecco, self.sgp4.argpo, self.sgp4.inclo, self.sgp4.mo, self.sgp4.no, self.sgp4.nodeo, self.sgp4 ) self.init = True
def test_legacy_initialized_with_sgp4init(): sat = model.Satellite() sgp4init( wgs72, 'i', VANGUARD_ATTRS['satnum'], VANGUARD_EPOCH, *sgp4init_args(VANGUARD_ATTRS) + (sat,) ) verify_vanguard_1(sat, legacy=True)
def sgp4init(self, whichconst, opsmode, satnum, epoch, bstar, ndot, nddot, ecco, argpo, inclo, mo, no_kozai, nodeo): whichconst = gravity_constants[whichconst] y, m, d, H, M, S = invjday(epoch + 2433281.5) jan0epoch = jday(y, 1, 0, 0, 0, 0.0) - 2433281.5 self.epochyr = y % 1000 self.epochdays = epoch - jan0epoch self.jdsatepoch, self.jdsatepochF = divmod(epoch, 1.0) self.jdsatepoch += 2433281.5 sgp4init(whichconst, opsmode, satnum, epoch, bstar, ndot, nddot, ecco, argpo, inclo, mo, no_kozai, nodeo, self)
def twoline2rv(longstr1, longstr2, whichconst, opsmode='i', satrec=None): """Return a Satellite imported from two lines of TLE data. Provide the two TLE lines as strings `longstr1` and `longstr2`, and select which standard set of gravitational constants you want by providing `gravity_constants`: `sgp4.earth_gravity.wgs72` - Standard WGS 72 model `sgp4.earth_gravity.wgs84` - More recent WGS 84 model `sgp4.earth_gravity.wgs72old` - Legacy support for old SGP4 behavior Normally, computations are made using various recent improvements to the algorithm. If you want to turn some of these off and go back into "opsmode" mode, then set `opsmode` to `a`. """ deg2rad = pi / 180.0 # 0.0174532925199433 xpdotp = 1440.0 / (2.0 * pi) # 229.1831180523293 # For compatibility with our 1.x API, build an old Satellite object # if the caller fails to supply a satrec. In that case we perform # the necessary import here to avoid an import loop. if satrec is None: from sgp4.model import Satellite satrec = Satellite() satrec.error = 0 satrec.whichconst = whichconst # Python extension: remembers its consts line = longstr1.rstrip() if (len(line) >= 64 and line.startswith('1 ') and line[8] == ' ' and line[23] == '.' and line[32] == ' ' and line[34] == '.' and line[43] == ' ' and line[52] == ' ' and line[61] == ' ' and line[63] == ' '): _saved_satnum = satrec.satnum = _alpha5(line[2:7]) satrec.classification = line[7] or 'U' satrec.intldesg = line[9:17].rstrip() two_digit_year = int(line[18:20]) satrec.epochdays = float(line[20:32]) satrec.ndot = float(line[33:43]) satrec.nddot = float(line[44] + '.' + line[45:50]) nexp = int(line[50:52]) satrec.bstar = float(line[53] + '.' + line[54:59]) ibexp = int(line[59:61]) satrec.ephtype = line[62] satrec.elnum = int(line[64:68]) else: raise ValueError(error_message.format(1, LINE1, line)) line = longstr2.rstrip() if (len(line) >= 69 and line.startswith('2 ') and line[7] == ' ' and line[11] == '.' and line[16] == ' ' and line[20] == '.' and line[25] == ' ' and line[33] == ' ' and line[37] == '.' and line[42] == ' ' and line[46] == '.' and line[51] == ' '): satrec.satnum = _alpha5(line[2:7]) if _saved_satnum != satrec.satnum: raise ValueError('Object numbers in lines 1 and 2 do not match') satrec.inclo = float(line[8:16]) satrec.nodeo = float(line[17:25]) satrec.ecco = float('0.' + line[26:33].replace(' ', '0')) satrec.argpo = float(line[34:42]) satrec.mo = float(line[43:51]) satrec.no_kozai = float(line[52:63]) satrec.revnum = line[63:68] #except (AssertionError, IndexError, ValueError): else: raise ValueError(error_message.format(2, LINE2, line)) # ---- find no, ndot, nddot ---- satrec.no_kozai = satrec.no_kozai / xpdotp # rad/min satrec.nddot = satrec.nddot * pow(10.0, nexp) satrec.bstar = satrec.bstar * pow(10.0, ibexp) # ---- convert to sgp4 units ---- satrec.ndot = satrec.ndot / (xpdotp * 1440.0) # ? * minperday satrec.nddot = satrec.nddot / (xpdotp * 1440.0 * 1440) # ---- find standard orbital elements ---- satrec.inclo = satrec.inclo * deg2rad satrec.nodeo = satrec.nodeo * deg2rad satrec.argpo = satrec.argpo * deg2rad satrec.mo = satrec.mo * deg2rad """ // ---------------------------------------------------------------- // find sgp4epoch time of element set // remember that sgp4 uses units of days from 0 jan 1950 (sgp4epoch) // and minutes from the epoch (time) // ---------------------------------------------------------------- // ---------------- temp fix for years from 1957-2056 ------------------- // --------- correct fix will occur when year is 4-digit in tle --------- """ if two_digit_year < 57: year = two_digit_year + 2000 else: year = two_digit_year + 1900 mon, day, hr, minute, sec = days2mdhms(year, satrec.epochdays) sec_whole, sec_fraction = divmod(sec, 1.0) satrec.epochyr = year satrec.jdsatepoch = jday(year, mon, day, hr, minute, sec) try: satrec.epoch = datetime(year, mon, day, hr, minute, int(sec_whole), int(sec_fraction * 1000000.0 // 1.0)) except ValueError: # Sometimes a TLE says something like "2019 + 366.82137887 days" # which would be December 32nd which causes a ValueError. year, mon, day, hr, minute, sec = invjday(satrec.jdsatepoch) satrec.epoch = datetime(year, mon, day, hr, minute, int(sec_whole), int(sec_fraction * 1000000.0 // 1.0)) # ---------------- initialize the orbit at sgp4epoch ------------------- sgp4init(whichconst, opsmode, satrec.satnum, satrec.jdsatepoch - 2433281.5, satrec.bstar, satrec.ndot, satrec.nddot, satrec.ecco, satrec.argpo, satrec.inclo, satrec.mo, satrec.no_kozai, satrec.nodeo, satrec) return satrec
def twoline2rv(longstr1, longstr2, whichconst, afspc_mode=False): """Return a Satellite imported from two lines of TLE data. Provide the two TLE lines as strings `longstr1` and `longstr2`, and select which standard set of gravitational constants you want by providing `gravity_constants`: `sgp4.earth_gravity.wgs72` - Standard WGS 72 model `sgp4.earth_gravity.wgs84` - More recent WGS 84 model `sgp4.earth_gravity.wgs72old` - Legacy support for old SGP4 behavior Normally, computations are made using various recent improvements to the algorithm. If you want to turn some of these off and go back into "afspc" mode, then set `afspc_mode` to `True`. """ deg2rad = pi / 180.0 # 0.0174532925199433 xpdotp = 1440.0 / (2.0 * pi) # 229.1831180523293 tumin = whichconst.tumin satrec = Satellite() satrec.error = 0 satrec.whichconst = whichconst # Python extension: remembers its consts line = longstr1.rstrip() # try/except is not well supported by Numba if (len(line) >= 64 and line.startswith('1 ') and line[8] == ' ' and line[23] == '.' and line[32] == ' ' and line[34] == '.' and line[43] == ' ' and line[52] == ' ' and line[61] == ' ' and line[63] == ' '): _saved_satnum = satrec.satnum = int(line[2:7]) # classification = line[7] or 'U' # intldesg = line[9:17] two_digit_year = int(line[18:20]) satrec.epochdays = float(line[20:32]) satrec.ndot = float(line[33:43]) satrec.nddot = float(line[44] + '.' + line[45:50]) nexp = int(line[50:52]) satrec.bstar = float(line[53] + '.' + line[54:59]) ibexp = int(line[59:61]) # numb = int(line[62]) # elnum = int(line[64:68]) else: raise ValueError(error_message.format(1, LINE1, line)) line = longstr2.rstrip() line_format_ok = False if (len(line) >= 69 and line.startswith('2 ') and line[7] == ' ' and line[11] == '.' and line[16] == ' ' and line[20] == '.' and line[25] == ' ' and line[33] == ' ' and line[37] == '.' and line[42] == ' ' and line[46] == '.' and line[51] == ' '): satrec.satnum = int(line[2:7]) if _saved_satnum != satrec.satnum: raise ValueError('Object numbers in lines 1 and 2 do not match') satrec.inclo = float(line[8:16]) satrec.nodeo = float(line[17:25]) satrec.ecco = float('0.' + line[26:33].replace(' ', '0')) satrec.argpo = float(line[34:42]) satrec.mo = float(line[43:51]) satrec.no = float(line[52:63]) #revnum = line[63:68] #except (AssertionError, IndexError, ValueError): else: raise ValueError(error_message.format(2, LINE2, line)) # ---- find no, ndot, nddot ---- satrec.no = satrec.no / xpdotp # rad/min satrec.nddot = satrec.nddot * pow(10.0, nexp) satrec.bstar = satrec.bstar * pow(10.0, ibexp) # ---- convert to sgp4 units ---- satrec.a = pow(satrec.no * tumin, (-2.0 / 3.0)) satrec.ndot = satrec.ndot / (xpdotp * 1440.0) # ? * minperday satrec.nddot = satrec.nddot / (xpdotp * 1440.0 * 1440) # ---- find standard orbital elements ---- satrec.inclo = satrec.inclo * deg2rad satrec.nodeo = satrec.nodeo * deg2rad satrec.argpo = satrec.argpo * deg2rad satrec.mo = satrec.mo * deg2rad satrec.alta = satrec.a * (1.0 + satrec.ecco) - 1.0 satrec.altp = satrec.a * (1.0 - satrec.ecco) - 1.0 """ // ---------------------------------------------------------------- // find sgp4epoch time of element set // remember that sgp4 uses units of days from 0 jan 1950 (sgp4epoch) // and minutes from the epoch (time) // ---------------------------------------------------------------- // ---------------- temp fix for years from 1957-2056 ------------------- // --------- correct fix will occur when year is 4-digit in tle --------- """ if two_digit_year < 57: year = two_digit_year + 2000 else: year = two_digit_year + 1900 mon, day, hr, minute, sec = days2mdhms(year, satrec.epochdays) sec_whole, sec_fraction = divmod(sec, 1.0) satrec.epochyr = year satrec.jdsatepoch = jday(year, mon, day, hr, minute, sec) satrec.epoch = datetime(year, mon, day, hr, minute, int(sec_whole), int(sec_fraction * 1000000.0 // 1.0)) # ---------------- initialize the orbit at sgp4epoch ------------------- sgp4init(whichconst, afspc_mode, satrec.satnum, satrec.jdsatepoch - 2433281.5, satrec.bstar, satrec.ecco, satrec.argpo, satrec.inclo, satrec.mo, satrec.no, satrec.nodeo, satrec) return satrec
def kep_to_sat(kep, epoch, bstar=0.21109E-4, whichconst=wgs72, afspc_mode=False): """kep_to_sat(kep,epoch,bstar=0.21109E-4,whichconst=wgs72,afspc_mode=False) Converts a set of keplerian elements into a Satellite object. Args: kep(1x6 numpy array): the osculating keplerian elements at epoch epoch(float): the epoch bstar(float): bstar drag coefficient whichconst(float): gravity model. refer pypi sgp4 documentation afspc_mode(boolean): refer pypi sgp4 documentation Returns: Satellite object: an sgp4 satellite object encapsulating the arguments """ deg2rad = np.pi / 180.0 # 0.0174532925199433 xpdotp = 1440.0 / (2.0 * np.pi) # 229.1831180523293 tumin = whichconst.tumin satrec = Satellite() satrec.error = 0 satrec.whichconst = whichconst # Python extension: remembers its consts satrec.satnum = 0 dt_obj = datetime.utcfromtimestamp(epoch) t_obj = dt_obj.timetuple() satrec.epochdays = (t_obj.tm_yday + t_obj.tm_hour / 24 + t_obj.tm_min / 1440 + t_obj.tm_sec / 86400) satrec.ndot = 0 satrec.nddot = 0 satrec.bstar = bstar satrec.inclo = kep[2] satrec.nodeo = kep[4] satrec.ecco = kep[1] satrec.argpo = kep[3] satrec.mo = __true_to_mean(kep[5], kep[1]) satrec.no = 86400 / (2 * np.pi * (kep[0]**3 / 398600.4405)**0.5) satrec.no = satrec.no / xpdotp # rad/min satrec.a = pow(satrec.no * tumin, (-2.0 / 3.0)) # ---- find standard orbital elements ---- satrec.inclo = satrec.inclo * deg2rad satrec.nodeo = satrec.nodeo * deg2rad satrec.argpo = satrec.argpo * deg2rad satrec.mo = satrec.mo * deg2rad satrec.alta = satrec.a * (1.0 + satrec.ecco) - 1.0 satrec.altp = satrec.a * (1.0 - satrec.ecco) - 1.0 satrec.epochyr = dt_obj.year satrec.jdsatepoch = epoch / 86400.0 + 2440587.5 satrec.epoch = dt_obj # ---------------- initialize the orbit at sgp4epoch ------------------- sgp4init(whichconst, afspc_mode, satrec.satnum, satrec.jdsatepoch - 2433281.5, satrec.bstar, satrec.ecco, satrec.argpo, satrec.inclo, satrec.mo, satrec.no, satrec.nodeo, satrec) return satrec
def twoline2rv(longstr1, longstr2, whichconst, afspc_mode=False): """Return a Satellite imported from two lines of TLE data. Provide the two TLE lines as strings `longstr1` and `longstr2`, and select which standard set of gravitational constants you want by providing `gravity_constants`: `sgp4.earth_gravity.wgs72` - Standard WGS 72 model `sgp4.earth_gravity.wgs84` - More recent WGS 84 model `sgp4.earth_gravity.wgs72old` - Legacy support for old SGP4 behavior Normally, computations are made using various recent improvements to the algorithm. If you want to turn some of these off and go back into "afspc" mode, then set `afspc_mode` to `True`. """ opsmode = 'a' if afspc_mode else 'i' deg2rad = pi / 180.0; # 0.0174532925199433 xpdotp = 1440.0 / (2.0 *pi); # 229.1831180523293 revnum = 0; elnum = 0; tumin = whichconst.tumin satrec = Satellite() satrec.error = 0; satrec.whichconst = whichconst # Python extension: remembers its consts # This is Python, so we convert the strings into mutable lists of # characters before setting the C++ code loose on them. longstr1 = [ c for c in longstr1 ] longstr2 = [ c for c in longstr2 ] # set the implied decimal points since doing a formated read # fixes for bad input data values (missing, ...) for j in range(10, 16): if longstr1[j] == ' ': longstr1[j] = '_'; if longstr1[44] != ' ': longstr1[43] = longstr1[44]; longstr1[44] = '.'; if longstr1[7] == ' ': longstr1[7] = 'U'; if longstr1[9] == ' ': longstr1[9] = '.'; for j in range(45, 50): if longstr1[j] == ' ': longstr1[j] = '0'; if longstr1[51] == ' ': longstr1[51] = '0'; if longstr1[53] != ' ': longstr1[52] = longstr1[53]; longstr1[53] = '.'; longstr2[25] = '.'; for j in range(26, 33): if longstr2[j] == ' ': longstr2[j] = '0'; if longstr1[62] == ' ': longstr1[62] = '0'; if longstr1[68] == ' ': longstr1[68] = '0'; # Concatenate lists back into real strings. longstr1 = ''.join(longstr1) longstr2 = ''.join(longstr2) (cardnumb,satrec.satnum,classification, intldesg, two_digit_year, satrec.epochdays,satrec.ndot, satrec.nddot, nexp, satrec.bstar, ibexp, numb, elnum) = \ sscanf(longstr1,"%2d %5ld %1c %10s %2d %12lf %11lf %7lf %2d %7lf %2d %2d %6ld ", ) if longstr2[52] == ' ': (cardnumb,satrec.satnum, satrec.inclo, satrec.nodeo,satrec.ecco, satrec.argpo, satrec.mo, satrec.no, revnum) = \ sscanf(longstr2,"%2d %5ld %9lf %9lf %8lf %9lf %9lf %10lf %6ld \n", ) else: (cardnumb,satrec.satnum, satrec.inclo, satrec.nodeo,satrec.ecco, satrec.argpo, satrec.mo, satrec.no, revnum) = \ sscanf(longstr2,"%2d %5ld %9lf %9lf %8lf %9lf %9lf %11lf %6ld \n", ) # ---- find no, ndot, nddot ---- satrec.no = satrec.no / xpdotp; # rad/min satrec.nddot= satrec.nddot * pow(10.0, nexp); satrec.bstar= satrec.bstar * pow(10.0, ibexp); # ---- convert to sgp4 units ---- satrec.a = pow( satrec.no*tumin , (-2.0/3.0) ); satrec.ndot = satrec.ndot / (xpdotp*1440.0); # ? * minperday satrec.nddot= satrec.nddot / (xpdotp*1440.0*1440); # ---- find standard orbital elements ---- satrec.inclo = satrec.inclo * deg2rad; satrec.nodeo = satrec.nodeo * deg2rad; satrec.argpo = satrec.argpo * deg2rad; satrec.mo = satrec.mo * deg2rad; satrec.alta = satrec.a*(1.0 + satrec.ecco) - 1.0; satrec.altp = satrec.a*(1.0 - satrec.ecco) - 1.0; """ // ---------------------------------------------------------------- // find sgp4epoch time of element set // remember that sgp4 uses units of days from 0 jan 1950 (sgp4epoch) // and minutes from the epoch (time) // ---------------------------------------------------------------- // ---------------- temp fix for years from 1957-2056 ------------------- // --------- correct fix will occur when year is 4-digit in tle --------- """ if two_digit_year < 57: year = two_digit_year + 2000; else: year = two_digit_year + 1900; mon,day,hr,minute,sec = days2mdhms(year, satrec.epochdays); sec_whole, sec_fraction = divmod(sec, 1.0) satrec.epochyr = year satrec.jdsatepoch = jday(year,mon,day,hr,minute,sec); satrec.epoch = datetime(year, mon, day, hr, minute, int(sec_whole), int(sec_fraction * 1000000.0 // 1.0)) # ---------------- initialize the orbit at sgp4epoch ------------------- sgp4init( whichconst, opsmode, satrec.satnum, satrec.jdsatepoch-2433281.5, satrec.bstar, satrec.ecco, satrec.argpo, satrec.inclo, satrec.mo, satrec.no, satrec.nodeo, satrec); return satrec
def twoline2rv(longstr1, longstr2, whichconst, afspc_mode=False): """Return a Satellite imported from two lines of TLE data. Provide the two TLE lines as strings `longstr1` and `longstr2`, and select which standard set of gravitational constants you want by providing `gravity_constants`: `sgp4.earth_gravity.wgs72` - Standard WGS 72 model `sgp4.earth_gravity.wgs84` - More recent WGS 84 model `sgp4.earth_gravity.wgs72old` - Legacy support for old SGP4 behavior Normally, computations are made using various recent improvements to the algorithm. If you want to turn some of these off and go back into "afspc" mode, then set `afspc_mode` to `True`. """ opsmode = 'a' if afspc_mode else 'i' deg2rad = pi / 180.0; # 0.0174532925199433 xpdotp = 1440.0 / (2.0 *pi); # 229.1831180523293 tumin = whichconst.tumin satrec = Satellite() satrec.error = 0; satrec.whichconst = whichconst # Python extension: remembers its consts line = longstr1.rstrip() try: assert line.startswith('1 ') satrec.satnum = int(line[2:7]) # classification = line[7] or 'U' assert line[8] == ' ' # intldesg = line[9:17] two_digit_year = int(line[18:20]) assert line[23] == '.' satrec.epochdays = float(line[20:32]) assert line[32] == ' ' assert line[34] == '.' satrec.ndot = float(line[33:43]) assert line[43] == ' ' satrec.nddot = float(line[44] + '.' + line[45:50]) nexp = int(line[50:52]) assert line[52] == ' ' satrec.bstar = float(line[53] + '.' + line[54:59]) ibexp = int(line[59:61]) assert line[61] == ' ' assert line[63] == ' ' # numb = int(line[62]) # elnum = int(line[64:68]) except (AssertionError, IndexError, ValueError): raise ValueError(error_message.format(1, LINE1, line)) line = longstr2.rstrip() try: assert line.startswith('2 ') satrec.satnum = int(line[2:7]) # TODO: check it matches line 1? assert line[7] == ' ' assert line[11] == '.' satrec.inclo = float(line[8:16]) assert line[16] == ' ' assert line[20] == '.' satrec.nodeo = float(line[17:25]) assert line[25] == ' ' satrec.ecco = float('0.' + line[26:33].replace(' ', '0')) assert line[33] == ' ' assert line[37] == '.' satrec.argpo = float(line[34:42]) assert line[42] == ' ' assert line[46] == '.' satrec.mo = float(line[43:51]) assert line[51] == ' ' satrec.no = float(line[52:63]) #revnum = line[63:68] except (AssertionError, IndexError, ValueError): raise ValueError(error_message.format(2, LINE2, line)) # ---- find no, ndot, nddot ---- satrec.no = satrec.no / xpdotp; # rad/min satrec.nddot= satrec.nddot * pow(10.0, nexp); satrec.bstar= satrec.bstar * pow(10.0, ibexp); # ---- convert to sgp4 units ---- satrec.a = pow( satrec.no*tumin , (-2.0/3.0) ); satrec.ndot = satrec.ndot / (xpdotp*1440.0); # ? * minperday satrec.nddot= satrec.nddot / (xpdotp*1440.0*1440); # ---- find standard orbital elements ---- satrec.inclo = satrec.inclo * deg2rad; satrec.nodeo = satrec.nodeo * deg2rad; satrec.argpo = satrec.argpo * deg2rad; satrec.mo = satrec.mo * deg2rad; satrec.alta = satrec.a*(1.0 + satrec.ecco) - 1.0; satrec.altp = satrec.a*(1.0 - satrec.ecco) - 1.0; """ // ---------------------------------------------------------------- // find sgp4epoch time of element set // remember that sgp4 uses units of days from 0 jan 1950 (sgp4epoch) // and minutes from the epoch (time) // ---------------------------------------------------------------- // ---------------- temp fix for years from 1957-2056 ------------------- // --------- correct fix will occur when year is 4-digit in tle --------- """ if two_digit_year < 57: year = two_digit_year + 2000; else: year = two_digit_year + 1900; mon,day,hr,minute,sec = days2mdhms(year, satrec.epochdays); sec_whole, sec_fraction = divmod(sec, 1.0) satrec.epochyr = year satrec.jdsatepoch = jday(year,mon,day,hr,minute,sec); satrec.epoch = datetime(year, mon, day, hr, minute, int(sec_whole), int(sec_fraction * 1000000.0 // 1.0)) # ---------------- initialize the orbit at sgp4epoch ------------------- sgp4init(whichconst, opsmode, satrec.satnum, satrec.jdsatepoch-2433281.5, satrec.bstar, satrec.ecco, satrec.argpo, satrec.inclo, satrec.mo, satrec.no, satrec.nodeo, satrec) return satrec
def test_sgp4_init(client): """ isimp 0 method 1 aycof 2 con41 3 cc1 4 cc4 5 cc5 6 d2 7 d3 8 d4 9 delmo 10 eta 11 argpdot 12 omgcof 13 sinmao 14 t 15 t2cof 16 t3cof 17 t4cof 18 t5cof 19 x1mth2 20 x7thm1 21 mdot 22 nodedot 23 xlcof 24 xmcof 25 nodecf 26 irez 27 d2201 28 d2211 29 d3210 30 d3222 31 d4410 32 d4422 33 d5220 34 d5232 35 d5421 36 d5433 37 dedt 38 del1 39 del2 40 del3 41 didt 42 dmdt 43 dnodt 44 domdt 45 e3 46 ee2 47 peo 48 pgho 49 pho 50 pinco 51 plo 52 se2 53 se3 54 sgh2 55 sgh3 56 sgh4 57 sh2 58 sh3 59 si2 60 si3 61 sl2 62 sl3 63 sl4 64 gsto 65 xfact 66 xgh2 67 xgh3 68 xgh4 69 xh2 70 xh3 71 xi2 72 xi3 73 xl2 74 xl3 75 xl4 76 xlamo 77 xlmth2 78 zmol 79 zmos 80 atime 81 xli 82 xni 83 bstar 84 ecco 85 argpo 86 inclo 87 mo 88 no 89 nodeo 90 afspc_mode 91 error 92 init 93 x 94 y 95 z 96 u 97 v 98 w 99 """ # @cuda.jit('void(float64[:, :], float64[:], float64[:], float64[:], float64[:], float64[:], float64[:], float64[:], float64[:], float64[:], float64[:, :])') # def sample_function(whichconst, afspc_mode, epoch, xbstar, xecco, xargpo, xinclo, xmo, xno, xnodeo, out): # idx = cuda.grid(1) # stride = cuda.gridsize(1) # for i in range(idx, afspc_mode.shape[0], stride): # si.sgp4_init_g( # whichconst[i, :], afspc_mode[i], epoch[i], xbstar[i], xecco[i], xargpo[i], xinclo[i], xmo[i], xno[i], # xnodeo[i], out[i, :] # ) n = 25 m = 100 afspc_mode = 1 epoch = 18441.78495062003 satn = 5 satrec = np.zeros((n, m), dtype=np.float64) xargpo = 5.790416027488515 xbstar = 2.8098e-05 xecco = 0.1859667 xinclo = 0.5980929187319208 xmo = 0.3373093125574321 xno = 0.04722944544077857 xnodeo = 6.08638547138321 which_const_array = np.array([client.whichconst for _ in range(n)], dtype=np.float64) afspc_mode_a = np.ones((n, )) * afspc_mode epoch_a = np.ones_like(afspc_mode_a) * epoch satn_a = np.ones_like(afspc_mode_a) * satn xargpo_a = np.ones_like(afspc_mode_a) * xargpo xbstar_a = np.ones_like(afspc_mode_a) * xbstar xecco_a = np.ones_like(afspc_mode_a) * xecco xinclo_a = np.ones_like(afspc_mode_a) * xinclo xmo_a = np.ones_like(afspc_mode_a) * xmo xno_a = np.ones_like(afspc_mode_a) * xno xnodeo_a = np.ones_like(afspc_mode_a) * xnodeo si.sgp4_init(which_const_array, afspc_mode_a, epoch_a, xbstar_a, xecco_a, xargpo_a, xinclo_a, xmo_a, xno_a, xnodeo_a, satrec) from sgp4.model import Satellite expected = Satellite() expected.whichconst = client.whichconst prop.sgp4init(client.whichconst, afspc_mode, satn, epoch, xbstar, xecco, xargpo, xinclo, xmo, xno, xnodeo, expected) assert np.allclose(satrec[:, 0], expected.isimp) assert np.allclose(satrec[:, 1], 1 if expected.method == 'd' else 0) # method assert np.allclose(satrec[:, 2], expected.aycof) assert np.allclose(satrec[:, 3], expected.con41) assert np.allclose(satrec[:, 4], expected.cc1) assert np.allclose(satrec[:, 5], expected.cc4) assert np.allclose(satrec[:, 6], expected.cc5) assert np.allclose(satrec[:, 7], expected.d2) assert np.allclose(satrec[:, 8], expected.d3) assert np.allclose(satrec[:, 9], expected.d4) assert np.allclose(satrec[:, 10], expected.delmo) assert np.allclose(satrec[:, 11], expected.eta) assert np.allclose(satrec[:, 12], expected.argpdot) assert np.allclose(satrec[:, 13], expected.omgcof) assert np.allclose(satrec[:, 14], expected.sinmao) assert np.allclose(satrec[:, 15], expected.t) assert np.allclose(satrec[:, 16], expected.t2cof) assert np.allclose(satrec[:, 17], expected.t3cof) assert np.allclose(satrec[:, 18], expected.t4cof) assert np.allclose(satrec[:, 19], expected.t5cof) assert np.allclose(satrec[:, 20], expected.x1mth2) assert np.allclose(satrec[:, 21], expected.x7thm1) assert np.allclose(satrec[:, 22], expected.mdot) assert np.allclose(satrec[:, 23], expected.nodedot) assert np.allclose(satrec[:, 24], expected.xlcof) assert np.allclose(satrec[:, 25], expected.xmcof) assert np.allclose(satrec[:, 26], expected.nodecf) assert np.allclose(satrec[:, 27], expected.irez) assert np.allclose(satrec[:, 28], expected.d2201) assert np.allclose(satrec[:, 29], expected.d2211) assert np.allclose(satrec[:, 30], expected.d3210) assert np.allclose(satrec[:, 31], expected.d3222) assert np.allclose(satrec[:, 32], expected.d4410) assert np.allclose(satrec[:, 33], expected.d4422) assert np.allclose(satrec[:, 34], expected.d5220) assert np.allclose(satrec[:, 35], expected.d5232) assert np.allclose(satrec[:, 36], expected.d5421) assert np.allclose(satrec[:, 37], expected.d5433) assert np.allclose(satrec[:, 38], expected.dedt) assert np.allclose(satrec[:, 39], expected.del1) assert np.allclose(satrec[:, 40], expected.del2) assert np.allclose(satrec[:, 41], expected.del3) assert np.allclose(satrec[:, 42], expected.didt) assert np.allclose(satrec[:, 43], expected.dmdt) assert np.allclose(satrec[:, 44], expected.dnodt) assert np.allclose(satrec[:, 45], expected.domdt) assert np.allclose(satrec[:, 46], expected.e3) assert np.allclose(satrec[:, 47], expected.ee2) assert np.allclose(satrec[:, 48], expected.peo) assert np.allclose(satrec[:, 49], expected.pgho) assert np.allclose(satrec[:, 50], expected.pho) assert np.allclose(satrec[:, 51], expected.pinco) assert np.allclose(satrec[:, 52], expected.plo) assert np.allclose(satrec[:, 53], expected.se2) assert np.allclose(satrec[:, 54], expected.se3) assert np.allclose(satrec[:, 55], expected.sgh2) assert np.allclose(satrec[:, 56], expected.sgh3) assert np.allclose(satrec[:, 57], expected.sgh4) assert np.allclose(satrec[:, 58], expected.sh2) assert np.allclose(satrec[:, 59], expected.sh3) assert np.allclose(satrec[:, 60], expected.si2) assert np.allclose(satrec[:, 61], expected.si3) assert np.allclose(satrec[:, 62], expected.sl2) assert np.allclose(satrec[:, 63], expected.sl3) assert np.allclose(satrec[:, 64], expected.sl4) assert np.allclose(satrec[:, 65], expected.gsto) assert np.allclose(satrec[:, 66], expected.xfact) assert np.allclose(satrec[:, 67], expected.xgh2) assert np.allclose(satrec[:, 68], expected.xgh3) assert np.allclose(satrec[:, 69], expected.xgh4) assert np.allclose(satrec[:, 70], expected.xh2) assert np.allclose(satrec[:, 71], expected.xh3) assert np.allclose(satrec[:, 72], expected.xi2) assert np.allclose(satrec[:, 73], expected.xi3) assert np.allclose(satrec[:, 74], expected.xl2) assert np.allclose(satrec[:, 75], expected.xl3) assert np.allclose(satrec[:, 76], expected.xl4) assert np.allclose(satrec[:, 77], expected.xlamo) # assert np.allclose(satrec[:, 78], expected.xlmth2) # xlmth2 assert np.allclose(satrec[:, 79], expected.zmol) assert np.allclose(satrec[:, 80], expected.zmos) assert np.allclose(satrec[:, 81], expected.atime) assert np.allclose(satrec[:, 82], expected.xli) assert np.allclose(satrec[:, 83], expected.xni) assert np.allclose(satrec[:, 84], expected.bstar) assert np.allclose(satrec[:, 85], expected.ecco) assert np.allclose(satrec[:, 86], expected.argpo) assert np.allclose(satrec[:, 87], expected.inclo) assert np.allclose(satrec[:, 88], expected.mo) assert np.allclose(satrec[:, 89], expected.no) assert np.allclose(satrec[:, 90], expected.nodeo) assert np.allclose(satrec[:, 91], 1 if expected.afspc_mode else 0) # afspc_mode assert np.allclose(satrec[:, 92], expected.error) assert np.allclose(satrec[:, 93], 1 if expected.init == 'y' else 0)
def twoline2rv(longstr1, longstr2, whichconst, afspc_mode=False): deg2rad = pi / 180.0; # 0.0174532925199433 xpdotp = 1440.0 / (2.0 *pi); # 229.1831180523293 tumin = whichconst.tumin satrec = Satellite() satrec.error = 0; satrec.whichconst = whichconst # Python extension: remembers its consts line = longstr1.rstrip() # try/except is not well supported by Numba if (len(line) >= 64 and line.startswith('1 ') and line[8] == ' ' and line[23] == '.' and line[32] == ' ' and line[34] == '.' and line[43] == ' ' and line[52] == ' ' and line[61] == ' ' and line[63] == ' '): _saved_satnum = satrec.satnum = int(line[2:7]) # classification = line[7] or 'U' # intldesg = line[9:17] two_digit_year = int(line[18:20]) satrec.epochdays = float(line[20:32]) satrec.ndot = float(line[33:43]) satrec.nddot = float(line[44] + '.' + line[45:50]) nexp = int(line[50:52]) satrec.bstar = float(line[53] + '.' + line[54:59]) ibexp = int(line[59:61]) # numb = int(line[62]) # elnum = int(line[64:68]) else: raise ValueError(error_message.format(1, LINE1, line)) line = longstr2.rstrip() if (len(line) >= 69 and line.startswith('2 ') and line[7] == ' ' and line[11] == '.' and line[16] == ' ' and line[20] == '.' and line[25] == ' ' and line[33] == ' ' and line[37] == '.' and line[42] == ' ' and line[46] == '.' and line[51] == ' '): satrec.satnum = int(line[2:7]) if _saved_satnum != satrec.satnum: raise ValueError('Object numbers in lines 1 and 2 do not match') satrec.inclo = float(line[8:16]) satrec.nodeo = float(line[17:25]) satrec.ecco = float('0.' + line[26:33].replace(' ', '0')) satrec.argpo = float(line[34:42]) satrec.mo = float(line[43:51]) satrec.no = float(line[52:63]) #revnum = line[63:68] #except (AssertionError, IndexError, ValueError): else: raise ValueError(error_message.format(2, LINE2, line)) # ---- find no, ndot, nddot ---- satrec.no = satrec.no / xpdotp; # rad/min satrec.nddot= satrec.nddot * pow(10.0, nexp); satrec.bstar= satrec.bstar * pow(10.0, ibexp); # ---- convert to sgp4 units ---- satrec.a = pow( satrec.no*tumin , (-2.0/3.0) ); satrec.ndot = satrec.ndot / (xpdotp*1440.0); # ? * minperday satrec.nddot= satrec.nddot / (xpdotp*1440.0*1440); # ---- find standard orbital elements ---- satrec.inclo = satrec.inclo * deg2rad; satrec.nodeo = satrec.nodeo * deg2rad; satrec.argpo = satrec.argpo * deg2rad; satrec.mo = satrec.mo * deg2rad; satrec.alta = satrec.a*(1.0 + satrec.ecco) - 1.0; satrec.altp = satrec.a*(1.0 - satrec.ecco) - 1.0; if two_digit_year < 57: year = two_digit_year + 2000; else: year = two_digit_year + 1900; mon,day,hr,minute,sec = days2mdhms(year, satrec.epochdays); sec_whole, sec_fraction = divmod(sec, 1.0) satrec.epochyr = year satrec.jdsatepoch = jday(year,mon,day,hr,minute,sec); satrec.epoch = datetime(year, mon, day, hr, minute, int(sec_whole), int(sec_fraction * 1000000.0 // 1.0)) # ---------------- initialize the orbit at sgp4epoch ------------------- sgp4init(whichconst, afspc_mode, satrec.satnum, satrec.jdsatepoch-2433281.5, satrec.bstar, satrec.ecco, satrec.argpo, satrec.inclo, satrec.mo, satrec.no, satrec.nodeo, satrec) return satrec
def __init__(self, whichconst, satnum, epoch, bstar, inclo, nodeo, ecco, argpo, mo, no_kozai, ndot=0, nddot=0, classification='U', intldesg=None, elnum=1, revnum=1, afspc_mode=False): """ :param whichconst: standard set of gravitational constants. `sgp4.earth_gravity.wgs72` - Standard WGS 72 model `sgp4.earth_gravity.wgs84` - More recent WGS 84 model `sgp4.earth_gravity.wgs72old` - Legacy support for old SGP4 behavior :param satnum: Unique satellite number given in the TLE file. :param epoch: naive datetime objects with TLE epoch :param bstar: Ballistic drag coefficient B* in inverse earth radii. :param inclo: Inclination in radians. :param nodeo: Right ascension of ascending node in radians. :param ecco: Eccentricity. :param argpo: Argument of perigee in radians. :param mo: Mean anomaly in radians. :param no_kozai: Mean motion in radians per minute (rad/min). :param ndot: First time derivative of the mean motion (ignored by SGP4). :param nddot: Second time derivative of the mean motion (ignored by SGP4). :param classification: (U=Unclassified, C=Classified, S=Secret) :param intldesg: International designator (last two digits of launch year, launch number of the year, piece of the launch) :param elnum: Element set number. Incremented when a new TLE is generated for this object. :param revnum: Revolution number at epoch (revolutions) :param afspc_mode: Normally, computations are made using various recent improvements to the algorithm. If you want to turn some of these off and go back into "afspc" mode, then set `afspc_mode` to `True`. """ self.whichconst = whichconst self.satnum = satnum self.epoch = epoch self.epochyr = epoch.year self.jdsatepoch = jday(epoch.year, epoch.month, epoch.day, epoch.hour, epoch.minute, epoch.second + 1e-6 * epoch.microsecond) days_in_the_year = (epoch.date() - datetime.date(epoch.year, 1, 1)).days + 1 self.epochdays = days_in_the_year + ( epoch.hour + epoch.minute / 60 + (epoch.second + 1e-6 * epoch.microsecond) / 60 / 60) / 24.0 self.bstar = bstar self.inclo = inclo self.nodeo = nodeo self.ecco = ecco self.argpo = argpo self.mo = mo self.no_kozai = no_kozai self.a = pow(self.no_kozai * whichconst.tumin, (-2.0 / 3.0)) self.alta = self.a * (1.0 + self.ecco) - 1.0 self.altp = self.a * (1.0 - self.ecco) - 1.0 self.ndot = ndot self.nddot = nddot self.classification = classification if intldesg: self.intldesg = intldesg else: self.intldesg = str(self.epochyr)[:-2] + '001A' self.elnum = elnum self.revnum = revnum self.error = 0 sgp4init(whichconst, afspc_mode, self.satnum, self.jdsatepoch - 2433281.5, self.bstar, self.ecco, self.argpo, self.inclo, self.mo, self.no_kozai, self.nodeo, self)