CBV Creator (corrections.CBVCreator
)
Creation of Cotrending Basis Vectors.
The CBV creation has three major steps, which are wrapped in the CBVCreator
class:
The CBVs for the specific todo-list are computed using the
CBVCreator.compute_cbv()
function.CBVs are split into “single-scale” CBVs and “spike” CBVs using the
CBVCreator.spike_sep()
function.An initial fitting is performed for all targets using linear least squares using the
CBVCreator.cotrend_ini()
function. This is done to obtain fitting coefficients for the CBVs that will be used to form priors for the final fit.Priors are constructed using the output from step 3, using the
CBVCreator.compute_weight_interpolations()
function. This function saves interpolation functions for each of the CBV coefficient priors.
Code author: Mikkel N. Lund <mikkelnl@phys.au.dk>
Code author: Rasmus Handberg <rasmush@phys.au.dk>
- class corrections.CBVCreator(*args, cadence='ffi', sector=None, cbv_area=None, ncomponents=16, threshold_correlation=0.5, threshold_snrtest=5.0, threshold_variability=1.3, threshold_entropy=- 0.5, output_folder=None, **kwargs)[source]
Bases:
corrections.BaseCorrector.BaseCorrector
Creation of Cotrending Basis Vectors.
- sector
TESS Sector.
- Type
int
- cadence
TESS observing cadence in seconds.
- Type
int
- cbv_area
- Type
int
- datasource
- Type
str
- ncomponents
Number of CBVs to be created.
- Type
int
- threshold_variability
- Type
float
- threshold_correlation
- Type
float
- threshold_snrtest
- Type
float
- threshold_entropy
- Type
float
- hdf
- Type
h5py.File
- hdf_filepath
Path to the HDF5 file containing the CBV.
- Type
str
- cbv_plot_folder
- Type
str
- random_state
- Type
int
Code author: Rasmus Handberg <rasmush@phys.au.dk>
Code author: Mikkel N. Lund <mikkelnl@phys.au.dk>
- __init__(*args, cadence='ffi', sector=None, cbv_area=None, ncomponents=16, threshold_correlation=0.5, threshold_snrtest=5.0, threshold_variability=1.3, threshold_entropy=- 0.5, output_folder=None, **kwargs)[source]
Initialize the CBV Creator.
- Parameters
sector (int, required) – TESS Sector.
cbv_area (int, required) –
cadence (int or str, optional) – TESS observing cadence in seconds.
ncomponents (int, optional) – Number of CBVs to be created.
threshold_variability (float, optional) –
threshold_correlation (float, optional) –
threshold_snrtest (float, optional) –
threshold_entropy (float, optional) –
output_folder (str, optional) –
Code author: Rasmus Handberg <rasmush@phys.au.dk>
Code author: Mikkel N. Lund <mikkelnl@phys.au.dk>
- compute_cbvs(targ_limit=150)[source]
Main function for computing CBVs.
The steps taken in the function are:
Run
lightcurve_matrix()
to obtain matrix with gap-filled, nan-removed light curves for the most correlated stars in a given cbv-area.Compute principal components.
Run
entropy_cleaning()
to remove significant single-star contributers based on entropy.Rerun SNR test on CBVs, and only retain CBVs that pass the test.
Recalculate principal components using cleaned star list.
Save CBVs and make diagnostics plots.
- Parameters
targ_limit (int, optional) – Maximum number of targets to remove during entropy-cleaning.
Code author: Mikkel N. Lund <mikkelnl@phys.au.dk>
Code author: Rasmus Handberg <rasmush@phys.au.dk>
- compute_distance_map()[source]
3D distance map for weighting initial-fit coefficients into a prior.
Code author: Mikkel N. Lund <mikkelnl@phys.au.dk>
- cotrend_ini(do_ini_plots=False)[source]
Function for running the initial co-trending to obtain CBV coefficients for the construction of priors.
The function will load the calculated CBVs and co-trend all light curves in area using fit of all CBVs using linear least squares. The CBV coefficients from the fit are saved into the HDF5 CBV file.
- Parameters
do_ini_plots (bool) – Plot the LS fit for each light curve? Default=False.
Code author: Mikkel N. Lund <mikkelnl@phys.au.dk>
Code author: Rasmus Handberg <rasmush@phys.au.dk>
- entropy_cleaning(matrix, targ_limit=150)[source]
Entropy-cleaning of lightcurve matrix using the SVD U-matrix.
- Parameters
matrix (
numpy.ndarray
) –targ_limit (int, optional) – Maximum number of targets to remove during cleaning.
Code author: Mikkel N. Lund <mikkelnl@phys.au.dk>
- interpolate_to_higher_cadence(cadence=120)[source]
Interpolate CBVs generated from FFIs to higher cadence (120 seconds).
New HDF5 files will be generated, containing the CBVs interpolated using a cubic spline to the higher cadence. All spike-CBVs are set to zero, since there is no good way to interpolate them.
- Parameters
cadence (int) –
- Returns
Path to the new CBV file.
- Return type
str
Code author: Rasmus Handberg <rasmush@phys.au.dk>
- lightcurve_matrix()[source]
Load matrix filled with light curves.
The steps performed are the following:
Only targets with a variability below a threshold are included.
Computes correlation matrix for light curves in a given cbv-area and only includes the
threshold_correlation()
most correlated light curves.Performs gap-filling of light curves and removes time stamps where all flux values are NaN.
- Returns
numpy.ndarray
: matrix of light curves to be used in CBV calculation.numpy.ndarray
: the indices for the timestamps with nans in all light curves.int: Number of timestamps.
- Return type
tuple
Code author: Rasmus Handberg <rasmush@phys.au.dk>
Code author: Mikkel N. Lund <mikkelnl@phys.au.dk>
- load_lightcurve(task)
Load lightcurve from task ID or full task dictionary.
- Parameters
task (integer or dict) –
- Returns
Lightcurve for the star in question.
- Return type
lightkurve.TessLightCurve
- Raises
ValueError – On invalid file format.
Code author: Rasmus Handberg <rasmush@phys.au.dk>
- plot_folder(lc)
Return folder path where plots for a given lightcurve should be saved.
- Parameters
lc (
lightkurve.TessLightCurve
) – Lightcurve to return plot path for.- Returns
Path to directory where plots should be saved.
- Return type
string
Code author: Rasmus Handberg <rasmush@phys.au.dk>
- search_database(select=None, join=None, search=None, order_by=None, limit=None, distinct=False)
Search list of lightcurves and return a list of tasks/stars matching the given criteria.
Returned rows are restricted to things not marked as
STATUS.SKIPPED
, since these have been deemed too bad to not require corrections, they are definitely also too bad to use in any kind of correction.- Parameters
select (list of strings or None) – List of table columns to return.
search (list of strings or None) – Conditions to apply to the selection of stars from the database
order_by (list, str or None) – Column to order the database output by.
limit (int or None) – Maximum number of rows to retrieve from the database. If limit is None, all the rows are retrieved.
distinct (bool) – Boolean indicating if the query should return unique elements only.
join (list) – Table join commands to merge several database tables together.
- Returns
All stars retrieved by the call to the database as dicts/tasks that can be consumed directly by load_lightcurve
- Return type
list
Code author: Rasmus Handberg <rasmush@phys.au.dk>
- spike_sep()[source]
Separate CBVs into a “slow” and a “spiky” component.
This is done by filtering the deta and identifying outlier with a peak-finding algorithm.
Code author: Mikkel N. Lund <mikkelnl@phys.au.dk>