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
@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)
def test_jday(self):
print("jday...")
jd = 2454115.05486 # Sunday 14 January 2007 at 13:18:59.9
# Reference Astropy as "answer"
t_astropy = Time(jd, format='jd')
jdF = jd-int(jd)
jd = int(jd)
jday_datetime = jday_to_datetime(jd, jdF)
self.assertRegex(jday_datetime.isoformat(sep=' ',timespec='milliseconds'),t_astropy.iso,msg="jday_to_datetime() failed")
(year, month, day, hour, minute, second) = invjday(jd)
jday_jd = jday(year, month, day, hour, minute, second)
self.assertEqual(jday_jd,jd,"jday() failed")
jd_tt = 2450203.5
ggr = EarthLocation('75 W', '45 N', 0.0, temperature=10.0, pressure=1010.0)
ra, dec, dis = ggr(jd_tt).observe(moon).radec(J2000)
print('RA: %s' % Angle(ra).hours())
print('dec: %s' % Angle(dec).degrees())
print('')
print('RA diff: %s' % (Angle(ra).hours() - 11.739849403))
print('dec diff: %s' % (Angle(dec).degrees() - -0.31860323))
print('')
print(dis)
#JD = 2450203.500000 RA = 11.739849403 Dec = -0.31860323 Dis = 0.0026040596
exit(0)
jd = jday(2006, 6, 19, 0, 0, 0)
pos = earth(jd).observe(mercury).radec(J2000) # Astrometric
print(pos.ra)
print(pos.dec)
print('----')
jd = jday(2008, 7, 25, 0, 0, 0)
pos = earth(jd).observe(jupiter).radec() # Apparent
print(pos.ra)
print(pos.dec)
# pos = earth(jd).view(mercury).radec() Apparent
# pos = chicago(jd).view(mercury).radec() Apparent
# altaz = chicago(jd).view(mercury).altaz() Apparent
# earth(jd).find(mercury)
# earth(jd).to(mercury)
# earth(jd).toward(mercury)
# earth(jd).vector(mercury)
# earth(jd).see(mercury)
# earth(jd).measure(mercury)
# earth(jd).trace(mercury)
# earth(jd).point(mercury)
# earth(jd).orient(mercury)
# earth(jd).face(mercury)
exit(0)
#jd = 2444391.5 # 1980.06.01
#jday(year, mon, day, hr, minute, sec)
jd = jday(2006, 6, 19, 0, 0, 0)
epos = earth.at(jd)
print('earth xyz and date:')
print(epos)
print(epos.date)
# epos = earth.at(jd)
# print('earth xyz:')
# print(epos)
diff = mercury.seen_from(epos)
print('diff:')
print(diff)
gxyz = coordinates.GeocentricXYZ(diff[0], diff[1], diff[2])
print()
def propagate(self, year, month=1, day=1, hour=0, minute=0, second=0.0):
"""Return a position and velocity vector for a given date and time."""
j = jday(year, month, day, hour, minute, second)
m = (j - self.jdsatepoch) * minutes_per_day
r, v = sgp4(self, m)
return r, v
def derived_values(self):
""" Calculate values which are determined from TLE parameters """
self.epoch_string = self.epoch_datetime.isoformat(timespec='microseconds')
(year, month, day, hour, minute, second) = self.epoch_datetime.timetuple()[:6]
microseconds = int(self.epoch_datetime.strftime('%f'))
sec_with_microseconds = second + microseconds/1.0E6
self.jdsatepoch = jday(year, month, day, hour, minute, sec_with_microseconds)
self.jdSGP4epoch = self.jdsatepoch - 2433281.5
self.inclination_radians = radians(self.inclination_degrees)
self.raan_radians = radians(self.raan_degrees)
self.arg_perigee_radians = radians(self.arg_perigee_degrees)
self.mean_anomaly_radians = radians(self.mean_anomaly_degrees)
self.mean_motion_radians_per_second = 2 * pi * self.mean_motion_orbits_per_day / 86400
xpdotp = 1440.0 / (2.0 *pi) # 229.1831180523293
self.mean_motion_radians_per_minute = self.mean_motion_orbits_per_day / xpdotp
if (self.designation and not self._id_launch_year):
try:
self._id_launch_year = int(self.designation[2:4])
if (self._id_launch_year >= 57):
self._id_launch_year = 1900 + self._id_launch_year