API reference

KeplerOrbit

KeplerOrbit.cart2kep(X, Y, Z, vx, vy, vz, m1, m2)

Convert an array of cartesian positions and velocities (in heliocentric coordinates) to an array of kepler orbital elements. Units are such that G=1. This function is fully vectorized.

Parameters:
  • X (numpy array of floats) – X position of body
  • Y (numpy array of floats) – Y position of body
  • Z (numpy array of floats) – Z position of body
  • vx (numpy array of floats) – x velocity of body
  • vy (numpy array of floats) – y velocity of body
  • vz (numpy array of floats) – z velocity of body
  • m1 (float) – mass of central body
  • m2 (numpy array of floats) – mass of orbiting body
Returns:

a, e, inc, asc_node, omega, M - Semimajor axis, eccentricity inclination, longitude of ascending node, longitude of perihelion and mean anomaly of orbiting body

Return type:

numpy array of floats

KeplerOrbit.kep2cart(sma, ecc, inc, Omega, omega, M, mass, m_central)

Convert a single set of kepler orbital elements into cartesian positions and velocities. Units are such that G=1.

Parameters:
  • sma (float) – semi-major axis body
  • ecc (float) – eccentricity of body
  • inc (float) – inclination of body
  • Omega (float) – longitude of ascending node of body
  • omega (float) – longitude of perihelion of body
  • M (float) – Mean anomaly of body
  • mass (float) – mass of body
  • m_central (float) – mass of central body
Returns:

X, Y, Z, vx, vy, vz - Cartesian positions and velocities of the bodies

Return type:

float

KeplerOrbit.orb_params(snap, isHelio=False, mCentral=1.0)

Takes a Pynbody snapshot of particles and calculates gives them fields corresponding to Kepler orbital elements. Assumes that the central star is particle #0 and that the positions and velocities are in barycentric coordinates.

Parameters:
  • snap (SimArray) – A snapshot of the particles
  • isHelio (boolean) – Skip frame transformation if the snap is already in heliocentric coordinates
  • mCentral (float) – Mass of central star in simulation units. Need to provide if no star particle in snap
Returns:

A copy of ‘snap’ with additional fields ‘a’, ‘ecc’, ‘inc’, ‘asc_node’, ‘omega’ and ‘M’ added.

Return type:

SimArray

KeplerOrbit.kep2poinc(a, e, i, omega, Omega, M, m1, m2)

Convert kepler orbital elements into Poincaire variables. Can accept either single values or lists of coordinates

Parameters:
  • a (float) – semi-major axis body
  • ecc (float) – eccentricity of body
  • inc (float) – inclination of body
  • Omega (float) – longitude of ascending node of body
  • omega (float) – longitude of perihelion of body
  • M (float) – Mean anomaly of body
  • mass (float) – mass of body
  • m_central (float) – mass of central body
Returns:

lam, gam, z, Lam, Gam, Z - Poincaire coordinates

Return type:

float

KeplerOrbit.kep2del(a, e, i, omega, Omega, M, m1, m2)

Convert kepler orbital elements into Delunay variables. Can accept either single values or lists of coordinates

Parameters:
  • a (float) – semi-major axis body
  • ecc (float) – eccentricity of body
  • inc (float) – inclination of body
  • Omega (float) – longitude of ascending node of body
  • omega (float) – longitude of perihelion of body
  • M (float) – Mean anomaly of body
  • mass (float) – mass of body
  • m_central (float) – mass of central body
Returns:

l, g, h, L, G, H - Delunay coordinates

Return type:

float

KeplerOrbit.kep2mdel(a, e, i, omega, Omega, M, m1, m2)

Convert kepler orbital elements into modified Delunay variables. Can accept either single values or lists of coordinates

Parameters:
  • a (float) – semi-major axis body
  • ecc (float) – eccentricity of body
  • inc (float) – inclination of body
  • Omega (float) – longitude of ascending node of body
  • omega (float) – longitude of perihelion of body
  • M (float) – Mean anomaly of body
  • mass (float) – mass of body
  • m_central (float) – mass of central body
Returns:

Lam, P, Q, lam, p, q - Delunay coordinates

Return type:

float