Skyfield far slower than ephem
See original GitHub issueI wrote a small script to match sightings with satellites via their TLE.
The script using skyfield is about 80x slower than the same using ephem.
My question is: can this be improved? Am I using skyfield wrong here?
#!/usr/bin/python3
import sys
import datetime
from skyfield.api import load, utc, Topos
satlist = load.tle_file(sys.argv[1])
ts = load.timescale(builtin=True)
tim=float(sys.argv[2])/1000.
lat=float(sys.argv[3])
lon=float(sys.argv[4])
alt=int(sys.argv[5])*1000
time_t = datetime.datetime.utcfromtimestamp(tim)
time_t = time_t.replace(tzinfo=utc)
t = ts.utc(time_t)
mysat=Topos(latitude_degrees=lat, longitude_degrees=lon, elevation_m=alt)
my=mysat.at(t)
minsep=9e9
sname=None
for sat in satlist:
pos=sat.at(t)
sep=pos.separation_from(my).degrees
if sep<minsep:
sname=sat.name
minsep=sep
print("Minimum: %4.2f: %s"%(minsep/1000,sname))
vs. similar code with ephem:
#!/usr/bin/python3
import sys
import math
import datetime
import ephem
degrees_per_radian = 180.0 / math.pi
satlist = loadTLE(sys.argv[1])
tim=float(sys.argv[2])/1000.
lat=float(sys.argv[3])
lon=float(sys.argv[4])
t = datetime.datetime.utcfromtimestamp(tim)
minsep=9e9
sname=None
for sat in satlist:
sat.compute(t)
sep=ephem.separation((sat.sublong,sat.sublat),(lon/degrees_per_radian,lat/degrees_per_radian))*degrees_per_radian
if sep<minsep:
sname=sat.name
minsep=sep
print("Minimum: %4.2f: %s"%(minsep,sname))
As a datapoint: using a TLE file with 75 satellites, and running in a 1000x loop, I get runtimes of 0.17s for ephem vs. 14s for skyfield.
Is a way to optimize/speed up what I’m doing with skyfield?
Thanks, Sec
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (12 by maintainers)
Top Results From Across the Web
calculation speed worst than pyepehm? · Issue #30 - GitHub
I am translating pyephem code to skyfield and I have noticed pyephem calculation run at least at 30x faster than skyfield one. My...
Read more >Positions — Skyfield documentation - Rhodes Mill
As an example, let's use an ephemeris to compute a geocentric position for Mars: ... To learn about them, the beginner will probably...
Read more >Discrepancy between PyEphem and Skyfield HA/dec results
It looks like you are asking Skyfield for astrometric positions, but PyEphem for apparent positions. According to the PyEphem documentation:.
Read more >What is ephem's body size attribute equivalent in Skyfield?
As far as I know, Skyfield itself doesn't contain any tabulated data on astronomical bodies itself†. Instead, it allows you to draw data ......
Read more >Shallow Thoughts : tags : python
NEOWISE is by far the best comet I've seen since Hale-Bopp. ... At first I tried using Skyfield, the Python library which is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, that’s indeed true, and we could avoid that call by stashing the value somewhere, maybe on the
Time
object. I even did a quick experiment to do so during that recent performance work, but:TEME_to_ITRF()
routine. In particular, it will raise the question of what we cache: the theta angle itself, which would make us compute the matrices over and over again? Or would we cache the matrices, at 9× the RAM cost?All of which has led to my holding off on caching that time unit for now. But it’s not impossible to imagine that in the near future that some kind of caching could take place in case a
Time
is used on several satellites; but as it will be a small gain, I would rather take our time with the design.@brandon-rhodes Thank you for the pointer to timelib.py showing the use of
@reify
. I have a new level of appreciation for the work that goes into converting coordinates!