{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# What are TargetPixelFile objects?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Target Pixel Files (TPFs) are a file common to Kepler/K2 and the TESS mission. They contain movies of the pixel data centered on a single target star.\n", "\n", "TPFs can be thought of as stacks of images, with one image for every timestamp the telescope took data. Each timestamp is referred to as a **cadence**. These images are cut out 'postage stamps' of the full observation to make them easier to work with. \n", "\n", "TPFs are given in FITS files, which you can read more about [here](https://fits.gsfc.nasa.gov/fits_primer.html). *Lightkurve* includes tools for you to work directly with these files easily and intuitively.\n", "\n", "In this tutorial we'll cover the basics of working with TPFs. In *lightkurve* there are classes to work with each mission. For example `KeplerTargetPixelFile` deals with data from the Kepler (and K2) mission. `TessTargetPixelFile` deals with data from the TESS mission. We'll use a Kepler TPF as an example.\n", "\n", "To load a `KeplerTargetPixelFile` from a local path or remote url, simply create a new object using the location of the file as the parameter:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from lightkurve import KeplerTargetPixelFile\n", "tpf = KeplerTargetPixelFile(\"https://archive.stsci.edu/pub/kepler/target_pixel_files/0069/006922244/kplr006922244-2010078095331_lpd-targ.fits.gz\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also search for the url automatically using the `search_targetpixelfile()` function. This will search for the right file in the [MAST data archive](https://archive.stsci.edu/kepler/) which holds all of the Kepler and K2 data.\n", "In this case we want the Target Pixel File with Kepler ID 6922244 for Quarter 4 (Kepler's observations were split into quarters of a year):" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from lightkurve import search_targetpixelfile\n", "tpf = search_targetpixelfile(6922244, quarter=4).download()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also pass the name of the target or its astronomical coordinates as a parameter to `search_targetpixelfile()`.\n", "\n", "The above code has created a variable named `tpf` which is a Python object of type `KeplerTargetPixelFile`:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "KeplerTargetPixelFile Object (ID: 6922244)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tpf" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can access lots of meta data using this object in a simple way. For example, we can find the mission name, and the quarter that the data was taken in by typing the following:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Kepler'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tpf.mission" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tpf.quarter" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can find the full list of properties in the [API documentation](http://lightkurve.keplerscience.org/api/targetpixelfile.html) on this object." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The most interesting data in a `KeplerTargetPixelFile` object are the `flux` and `time` values which give access to the brightness of the observed target over time. You can access the timestamps of the observations using the `time` property:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "array([352.37632485, 352.39675805, 352.43762445, ..., 442.16263546,\n", " 442.18306983, 442.2035041 ])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tpf.time" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By default, `time` is in the Kepler-specific *Barycentric Kepler Julian Day* format (BKJD). You can easily convert this into [AstroPy Time objects](http://docs.astropy.org/en/stable/time/) using the `astropy_time` property:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "