danielk333 / pyorb

Python implementation of the definition of Kepler orbits and related transformations, nothing more, nothing less.
https://danielk.developer.irf.se/pyorb/
MIT License
9 stars 1 forks source link

PyOrb

PyOrb is a lightweight package designed to convert back and forth between cartesian and kepler coordinates seamlessly and in a physically consistent manner, following defined rules. It provides a convenience class for handling orbits and is tested for special cases such as planar and circular orbits.

See full documentation here.

Example interactive orbit

Feature list

Current features:

On the upcoming feature list:

To install

pip install pyorb

or to do the "nightly" build:

git clone https://github.com/danielk333/pyorb
cd pyorb
git checkout develop
pip install .

Alternatively, if you are following updates closely you can install using pip install -e . so that in the future a git pull will update the library.

Example

import pyorb

orb = pyorb.Orbit(M0 = pyorb.M_sol, degrees=True)
orb.update(a=1*pyorb.AU, e=0, i=0, omega=0, Omega=0, anom=0)

# Convert and get cartesian elements
print(orb.cartesian)

# Make eccentric and place at aphelion
orb.e = 0.2
orb.anom = 180

# print cartesian position in AU at aphelion after the above changes
print(orb.r/pyorb.AU)

To develop

First clone and branch off develop

git clone https://github.com/danielk333/pyorb
cd pyorb
git checkout develop
git checkout -b my-name/my-feature

then editable install with development extras and install the pre-commit hooks

pip install -e .[develop]
pre-commit install

and get to hacking!

Internal development

Please refer to the style and contribution guidelines documented in the IRF Software Contribution Guide.

External code-contributions

Generally external code-contributions are made trough a "Fork-and-pull" workflow towards the develop branch.

Ellipse and angle definitions

Variables:

Orientation of the ellipse in the coordinate system and angle definitions:

Notes

Disabling direct conversion

There are two toggle flags in the pyorb.Orbit class for changing the conversion behavior: direct_update and auto_update that are True by default.

Disabling direct_update will stop automatic conversion between elements if any element is changed. This would allow for e.g.

orb.a = 1
orb.omega = 0

without any conversion to be done. However, as the kepler elements changed, the class has internally tracked this change and if auto_update=True once an access to a cartesian property is performed, e.g. print(orb.x), the conversion is performed so that the pair of cartesian-kepler elements are never contradictory.

If also auto_update is disabled, the update between kepler and cartesian needs to be manually by calling

orb.calculate_cartesian()

or

orb.calculate_kepler()

Using conversion functions directly

The pyorb.cart_to_kep or pyorb.kep_to_cart uses True anomaly and takes only numpy arrays ordered as per the function documentation.

Frames

Remember that an Keplerian orbit only makes sense in an inertial frame if gravitation dominated physics is your concern.

Array orbits

Rebound

The very excellent multi-purpose N-body integrator rebound has also implemented conversion from their particles to orbital elements. Important to note is that their conventions differ somewhat from ours by:

otherwise the orbit routines should produce identical results.