question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

\lib\site-packages\skyfield\functions.py:77: RuntimeWarning

See original GitHub issue

Hello Brandon,

Today I was working with the Skyfiled, and I’ve got the following warning. I believe you should handle the exception.

e = ephemeris[399]
obj = ephemeris[399]
coordinates = e.at(t).observe(obj).radec()

.\lib\site-packages\skyfield\functions.py:77: RuntimeWarning: invalid value encountered in double_scalars theta = arcsin(z / r)

You might be asking why I am calculating geocentric astrometric coordinates of earth !!

Actually, I do not, It was happened by mistake. Then I got curious and I checked geocentric astrometric position as below:

e = ephemeris[399]
obj = ephemeris[399]
positions = e.at(t).observe(obj).position.au

And the result was successful [0.0, 0.0, 0.0]. As logically, we can guess.

Finally, I guess you should handle the exception somewhere in your code to get off that warning in the previous code and get a logical result. (Maybe it is a division by zero exception).

Best,

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
brandon-rhodescommented, Dec 12, 2020

I guess you should handle the exception somewhere in your code to get off that warning

The message, it turns out, is a warning and not an exception. There are two big differences. First: the program keeps going, as can be confirmed with a print.

from skyfield.api import load
ts = load.timescale()
t = ts.now()
ephemeris = load('de421.bsp')
e = ephemeris[399]
obj = ephemeris[399]
coordinates = e.at(t).observe(obj).radec()
print(coordinates)

This results in:

/home/brandon/skyfield/skyfield/functions.py:77: RuntimeWarning: invalid value encountered in double_scalars
  theta = arcsin(z / r)
(<Angle 00h 00m 00.00s>, <Angle nan>, <Distance 0.0 au>)

Since the print() runs, the program survived and did not encounter an exception.

Second: because this is not an exception, it cannot be caught. If you will try putting a try…except around the statement yourself, I think you will be able to confirm that you cannot catch the warning; it is transparent to the Skyfield code.

There is probably a way to ask NumPy to promote warnings to exceptions, but in general libraries like Skyfield are not supposed to set global NumPy options for their own purposes; instead, end-user code is supposed to be in full control.

My understanding, then, is that there is nothing Skyfield can do that will improve the situation? Please run your own checks and see if I am correct. If I am wrong, then simply provide the sample code that you think Skyfield should run that handles this case differently, and we can try it out. Thanks!

0reactions
reza-ghazicommented, Dec 14, 2020

Of course. Thank you. Until then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

invalid value encountered in double_scalars at line 70 in ...
Hi, I'm trying to do some satellite propagation. I ran into some issues with my script, so I pulled up a skyfield example...
Read more >
RuntimeWarning: invalid value encountered in greater
Your problem is caused by the NaN or Inf elements in your out_vec array. You could use the following code to avoid this...
Read more >
Skyfield — documentation - Rhodes Mill
Elegant Astronomy for Python. Skyfield computes positions for the stars, planets, and satellites in orbit around the Earth. Its results should agree with ......
Read more >
Python Tutorial
Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach ...
Read more >
1. Whetting Your Appetite
function or module to the interpreter, either to perform critical operations at maximum speed, or to link Python programs to libraries that may...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found