skyfielders / python-skyfield

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

planetary_magnitude() failes for Saturn #739

Closed AndyM15 closed 2 years ago

AndyM15 commented 2 years ago

Following code (which is based on the "Charting an apparition of Venus" code at the homepage of skyfield) fails for Saturn, as planetary_magnitude() seems not to support the list t for Saturn.

from skyfield import almanac
from skyfield.api import load, wgs84
from skyfield.magnitudelib import planetary_magnitude

eph = load('de421.bsp')
earth, sun, saturn = eph['earth'], eph['sun'], eph['saturn barycenter']

observer = wgs84.latlon(+40.0, 0.0)
ts = load.timescale()
start, end = ts.utc(2021, 3, 7), ts.utc(2022, 3, 7)

f = almanac.sunrise_sunset(eph, observer)
t, y = almanac.find_discrete(start, end, f)
apparent = (earth + observer).at(t).observe(saturn).apparent()

m = planetary_magnitude(apparent)

Result into following error output:

Traceback (most recent call last):
  File "test.py", line 16, in <module>
    m = planetary_magnitude(apparent)
  File "C:\ProgramData\Anaconda3\lib\site-packages\skyfield\magnitudelib.py", line 83, in planetary_magnitude
    a = angle_between(_SATURN_POLE, sun_to_planet)
  File "C:\ProgramData\Anaconda3\lib\site-packages\skyfield\functions.py", line 66, in angle_between
    a = u * length_of(v)
ValueError: operands could not be broadcast together with shapes (3,) (730,) 
brandon-rhodes commented 2 years ago

Thanks for the report! I've improved the test cases to catch this situation, and have landed a fix, now that I'm back from the PyCon conference in Salt Lake City (which is what delayed my response to your issue). To install the development version of Skyfield and try out the fix ahead of the next real release, you could run:

pip install -U https://github.com/skyfielders/python-skyfield/archive/master.zip