Detrending algorithms#

CoFiAM#

This module contains functions to implement the CoFiAM (Cosine Filtering with Autocorrelation Minimization) detrending method.

democratic_detrender.cofi_AM.cofiam_function(times, fluxes, degree)[source]#

Calculate the CoFiAM function.

Parameters:
  • times – array-like, time values

  • fluxes – array-like, flux values

  • degree – int, degree of the CoFiAM fit

Returns:

CoFiAM function values

Return type:

array

democratic_detrender.cofi_AM.cofiam_iterative(times, fluxes, mask, mask_fitted_planet, local_start_x, local_end_x, max_degree=30, min_degree=1)[source]#

Iteratively apply CoFiAM method for multiple CoFiAM degrees and select the best fit.

Parameters:
  • times – array-like, time values

  • fluxes – array-like, flux values

  • mask – array-like, boolean mask for data points

  • mask_fitted_planet – array-like, boolean mask for fitted planet

  • local_start_x – float, start time for local region

  • local_end_x – float, end time for local region

  • max_degree – int, maximum CoFiAM degree to try

  • min_degree – int, minimum CoFiAM degree to try

Returns:

best-fit model, best degree, best Durbin-Watson statistic, maximum degree

Return type:

tuple

democratic_detrender.cofi_AM.cofiam_matrix_coeffs(times, fluxes, degree)[source]#

Calculate the coefficients for the CoFiAM method.

Parameters:
  • times – array-like, time values

  • fluxes – array-like, flux values

  • degree – int, degree of the CoFiAM fit

Returns:

design matrix for CoFiAM, coefficients

Return type:

tuple

democratic_detrender.cofi_AM.cofiam_matrix_gen(times, degree)[source]#

Generate the design matrix for the CoFiAM method.

Parameters:
  • times – array-like, time values

  • degree – int, degree of the CoFiAM fit

Returns:

design matrix for CoFiAM

Return type:

array

democratic_detrender.cofi_AM.cofiam_method(x, y, yerr, mask, mask_fitted_planet, t0s, duration, period, local_x)[source]#

Apply the CoFiAM method for detrending a light curve.

We need to solve the problem \(AX = B\), where \(A\) is a vector of coefficients for our linear problem and \(X\) is a matrix of terms whose values when multiplied by the coefficients in \(A\) given the function values \(B\).

To do this, the CoFiAM algorithm fits terms up to arbitrary degree as:

\[f_k(t) = a_0 + \sum_{k=1}^N_{\rm order} x_k \sin(\frac{2\pi t k}{2D}) + y_k \cos(\frac{2\pi t k}{2D})\]

where \(a_0\) is the offset, \(N_{\rm order}\) is the highest allowed harmonic order, \(x_k\) and \(y_k\) are are free parameters, \(t\) is the set of observing times in a given epoch, and \(D\) is the total baseline of the time-series data in the given epoch.

For the matrix representation, this must be done for every timestep, i.e., the matrix rows are for each time in your array.

Parameters:
  • x – array-like, time values

  • y – array-like, flux values

  • yerr – array-like, flux error values

  • mask – array-like, boolean mask for data points

  • mask_fitted_planet – array-like, boolean mask for fitted planet

  • t0s – array-like, transit center times

  • duration – float, transit duration

  • period – float, transit period

  • local_x – array-like, local region times for each epoch

Returns:

detrended light curve, Durbin-Watson statistics

Return type:

tuple

Gaussian process#

This module contains functions to implement the Gaussian Process (GP) detrending method.

democratic_detrender.gp.gp_method(x, y, yerr, mask, mask_fitted_planet, t0s, duration, period)[source]#

A function that applies the GP detrending method to a list of light curve epochs. It fits a GP to the out-of-transit data of each epoch and returns the detrended light curve.

Parameters:
  • x (list of arrays) – A list of time arrays for each epoch.

  • y (list of arrays) – A list of flux arrays for each epoch.

  • yerr (list of arrays) – A list of flux error arrays for each epoch.

  • mask (list of arrays) – A list of boolean arrays indicating the in-transit data points for each epoch.

  • mask_fitted_planet (list of arrays) – A list of boolean arrays indicating the data points used to fit the planet model for each epoch.

  • t0s (array) – The transit midpoints of the planet.

  • duration (float) – The duration of the planet transit in hours.

  • period (float) – The orbital period of the planet in days.

Returns:

detrended_lc – The detrended light curve obtained by applying the GP method.

Return type:

array

democratic_detrender.gp.gp_new(time_star, lc_star, lc_err_star, time_model)[source]#

A function that fits a GP to the out-of-transit data of a single epoch and returns the maximum a posteriori solution.

Parameters:
  • time_star (array) – The time array of the light curve.

  • lc_star (array) – The flux array of the light curve.

  • lc_err_star (array) – The flux error array of the light curve.

  • time_model (array) – The time array of the full light curve (including in-transit data). This is used to compute the GP prediction.

Returns:

map_soln – A dictionary containing the maximum a posteriori solution of the GP fit.

Return type:

dict

polyAM#

This module contains functions to implement the Polynomial Autocorrelation Minimization (polyAM) detrending method.

democratic_detrender.poly_AM.polyAM_function(times, fluxes, degree)[source]#
democratic_detrender.poly_AM.polyAM_iterative(times, fluxes, mask, mask_fitted_planet, local_start_x, local_end_x, max_degree=30, min_degree=1)[source]#
democratic_detrender.poly_AM.polynomial_method(x, y, yerr, mask, mask_fitted_planet, t0s, duration, period, local_x)[source]#

polyLOC#

This module contains functions to implement the Polynomial Local (polyLOC) detrending method.

democratic_detrender.poly_local.BIC(model, data, errors, nparams)[source]#
democratic_detrender.poly_local.local_method(x_epochs, y_epochs, yerr_epochs, mask_epochs, mask_fitted_planet_epochs, t0s, duration, period)[source]#
democratic_detrender.poly_local.polyLOC_function(times, fluxes, degree)[source]#
democratic_detrender.poly_local.polyLOC_iterative(times, fluxes, errors, mask, max_degree=30, min_degree=1)[source]#