# Background¶

The foundation of `linea`

is linear detrending via least squares, so some
background reading on least squares from
wikipedia might be helpful
before you browse this tutorial. We’ll use some of the same symbols as the
wikipedia entry for consistency.

## Linear detrending¶

The default raw aperture photometry from CHEOPS, \(f_i\), contains several systematic trends as a function of time \(t\), roll angle \(\theta\), stellar centroid position (\(x, y\)), contamination \(c\), and varying background flux \(d\). To first order, the flux that we observe is a linear combination of the astrophysical signals we wish to detect and some unknown function of these observational basis vectors. For some CHEOPS programs, the astrophysical signal has unconstrained quantities, like transit times or depths. For this particular analysis, the orbit of 55 Cnc e is known with great precision, allowing us to fix the planet’s parameters and fit only for the phase and amplitude of the sinusoidal phase curve signal. In principle, there is some design matrix \(\bf X\) for which we can solve for the least-squares estimators \(\hat{\beta}\) such that

In practice, we do not know the precise functional form of the linear combination of basis vectors which produces the flux variations we observe, so we assemble a design matrix \(\bf X\) from the observational vectors mentioned earlier, of the form

for all \(M\) observations, after \(3\sigma\)-clipping the raw fluxes.
We call the matrix \(\bf X_{\rm sys}\) the *systematics matrix*, which we
assemble from the FITS record array associated with each CHEOPS observation.

The systematics matrix does not include any astrophysical signal associated with this observation, so in order to properly model the flux variations due to the transit event and the phase curve, we introduce three more column vectors to concatenate with \(\bf X_{\rm sys}\), which we call \(\bf X_{\rm model}\),

where \(T_i\) is the Mandel & Agol (2002) transit model minus one. We solve for the least-squares estimators for the two sinusoidal column vectors to account for the unknown phase of the sinusoidal phase curve signal. The complete design matrix is

We also define the uncertainty matrix \(\bf N\),

where \(\bf I_M\) is the identity matrix.

Now we solve for the least-squares estimators \(\hat{\beta}\),

Uncertainties on each of the least-squares estimators are computed with the pre-computed matrix inversion,