Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_all_three_gravity_models_with_twoline2rv():
# The numbers below are those produced by Vallado's C++ code.
# (Why does the Python version not produce the same values to
# high accuracy, instead of agreeing to only 4 places?)
assert_wgs72old(Satrec.twoline2rv(LINE1, LINE2, WGS72OLD))
assert_wgs72(Satrec.twoline2rv(LINE1, LINE2, WGS72))
assert_wgs84(Satrec.twoline2rv(LINE1, LINE2, WGS84))
# Not specifying a gravity model should select WGS72.
assert_wgs72(Satrec.twoline2rv(LINE1, LINE2))
# ISS [Orbit 606], whose date is 2019 plus 366.82137887 days.
# The core SGP4 routines handled this fine, but my hamfisted
# attempt to provide a Python datetime for "convenience" ran
# into an overflow.
a = '1 25544U 98067A 19366.82137887 .00016717 00000-0 10270-3 0 9129'
b = '2 25544 51.6392 96.6358 0005156 88.7140 271.4601 15.49497216 6061'
correct_epoch = dt.datetime(2020, 1, 1, 19, 42, 47, 134368)
# Legacy API.
sat = io.twoline2rv(a, b, wgs72)
assertEqual(sat.epoch, correct_epoch)
correct_epoch = correct_epoch.replace(tzinfo=conveniences.UTC)
# Modern API.
sat = Satrec.twoline2rv(a, b)
assertEqual(conveniences.sat_epoch_datetime(sat), correct_epoch)
def test_all_three_gravity_models_with_twoline2rv():
# The numbers below are those produced by Vallado's C++ code.
# (Why does the Python version not produce the same values to
# high accuracy, instead of agreeing to only 4 places?)
assert_wgs72old(Satrec.twoline2rv(LINE1, LINE2, WGS72OLD))
assert_wgs72(Satrec.twoline2rv(LINE1, LINE2, WGS72))
assert_wgs84(Satrec.twoline2rv(LINE1, LINE2, WGS84))
# Not specifying a gravity model should select WGS72.
assert_wgs72(Satrec.twoline2rv(LINE1, LINE2))
)
it.reset()
for itup in it:
tle = itup[0]
mjd = itup[2]
size = mjd.shape[0]
# TODO code path for api.accelerated == True
for i in range(size):
line1, line2 = tle[i].tle_strings()[1:]
sat = Satrec.twoline2rv(line1, line2)
_f, _i = np.modf(mjd[i])
err_code, pos, vel = sat.sgp4(_i + 2400000.5, _f)
if err_code:
raise ValueError(
'Satellite propagation error', err_code,
'({})'.format(SGP4_ERRORS[err_code])
)
eci_pos_x, eci_pos_y, eci_pos_z = pos
eci_vel_x, eci_vel_y, eci_vel_z = vel
itup[3][i][0] = eci_pos_x
itup[3][i][1] = eci_pos_y
itup[3][i][2] = eci_pos_z
Args:
tle (array): two-line element string array.
epoch_start (astropy.time.Time): starting epoch.
epoch_end (astropy.time.Time): ending epich.
step (float): step in Julian Day fractions.
verbose (bool): debug output. Defaults to False.
Returns:
e (np.ndarray): vector of SGP4 error codes.
r (np.ndarray): vector of satellite positions (TEME).
v (np.ndarray): vector of satellite velocities (TEME).
jd (np.ndarray): vector of Julian Day numbers.
fr (np.ndarray): vector of Julian Day fractions.
"""
satellite = Satrec.twoline2rv(tle[0], tle[1])
fr = np.arange(epoch_start.jd2, epoch_end.jd2, step)
jd = np.ones(fr.shape[0]) * epoch_start.jd1
e, r, v = satellite.sgp4_array(jd, fr)
return e, r, v, jd, fr