sbpy icon indicating copy to clipboard operation
sbpy copied to clipboard

Manually add orbits to Orbit()

Open jrob93 opened this issue 2 years ago • 2 comments

This is a request for

  • [ ] a new feature
  • [x] an enhancement to existing sbpy functionality
  • [ ] somethings else: [explain here]

The requested changes will be implemented by

  • [x] me (I could give it a go...)
  • [ ] the sbpy developers

High-level concept Add the ability to initialise an Orbit() object from a table/dataframe containing orbital elements.

Explain the relevance to sbpy sbpy Orbit() documentation only references from_mpc and from_horizons as the way to set up an orbit (unless I've missed something).

Proposal details It is possible to create an empty Orbit() instance and fill the fields manually, this would probably just need a wrapper function. This functionality would be handy for dealing with simulated orbits, e.g. the LINCC Simulated Solar System Products Data Base

Example (pseudo-)code e.g. from dataframe

df_orb = ... # pandas dataframe with orbital element fields ["a","e","incl","Omega","w","M"]

elem = Orbit() # empty orbit instance

Fill fields (remember astropy units):

orb_col = list(df_orb)]
orb_unit = [u.au,u.dimensionless_unscaled,u.deg,u.deg,u.deg,u.deg]
for i in range(len(orb_col)):
    elem[orb_col[i]] = df_orb[orb_col[i]] * orb_unit[i]

Add extra required fields:

elem["epoch"] = Time(...)
elem["targetname"] = ...
elem["H"] = ... * u.mag
elem["G"] = ... * u.dimensionless_unscaled

jrob93 avatar Jun 16 '22 13:06 jrob93

Thanks, @jrob93 . I actually have an active pull request that aims to improve the documentation and this could be a good example. Or maybe for our tutorial repository. (We definitely need this in the SSSC technical documentation.)

I think the main problem with the pandas dataframe is that it lacks (astropy) units, right? But we can go through an astropy QTable. How about something like this:

from astropy.table import QTable
tab = QTable.from_pandas(df_orb, units={'a': u.au, 'incl': u.deg, 'Omega': u.deg, 'w': u.deg, 'M': u.deg})
orbits = Orbit.from_table(tab)

QTable.from_pandas can handle time objects, too, but I don't understand dataframes well enough to experiment with it right now: https://docs.astropy.org/en/stable/api/astropy.table.Table.html#astropy.table.Table.from_pandas

mkelley avatar Jun 16 '22 14:06 mkelley

Ah cool, that's much better using QTable. I've never really used tables before because I was more familiar with pandas when I started learning astropy type things, but yes the units are easier with tables. I'm nearly finished the notebook you requested for the SSSC technical docs so I'll use those lines in it.

jrob93 avatar Jun 16 '22 14:06 jrob93