hannorein / rebound

💫 An open-source multi-purpose N-body code.
https://rebound.readthedocs.io/
GNU General Public License v3.0
824 stars 218 forks source link

Horizons ambiguous input errors in unexpected line #620

Closed danielk333 closed 1 year ago

danielk333 commented 1 year ago

Hey,

i noticed that a script using rebound and horizons retrieval of states, that previously worked, now fails.

Running

import rebound

date = '2022-01-01 00:00'
bodies = [
    'Sun', 'Mercury', 'Venus',
    'Earth', 'Mars', 'Jupiter', 
    'Saturn', 'Uranus', 'Neptune',
]

sim = rebound.Simulation()
sim.units = ('yr', 'AU', 'Msun')

for body in bodies:
    sim.add(body, date=date)

generates

Searching NASA Horizons for 'Sun'... 
Found: Sun (10) 
Searching NASA Horizons for 'Mercury'... 
Traceback (most recent call last):
  File "/home/danielk/python_scripts/projects/phd_defense/solar_system.py", line 29, in <module>
    sim.add(body, date=date)
  File "/home/danielk/git/rebound/rebound/simulation.py", line 1355, in add
    self.add(horizons.getParticle(particle, **kwargs), hash=particle)
  File "/home/danielk/git/rebound/rebound/horizons.py", line 139, in getParticle
    p.x, p.y, p.z = [float(i) for i in lines[2].split()]
ValueError: not enough values to unpack (expected 3, got 0)

I assumed this was due to ambiguities in the names that appeared since last time and sure enough changing the input names to

bodies = [
    'Sun', 'Mercury Barycenter', 'Venus Barycenter',
    'Earth', 'Mars', 'Jupiter', 
    'Saturn Barycenter', 'Uranus Barycenter', 'Neptune Barycenter',
]

makes it work again, just thought id post it here in case someone becomes confused by the error message. Also it might be a good idea to make the case of ambiguous input raise an appropriate error :)

hannorein commented 1 year ago

Thanks for reporting this. It seems like the NASA Horizons API has changed.

hannorein commented 1 year ago

I think this is actually a bug in the NASA Horizons system, not REBOUND. Or at least their documentation is not correct. I'll file a bug report with them.

hannorein commented 1 year ago

Got a confirmation from Alan Chamberlin that this is a NASA Horizons bug and that they are working on a fix! Keeping this open for now in case their fix requires us to change something too....

danielk333 commented 1 year ago

Awesome, thanks for the further investigation!

Findus23 commented 1 year ago

I really didn't expect NASA Horizons to break before my API parsing code...

hannorein commented 1 year ago

Seems they have fixed the issue already...