This tutorial demonstrates the basic steps required to recover a transiting planet candidate in the Kepler data.
We will show how you can recover the signal of Kepler-10b, the first rocky planet that was discovered by Kepler!
from lightkurve import search_targetpixelfile
tpf = search_targetpixelfile("Kepler-10", quarter=3).download()
tpf.shape
(4140, 10, 11)
Let's use the plot
method and pass along an aperture mask and a few plotting arguments.
tpf.plot(scale='log');
The target pixel file contains one bright star with approximately 50,000 counts.
Now, we will use the to_lightcurve
method to create a simple aperture photometry lightcurve using the
mask defined by the pipeline which is stored in tpf.pipeline_mask
.
lc = tpf.to_lightcurve(aperture_mask=tpf.pipeline_mask)
Let's take a look at the output lightcurve.
lc.plot();
Now let's use the flatten
method, removes long-term variability that we are not interested in.
flat, trend = lc.flatten(window_length=301, return_trend=True)
Let's plot the trend estimated by the Savitzky-Golay filter:
ax = lc.errorbar() # plot() returns a matplotlib axes ...
trend.plot(ax=ax, color='red', label='Trend'); # which we can pass to the next plot() to use the same axes
and the flat lightcurve:
flat.errorbar();
Now, let's run a period search function using the Box-Least Squares algorithm, which was added to the AstroPy package in version 3.1.
from astropy.stats import BoxLeastSquares
bls = BoxLeastSquares(flat.time, flat.flux, flat.flux_err)
We will use the BLS algorithm to search a pre-defined grid of transit periods and durations:
import numpy as np
periods = np.arange(0.3, 1.5, 0.001)
durations = np.arange(0.005, 0.15, 0.001)
periodogram = bls.power(periods, durations)
import matplotlib.pyplot as plt
plt.plot(periodogram.period, periodogram.power)
plt.ylabel("Power")
plt.xlabel("Period [day]");
best_fit = periods[np.argmax(periodogram.power)]
print('Best Fit Period: {:0.4f} days'.format(best_fit))
Best Fit Period: 0.8380 days
flat.fold(best_fit).errorbar();
We successfully recovered the planet!