Skip to content

src/core/detrend.js ​

text
Photometric detrending: the columns a light curve is decorrelated against, and how they enter the one likelihood
(buildProblem in model.js). No DOM, runs in Node.

Three families, all evaluated inside buildProblem so the transit and the systematics are fitted together:

 1. Linear regressors (data.regressors): centroid x and y, PSF width, sky background, airmass, the comparison
    star's flux, a polynomial in time, and the principal components of pixel-level decorrelation (PLD, Deming et
    al. 2015). The baseline of each epoch is a1 + sum_k c_k x_k (times the airmass exponential), and a1 and every
    c_k are integrated out analytically. Columns are centred and scaled to unit standard deviation within each
    epoch here, so the U(-1, 1) prior on c_k (REG_PRIOR_WIDTH in model.js) is wide: a coefficient of 1 is a 100%
    change of flux per standard deviation of the regressor.

 2. Nearest-neighbour Gaussian kernel regression (data.kernel): the systematic at point i is the Gaussian-weighted
    mean of (data / transit) over its k nearest neighbours in a feature space (centroids, PSF width), as in EXOTIC's
    elca.gaussian_weights + lc_fitter(features=...) and in the Spitzer analyses of Knutson et al. (2012) and Lewis
    et al. (2013). The neighbours and weights depend only on the features, so they are computed once
    (gaussianWeights) and the smoothing is applied at every likelihood call.

 3. A comparison ensemble with inverse-variance weights (ensembleWeights), the noise of each star measured by the
    "three-cornered hat" from the scatter of every pairwise flux ratio.

Every function is checked in test/detrend.test.mjs against numpy / scipy (test/make_detrend_reference.py) and
against EXOTIC's own gaussian_weights run in its conda environment.

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

standardise ​

js
function standardise(x, epoch = null, keep = null)

Centre a column and scale it to unit (population) standard deviation within each epoch. Points where keep is 0 or the value is not finite do not enter the mean and the scale; they are set to 0.

  • returns { x: Float64Array, constant: true when some epoch has no spread (the column cannot be used there) }

legendre ​

js
function legendre(n, u)

