3

I'm trying to transform the coordinates of the ISS (x, y, z in km in J2000 frame) with astropy. The goal is to get an EarthLocation object with the latitude, longitude (geocoordinates) and the height above of Earth. Therefore, I transform the coordinates from J2000 to ITRS and then to an EarthLocation object.

With the code below, I would expect to get a result similar to "33d48m42.99930589s -167d12m27.04542887s 419.72854842620103 km". Instead, I get "-12d07m30.58291072s -81d47m17.54396528s 149126429.9876054 km":

    from astropy import coordinates as coord
    from astropy import units as u
    from astropy import time
    from astropy.time import Time
    from astropy.coordinates import SkyCoord
    
    xyz = [-2415.481355926250, -5107.787275649850, 3767.949519775400]
    now = time.Time('2022-02-16 17:41:39.000', scale='utc') #Time in UTC for xyz
    
    
    ctest = SkyCoord(*xyz, unit='km', representation_type='cartesian')
    ittest = ctest.transform_to(coord.ITRS(obstime=now))
    lt = coord.EarthLocation(ittest.x, ittest.y, ittest.z)
    print(lt.lat, lt.lon, lt.height)`

So where do I go wrong on my way to geocoordinates?

EDIT: After applying the comment from Iguananaut and setting the frame for the SkyCoord object, I get better results:

    ctest = SkyCoord(*xyz, unit='km', representation_type='cartesian', frame=coord.ITRS(obstime=now))
    lt = coord.EarthLocation(ctest.x, ctest.y, ctest.z)
    print(lt.lat, lt.lon, lt.height)

Result: 33d51m55.03376088s -115d18m34.37004873s 419.74690981022917 km

So the height is now within tolerance, and latitude is closer. But there still seems to be a problem with the longitude.

C Mag
  • 31
  • 3
  • `representation_type` is just the coordinate basis being used, but you still need to give `SkyCoord` a frame of reference (otherwise it's "3000km from...???". Actually the default frame is `ICRS`. You might want to try `frame='itrs'` – Iguananaut Feb 19 '22 at 00:41
  • Or, more simply, I should say pass `frame=coord.ITRS(obstime=now)`. You don't need to use `transform_to` because that's for transforming to different frames. If you want to change the representation to spherical coordinates you an do `c.represent_as('spherical')` – Iguananaut Feb 19 '22 at 00:50
  • Thank you so much! This helped a lot! As mentioned in the Edit, the results are now better, but there's still a huge deviation with the longitude. – C Mag Feb 19 '22 at 16:51

0 Answers0