Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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
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
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
@lru_cache(maxsize=365)
def jday_day(year, mon, day):
return (367.0 * year -
7.0 * (year + ((mon + 9.0) // 12.0)) * 0.25 // 1.0 +
275.0 * mon // 9.0 +
day + 1721013.5)
def jday(year, mon, day, hr, minute, sec):
base = jday_day(year, mon, day)
return base + ((sec / 60.0 + minute) / 60.0 + hr) / 24.0
ext.jday = jday
model.jday = jday
# finish hack zone
class HighAccuracyTLEPredictor(CartesianPredictor):
"""A pass predictor with high accuracy on estimations"""
@reify
def tle(self):
return self.source.get_tle(self.sate_id, dt.datetime.utcnow())
@reify
def _propagator(self):
tle_line_1, tle_line_2 = self.tle.lines
return twoline2rv(tle_line_1, tle_line_2, wgs84)
baseline = Timer(lambda: tsp.find_rms_inline_scalar(satnew, rd, ll, odata)).timeit(number=num)
print("find_rms_inline_scalar: {:.6f} {:.2f}x".format( *tac(baseline, Timer(lambda: tsp.find_rms_inline_scalar(satnew, rd, ll, odata)).timeit(number = num)) ))
print("find_rms: {:.6f} {:.2f}x".format( *tac(baseline, Timer(lambda: find_rms(satnew, rd, ll, odata)).timeit(number = num)) ))
print("find_rms_old: {:.6f} {:.2f}x".format( *tac(baseline, Timer(lambda: tsp.find_rms_old(satold, rd, ll, odata)).timeit(number = num)) ))
print("find_rmspy: {:.6f} {:.2f}x".format( *tac(baseline, Timer(lambda: tsp.find_rmspy(satold, rd, ll, odata)).timeit(number = num)) ))
else:
print("find_rms: {:.6f}".format( Timer(lambda: find_rms(satnew, rd, ll, odata)).timeit(number = num)) )
print()
find_rms_inline_baseline = baseline
tsince = (60 + satnew.jdsatepoch) * 1440.0 # time since epoch in minutes
(jd, fr) = divmod(satnew.jdsatepoch,1)
satnew.sgp4(jd, fr)
satrec3 = Satrec()
satrec3_jdsatepoch = 2451723.28495062
satrec3.sgp4init(WGS72, 'i', satnum, satrec3_jdsatepoch-2433281.5, bstar,
ndot, nddot, ecco, argpo, inclo, mo, no_kozai, nodeo)
print("Single element SGP4")
baseline = Timer(lambda: satrec3.sgp4(jd,fr)).timeit(number = num)
print("sgp4_cpp(1): {:.6f} {:.2f}x".format( *tac(baseline, Timer(lambda: satrec3.sgp4(jd,fr)).timeit(number = num)) ))
print("sgp4_py: {:.6f} {:.2f}x".format( *tac(baseline, Timer(lambda: sgp4(satold, tsince)).timeit(number = num)) ))
print()
print("Vector element SGP4 vs scalar loop of same #")
sats = []
sats.append(satnew)
a = SatrecArray(sats)
for j in range(len(odata)):
def test_satrec_initialized_with_sgp4init_in_afspc_mode():
sat = Satrec()
sat.sgp4init(
WGS72,
'a',
VANGUARD_ATTRS['satnum'],
VANGUARD_EPOCH,
*sgp4init_args(VANGUARD_ATTRS)
)
assertEqual(sat.operationmode, 'a')
bmax = 1.1*b
bmin = 0.9*b
bstep = (bmax-bmin)/20.0
satnum = 5
bstar = 2.8098e-05
ndot = 6.96919666594958e-13
nddot = 0.0
ecco = 0.1859667
argpo = 5.790416027488515
inclo = 0.5980929187319208
mo = 0.3373093125574321
no_kozai = 0.04722944544077857
nodeo = 6.08638547138321
sat2 = Satrec()
sat2_jdsatepoch = 2451723.28495062
sat2.sgp4init(WGS72, 'i', satnum, sat2_jdsatepoch, bstar, ndot, nddot,
ecco, argpo, inclo, mo, no_kozai, nodeo)
# Vectorized Python-SGP4 array initialization
jd = np.linspace(2451723, 2451723+900, 100)
fr = np.zeros((jd.shape[0],))
rv_template = np.zeros((1, len(jd), 3), dtype='double')
print()
np_zeros_template = np.zeros((1,10,3), dtype='double')
np_empty_template = np.empty((1,10,3), dtype='double')
def tac(baseline, time):
def test_all_three_gravity_models_with_sgp4init():
# Gravity models specified with sgp4init() should also change the
# positions generated.
sat = Satrec()
args = sgp4init_args(VANGUARD_ATTRS)
sat.sgp4init(WGS72OLD, 'i', VANGUARD_ATTRS['satnum'], VANGUARD_EPOCH, *args)
assert_wgs72old(sat)
sat.sgp4init(WGS72, 'i', VANGUARD_ATTRS['satnum'], VANGUARD_EPOCH, *args)
assert_wgs72(sat)
sat.sgp4init(WGS84, 'i', VANGUARD_ATTRS['satnum'], VANGUARD_EPOCH, *args)
assert_wgs84(sat)
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 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)