pythoncoordinate-systemsastropy

How do I use Astropy to transform coordinates from J2000 to Lat, Lon, and Altitude


I've followed the instructions from questions present on this site pertaining to this issue, but the code all seems off. For one thing, the altitude seems far too low, and it doesn't appear that the time I set impacts the location substantially, which it should since as I understand the J2000 frame is time sensitive.

Here is the code I'm running in VSCODE:

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

now = Time("2024-03-07 00:46:00.000", scale='utc')
xyz = [1155.746046202530, -6632.420367726780, 953.533229633281]
cartrep = coord.CartesianRepresentation(*xyz, unit=u.m)



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

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

This returns -1d21m45.24750203s 103d26m20.83691865s -6371417.547754194 m, which I'm not certain is correct. The altitude is close to the surface of the earth when it should be nearly 500 km higher. And it doesn't seem the time affects it greatly. These coordinates and times are all based on the ISS Trajectory Data from: https://spotthestation.nasa.gov/trajectory_data.cfm


Solution

  • Your units are incorrect. It should be kilometers:

    cartrep = coord.CartesianRepresentation(*xyz, unit=u.km)
    

    That will give you

    8d07m57.90049783s 103d26m20.84968463s 421.84457018512904 km
    

    From the linked webpage with the ephemeris (emphasis mine):

    After the header, ISS state vectors in the Mean of J2000 (J2K) reference frame are listed at four-minute intervals spanning a total length of 15 days. During reboosts (translation maneuvers), the state vectors are reported in two-second intervals. Each state vector lists the time in UTC; position X, Y, and Z in km; and velocity X, Y, and Z in km/s.


    The real question is where you get data for 2024-03-07 00:46:00.000 from; I can only see data for the 44 and 48 minutes past midnight (UTC) timestamps on that day. And looking at the X, Y, Z data and doing a guess-interpolation, I don't get input values near yours for the 46 minutes past midnight timestamp.