High-level Orbit class API#
This page renders the full API of Orbit from
its docstrings. See Orbit class overview for the conceptual tour
and a quickstart, and Analytic parameter derivatives for the gradient math when
the class is used in derivative mode.
- class meepmeep.orbit.Orbit(npt: int = 15, ep_placement: str = 'ea', derivatives: bool = False, parallel: bool = False)[source]#
Bases:
objectEvaluate Keplerian orbits at arbitrary times, with optional analytic gradients.
Bind a handful of orbital elements once via
set_pars(), hand it a time grid viaset_data(), and then ask for any of the quantities that exoplanet light-curve and radial-velocity modelling typically need: planet position, velocity, sky-projected separation, phase angle, radial velocity, reflected-light and thermal phase curves, ellipsoidal variation, light travel time. Construct withderivatives=Trueto additionally receive the analytic gradient of each quantity w.r.t. the seven orbital parameters (and any method-specific extras such askorag), which is what a gradient-based optimiser or HMC sampler wants.Workflow:
Orbit(npt, ep_placement, derivatives) → set_pars(tc=..., p=..., a=..., i=..., e=..., w=...) → set_data(times) → call any observable. Passtp=...instead oftc=...to anchor the orbit at periastron passage instead of transit center.- Parameters:
- npt
int Number of expansion points used by the multi-expansion-point Taylor expansion (default 15). Includes the periodic-image slot; raise this when the orbit is eccentric enough that 15 expansion points no longer cover periastron with adequate per-expansion-point accuracy.
- ep_placement
str Expansion point placement strategy:
'mm'(uniform in mean motion),'ea'(uniform in eccentric anomaly; default and preferred for eccentric orbits), or'ta'(uniform in true anomaly).- derivativesbool
If
True, every evaluator method also returns parameter derivatives in addition to its value(s). The derivative ordering is(tc, p, a, i, e, w, lan)followed by per-method physical extras (e.g.kforradial_velocity();ag, kforlambert_phase_curve();k, fratio, offsetforemission_phase_curve();alpha, mass_ratio, incforellipsoidal_variation(); see the underlying*_odroutines inmeepmeep.backends.numba.orbit3ddfor the full signatures).The timing slot and the shape derivatives follow the timing parameter bound via
set_pars(). Bindtc(the default) and slot 0 is \(\partial/\partial t_c\) with thee,w,pderivatives taken at constanttc; bindtpand the gradient is returned in the periastron basis(tp, p, a, i, e, w, lan)(constanttp). See the “Transit-centre vs periastron parametrisation” section of the derivatives documentation for the exact relationship.With
derivatives=True, multi-coordinate returns are extended with derivative arrays (e.g.xyz()returns(xs, ys, zs, dxs, dys, dzs)with eachd*sof shape(N, 7)); single-value returns become(value, dvalue).rstarderivatives forlight_travel_time()are not returned (per package spec); only the seven orbital derivatives.- parallelbool
If
True, evaluations over time arrays with at least_PARALLEL_NMIN_GRAD(gradient mode) or_PARALLEL_NMIN_VALUE(value mode) samples route to multi-threadedprangekernel twins; smaller arrays always take the serial kernels, which are faster below those sizes. The results are identical either way. Defaults toFalse: leave it off when the surrounding application already parallelises at a higher level (e.g. one process per MCMC chain), where nested thread pools oversubscribe the machine.
- npt
- Attributes:
- npt
int Number of expansion points, set at construction.
- times
ndarrayorNone Time grid bound via
set_data().Noneuntil set.- _tc
float Transit-center time, set by
set_pars()(directly if you passtc, or derived fromtpotherwise). Used by the Newton-Raphson diagnostic paths and byplot(show_exact=True)().- _tp
float Periastron-anchor time. Passed straight through to every orbit3d / orbit3dd dispatcher as their
tpaargument. Set byset_pars()(directly if you passtp, or derived fromtcotherwise).- _timing
str Which timing convention was last bound via
set_pars(),"tc"(transit centre) or"tp"(periastron passage). In derivative mode it selects the gradient basis:"tp"triggers a reparametrisation of_dcoeffsinto the periastron basis.- _coeffs
ndarray, shape (npt, 3, 5) Taylor coefficient matrices at every expansion point, built in
set_pars().- _dcoeffs
ndarray, shape (npt, 7, 3, 5) orNone Parameter-derivative coefficient tensors at every expansion point.
Noneunless the instance was constructed withderivatives=True.- _ep_times
ndarray, shape (npt,) Normalised expansion-point phases in
[0, 1]fromcreate_expansion_points(). Built at construction fore = _EP_GRID_E_FLOORand rebuilt byset_pars()when the bound eccentricity drifts more than_EP_GRID_E_TOLfrom the grid’s construction eccentricity ('ea'/'ta'placements only; the'mm'grid is eccentricity-independent).- _grid_e
float Eccentricity the current expansion-point grid was built for,
max(e, _EP_GRID_E_FLOOR)at the last rebuild.- _dt
float Width of one
_ep_tablebucket in fraction of the period.- _ep_table
ndarrayofint Time-to-expansion-point lookup table.
- npt
Notes
Convention bridge: this class accepts either
tc(transit-center time) ortp(periastron-passage time) viaset_pars(). The underlying orbit3d / orbit3dd dispatchers anchor their expansion-point grid at periastron, soset_pars()converts once via \(t_p = t_c - M_\mathrm{tr}(e, w) \cdot p / (2\pi)\) and stores both values:self._tc(transit center) andself._tp(periastron anchor). Every dispatcher call usesself._tp;self._tcis used only by the Newton-Raphson diagnostic paths (_xyz_error(),_cos_phase_error(),mean_anomaly(),true_anomaly(exact=True)()) and byplot(show_exact=True)().- set_data(times)[source]#
Bind a time grid to the instance.
The bound grid is used as the default
timesargument by every evaluator that takes atimes=Noneparameter, and unconditionally by methods that don’t exposetimesat all (vxyz(),cos_phase(),phase(),theta(),light_travel_time(),radial_velocity()).- Parameters:
- times
ndarray, shape (N,) Times at which to evaluate the orbit [days].
- times
- set_pars(*, tc=None, tp=None, p, a, i, e, w, lan=0.0)[source]#
Bind orbital parameters and (re-)compute the per-expansion-point Taylor coefficients.
The time anchor is specified by exactly one of
tc(transit center) ortp(periastron passage); the two are related by \(t_p = t_c - M_\mathrm{tr}(e, w) \cdot p / (2\pi)\). Whichever is supplied, the other is derived and stored, so the diagnostic paths that needt_c(e.g. the Newton-Raphson reference) and the orbit3d / orbit3dd dispatchers that needt_paare both satisfied from one call.All parameters are keyword-only, so the call site always names the convention explicitly.
- Parameters:
- tc
float, optional Time of inferior conjunction (transit center) [days].
- tp
float, optional Time of periastron passage [days].
- p
float Orbital period [days].
- a
float Scaled semi-major axis \(a/R_\star\).
- i
float Inclination [radians]. \(i = \pi/2\) is edge-on.
- e
float Eccentricity, \(0 \le e < 1\).
- w
float Argument of periastron [radians].
- lan
float, optional Longitude of the ascending node [radians]. A constant rotation of the sky-plane (x, y) coordinates about the line of sight; the line-of-sight (z) coordinate is unaffected. Defaults to 0.0. In derivative mode the gradient w.r.t.
lanis returned as the seventh orbital-parameter column.
- tc
- Raises:
TypeErrorIf both
tcandtpare supplied, or if neither is.
Notes
After this call,
self._tcholds the transit-center time andself._tpholds the periastron-anchor time, regardless of which input was used.For the
'ea'and'ta'expansion point placements the expansion-point grid is rebuilt whenmax(e, 0.2)differs from the eccentricity the current grid was built for by more than_EP_GRID_E_TOL, so the expansion points stay clustered near periastron as the bound orbit changes. Small eccentricity jitter (e.g. between MCMC steps) does not trigger a rebuild.
- mean_anomaly()[source]#
Mean anomaly at every bound time, wrapped into \([0, 2\pi)\).
Computed analytically from
self._tc(transit-center time) via the mean-anomaly-at-transit offset, so this method does not use the Taylor backend at all.- Returns:
- m
ndarray, shape (N,) Mean anomaly per time in radians, in \([0, 2\pi)\).
- m
- true_anomaly(exact: bool = False)[source]#
True anomaly at every bound time.
- Parameters:
- Returns:
- Raises:
NotImplementedErrorIf
exact=Trueis combined withderivatives=True; the Newton-Raphson reference does not produce parameter gradients.
- xyz(times: ndarray | None = None)[source]#
Planet (x, y, z) position in the sky frame.
- Parameters:
- times
ndarrayorNone Times at which to evaluate the position. If
None, uses the grid bound viaset_data().
- times
- Returns:
- xs, ys, zs
ndarray, shape (N,) Position components in units of the stellar radius.
xs,ysare the sky-plane coordinates;zsis the line-of-sight depth (positive toward the observer).- dxs, dys, dzs
ndarray, shape (N, 7) Gradients w.r.t.
(tc, p, a, i, e, w, lan). Only returned whenself._derivativesisTrue.
- xs, ys, zs
- cos_phase()[source]#
Cosine of the phase angle, \(\cos\alpha = -z/r\).
Equals
+1at superior conjunction (full phase, planet behind star) and-1at inferior conjunction (new phase, planet in front).
- phase()[source]#
Phase angle \(\alpha = \arccos(\cos\alpha)\).
- Returns:
Notes
When
derivatives=True, the gradient is computed via the \(\arccos\) chain rule \(d\alpha/d\theta = -d\cos\alpha/d\theta / \sqrt{1 - \cos^2\alpha}\). At the transit/eclipse extrema \(|\cos\alpha| \to 1\) the derivative diverges; the implementation clamps \(\cos\alpha\) slightly inside(-1, 1)so the returned gradient stays finite but loses physical meaning at the clamped points.
- theta()[source]#
Supplement angle \(\theta = \arccos(-\cos\alpha) = \pi - \alpha\).
Useful when the natural reference direction is the line from the star to the observer rather than the line from the planet to the observer.
- Returns:
Notes
See
phase()for the derivative-clamping caveat near \(|\cos\alpha| = 1\).
- star_planet_distance(times: ndarray | None = None)[source]#
3D star-planet separation \(r = \sqrt{x^2 + y^2 + z^2}\).
Distinct from
projected separation()(currently only available through the low-levelsep_odispatcher), which drops the line-of-sight component.- Parameters:
- times
ndarrayorNone Times at which to evaluate the separation. If
None, uses the grid bound viaset_data().
- times
- Returns:
- light_travel_time(rstar: float)[source]#
Light-travel-time correction, referenced to primary transit.
The correction is \(\mathrm{ltt}(t) = -(z(t) - z(t_\mathrm{transit})) \cdot r_\star \cdot (R_\odot/c)\) with \(z\) in stellar radii and the result in days. The reference is the primary transit, so
ltt(t_transit) = 0.- Parameters:
- rstar
float Stellar radius [R_sun].
- rstar
- Returns:
- radial_velocity(k: float)[source]#
Stellar radial velocity (Perryman 2018, Eq. 2.23).
Scales the line-of-sight planet velocity by the closed-form factor \(K / [(2\pi/p)\,(a\sin i)/\sqrt{1-e^2}]\) so the result is the observed stellar RV in m/s.
- lambert_phase_curve(k: float, ag: float, times: ndarray | None = None)[source]#
Reflected-light phase curve assuming Lambertian scattering.
Evaluates \(F(t) = (k/r(t))^2\,A_g\,f(\alpha(t))\) with the Lambert kernel \(f(\alpha) = (\sin\alpha + (\pi - \alpha)\cos\alpha)/\pi\), using the instantaneous star-planet distance \(r(t)\) (in stellar radii) for the inverse-square illumination - exact for eccentric orbits, not just the circular case \(r = a\).
- Parameters:
- k
float Planet-to-star radius ratio \(R_p/R_\star\).
- ag
float Geometric albedo.
- times
ndarrayorNone Times at which to evaluate the flux. If
None, uses the grid bound viaset_data().
- k
- Returns:
- emission_phase_curve(k: float, fratio: float, offset: float, times: ndarray | None = None)[source]#
Thermal-emission phase curve from a simple cosine model.
Evaluates \(F(t) = k^2\,f_\mathrm{ratio}\,(1 + \cos\delta\,c_z(t) + \sin\delta\,s(t))/2\), where \(c_z = -z/d\) is the cosine of the phase angle and \(s\) the signed in-plane component built from the orbital normal. The flux peaks at \(k^2 f_\mathrm{ratio}\) when the hotspot faces the observer; the offset \(\delta\) shifts the peak away from secondary eclipse, breaking the curve’s time symmetry.
- Parameters:
- k
float Planet-to-star radius ratio \(R_p/R_\star\).
- fratio
float Dayside-to-nightside per-surface-element flux ratio, scaling the phase-curve amplitude so the peak-to-peak swing is \(k^2 f_\mathrm{ratio}\).
- offset
float Hotspot offset [radians].
- times
ndarrayorNone Times at which to evaluate the flux. If
None, uses the grid bound viaset_data().
- k
- Returns:
- ellipsoidal_variation(alpha: float, mass_ratio: float, times: ndarray | None = None)[source]#
Ellipsoidal variation signal (Lillo-Box et al. 2014, Eqs. 6-10).
Relative flux variation induced by the tidally distorted primary as a function of orbital phase. The amplitude scales with the mass ratio, the projected-area factor \(\sin^2 i\), and the inverse cube of the instantaneous 3D star-planet separation.
- Parameters:
- alpha
float Gravity-darkening coefficient.
- mass_ratio
float Planet-to-star mass ratio \(M_p/M_\star\).
- times
ndarrayorNone Times at which to evaluate the signal. If
None, uses the grid bound viaset_data().
- alpha
- Returns:
- plot(figsize: tuple | None = None, show_exact: bool = False, sr: float = 1.0, pr: float = 0.5, pc='k', npt: int = 1000)[source]#
Diagnostic three-panel plot of the orbit geometry.
Renders front (X-Y), top (X-Z), and side (Z-Y) projections with the planet drawn at the first expansion point, the orbit traced over one full period, and arrows along the X-Z trace indicating the direction of motion. Temporarily rebinds
self.timesto a dense grid ofnptsamples for the plot and restores it on exit.- Parameters:
- figsize
tupleorNone Matplotlib figure size; passed to
subplots.- show_exactbool, default
False If
True, overlay the Newton-Raphson reference trajectory (xyz_newton_v) as a black dashed line in each panel.- sr
float, default 1.0 Stellar radius drawn at the origin [stellar radii]. Used only for the cosmetic stellar disc.
- pr
float, default 0.5 Planet-marker radius [stellar radii]. Cosmetic only.
- pcmatplotlib color, default
"k" Planet-marker face colour.
- npt
int, default 1000 Number of samples used to draw the orbit trace.
- figsize
- Returns:
NoneThe figure is rendered in-place; the function does not return the
Figure/Axeshandles.