Skip to content

Commit

Permalink
Fixes horizon units. See issue #767
Browse files Browse the repository at this point in the history
  • Loading branch information
hannorein committed Apr 19, 2024
1 parent d122fc1 commit 23af96f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions rebound/horizons.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import re
import warnings
import sys
from .units import convert_mass

HORIZONSBASEURL = "https://ssd.jpl.nasa.gov/api/horizons.api?"

Expand Down Expand Up @@ -65,7 +66,7 @@ def api_request(particle, datestart, dateend, plane):
return body


def query_horizons_for_particle(particle=None, m=None, x=None, y=None, z=None, vx=None, vy=None, vz=None, primary=None, a=None,
def query_horizons_for_particle(mass_unit=None, particle=None, m=None, x=None, y=None, z=None, vx=None, vy=None, vz=None, primary=None, a=None,
anom=None, e=None, omega=None, inc=None, Omega=None, MEAN=None, date=None, plane="ecliptic", hash=0):
if plane not in ["ecliptic", "frame"]:
raise AttributeError(
Expand Down Expand Up @@ -152,7 +153,11 @@ def query_horizons_for_particle(particle=None, m=None, x=None, y=None, z=None, v
else:
print("Found body (Name could not be detected)")
if m is not None:
p.m = m
if mass_unit is not None:
p.m = convert_mass(m, mass_unit, "kg")
else:
## Assume kg
p.m = m
elif idn is not None:
try:
p.m = float(
Expand Down
3 changes: 2 additions & 1 deletion rebound/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,8 @@ def add(self, particle=None, **kwargs):
if "frame" not in kwargs:
if hasattr(self, 'default_plane'):
kwargs["plane"] = self.default_plane # allow ASSIST to set default plane
self.add(horizons.query_horizons_for_particle(particle, **kwargs), hash=particle)
mass_unit = hash_to_unit(self.python_unit_m) # For manually provided masses
self.add(horizons.query_horizons_for_particle(mass_unit, particle, **kwargs), hash=particle)
units_convert_particle(self.particles[-1], 'km', 's', 'kg', hash_to_unit(self.python_unit_l), hash_to_unit(self.python_unit_t), hash_to_unit(self.python_unit_m))
else:
raise ValueError("Argument passed to add() not supported.")
Expand Down

0 comments on commit 23af96f

Please sign in to comment.