0

I am trying to use AstroPy to convert coordinates for a satellite from ECI to Latitude, Longitude, and Altitude at a given time. However, I cannot get the time part to work with AstroPy obstime. I'm not sure if it's a syntax error for the UTC time or something else.

'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)

My inputs: (Position(x=-2686197.0596728502, y=-6402017.6107924329, z=10956.564679617248))

Rose
  • 279
  • 1
  • 7
  • 20

1 Answers1

2

The solution is similar to the answer to your previous question How to convert Earth Centered Inertial (ECI) coordinates to Earth Centered Earth Fixed (ECEF) AstroPy? Other?

obstime needs to be passed to the ITRS() class:

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

So, in full (I copied the xyz coordinates from your question because I don't see a definition for 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)
ampw
  • 175
  • 10