pca2d-preclean

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

← Home

METHOD · PREPROCESSING

The high pass,
and a moving hole

A Savitzky-Golay filter is dragged down by every deep line it crosses. That would be harmless if the holes in the data stayed put. They do not: a telluric line walks across the stellar core as the BERV changes, and the bias walks with it.

Why there is a high pass at all

The fit works on line shapes, not on the continuum. The continuum carries the blaze, the flat-field response, the atmospheric extinction and the exposure's throughput, and none of that is the quantity of interest. Worse, it varies by tens of percent between exposures while the lines move by parts per thousand, so a PCA run on the raw spectra would spend all its components describing the lamp.

So each exposure is high-passed before it enters the cube: a Savitzky-Golay filter estimates the smooth part, and the smooth part is subtracted in log flux. The filter runs per order segment, never across the gaps between orders, since a polynomial fitted across a gap is a polynomial fitted to nothing.

\[ y(x) \;=\; s(x) \;-\; \mathrm{SG}_{W,p}\!\left[s\right](x), \qquad s(x) \equiv \ln f(x) \]

with \(W\) the window, set in velocity units so that it means the same thing at every wavelength, and \(p\) the polynomial order.

The problem: a filter is dragged by the lines it crosses

A Savitzky-Golay filter is a local least-squares polynomial. It does not know what a line is. When the window straddles a deep absorption line, the fitted polynomial is pulled downward, and the “continuum” it returns is the continuum minus some fraction of the line.

On its own that bias is harmless: it is a fixed function of wavelength, the same in every exposure, so the PCA sees it as part of the mean and it never reaches the velocities. The trouble starts when the bias stops being fixed.

The mechanism. LBL blanks any pixel where the telluric transmission is below \(e^{-1}\); those pixels carry no usable information and are set to NaN. As the BERV sweeps through the year, a telluric line walks across a stellar line. The blanked pixels therefore move relative to the stellar line. The Savitzky-Golay filter sees a different support on each exposure, so it is dragged by a different amount, and it leaves behind a residual that changes with the BERV while being entirely non-stellar.

A residual that tracks the BERV is the single most dangerous systematic in this business: it is periodic at one year, it is coherent across all the lines of a star, and it looks exactly like a planet.

HD 69830, line at 688.85 nm
 
Telluric depth at the core, BERV −25 km/s
3 %
Same line, BERV −5 km/s
89 %

Between those two epochs the mask over the stellar core goes from essentially absent to essentially total. The filter cannot not notice.

The fix: filter the residual to a template

Instead of filtering the spectrum, filter what the spectrum has that the template does not, then add the template's own filtered version back:

\[ y \;=\; \underbrace{\big[(s - \bar{S}) - \mathrm{SG}[s - \bar{S}]\big]}_{\textstyle\text{the residual, high-passed}} \;+\;\underbrace{\big[\bar{S} - \mathrm{SG}[\bar{S}]\big]}_{\textstyle\text{the template, high-passed}} \]

\(\bar{S}\) is the median of the whole campaign taken in the star's rest frame and carried back into each exposure's own frame. The crucial property is that the template has no holes: a pixel blanked in one exposure is perfectly well measured in the fifty other exposures where the telluric line sat somewhere else, so the median is defined everywhere.

The deep line now lives almost entirely in \(\bar{S}\). What is left in \(s - \bar{S}\) is small and flat, so the filter applied to it is not dragged by anything, whatever the mask does. And \(\mathrm{SG}[\bar{S}]\) is computed once on a support that never changes, so its bias is a fixed function of wavelength again, back to the harmless case.

Why the two forms are not algebraically the same

There is a tempting argument that this changes nothing. Savitzky-Golay is linear, so

\[ (s - \bar{S}) - \mathrm{SG}[s - \bar{S}] + \bar{S} - \mathrm{SG}[\bar{S}] \;=\; s - \mathrm{SG}[s]. \]

That identity is correct, and it only holds when both filters see the same support. They do not. The residual \(s - \bar{S}\) inherits the exposure's mask, with its holes where the tellurics saturate; the template \(\bar{S}\) has no holes at all. Linearity does not survive two different supports, and the difference between the two sides is precisely the BERV-dependent term we are trying to remove.

A synthetic deep line with a moving mask, filtered both ways.
A controlled experiment. The spectrum is held exactly fixed; only the ten-pixel mask moves across the line core, as the BERV would move it. Top: the line and the mask at three positions. Bottom: the high-passed value of one continuum pixel as a function of where the mask sits. The ordinary filter wanders by 0.00230 rms; filtered against a template it wanders by 0.00030, a factor of 7.6 less, for an input that never changed.
The test that matters is the one with a moving mask. With a fixed mask the two forms agree to machine precision, which is how the identity above misleads. It took holding the spectrum still and moving only the mask to see the effect at all.

What it bought, measured honestly

The expectation was never a large drop in rms: the mechanism feeds a small, slow systematic, not a large scatter. What it should do is clean up the components, so the stellar block stops hooking onto something that follows the BERV.

StarHigh passrms (m/s)MAD (m/s)Component 2 vs BERV
HD 69830 ordinary3.513.360.106
against a template3.503.290.040
GJ 581 ordinary9.0310.880.325
against a template9.0610.760.507

The rms is unchanged to within the error bars, as expected. On HD 69830 the second component's correlation with the BERV drops from 0.106 to 0.040, which is the effect the change was made to produce. On GJ 581 it goes the other way, from 0.325 to 0.507, and that is reported here rather than left out: an M dwarf's spectrum is dense enough that the median template is itself harder to build, and the diagnosis is not finished.

The template high pass is nevertheless the nominal path since 2026-10-16, on the conceptual argument rather than on the rms: a filter whose bias depends on which pixels happen to be masked tonight is not something to keep because its scatter happens to come out the same.

The template travels with the cube. It is written beside the cube as hp_template.npy, so the correct stage applies the identical second pass to the delivered spectra. The first version of this change forgot that: the corrected files were built from raw log flux (median +10.14 instead of +0.017), their noise doubled, and the report's river plots stayed perfectly clean, because the report was reading the cube, which was right, while the files were not.