Python Interface¶

This describes the Python interface to TLS.

Return values¶

The TLS spectra:

periods: (array) The period grid used in the search (array) The power spectrum per period as defined in the TLS paper. We recommend to use this spectrum to assess transit signals. It is the median-smoothed power_raw spectrum. (array) The raw power spectrum (without median smoothing) as defined in the TLS paper (array) Signal residue similar to the BLS SR (array) Minimum chi-squared ($$\chi^2$$) per period (array) Minimum chi-squared per degree of freedom ($$\chi^2_{\nu}=\chi^2/\nu$$) per period, where $$\nu=n-m$$ with $$n$$ as the number of observations, and $$m=4$$ as the number of fitted parameters (period, T0, transit duration, transit depth).

The TLS statistics:

SDE: (float) Maximum of power (float) Maximum of power_raw (float) Minimum of chi2 (float) Minimum of chi2red

Additional transit statistics based on the power spectrum:

period: period_uncertainty: (float) Period of the best-fit signal (float) Uncertainty of the best-fit period (half width at half maximum) (float) Mid-transit time of the first transit within the time series (float) Best-fit transit duration (float) Best-fit transit depth (measured at the transit bottom) (tuple of floats) Transit depth measured as the mean of all intransit points. The second value is the standard deviation of these points multiplied by the square root of the number of intransit points (tuple of floats) Mean depth and uncertainty of even transits (1, 3, …) (tuple of floats) Mean depth and uncertainty of odd transits (2, 4, …) (float) Radius ratio of planet and star using the analytic equations from Heller 2019 (array) Mean depth of each transit (array) Uncertainty (1-sigma) of the mean depth of each transit (float) Signal-to-noise ratio. Definition: $${\rm SNR} = \frac{d}{\sigma_o}n^{1/2}$$ with $$d$$ as the mean transit depth, $$\sigma$$ as the standard deviation of the out-of-transit points, and $$n$$ as the number of intransit points (Pont et al. 2006) (array) Signal-to-noise ratio per individual transit (array) Signal-to-pink-noise ratio per individual transit as defined in Pont et al. (2006) (float) Significance (in standard deviations) between odd and even transit depths. Example: A value of 5 represents a $$5\,\sigma$$ confidence that the odd and even depths have different depths (array) The mid-transit time for each transit within the time series (array) Number of data points during each unique transit (int) The number of transits (int) The number of transits with intransit data points (int) The number of transits with no intransit data points (float) The false alarm probability for the SDE assuming white noise. Returns NaN for FAP>0.1. (int) * Number of data points in transit (phase-folded) (int) Number of data points in a bin of length transit duration before transit (phase-folded) (int) Number of data points in a bin of length transit duration after transit (phase-folded)

Time series model for visualization purpose:

model_lightcurve_time:
(array) Time series spanning t, but without gaps, and oversampled by a factor of 5
model_lightcurve_model:
(array) Model flux value of each point in model_lightcurve_time

Phase-folded model for visualization purpose:

folded_phase: folded_y: (array) Phase of each data point y when folded to period so that the transit is at folded_phase=0.5 (array) Data flux of each point (array) Data uncertainty of each point (array) Linear array [0..1] which can be used to plot the model_folded_model. This is a separate array from folded_phase, because the data may have gaps which would prevent plotting the complete model. This array here is complete. (array) Model flux of each point in model_folded_phase

Note

The models are oversampled and calculated for each point in time and phase. This way, the models cover the entire time series (phase space), including gaps. Thus, these curves are not exact representations of the models used during the search. They are intended for visualization purposes.

Period grid¶

When searching for sine-like signals, e.g. using Fourier Transforms, it is optimal to uniformly sample the trial frequencies. This was also suggested for BLS (Kovács et al. 2002). However, when searching for transit signals, this is not optimal due to the transit duty cycle which changes as a function of the planetary period due to orbital mechanics. The optimal period grid, compared to a linear grid, reduces the workload (at the same detection efficiency) by a factor of a few. The optimal frequency sampling as a function of stellar mass and radius was derived by Ofir (2014) as

