AstroPy 的 Obstime 语法? Python坐标转换的UTC时间

Obstime Syntax for AstroPy? Python UTC time for coordinate conversion

我正在尝试使用 AstroPy 在给定时间将卫星坐标从 ECI 转换为纬度、经度和高度。但是,我无法获得与 AstroPy obstime 一起工作的时间部分。我不确定这是 UTC 时间的语法错误还是其他原因。

'New Method #1: ECI --> Lat, Lon, Alt'
from astropy import coordinates as coord
from astropy import units as u
from astropy import time
from astropy.time import Time

xyz = (orbitPineapple.r.x, orbitPineapple.r.y, orbitPineapple.r.z)      #position of satellite in GCRS or J2000 ECI
now = time.Time('2017-09-28 16:53:40') #Time in UTC for xyz
cartrep = coord.CartesianRepresentation(*xyz, unit=u.m) #adding units of [m] to xyz

gcrs = coord.GCRS(cartrep, obstime=now)
itrs = gcrs.transform_to(coord.ITRS, obstime=now)
loc = coord.EarthLocation(*itrs.cartesian.xyz)

print(orbitPineapple.r)
print('')
print(loc.lat, loc.lon, loc.height)

我的输入:(位置(x=-2686197.0596728502,y=-6402017.6107924329,z=10956.564679617248))

解决方案与您上一个问题的答案相似

obstime 需要传递给 ITRS() class:

itrs = gcrs.transform_to(coord.ITRS(obstime=now))

所以,完整(我从你的问题中复制了 xyz 坐标,因为我没有看到 orbitPineapple 的定义)

from astropy import coordinates as coord
from astropy import units as u
from astropy import time
from astropy.time import Time

xyz = [-2686197.0596728502, -6402017.6107924329, 10956.564679617248]
now = time.Time('2017-09-28 16:53:40') #Time in UTC for xyz
cartrep = coord.CartesianRepresentation(*xyz, unit=u.m) #adding units of [m] to xyz

gcrs = coord.GCRS(cartrep, obstime=now)
itrs = gcrs.transform_to(coord.ITRS(obstime=now))
loc = coord.EarthLocation(*itrs.cartesian.xyz)

print('')
print(loc.lat, loc.lon, loc.height)