pca2d-preclean

Two frames, one fit · SPIRou, NIRPS, HARPS, HARPS-N, ESPRESSO

← Home

METHOD

The model,
written out

Two blocks of components, one anchored in the star's rest frame and one at the telescope, solved together with photon weights. This page is the derivation, the conventions, and the places where a shortcut would cost metres per second.

Why two frames separate at all

A spectrum recorded at the telescope is a product of things that live in different reference frames. The star's photospheric lines arrive Doppler-shifted by the motion of the observatory around the barycentre of the Solar System; the absorption imprinted by the Earth's atmosphere, the detector's fringing, and every instrumental artefact do not move with that velocity at all. Over a campaign, the barycentric velocity \(v_{\mathrm{berv}}(t)\) sweeps through a range of tens of km/s, so the same stellar line lands on a different set of detector pixels in February than it does in August.

That sweep is the whole lever. If a feature keeps its place on the detector while the star slides past it, the feature is not stellar. The model below is nothing more than that statement written down with enough care to be solvable.

What makes or breaks it: the BERV span. With a wide span the two frames are well separated and the fit gains a factor of two; with a span of 0.7 km/s the blocks become nearly collinear, the fit cannot tell them apart, and the correction loses a factor of 2.4. Measured on two slices of the same TOI-4552 campaign, identical in every other respect.

The sampling grid

Everything is resampled onto one common grid, uniform in \(\ln\lambda\). This is not a convenience: on such a grid a Doppler shift is a translation, identical at every wavelength, so carrying a spectrum from one frame to another is one interpolation with one offset rather than a wavelength-dependent stretch.

\[ x \;=\; \frac{\ln\lambda - \ln\lambda_0}{\Delta}, \qquad \Delta \;=\; \ln\!\left(1 + \frac{\delta v}{c}\right) \]

with \(\delta v\) the step in velocity units, typically a fraction of a resolution element. A source moving at velocity \(v\) then shifts by

\[ \delta x(v) \;=\; \frac{\operatorname{artanh}(v/c)}{\Delta} \qquad\text{pixels.} \]

The inverse, used whenever a velocity is read back out of a fitted shift, is \(v = c\tanh(\Delta\,\delta x)\). The interpolation itself is a windowed Lanczos kernel (\(a = 8\)), which preserves the line shapes far better than a cubic spline at the sub-pixel shifts that matter here.

Always relativistic. The first-order form \(1 + v/c\) is wrong by \(\tfrac{1}{2}(v/c)^2\), which is 1.5 m/s at a 30 km/s BERV. Since the whole point of the exercise is to chase systematics at the m/s level, the approximation is never used, anywhere in the code.

The model, term by term

Let \(y(x, t)\) be the high-passed log flux of exposure \(t\) on the common grid. The model is

\[ y(x, t)\;=\;\underbrace{\bar{S}\!\left(x - \delta x_t\right) \;+\;\sum_{i=1}^{n_\star} a_i(t)\,P_i\!\left(x - \delta x_t\right)}_{\textstyle\text{star frame}} \;+\;\underbrace{\sum_{j=1}^{n_\oplus} b_j(t)\,Q_j(x)}_{\textstyle\text{observer frame}} \;+\;\varepsilon(x, t) \]

Both \(P\) and \(Q\) are found from the data by a weighted PCA on the cube itself. Nothing here comes from a model atmosphere or a telluric line list: if the fit says a component sits still at the telescope, it is because the campaign showed it sitting still.

How it is solved