Legendre polynomial P_n at u in [-1, 1] (Bonnet's recursion).

timePolynomial ​

js
function timePolynomial(t, order, epoch = null)

A polynomial in time as regressors: P_1 .. P_order of the time scaled to [-1, 1] within each epoch (Legendre polynomials, nearly orthogonal on evenly spaced points, so the coefficients are not degenerate as plain powers are). The constant term is a1, already in the model.

DETREND_COLUMNS ​

js
const DETREND_COLUMNS

The detrending columns a light curve can carry, by the names used in exported files and in the hand-off.

buildRegressors ​

js
function buildRegressors(cols, spec = {}, t = null, epoch = null, keep = null)

The linear regressors of a fit (data.regressors) from named columns.

  • param cols { name: array, ... } one value per point (e.g. parseLightCurve(...).columns, or the photometry page's arrays)
  • param spec { columns: ['xc', 'yc', ...] (products 'xy', squares 'xc2', 'yc2' are formed from xc and yc), poly: order of the time polynomial (0 = none), pld: [pc arrays] (already orthogonal, added as they are) }
  • param t times (needed for poly), epoch: per-point epoch index or null, keep: points that set the scaling
  • returns { regressors: [Float64Array], names: [...], dropped: [{ name, why }] }

symEig ​

js
function symEig(A, n)
text
Eigen-decomposition of the symmetric n x n matrix A (row-major, not modified) by cyclic Jacobi rotations. Returns { values, vectors (column k = vectors[k]) } sorted by decreasing value.

pldBasis ​

js
function pldBasis(pix, opts = {})

Pixel-level decorrelation (Deming et al. 2015): the fractional flux of each pixel, P_k / sum_j P_j, carries the motion of the star on the detector independently of its brightness. Those fractions sum to one, so one of them is redundant with the constant a1; they are centred and turned into principal components (eigenvectors of their covariance), and the leading ncomp components, scaled to unit standard deviation, are the regressors. With order 2 the products of the first-order components are added before a second PCA (Luger et al. 2016, EVEREST).

  • param pix array of nPix series (one per pixel, background-subtracted), each of length n
  • param opts { ncomp (default: as many as explain 99.9% of the variance, at most 12), order: 1 | 2, keep }
  • returns { regressors: [Float64Array], explained: [fraction of variance per component], ncomp, frac: [the fractional pixel series] }

gaussianWeights ​

js
function gaussianWeights(X, opts = {})
text
Gaussian-weighted nearest neighbours in a feature space: EXOTIC's elca.gaussian_weights, line for line.
  Xm = (X - median(X)) * w;  for every point the k nearest other points (Euclidean in Xm);
  the weight of neighbour j of point i is prod_d exp(-(Xm_jd - Xm_id)^2 / (2 s_d^2)), s_d the (population) standard
  deviation of those k offsets in feature d (an adaptive bandwidth), normalised to sum to one. A feature whose offsets
  all vanish gets s = 1e-12; a point whose weights all vanish gets 1/k each (both as in EXOTIC).
The neighbours are found by brute force (n^2 d operations: 0.4 s for n = 5000 in Node); the point itself is excluded,
so a point's systematic is predicted from the others only.
  • param X array of d feature series of length n (e.g. [xc, yc] or [xc, yc, fwhm])
  • param opts { neighbors = 50, w = 1 (number or one per feature) }
  • returns { idx: Int32Array nk, w: Float64Array nk, k, n }

kernelSmooth ​

js
function kernelSmooth(y, kern, out = new Float64Array(kern.n)
text
Kernel-smoothed series: out_i = sum_q w_iq y[idx_iq] (EXOTIC's weightedflux).

ensembleWeights ​

js
function ensembleWeights(comps, target = null, opts = {})
text
Inverse-variance weights for an ensemble of comparison stars.
The white noise of each light curve is measured without assuming any of them is quiet, by the "three-cornered hat"
(Gray & Allan 1974): for every pair (i, j) of series the variance of the point-to-point differences of
ln(F_i / F_j), halved, is sigma_i^2 + sigma_j^2 (the atmosphere, common to all stars, cancels in the ratio; slow
trends and a transit hardly change point-to-point differences). The m sigma^2 follow by least squares from the
m(m-1)/2 pair variances; with m >= 3 series (the target counts as one) they are determined. The ensemble is then
  C = sum_j w_j F_j / median(F_j),   w_j = (1 / sigma_j^2) / sum_l (1 / sigma_l^2)
whose fractional white noise 1 / sqrt(sum 1/sigma_j^2) is the least any weighted mean of these stars can have.
A plain sum (EXOTIC's single best star, or this code's "all summed") is weighted by brightness instead, which is
optimal only when every star is photon-noise limited.
  • param comps array of comparison flux series (length n each)
  • param target the target's flux series (used only to measure the noise; recommended), or null
  • param opts { keep: points to use, floor: smallest sigma^2 as a fraction of the median (default 1e-3) }
  • returns { weights (sum 1), sigma (fractional white noise of each comparison), sigmaTarget, comparison (the weighted ensemble, median 1), sigmaEnsemble, pairs: [{ i, j, v }] }

detrendFromColumns ​

js
function detrendFromColumns(columns, detrend = {}, t = null, epoch = null)

Everything the analyzer needs from a hand-off (or a file with detrending columns) in one call.

  • param columns { name: array } aligned with the light curve's points (parseLightCurve(...).columns)
  • param detrend { columns: [names], poly, pld: [names of PLD columns, e.g. 'pld1'...], kernel: { features: [names], neighbors } }
  • param t, epoch the light curve's times and epoch index
  • returns { regressors: [...] | null, names, kernel: from gaussianWeights | null, dropped }

alignColumns ​

js
function alignColumns(srcTime, columns, dstTime, tol = 1e-6)
text
Put columns that came with a light curve onto the points the analyzer kept: for every time in `dstTime` the row of
`srcTime` with the same time (within `tol` days, default 1e-6 d = 0.09 s) is taken; points with no match get NaN.
The light-curve reader sorts rows and drops duplicate times, so this is how the hand-off's arrays (in the order the
photometry page wrote them) are aligned with data.t (+ data.tRef).
  • returns { columns: { name: Float64Array }, matched: number of points found }

MIT licensed · Kyle A. Pearson