{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How to recover a known planet in Kepler data?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This tutorial will demonstrate the basic steps required to recover the signal of [Kepler-10b](https://en.wikipedia.org/wiki/Kepler-10b), the first rocky planet that was discovered by Kepler!\n", "\n", "Let's start by downloading the pixel data for this target for one of Kepler's observing quarters:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import lightkurve as lk\n", "tpf = lk.search_targetpixelfile(\"Kepler-10\", author=\"Kepler\", quarter=3, cadence=\"long\").download()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's use the `plot` method to show the pixel data at one point in time (frame index 100). We'll also pass along a few plotting arguments." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tpf.plot(frame=100, scale='log', show_colorbar=True);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The target pixel file appears to show one bright star with a core brightness of approximately 50,000 electrons/seconds." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, we will use the [to_lightcurve](https://docs.lightkurve.org/reference/api/lightkurve.KeplerTargetPixelFile.to_lightcurve.html?highlight=to_lightcurve) method to create a simple aperture photometry lightcurve using the\n", "mask defined by the pipeline which is stored in [tpf.pipeline_mask](https://docs.lightkurve.org/reference/api/lightkurve.KeplerTargetPixelFile.pipeline_mask.html?highlight=pipeline_mask)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lc = tpf.to_lightcurve(aperture_mask=tpf.pipeline_mask)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's take a look at the output lightcurve." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lc.plot();" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's use the [.flatten()](https://docs.lightkurve.org/reference/api/lightkurve.LightCurve.flatten.html?highlight=flatten#lightkurve.LightCurve.flatten) method, which removes long-term variability that we are not interested in using a high-pass filter called *Savitzky-Golay*." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "flat, trend = lc.flatten(window_length=301, return_trend=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's plot the trend estimated in red:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ax = lc.errorbar(label=\"Kepler-10\") # plot() returns a matplotlib axes ...\n", "trend.plot(ax=ax, color='red', lw=2, label='Trend'); # which we can pass to the next plot() to use the same axes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and the flat lightcurve:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "flat.errorbar(label=\"Kepler-10\");" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, let's run a period search function using the well-known Box-Least Squares algorithm (BLS), which was added to the [AstroPy package](http://docs.astropy.org) in version 3.1.\n", "\n", "We will use the BLS algorithm to search a pre-defined grid of transit periods:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "periodogram = flat.to_periodogram(method=\"bls\", period=np.arange(0.5, 1.5, 0.001))\n", "periodogram.plot();" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It looks like we found a strong signal with a periodicity near 0.8 days!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "best_fit_period = periodogram.period_at_max_power\n", "print('Best fit period: {:.3f}'.format(best_fit_period))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "flat.fold(period=best_fit_period, epoch_time=periodogram.transit_time_at_max_power).errorbar();" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We successfully recovered the planet!" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.10" } }, "nbformat": 4, "nbformat_minor": 4 }