Plotting and helper functions#
Plotting#
This module contains functions to plot light curves and detrending results.
- democratic_detrender.plot.plot_detrended_lc(xs, ys, detrend_labels, t0s_in_data, window, period, colors, duration, mask_width=1.1, depth=None, figname=None, title=None)[source]#
inputs: x = times ys = [detrended light curves] of length N number of detrendings detrend_labels = [detrending type] of length N number of detrendings t0s_in_data = midtransits in data window = what fraction of the period to plot on either side of transit (ie. window=1/2 means 1/2 period on either side) period = planet period to define plotting limit colors = [colors] of length N number of detrendings figname = Name of file if you want to save figure
return: None
- democratic_detrender.plot.plot_individual_outliers(time, flux, time_out, flux_out, t0s, period, window, depth, figname)[source]#
input:#
time = array of time values flux = array of flux values time_out = array of time values without outliers flux_out = array of flux values without outliers period = planet period to define plotting limit window = what fraction of the period to plot on either side of transit (ie. window=1/2 means 1/2 period on either side) t0s = midtransits in data
- democratic_detrender.plot.plot_outliers(time, flux, time_out, flux_out, moving_median, kepler_quarters, figname, object_id)[source]#
input:#
time = array of time values flux = array of flux values time_out = array of time values without outliers flux_out = array of flux values without outliers
Helper functions#
This module contains helper functions for statistical calculations and data processing.
- democratic_detrender.helper_functions.durbin_watson(residuals)[source]#
Calculate the Durbin-Watson statistic for a given set of residuals.
- Parameters:
residuals – array-like, residuals from a model
- Returns:
Durbin-Watson statistic
- Return type:
float
- democratic_detrender.helper_functions.ensemble_step(y_detrended, yerr_detrended=None, method='median')[source]#
Combine multiple detrending methods into a single flux time series (method-marginalized light curve) and propagate uncertainties.
- Parameters:
y_detrended (array-like, shape (n_times, n_methods)) – Detrended flux values. Each column is the SAME target light curve after a different detrending method. Rows are timestamps. Can include NaNs.
yerr_detrended (array-like, shape (n_times,)) – The per-point uncertainty for the target light curve BEFORE method-marginalization. If None, it’s treated as zeros. (This matches how your snippet uses
yerr_detrendedas a 1D array.)method ({"median", "mean"}) –
How to combine across methods at each timestamp: - “median”: use np.nanmedian across methods,
and use MAD as the method-scatter term.
- ”mean”: use np.nanmean across methods,
and use standard deviation as the method-scatter term.
- Returns:
flux_mm (ndarray, shape (n_times,)) – Method-marginalized flux (the final combined light curve).
flux_err_mm (ndarray, shape (n_times,)) – Updated per-point uncertainty after marginalizing over method. This is:
sqrt( yerr_detrended^2 + scatter_term^2 )
where scatter_term is MAD (for median) or std (for mean), both computed across methods at that timestamp.
Notes
We transpose internally only to mirror your original code, where you did y_detrended.T then axis=1. After transpose we have shape (n_methods, n_times), so axis=0 would also work, but we’ll stick to axis=0/axis=1 choices that reproduce your math exactly.
MAD uses scale=1/1.4826 to match your exact call, i.e. the raw unscaled MAD, not the Gaussian-scaled MAD.
- democratic_detrender.helper_functions.get_detrended_lc(y, detrending_model)[source]#
Get detrended light curve (LC).
- Parameters:
y (array) – Light curve (LC).
detrending_model (array) – Stellar detrending model evaluated at the same time as LC.
- Returns:
Detrended light curve evaluated at the same time as input LC.
- Return type:
array