NASA-Planetary-Science / sbpy

A Python package for small bodies research
https://sbpy.org/
Other
67 stars 34 forks source link

Orbit type lost after Orbit.oo_transform #341

Open mkelley opened 2 years ago

mkelley commented 2 years ago
from astropy.time import Time
from sbpy.data import Orbit

orbit = Orbit.from_mpc('2P')
orbit['targetname'] = '2P'
orbit['orbtype'] = 'COM'   # cometary style orbit with q, Tp (otherwise use KEP with a, M)
orbit['H'] = 15 * u.mag
orbit['G'] = 0.15
print(orbit['orbtype'])

# propagate the orbit forward to 2026 with openorb
future_orbit = orbit.oo_propagate(Time('2026-06-06'))
print(future_orbit['orbtype'])

Output

orbtype
-------
    COM
orbtype
-------
    2.0

Instead of 2.0, it should have been COM.

jrob93 commented 2 years ago

I noticed this recently too because I was trying to propagate an orbit to multiple Time objects and it would just hang mysteriously:

from astropy.time import Time
from sbpy.data import Orbit

orbit = Orbit.from_horizons('Ceres')
orbit["orbtype"] = "KEP"
print(orbit['orbtype'])

# propagate the orbit forward to 2026 with openorb
times = Time(['2024-06-06','2025-06-06','2026-06-06'])
future_orbit = orbit.oo_propagate(times)
print(future_orbit['orbtype'])

Silly hack is to do one timestep at a time and drop (or overwrite) the orbtype:

# propagate the orbit forward to 2026 with openorb
times = Time(['2024-06-06','2025-06-06','2026-06-06'])
for i in range(len(times)):
    print(i)
    future_orbit = orbit.oo_propagate(times[i]) # propagate the orbit one time step
    del future_orbit.table["orbtype"] # orbtype is added as int, sbpy freaks out so delete the orbtype and then _to_oo works it out
    statevec = future_orbit.oo_transform('CART') # transform from orbital elements to cartesian
    print(statevec.table[["epoch","x","y","z"]])