Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually add orbits to Orbit() #348

Open
2 of 5 tasks
jrob93 opened this issue Jun 16, 2022 · 2 comments
Open
2 of 5 tasks

Manually add orbits to Orbit() #348

jrob93 opened this issue Jun 16, 2022 · 2 comments
Labels
feature request request for new functionality

Comments

@jrob93
Copy link

jrob93 commented Jun 16, 2022

This is a request for

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

The requested changes will be implemented by

  • 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 jrob93 added the feature request request for new functionality label Jun 16, 2022
@mkelley
Copy link
Member

mkelley commented Jun 16, 2022

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

@jrob93
Copy link
Author

jrob93 commented Jun 16, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request request for new functionality
Projects
None yet
Development

No branches or pull requests

2 participants