pca2d-preclean

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

← Home

METHOD · ATMOSPHERE

The atmosphere,
measured first

In the optical the spectra arrive with the sky still in them. How well that is removed sets the floor for everything downstream, so the measurement is worth doing carefully: a derivative criterion instead of a cross-correlation, and always against a stellar template.

Where this fits

In the near infrared, APERO has already removed the tellurics before pca2d ever sees the data, and the fit works on what APERO left behind. In the optical (HARPS, HARPS-N, ESPRESSO) the spectra arrive with the atmosphere still in them, so LBL's telluric cleaning runs first and pca2d fits the residuals of that cleaning.

That makes the quality of the telluric step part of this pipeline's business, and two things about it were changed in the course of this work: how the absorption is measured, and what it is measured against.

The absorption model

An atmospheric transmission spectrum, to first order, scales as a power of a reference transmission: Beer-Lambert with the column as the exponent. Two components suffice for a radial-velocity pipeline:

\[ T(\lambda)\;=\;T_{\mathrm{H_2O}}(\lambda)^{\,\alpha}\;\cdot\; T_{\mathrm{dry}}(\lambda)^{\,\beta} \]

\(\alpha\) tracks the precipitable water vapour, which changes on the timescale of minutes; \(\beta\) tracks everything that scales with the dry airmass (O\(_2\), CO\(_2\), CH\(_4\)), which is smooth and predictable. Both are fitted per exposure, \(\beta\) free rather than pinned to the airmass, because at a given airmass the dry column still depends on the pressure at the summit.

Measuring the exponents from the derivative

The classical way to find \(\alpha\) is a cross-correlation against a telluric template. It works, but it has a weakness: a CCF is sensitive to anything that looks like a shifted copy of the template, including the stellar lines, and it degrades when the water lines are shallow.

The alternative used here asks a sharper question. A correctly removed absorption line leaves a smooth spectrum behind; an incorrectly removed one leaves a kink. So minimise the scatter of the derivative of the corrected spectrum:

\[ \hat{\alpha} \;=\; \arg\min_{\alpha}\; \operatorname{Var}_w\!\left[ \frac{\partial}{\partial x} \left(\frac{s(x)}{T_{\mathrm{H_2O}}(x)^{\alpha}\,T_{\mathrm{dry}}(x)^{\beta}}\right) \right] \]

where the variance is taken over the telluric-bearing pixels only, with photon weights. The criterion is scanned over \(\alpha \in [0.002,\,2.5]\) before a simplex refines it, because the cost surface has a shallow floor and a simplex started in the wrong place walks into it.

MethodScatter of the gradientChange
Uncorrected344.8-
LBL's CCF loop359.6+4.3 % (worse)
Derivative criterion304.1−11.8 %

The CCF loop making things actively worse on this star is not a typo: on a line-dense spectrum, without a template to divide by, the correlation locks onto stellar structure.

River plot of a water band through a campaign.
What the atmosphere looks like when it has not been removed well: a water band through a whole campaign, in the star's rest frame. The stellar lines stand still and the atmospheric residual walks diagonally across them as the barycentric velocity changes through the year. Panel 2 is what the fit reconstructs, panel 3 what a corrected file holds once the observer block is divided out, and panel 5 what nothing accounted for.

What it is measured against: the template is not optional

This is the part that is easy to get wrong, and this project got it wrong before getting it right. The fit must be performed on the spectrum divided by the stellar template, never on the raw spectrum.

Without the division, the criterion sees the entire stellar spectrum. On a star dense in lines, the derivative scatter is dominated by the photosphere, and the shallow telluric signal it is supposed to measure contributes almost nothing. The procedure is therefore three passes, and APERO has always done it this way:

  1. Clean without a template. A first approximation, good enough to build on.
  2. Build the stellar template from the spectra cleaned that way.
  3. Re-clean the raw spectra with that template, the fit now running on \(s/\bar{S}\).
The tell-tale. If the exponents come out identical between the pass without a template and the pass with one, the template is not reaching the fit. On HD 10700 the median was 0.332 on both sides, which is how the bug was caught.

What the division buys, measured on GJ 581 (M3V): of five exposures that had been falling back to a default value for want of a measurable signal, three converge to a real measurement (0.0275, 0.1486, 0.0347) as soon as a template, even a crude one, is divided out.

When there is nothing to measure

On a late M dwarf the water lines are genuinely faint against the stellar forest: a 5 % water line is 2.8 σ per pixel on GJ 581 where it is 13.4 σ on HD 10700. When the cost curve is flat (less than 5 % of span) or its minimum sits on the edge of the scan, the fit refuses to report a number and falls back to a default column.

Refusing is the right answer, and the fallback exposures are not thereby ruined: the residual, scaled by SNR, comes out at 1.70 for fallback exposures against 1.85 for measured ones on HD 10700, and 1.74 against 1.77 on HD 69830. A default column is a perfectly good estimate when the data cannot improve on it.

A trap worth recording. The fallback value, 0.35, is also one of the points on the scan grid, so a genuine measurement that lands there is indistinguishable from a refusal. Fallbacks are therefore marked by an epsilon offset of \(10^{-7}\) rather than by their value, and the counts are read from the headers and not from the four-decimal log.

Making it fast

The first working version took 16.55 s per exposure, of which 14.16 s was a double Python loop propagating saturation contamination outward from each blanked pixel. The same operation is a pair of running maxima:

for backwards in (False, True): this_sat = sat[::-1] if backwards else sat this_above = above[::-1] if backwards else above last_sat = np.maximum.accumulate(np.where(this_sat, where, -1)) last_above = np.maximum.accumulate(np.where(this_above, where, -1)) here = (last_sat >= 0) & (this_sat | (last_sat > last_above)) contam |= here[::-1] if backwards else here

With that, plus building the convolved transmission grid only over the wavelength spans that actually constrain the fit (margins half a kernel wide, merged, and snapped to the grid so the convolution phases match), the cost went from 16.55 s to 0.49 s per fit.

Per exposure, before
16.55 s
Per exposure, after
0.49 s
Speed-up
34×
A full campaign
79 → 19 min

No logic changed: the two versions return the same exponents.

A figure that is not on this page. A synthetic demonstration of the template's advantage was built for this page and then dropped: on a toy spectrum of Gaussian lines the two cost curves come out equally sharp, and the figure would have illustrated a claim it did not support. The real gain is measured on real M dwarfs, where the lines are deep and saturated and the derivative criterion has something to bite on, and the numbers above are that measurement.

Two fibres are two instruments

HARPS has been through two fibre configurations, HAM (the 1″ fibre) and EGGS (the 1.4″ one), and they have different instrumental profiles and different velocity zero points. Mixing them in a single series puts a step function in the middle of the time series that no amount of precleaning will fix.

Never cross the modes. Every comparison on this site uses a single mode per star, the one with the most epochs. A related trap upstream: LBL's NIRPS_HE + CADC combination loads the HA instrument profile through a one-line table bug, so every NIRPS HE run before that was found used the wrong profile.