skyfielders / python-skyfield

Elegant astronomy for Python
MIT License
1.41k stars 211 forks source link

RuntimeWarning: invalid value encountered in double_scalars at line 70 in earthlib.py #294

Closed bismurphy closed 4 years ago

bismurphy commented 4 years ago

Hi, I'm trying to do some satellite propagation. I ran into some issues with my script, so I pulled up a skyfield example to make sure I'm not coding wrong. Here's the code:

from skyfield.api import EarthSatellite, Topos, load

ts = load.timescale()
t = ts.now()

line1 = '1 25544U 98067A   14020.93268519  .00009878  00000-0  18200-3 0  5082'
line2 = '2 25544  51.6498 109.4756 0003572  55.9686 274.8005 15.49815350868473'

boston = Topos('42.3583 N', '71.0603 W')
satellite = EarthSatellite(line1, line2, name='ISS (ZARYA)')

# Geocentric

geometry = satellite.at(t)

# Geographic point beneath satellite

subpoint = geometry.subpoint()
latitude = subpoint.latitude
longitude = subpoint.longitude
elevation = subpoint.elevation
print(latitude)
print(longitude)

This gives:

Warning (from warnings module):
  File "C:\PythonPath\Python\Python37-32\lib\site-packages\skyfield\earthlib.py", line 70
    lon = (arctan2(y, x) - 15 * DEG2RAD * gast - pi) % tau - pi
RuntimeWarning: invalid value encountered in double_scalars

and the latitude and longitude values that get printed are NaN's. I uninstalled and reinstalled Skyfield, which didn't help.

brandon-rhodes commented 4 years ago

The underlying problem is that those satellite elements are only valid for a few weeks around a date back in 2014:

print(satellite.epoch.utc_jpl())

Prints:

A.D. 2014-Jan-20 22:23:04.0004 UT

For satellite propagation to return nan so many weeks from the date of the elements is normal and expected.

What's a bit more confusing is the exception, which I've never seen before; your script on my computer simply prints nan twice without any exception. If you're curious why a nan calculation causes that exception on your platform, you might try searching Stack Overflow; it looks like it might be something specific to Windows?

brandon-rhodes commented 4 years ago

I'm going to close this for now since I don't have a way to reproduce it on my own machine, but if you have concerns that my answer last week didn't address, simply re-open the issue and follow up with more information. Thanks!