Skip to content

src/core/kepler.js ​

text
Keplerian orbit geometry for transit modelling.

Frame (same physical convention as pylightcurve.planet_orbit, relabelled):
  X, Y  : plane of the sky, in units of the stellar radius
  Z     : toward the observer. Z > 0 means the planet is in front of the star.
Mid-transit (inferior conjunction) is where  omega + nu = pi/2.

Import: import { … } from './src/core/kepler.js' — no DOM, runs in Node and the browser.

solveKepler ​

js
function solveKepler(M, e)
text
Solve Kepler's equation  E - e sin E = M  for the eccentric anomaly.

pylightcurve iterates plain Newton from E0 = M to |dE| < 1e-7 on the whole
array. That start is poor for e > ~0.8 (HD 80606 b, e = 0.93) and the loose
tolerance leaves ~1e-7 rad of phase error. Here: Danby's starter and a
quartic (Halley+1) update, iterated to machine precision. Converges in
2-4 iterations for every e < 1.

trueAnomaly ​

js
function trueAnomaly(E, e)
text
True anomaly from eccentric anomaly (atan2 form, safe near E = pi).

meanAnomalyAtTransit ​

js
function meanAnomalyAtTransit(e, omega)

Mean anomaly at inferior conjunction (mid-transit) for given e, omega [rad].

orbitElements ​

js
function orbitElements(p)

Precompute everything that does not depend on time. p: { per, tmid, ars, inc (deg), ecc, omega (deg) }

orbitPosition ​

js
function orbitPosition(el, t, out)

Position at time t. Writes [X, Y, Z] (stellar radii) into out.

orbitPath ​

js
function orbitPath(el, n = 512)

Sample the full orbit as n points (for drawing). Returns Float32Array(3n).

derived ​

js
function derived(p)

Derived transit quantities (Winn 2010, eqs. 7, 14-16). Durations in days.

separation ​

js
function separation(el, t, tmp = [0, 0, 0])

Projected star-planet separation (stellar radii) and whether the planet is in front.

contactDuration ​

js
function contactDuration(el, limit, tc)
text
Contact-to-contact duration of an occultation centred near tc, found
numerically from the orbit (bisection on separation = limit). Exact for any
eccentricity, unlike the closed-form approximations. Returns 0 if the discs
never reach `limit` at tc.

eclipseTime ​

js
function eclipseTime(el)

Time of superior conjunction (mid-eclipse) nearest to tmid, from precomputed elements.

eventTimes ​

js
function eventTimes(p)

Time of periastron (the passage preceding this transit) and of superior conjunction (the mid-eclipse nearest to this transit, except that an eclipse more than 0.4 P away is taken after it, so a near-circular orbit gives tmid + P/2 rather than flipping between tmid - P/2 and tmid + P/2), plus exact transit and eclipse durations. Either epoch repeats every period: summarise posterior draws of them with derive.js summarizeEpoch, which does not split a posterior that straddles the branch (periastron near the transit, omega near 90 deg).

eventAnomaly ​

js
function eventAnomaly(el, kind)
text
True anomaly [rad] of a named orbit event, from precomputed elements:
  'transit'    mid-transit, inferior conjunction      omega + nu = +pi/2
  'eclipse'    mid-eclipse, superior conjunction      omega + nu = -pi/2
  'periastron' nu = 0            'apastron' nu = pi
  'ascending'  omega + nu = 0: the node at which the planet crosses the plane of
               the sky coming toward the observer (Z = 0, dZ/dt > 0, X = -r), a
               quarter of an orbit before mid-transit when e = 0. The star is then
               receding fastest, so a circular orbit has its radial-velocity maximum here.
Returns NaN for an unknown kind.

eventPosition ​

js
function eventPosition(el, kind, out = [0, 0, 0])

Position [X, Y, Z] (stellar radii) of a named orbit event; see eventAnomaly. Writes into out.

eventTime ​

js
function eventTime(el, kind)

Time of a named orbit event, the occurrence nearest to tmid (within half a period); see eventAnomaly.

MIT licensed · Kyle A. Pearson