I'm trying to calculate satellite orbit from the TLE set at first, I used several libraries including SGP4, Skyfiled to get the initial position and velocity of the satellite at the epoch time I know that both provide position and velocity in the TEME(True Equator Mean Equinox) reference frame then I used astropy to convert to ITRS reference frame(the target) but the final r,v is not as expected.
The expected state vector is:
(-5443.785402, 3893.913532, 0.005474) km
( -2.493203, -3.506504, 6.055634) km/sec
but I get:
(-5443.81607435, 3893.87064814, 0.01495843) km
( -2.77711623, -3.90350078, 6.0556312) km/sec
The code is as follow:
from skyfield.api import EarthSatellite, load, wgs84
import update_tle_v1 as tle
from astropy import coordinates as coord
from astropy import units as u
from astropy.time import Time
#gitting tle from file
file = 'satellite.txt'
tle = tle.UpdateTle()
lines = tle.from_txt(file, True)
analyzed = tle.analyze_tle(lines)
s, t = lines[-2], lines[-1]
epochyr = analyzed[1][4]
epochdays = analyzed[1][5]
year = int('20' + epochyr)
month, day, hour, minute, second = tle.epoch(epochyr, epochdays)
ts = load.timescale()
line1 = s
line2 = t
satellite = EarthSatellite(line1, line2, 'satellite', ts)
print(satellite.epoch.utc_jpl())
#---------------------position, velocity---------------------------
t = ts.utc(year, month, day, hour, minute, second)
geocentric = satellite.at(t)
r = geocentric.position.km
v = geocentric.velocity.km_per_s
print(r)
print(v)
#epoch time
now = Time('2021-11-5 7:59:44.801')
# position of satellite in GCRS or J20000 ECI:
cartrep = coord.CartesianRepresentation(x=r[0],
y=r[1],
z=r[2],
unit=u.km)
gcrs = coord.GCRS(cartrep, obstime=now)
position = gcrs.transform_to(coord.ITRS(obstime=now))
cartrep = coord.CartesianRepresentation(x=v[0],
y=v[1],
z=v[2],
unit=u.km)
gcrs = coord.GCRS(cartrep, obstime=now)
velocity = gcrs.transform_to(coord.ITRS(obstime=now))
print(position, '\n', velocity, sep='')