$N_{\rm freq,{ }optimal} = \left( f_{\rm max}^{1/3} - f_{\rm min}^{1/3} + \frac{A}{3} \right) \frac{3}{A}$

with

$A=\frac{(2\pi)^{2/3}}{\pi }\frac{R}{(GM)^{1/3}}\frac{1}{S \times OS}$

where $$M$$ and $$R$$ are the stellar mass and radius, $$G$$ is the gravitational constant, $$S$$ is the time span of the dataset and $$OS$$ is the oversampling parameter to ensure that the peak is not missed between frequency samples. The search edges can be found at the Roche limit,

$f_{\rm max}=\frac{1}{2 \pi} \sqrt{\frac{GM}{(3R)^3}}; f_{\rm min}=2/S$
period_grid(parameters)
R_star: M_star: Stellar radius (in units of solar radii) Stellar mass (in units of solar masses) Duration of time series (in units of days) Minimum trial period (in units of days). Optional. Maximum trial period (in units of days). Optional. Default: 2. Optional. Returns: a 1D array of float values representing a grid of trial periods in units of days.

Example usage:

from transitleastsquares import period_grid
periods = period_grid(R_star=1, M_star=1, time_span=400)


returns a period grid with 32172 values:

[200, 199.889, 199.779, ..., 0.601, 0.601, 0.601]


Note

TLS calls this function automatically to derive its period grid. Calling this function separately can be useful to employ a classical BLS search, e.g., using the astroPy BLS function.

Note

To avoid generating an infinitely large period_grid, parameters are auto-enforced to the ranges 0.1 < R_star < 10000 and 0.01 < M_star < 1000. Some combinations of mostly implausible values, such as R_star=1 with M_star=5 yield empty period grids. If the grid size is less than 100 values, the function returns the default grid R_star=M_star=1. Very short time series (less than a few days of duration) default to a grid size with a span of 5 days.

Priors for stellar parameters¶

This function provides priors for stellar mass, radius, and limb darkening for stars observed during the Kepler K1, K2 and TESS missions. It is planned to extend this function for past and future missions such as CHEOPS and PLATO.

catalog_info(EPIC_ID or TIC_ID)
EPIC_ID: (int) The EPIC catalog ID (K2, Ecliptic Plane Input Catalog) (int) The TIC catalog ID (TESS Input Catalog) (int) The Kepler Input Catalog ID (Kepler K1 Input Catalog)

Returns

ab: (tuple of floats) Quadratic limb darkening parameters a, b (float) Stellar mass (in units of solar masses) (float) 1-sigma upper confidence interval on stellar mass (in units of solar mass) (float) 1-sigma lower confidence interval on stellar mass (in units of solar mass) (float) Stellar radius (in units of solar radii) (float) 1-sigma upper confidence interval on stellar radius (in units of solar radii) (float) 1-sigma lower confidence interval on stellar radius (in units of solar radii)

Note

The matching between the stellar parameter table and the limb darkening table is performed by first finding the nearest $$T_{\rm eff}$$, and subsequently the nearest $${\rm logg}$$.

Note

Data sources:

K1 data are pulled from the catalog for Revised Stellar Properties of Kepler Targets (Mathur et al. 2017) with limb darkening coefficients from Claret et al. (2012, 2013). Data are pulled from Vizier using AstroQuery and matched to limb darkening values saved locally in a CSV file within the TLS package.

K2 data are collated from the K2 Ecliptic Plane Input Catalog (Huber et al. 2016) with limb darkening coefficients from Claret et al. (2012, 2013). Data are pulled from Vizier using AstroQuery and matched to limb darkening values saved locally in a CSV file within the TLS package.

TESS data are collated from the TESS Input Catalog (TIC, Stassun et al. 2018) with limb darkening coefficients from Claret et al. (2017). TIC data are pulled from MAST and matched to limb darkening values saved locally in a CSV file within the TLS package.