The two bases and the amplitudes are not known at the same time, so the fit alternates. Each half-step is linear and closed-form; only the alternation is iterative.

  1. Build the cube. Every exposure is resampled onto the common grid with its variance, its telluric transmission and its mask. Nothing is co-added: the cube is \(N_{\mathrm{exp}} \times N_{\mathrm{pix}}\).
  2. Take the star's mean. Carry every exposure into the star's rest frame and take a weighted median down the time axis. This is \(\bar{S}\), and it is also what the high pass is taken against (why that matters).
  3. Solve for the amplitudes. With the bases held fixed, each exposure gives an independent linear least-squares problem in \((a_i, b_j)\), weighted by the inverse variance of each pixel.
  4. Update the bases. With the amplitudes held fixed, a weighted PCA of the residual in each frame (the star's residual carried into the star's frame, the observer's left where it is) gives the next \(P\) and \(Q\).
  5. Repeat until the \(\chi^2\) stops moving.

The weighted least-squares step, per exposure, is the normal equation

\[ \begin{pmatrix} \mathbf{a} \\ \mathbf{b}\end{pmatrix} \;=\; \left(\mathbf{M}_t^{\!\top} \mathbf{W}_t\, \mathbf{M}_t\right)^{-1} \mathbf{M}_t^{\!\top} \mathbf{W}_t \left(\mathbf{y}_t - \bar{S}_t\right) \]

where \(\mathbf{M}_t\) stacks the shifted \(P_i\) and the unshifted \(Q_j\) as columns, \(\mathbf{W}_t\) is diagonal with the inverse variances, and \(\bar{S}_t\) is the mean carried to that exposure's frame. Writing the mean on the right-hand side rather than as a column of \(\mathbf{M}_t\) is exactly what fixes its coefficient at one.

What the amplitudes do in time

Fitted amplitudes of each component against time.
TOI-2120, 316 exposures, with the nightly means ringed. Left is the star-anchored block, right the Earth-anchored one, and each panel carries its share of the weighted variance. The ordering is worth noting: \(b_1\) carries 17.2 % on its own, five times the stellar component's 3.4 %, which is what it looks like when the thing being removed is larger than the thing being kept.

The sanity check

Rank correlation of every coefficient against the ancillary quantities.
Rank correlation of each amplitude against every quantity in the headers. This is the diagnostic that says whether the two blocks have stayed separate: a stellar component that starts tracking the sky, or an observer component that tracks the BERV, is the sign they have begun to mix.

What is written back

The correction applied to the files is the observer block alone, evaluated on each exposure's own original wavelength grid and divided out of the delivered flux:

\[ f^{\mathrm{corr}}(\lambda, t) \;=\; f(\lambda, t) \,\Big/\, \exp\!\Big(\sum_j b_j(t)\,Q_j(\lambda)\Big) \]

Nothing stellar is removed, nothing is smoothed, and the grid is never changed. A corrected file holds exactly what the report's third panel shows, sample for sample, which is a property the test suite checks rather than a claim.

What it costs: samples. Every sample the fit could not weight is written as NaN rather than guessed at, and with mask: common the kept set is decided once for the whole campaign rather than exposure by exposure, so the line list a velocity code sees does not change from night to night. On TOI-2120 that takes the files from 27.2 % NaN as delivered to 51.3 %: twenty-four points of the spectrum, traded for a line set that is stable across the campaign. On a star already photon-limited, that is a trade worth checking before accepting.
The corrected spectrum compared with panel three of the report.
The corrected files laid over panel 3 of the run's own report, around 1267 nm, every exposure ordered by BERV. Where both hold a value they agree to an rms of 0.0225 in the high-passed log flux, which is the interpolation back onto the original grid and nothing else. The yellow in the middle panel is what the files do not hold: it is wider than in panel 3 because mask: common fixes one line set for the whole campaign, and it slants because that set is defined in the observer's frame while the figure is drawn in the star's. The bottom panel is how the files looked before 2026-09-10, when the parity mean was still left in them.

Choosing the component counts

--n-star and --n-earth are the only two numbers the user has to pick, and they trade the same way every regularised fit does: too few and the correction is incomplete, too many and the star starts to be absorbed into the Earth block.

TOI-2120, nominal
1–3
rms, delivered → corrected
47.5 → 14.2
Paired gain, 80 common epochs
3.38×
Bootstrap, 16–84 %
3.14–3.65
Two stellar components go degenerate. On TOI-2120 with --n-star 2, the second stellar amplitude starts following the sky: the fit absorbs a 232 m/s shift into it and the LBL rms climbs to 67 m/s. One stellar component is the nominal choice for a reason, and the degeneracy is the reason.

The full table of what this is worth, star by star →