contaminante API

contaminante Core Functions

Basic contaminante functionality

contaminante.contaminante.calculate_contamination(targetid, period, t0, duration, mission='kepler', plot=True, gaia=False, quarter=None, sector=None, campaign=None, bin_points=None)

Calculate the contamination for a target

Parameters:
  • targetid (str) -- The ID of the target, either KIC, EPIC or TIC from Kepler, K2 or TESS
  • period (float) -- Period of transiting object in days
  • t0 (float) -- Transit midpoint of transiting object in days
  • duration (float) -- Duration of transit in days
  • mission (str) -- Kepler, K2 or TESS
  • plot (bool) -- If True, will generate a figure
  • gaia (bool) -- If True, will plot gaia sources over image
  • quarter (int, list or None) -- Quarter of Kepler data to use. Specify either using an integer (e.g. 1) or a range (e.g. [1, 2, 3]). None will return all quarters.
  • sector (int, list or None) -- Sector of TESS data to use. Specify either using an integer (e.g. 1) or a range (e.g. [1, 2, 3]). None will return all sectors.
  • campaign (int, list or None) -- Campaign of K2 data to use. Specify either using an integer (e.g. 1) or a range (e.g. [1, 2, 3]). None will return all campaigns.
  • bin_points (None or int) -- Number of points to bin the data by, if None a sensible default will be chosen.
Returns:

  • fig (matplotlib.pyplot.figure) -- If plot is True, will return a figure showing the contamination
  • result (dict) -- Dictionary containing the contamination properties

contaminante Utility Functions

Utility functions for contaminante

contaminante.utils.build_X(tpf, flux, t_model=None, background=False, cbvs=None, spline=True, spline_period=2, sff=False)

Build a design matrix to model pixel in target pixel files

Parameters:
  • tpf (lightkurve.TargetPixelFile) -- Input target pixel file to make the design matrix for
  • flux (np.ndarray) -- The SAP flux to use for creating the design matrix
  • t_model (None or np.ndarray) -- The transit model, if None no transit model will be used in the design matrix
  • background (None or np.ndarray) -- Background model, useful for TESS data. If None will not be used in design matrix
  • cbvs (None or np.ndarray) -- Cotrending Basis vectors. If None will not be used in design matrix
  • spline (bool) -- Whether to use a B-Spline in time
  • spline_period (float) -- If using a spline, what time period the knots should be spaced at
  • sff (bool) -- Whether to use the SFF method of buildign centroids
Returns:

SA -- The design matrix to use to detrend the input TPF

Return type:

scipy.sparse.csr_matrix

contaminante.utils.build_lc(tpf, aperture_mask, cbvs=None, errors=False, cadence_mask=None, background=False, spline=True, spline_period=2)

Build a corrected light curve

Parameters:
  • tpf (lightkurve.TargetPixelFile) -- Input target pixel file to make the design matrix for
  • aperture_mask (np.ndarray of bool) -- Aperture mask to sum the light curve over
  • cbvs (None or np.ndarray) -- Cotrending Basis vectors. If None will not be used in design matrix
  • errors (bool) -- Whether to calculate the errors on the model and propagate them
  • cadence_mask (None or np.ndarray) -- A mask to specify which cadences to use. Cadences where True will not be used in the analysis.
  • background (bool) -- Whether to calculate a background model
  • spline (bool) -- Whether to use a B-Spline in time
  • spline_period (float) -- If using a spline, what time period the knots should be spaced at
Returns:

corrected_lc -- The corrected light curve

Return type:

lightkurve.LightCurve

contaminante.utils.build_model(tpf, flux, cbvs=None, t_model=None, errors=False, cadence_mask=None, background=False, spline=True)

Build a model for the pixel level light curve

Parameters:
  • tpf (lightkurve.TargetPixelFile) -- Input target pixel file to make the design matrix for
  • flux (np.ndarray) -- The SAP flux to use for creating the design matrix
  • cbvs (None or np.ndarray) -- Cotrending Basis vectors. If None will not be used in design matrix
  • t_model (None or np.ndarray) -- The transit model, if None no transit model will be used in the design matrix
  • errors (bool) -- Whether to return the errors of the models
  • cadence_mask (None or np.ndarray) -- A mask to specify which cadences to use. Cadences where True will not be used in the analysis.
  • background (bool) -- Whether to estimate the background flux, useful for TESS
  • spline (bool) -- Whether to use a B-Spline in time
Returns:

  • model (np.ndarray) -- Model of the TPF, with shape ncadences x npixels x npixels.
  • model_err (np.ndarray) -- If errors is true, returns model errors
  • transit_pixels (np.ndarray) -- If t_model is specified, the weight of the transit in each pixel. Shape npixel x npixel
  • transit_pixels_err (np.ndarray) -- If t_model is specified, the error of the weight of the transit in each pixel. Shape npixel x npixel
  • aper (bool) -- The aperture that contains the transit signal (npixels x npixels)

contaminante.utils.search(targetid, mission, search_func=<function search_targetpixelfile>, quarter=None, sector=None, campaign=None)

Convenience function to help lightkurve searches

Parameters:
  • targetid (str) -- The ID of the target, either KIC, EPIC or TIC from Kepler, K2 or TESS
  • mission (str) -- Kepler, K2 or TESS
  • search_func (func) -- The search function to use, default is lk.search_targetpixelfile. Users may want lk.search_tesscut
  • quarter (int, list or None) -- Quarter of Kepler data to use. Specify either using an integer (e.g. 1) or a range (e.g. [1, 2, 3]). None will return all quarters.
  • sector (int, list or None) -- Sector of TESS data to use. Specify either using an integer (e.g. 1) or a range (e.g. [1, 2, 3]). None will return all sectors.
  • campaign (int, list or None) -- Campaign of K2 data to use. Specify either using an integer (e.g. 1) or a range (e.g. [1, 2, 3]). None will return all campaigns.
Returns:

sr -- Search result object containing the valid files.

Return type:

lk.search.SearchResult