Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 format_long_line(satrec, tsince, mu, r, v):
"""Long line, using the same format string that testcpp.cpp uses."""
short = format_short_line(tsince, r, v).strip('\n')
jd = satrec.jdsatepoch + satrec.jdsatepochF + tsince / 1440.0
year, mon, day, hr, minute, sec = invjday(jd)
(p, a, ecc, incl, node, argp, nu, m, arglat, truelon, lonper
) = rv2coe(r, v, mu)
return short + (
' %14.6f %8.6f %10.5f %10.5f %10.5f %10.5f %10.5f'
' %5i%3i%3i %2i:%2i:%9.6f\n'
) % (
a, ecc, incl*rad, node*rad, argp*rad, nu*rad,
m*rad, year, mon, day, hr, minute, sec,
)
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")
instant of the creation of the object."""
self.time = datetime.utcnow()
self.timevars_from_datetime()
elif (self.time):
""" Creates a date object, t1, initialized to the time,
which can be in either Julian date or TLE format."""
if (self.time < 2400000): # this date is in tle format
self.tle = self.time
self.time = datetime_from_tle_fmt(self.tle)
self.timevars_from_datetime()
self.jd = myjday(self.yy, self.mm, self.dd, self.hr, self.mm, self.ss)
self.sidereal()
else: # this date is julian
self.jd = self.time
self.calcmjd()
(self.yy, self.mm, self.dd, self.hr, self.mn, self.ss) = invjday(self.jd)
self.sidereal()
(_, subsec) = divmod(self.ss,1)
subsec = int(subsec*1E6)
intss = int(self.ss)
self.time = datetime(self.yy,self.mm,self.dd,self.hr,self.mn,intss,subsec)
elif (self.yy):
""" Creates a date object, t1, initialized to the calendar date and
time passed by the six calendar variables """
# TODO: Deal with other variables potentially being "None"
(_, subsec) = divmod(self.ss,1)
subsec = int(subsec*1E6)
intss = int(self.ss)
self.time = datetime(self.yy,self.mm,self.dd,self.hr,self.mn,intss,subsec)
else:
# Shouldn't ever get here, default is to create the current time
pass