skyfielders / python-skyfield

Elegant astronomy for Python
MIT License
1.43k stars 213 forks source link

Velocity of Earth Satellite Loaded from TLE #187

Closed dsholes closed 6 years ago

dsholes commented 6 years ago

I'm trying to get the velocity of an EarthSatellite loaded from a TLE. For example:

from skyfield.api import Topos, load
import numpy as np

ts = load.timescale()
stations_url = 'http://celestrak.com/NORAD/elements/planet.txt'
satellites = load.tle(stations_url,reload=True,)
cubesat = satellites['FLOCK 2K-08']
t = ts.now()
print(cubesat.at(t).velocity.km_per_s)

But this returns [0., 0., 0.]. Note that cubesat.at(t).position, cubesat.at(t).subpoint() both behave as expected. Am I misunderstanding what cubesat.at(t).velocity is supposed to return?

brandon-rhodes commented 6 years ago

Velocity is not yet supported; when I wrote that code, I knew how to rotate the position into GCRS coordinates, but not how to rotate the velocity:

        rITRF, vITRF = TEME_to_ITRF(t.ut1, rTEME, vTEME)
        rGCRS = ITRF_to_GCRS(t, rITRF)
        vGCRS = zeros_like(rGCRS)  # todo: someday also compute vGCRS?

If the holiday tomorrow gives me some free time, I might look at whether I can figure out the transformation and return something other than zeros!

brandon-rhodes commented 6 years ago

Oh — I should ask for a clarification: are you interested in the satellite's velocity relative to a non-rotating observer watching the rotating Earth from a distance? Or in its velocity relative to a location on Earth which is itself veering constantly in a circle at high speed?

dsholes commented 6 years ago

Thank you for the quick response! I'm interested in its velocity relative to a location on earth. I think vITRF would be enough for me, but since you're returning everything else in GCRS, it would be nice to have that as well.

By the way, I think it has already been asked in Issue #85, but is there a reason you don't offer a method to return rITRF and vITRF, considering you're often already calculating them?

I'm new to skyfield but I'm really enjoying it so far. The code and documentation is very clean and easy to follow. Thank you for all of your work!

ghost commented 6 years ago

The SPICE routine xf2rav() may be helpful here. It's documented at:

https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xf2rav_c.html

and should be available in the source code. It's description is "This routine determines a state transformation matrix from a rotation matrix and the angular velocity of the rotation."