Warning

Upper and lower confidence intervals may be identical. Radius confidence interval may be identical to the radius. Values not available in the catalog are returned as None. When feeding these values to TLS, make sure to validate accordingly.

Example usage:

ab, R_star, R_star_min, R_star_max, M_star, M_star_min, M_star_max = catalog_info(EPIC_ID=211611158)
print('Quadratic limb darkening a, b', ab[0], ab[1])
print('Stellar radius', R_star, '+', R_star_max, '-', R_star_min)
print('Stellar mass', M_star, '+', M_star_max, '-', M_star_min)


produces these results:

Quadratic limb darkening a, b 0.4899 0.1809
Stellar radius 1.055 + 0.12 - 0.1
Stellar mass 1.267 + 0.64 - 0.286


Note

Missing catalog entries will be returned as NaN values. These have to be treated on the user side.

Can be used to plot in-transit points in a different color, or to cleanse the data from a transit signal before a subsequent TLS run to search for further planets.

transit_mask(t, period, duration, T0)
t: (array) Time series of the data (in units of days) (float) Transit period e.g. from results: period (float) Transit duration e.g. from results: duration (float) Mid-transit of first transit e.g. from results: T0

Returns

intransit: (numpy array mask) A numpy array mask (of True/False values) for each data point in the time series. True values are in-transit.

Example usage:

intransit = transit_mask(t, period, duration, T0)
print(intransit)
>>> [False False False ...]
plt.scatter(t[in_transit], y[in_transit], color='red')  # in-transit points in red
plt.scatter(t[~in_transit], y[~in_transit], color='blue')  # other points in blue


Data cleansing¶

TLS may not work correctly with corrupt data, such as arrays including values as NaN, None, infinite, or negative. Masked numpy arrays may also be problematic, e.g., when performing a transit_mask. When in doubt, it is recommended to clean the data from masks and non-floating point values. For this, TLS offers a convenience function:

cleaned_array(t, y, dy)
t: (array) Time series of the data (in units of days) (array) Flux series of the data (array, optional) Measurement errors of the data

Returns

Cleaned arrays, where values of type NaN, None, +-inf, and negative have been removed, as well as masks. Removed values make the output arrays shorter.

Example usage:

from transitleastsquares import cleaned_array
dirty_array = numpy.ones(10, dtype=object)
time_array = numpy.linspace(1, 10, 10)
dy_array = numpy.ones(10, dtype=object)
dirty_array[1] = None
dirty_array[2] = numpy.inf
dirty_array[3] = -numpy.inf
dirty_array[4] = numpy.nan
dirty_array[5] = -99
print(time_array)
print(dirty_array)

>>> [ 1.  2.  3.  4.  5.  6.  7.  8.  9. 10.]
>>> [1 None inf -inf nan -99 1 1 1 1]

t, y, dy = cleaned_array(time_array, dirty_array, dy_array)
print(t)
print(y)
>>> [ 1.  7.  8.  9. 10.]
>>> [1. 1. 1. 1. 1.]


Data resampling (binning)¶

TLS run times are strongly dependent on the amount of data. Very roughly, an increase in the data volume by one order of magnitude results in a run time increase of two orders of magnitude (see paper Figure 9).

For a first quick look, or for short cadence data, it may be adequate to down-sample (bin) the data. In general, binning is adequate if there are many data points between two phase grid points at the critical phase sampling.

To bin the data, TLS offers a convenience function:

resample(t, y, dy, factor)
t: (array) Time series of the data (in units of days) (array) Flux series of the data (array, optional) Measurement errors of the data (float, optional, default: 2.0) Binning factor

Returns

Resampled arrays of length len(t)*int(1/factor), where the flux (and optionally, dy) values are binned by linear interpolation.

Example usage:

from transitleastsquares import resample
time_new, flux_new = resample(time, flux, factor=3.0)


Note

Values of type (NaN, None, +-inf, negative, or empty) lead to undefined behavior. It is recommended to first use cleaned_array if needed.