src/core/ephemeris.js
text
Transit ephemerides from mid-transit times.
linear T(E) = T0 + P E
quadratic T(E) = T0 + P E + (1/2) (dP/dE) E^2 (orbital decay, apsidal precession to first order)
Weighted least squares with the covariance taken from the supplied error bars
(not rescaled by chi^2). The fit is done in a centred, scaled epoch variable and
with a time offset removed, so Julian dates of 2.4 million keep their precision;
the result is then mapped back to epoch 0. No DOM, no dependencies.Import: import { … } from './src/core/ephemeris.js' — no DOM, runs in Node and the browser.
MS_PER_YEAR
js
const MS_PER_YEARMilliseconds per year for each day/day of period change.
fitEphemeris
js
function fitEphemeris(epochs, times, errs, order = 1)text
Fit an ephemeris. epochs: integers; times, errs: days. order: 1 (linear) or 2 (quadratic).
Returns { order, n, k, t0, per, dPdE, err: {t0, per, dPdE}, cov (k x k, order t0, per, dPdE),
chi2, dof, bic, dPdt (days/day), dPdtErr, predict(E) -> {t, sigma}, residual(i) }.
Throws when there are too few points or the epochs cannot constrain the model.assignEpochs
js
function assignEpochs(times, per, tRef)Whole-orbit counts for a list of times, given a period and a reference time. Returns { epochs, maxFrac }: maxFrac is the largest distance from a whole orbit, in periods (near 0.5 means the period is too uncertain to count orbits).
parseTimings
js
function parseTimings(text)Read mid-transit times from text: one transit per line, columns separated by commas, semicolons, tabs or spaces. Two columns are (time, uncertainty); with three, the all-integer column is the epoch. Lines that are not numbers (headers, comments) are skipped. Returns { rows: [{ t, e, epoch|null }], skipped }.