Using Kepler Target Pixel File Products with Lightkurve#

Learning Goals#

By the end of this tutorial, you will:

  • Be able to download and plot target pixel files from the data archive using Lightkurve.

  • Be able to access target pixel file metadata.

  • Understand where to find more details about Kepler target pixel files.

Introduction#

The Kepler, K2, and TESS telescopes observe stars for long periods of time, from just under a month to four years. By doing so they observe how the brightnesses of stars change over time.

Kepler selected certain pixels around targeted stars to be downloaded from the spacecraft. These were stored as target pixel files that contain data for each observed cadence. In this tutorial, we will learn how to use Lightkurve to download these raw data, plot them, and understand their properties and units.

It is recommended that you first read the tutorial on how to use Kepler light curve products with Lightkurve. That tutorial will introduce you to some specifics of how Kepler, K2, and TESS make observations, and how these are displayed as light curves. It also introduces some important terms and concepts that are referred to in this tutorial.

Kepler observed a single field in the sky, although not all stars in this field were recorded. Instead, pixels were selected around certain targeted stars. This series of cutouts were downloaded and stored as an array of images in target pixel files, or TPFs. By summing up the amount of light (the flux) captured by the pixels in which the star appears, you can make a measurement of the brightness of a star over time.

TPFs are an important resource when studying an astronomical object with Kepler, K2, or TESS. The files allow us to understand the original images that were collected, and identify potential sources of noise or instrument-induced trends which may be less obvious in derived light curves. In this tutorial, we will use the Kepler mission as the main example, but these tools equally work for TESS and K2.

Imports#

This tutorial requires Lightkurve, which in turn uses matplotlib for plotting.

import lightkurve as lk
%matplotlib inline 

1. What is a Target Pixel File?#

The target pixel file (TPF) of a star contains an image for each observing cadence, either a 30-minute Long Cadence or one-minute Short Cadence exposure in the case of Kepler. The files also include metadata detailing how the observation was made, as well as post-processing information such as the estimated intensity of the astronomical background in each image. (Read the Kepler Archive Manual, Section 2.3.2 for more information.)

TPFs are stored in a FITS file format. The Lightkurve package allows us to work with these binary files without having to worry about the details of the file structure. For examples on how to work with FITS files directly, read this tutorial on Plotting Images from Kepler Target Pixel Files.

2. Downloading a Target Pixel File#

The TPFs of stars observed by the Kepler mission are stored on the Mikulksi Archive for Space Telescopes (MAST) archive, along with metadata about the observations, such as which charge-coupled device (CCD) was used at each time.

Lightkurve’s built-in tools allow us to search and download TPFs from the archive. As we did in the accompanying tutorial on light curves, we will start by downloading one quarter (a Kepler observing period approximately 90 days in duration) of Kepler data for the star named Kepler-8, a star somewhat larger than the Sun, and the host of a hot Jupiter planet.

Using the search_targetpixelfile function, we can find an itemized list of different TPFs available for Kepler-8.

search_result = lk.search_targetpixelfile("Kepler-8", mission="Kepler")
search_result
SearchResult containing 49 data products.
#missionyearauthorexptimetarget_namedistance
sarcsec
0Kepler Quarter 022009Kepler60kplr0069222440.0
1Kepler Quarter 022009Kepler60kplr0069222440.0
2Kepler Quarter 022009Kepler60kplr0069222440.0
3Kepler Quarter 032009Kepler60kplr0069222440.0
4Kepler Quarter 032009Kepler60kplr0069222440.0
5Kepler Quarter 032009Kepler60kplr0069222440.0
6Kepler Quarter 002009Kepler1800kplr0069222440.0
7Kepler Quarter 012009Kepler1800kplr0069222440.0
8Kepler Quarter 022009Kepler1800kplr0069222440.0
.....................
39Kepler Quarter 132012Kepler60kplr0069222440.0
40Kepler Quarter 132012Kepler60kplr0069222440.0
41Kepler Quarter 132012Kepler60kplr0069222440.0
42Kepler Quarter 112012Kepler1800kplr0069222440.0
43Kepler Quarter 122012Kepler1800kplr0069222440.0
44Kepler Quarter 132012Kepler1800kplr0069222440.0
45Kepler Quarter 142012Kepler1800kplr0069222440.0
46Kepler Quarter 162013Kepler1800kplr0069222440.0
47Kepler Quarter 152013Kepler1800kplr0069222440.0
48Kepler Quarter 172013Kepler1800kplr0069222440.0
Length = 49 rows

In this list, each row represents a different observing period. We find that Kepler recorded 18 quarters of data for this target across four years. The search_targetpixelfile() function takes several additional arguments, such as the quarter number or the mission name. You can find examples of its use in the online documentation for this function.

The search function returns a SearchResult object which has several convenient operations. For example, we can select the fourth data product in the list as follows:

search_result[4]
SearchResult containing 1 data products.
#missionyearauthorexptimetarget_namedistance
sarcsec
0Kepler Quarter 032009Kepler60kplr0069222440.0

We can download this data product using the download() method.

tpf = search_result[4].download()

This instruction is identical to the following line:

tpf = lk.search_targetpixelfile("Kepler-8", mission="Kepler", quarter=4).download()
/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/lightkurve/search.py:424: LightkurveWarning: Warning: 4 files available to download. Only the first file has been downloaded. Please use `download_all()` or specify additional criteria (e.g. quarter, campaign, or sector) to limit your search.
  warnings.warn(

The tpf_file variable we have obtained in this way is a KeplerTargetPixelFile object.

tpf
KeplerTargetPixelFile Object (ID: 6922244)

This file object provides a convenient way to interact with the data file that has been returned by the archive, which contains both the TPF as well as metadata about the observations.

Before diving into the properties of the KeplerTargetPixelFile, we can plot the data, also using Lightkurve.

%matplotlib inline
tpf.plot();
../../../_images/0499d742a5aafc6adb1350e005ee32c778a62c7c826a48456d9ec7fa6a4001f4.png

What you are seeing in this figure are pixels on the CCD camera, with which Kepler-8 was observed. The color indicates the amount of flux in each pixel, in electrons per second. The y-axis shows the pixel row, and the x-axis shows the pixel column. The title tells us the Kepler Input Catalogue (KIC) identification number of the target, and the observing cadence of this image. By default, plot() shows the first observation cadence in the quarter, but this can be changed by passing optional keyword arguments. You can type help(tpf.plot) to see a full list of those options.

Note#

You can also download TPF FITS files from the archive by hand, store them on your local disk, and open them using the lk.read(<filename>) function. This function will return a KeplerTargetPixelFile object just as in the above example. You can find out where Lightkurve stored a given TPF by typing tpf.path:

tpf.path
'/home/runner/.lightkurve/cache/mastDownload/Kepler/kplr006922244_sc_Q003333310333330000/kplr006922244-2010019161129_spd-targ.fits.gz'

3. Accessing the Metadata#

Our KeplerTargetPixelFile includes the observation’s metadata, loaded from the header of the TPF files downloaded from MAST. Many of these are similar to the metadata stored in the KeplerLightCurve, which are discussed in the accompanying tutorial.

The headers containing the metadata can be accessed from the KeplerTargetPixelFile through the get_header() method.

For example, the first extension (“extension 0”) of the file provides metadata related to the star, such as its magnitude in different passbands, its movement and position on the sky, and its location on Kepler’s CCD detector:

tpf.get_header(ext=0)
SIMPLE  =                    T / conforms to FITS standard                      
BITPIX  =                    8 / array data type                                
NAXIS   =                    0 / number of array dimensions                     
EXTEND  =                    T                                                  
NEXTEND =                    2 / number of standard extensions                  
EXTNAME = 'PRIMARY '           / name of extension                              
EXTVER  =                    1 / extension version number (not format version)  
ORIGIN  = 'NASA/Ames'          / institution responsible for creating this file 
DATE    = '2016-05-26'         / file creation date.                            
CREATOR = '1200109 TargetPixelExporterPipelineModule' / pipeline job and program
PROCVER = 'svn+ssh://murzim/repo/soc/tags/release/9.3.47 r61408' / SW version   
FILEVER = '6.1     '           / file format version                            
TIMVERSN= 'OGIP/93-003'        / OGIP memo number for file format               
TELESCOP= 'Kepler  '           / telescope                                      
INSTRUME= 'Kepler Photometer'  / detector type                                  
OBJECT  = 'KIC 6922244'        / string version of target id                    
KEPLERID=              6922244 / unique Kepler target identifier                
CHANNEL =                   31 / CCD channel                                    
SKYGROUP=                   31 / roll-independent location of channel           
MODULE  =                   10 / CCD module                                     
OUTPUT  =                    3 / CCD output                                     
QUARTER =                    4 / Observing quarter                              
SEASON  =                    2 / mission season during which data was collected 
DATA_REL=                   25 / data release version number                    
OBSMODE = 'short cadence'      / observing mode                                 
MISSION = 'Kepler  '           / Mission name                                   
TTABLEID=                   29 / target table id                                
RADESYS = 'ICRS    '           / reference frame of celestial coordinates       
RA_OBJ  =           281.288120 / [deg] right ascension                          
DEC_OBJ =            42.451080 / [deg] declination                              
EQUINOX =               2000.0 / equinox of celestial coordinate system         
PMRA    =               0.0000 / [arcsec/yr] RA proper motion                   
PMDEC   =               0.0000 / [arcsec/yr] Dec proper motion                  
PMTOTAL =               0.0000 / [arcsec/yr] total proper motion                
PARALLAX=                      / [arcsec] parallax                              
GLON    =            71.658900 / [deg] galactic longitude                       
GLAT    =            19.012749 / [deg] galactic latitude                        
GMAG    =               13.886 / [mag] SDSS g band magnitude                    
RMAG    =               13.511 / [mag] SDSS r band magnitude                    
IMAG    =               13.424 / [mag] SDSS i band magnitude                    
ZMAG    =               13.413 / [mag] SDSS z band magnitude                    
D51MAG  =               13.700 / [mag] D51 magnitude,                           
JMAG    =               12.576 / [mag] J band magnitude from 2MASS              
HMAG    =               12.323 / [mag] H band magnitude from 2MASS              
KMAG    =               12.292 / [mag] K band magnitude from 2MASS              
KEPMAG  =               13.563 / [mag] Kepler magnitude (Kp)                    
GRCOLOR =                0.375 / [mag] (g-r) color, SDSS bands                  
JKCOLOR =                0.284 / [mag] (J-K) color, 2MASS bands                 
GKCOLOR =                1.594 / [mag] (g-K) color, SDSS g - 2MASS K            
TEFF    =                 6225 / [K] Effective temperature                      
LOGG    =                4.169 / [cm/s2] log10 surface gravity                  
FEH     =               -0.040 / [log10([Fe/H])]  metallicity                   
EBMINUSV=                0.096 / [mag] E(B-V) reddening                         
AV      =                0.297 / [mag] A_v extinction                           
RADIUS  =                1.451 / [solar radii] stellar radius                   
TMINDEX =            262064792 / unique 2MASS catalog ID                        
SCPID   =            262064792 / unique SCP processing ID                       
CHECKSUM= 'Z4BPi39NZ3ANf37N'   / HDU checksum updated 2016-05-26T23:26:21Z      

This is an Astropy astropy.io.fits.Header object, which has many convenient features. For example, you can retrieve the value of an individual keyword as follows:

tpf.get_header(ext=0).get('QUARTER')
4

When constructing a KeplerTargetPixelFile from a FITS file, Lightkurve carries a subset of the metadata through into user-friendly object properties for convenience, which are available through shorthands (for example, tpf.quarter). You can view these properties with the the show_properties() method:

tpf.show_properties()
   Attribute                                                                Description                                                             
--------------- ------------------------------------------------------------------------------------------------------------------------------------
        channel                                                                                                                                   31
         column                                                                                                                                  680
         module                                                                                                                                   10
         output                                                                                                                                    3
        quarter                                                                                                                                    4
            row                                                                                                                                  188
       targetid                                                                                                                              6922244
        mission                                                                                                                               Kepler
        obsmode                                                                                                                        short cadence
           path /home/runner/.lightkurve/cache/mastDownload/Kepler/kplr006922244_sc_Q003333310333330000/kplr006922244-2010019161129_spd-targ.fits.gz
quality_bitmask                                                                                                                              default
            hdu                                                                                                      PRIMARY, TARGETTABLES, APERTURE
      cadenceno                                                                                                                       array (45453,)
           flux                                                                                                                  array (45453, 5, 5)
       flux_bkg                                                                                                                  array (45453, 5, 5)
   flux_bkg_err                                                                                                                  array (45453, 5, 5)
       flux_err                                                                                                                  array (45453, 5, 5)
  nan_time_mask                                                                                                                       array (45453,)
  pipeline_mask                                                                                                                         array (5, 5)
      pos_corr1                                                                                                                       array (45453,)
      pos_corr2                                                                                                                       array (45453,)
        quality                                                                                                                       array (45453,)
   quality_mask                                                                                                                       array (45600,)
       campaign                                                                                                                   <class 'NoneType'>
            dec                                                                                                                      <class 'float'>
           meta                                                                                <class 'lightkurve.targetpixelfile.HduToMetaMapping'>
             ra                                                                                                                      <class 'float'>
          shape                                                                                                                      <class 'tuple'>
           time                                                                                                     <class 'astropy.time.core.Time'>
            wcs                                                                                                                  astropy.wcs.wcs.WCS

A new piece of metadata not included in the KeplerLightCurve objects is the World Coordinate System (WCS). The WCS contains information about how pixel positions map to celestial sky coordinates. This is important when comparing a TPF from a Kepler, K2, or TESS observation to an observation of the same star with a different telescope.

You can access the WCS using tpf.wcs, which is an Astropy WCS object:

type(tpf.wcs)
astropy.wcs.wcs.WCS

For example, you can obtain the sky coordinates for the bottom left corner of the TPF as follows:

tpf.wcs.pixel_to_world(0, 0)
<SkyCoord (ICRS): (ra, dec) in deg
    (281.2877627, 42.44724476)>

Altogether, the metadata contains a lot of information, and you will rarely use it all, but it is important to know that it is available if you need it. For more details and a better overview of all of the metadata stored in a TPF, read the Kepler Archive Manual, specifically:

  • Section 2.3.2 Target Pixel Data

  • Appendix A.1: Target Pixel File Headers

##4. Time, Flux, and Background

Finally, we have the most important properties of the TPF: the time and flux information. Just like a KeplerLightCurve object, we can access the time information as an Astropy Time object as follows:

tpf.time
<Time object: scale='tdb' format='bkjd' value=[352.36644886 352.36712985 352.36781104 ... 383.42321606 383.42389716
 383.42457836]>

The pixel brightness data is available as an Astropy Quantity object named tpf.flux:

tpf.flux
\[ \begin{align}\begin{aligned}[[[{\rm NaN},~8.0390711,~48.509899,~80.933449,~37.914341],~ [49.503891,~73.099373,~1129.402,~3242.1128,~460.83792],~ [23.193569,~219.91617,~9372.5166,~23602.078,~1213.2692],~ [31.846043,~892.15948,~1703.8822,~2624.7312,~719.24988],~ [153.39867,~833.42633,~510.965,~1159.3601,~174.46196]],~\\ [[{\rm NaN},~9.2187738,~50.246441,~78.645706,~21.409729],~ [49.968575,~69.388664,~1131.1167,~3237.4475,~446.69821],~ [38.243187,~216.14751,~9337.7998,~23587.406,~1198.8284],~ [52.038555,~888.50934,~1700.7366,~2620.0574,~724.65277],~ [156.37003,~834.63757,~507.69263,~1152.0886,~189.88081]],~\\ [[{\rm NaN},~2.4421179,~55.98457,~75.091576,~36.298214],~ [38.19899,~82.178314,~1131.897,~3221.8352,~451.87534],~ [24.024801,~231.75333,~9374.9941,~23586.387,~1228.9484],~ [44.997749,~903.73022,~1711.1895,~2626.2844,~700.37891],~ [149.28247,~835.1701,~503.42889,~1160.9066,~185.26564]],~\\ \dots,~\\ [[{\rm NaN},~19.621168,~38.646904,~44.709297,~25.876413],~ [47.28941,~50.153313,~832.58044,~1934.9481,~311.76328],~ [26.834848,~282.53635,~11589.739,~21260.182,~830.58459],~ [51.953953,~975.21808,~2349.7029,~3535.4851,~862.76367],~ [174.99953,~901.81152,~451.0145,~1095.6648,~155.06113]],~\\ [[{\rm NaN},~-0.42827752,~45.577076,~50.596378,~18.026659],~ [26.726322,~44.703861,~832.05835,~1938.2916,~323.35406],~ [30.515184,~294.59793,~11516.533,~21344.93,~820.2146],~ [26.136087,~959.98395,~2363.6814,~3555.8074,~891.78656],~ [168.82539,~891.47003,~460.54691,~1094.1451,~159.44005]],~\\ [[{\rm NaN},~-4.5136657,~43.791656,~54.902508,~11.35603],~ [46.581718,~48.010975,~825.37323,~1923.1105,~311.74121],~ [28.555607,~280.34921,~11599.616,~21240.707,~815.6781],~ [51.237385,~973.07965,~2340.2271,~3526.0762,~867.67297],~ [176.7923,~924.26355,~453.80658,~1098.4874,~165.04802]]] \; \mathrm{\frac{e^{-}}{s}}\end{aligned}\end{align} \]

This object is a three-dimensional array, where each entry in the array represents one observing cadence. In our example, the flux array is composed of 4116 images, which are 5x5 pixels in size each:

tpf.flux.shape
(45453, 5, 5)

We can access the values of the first 5x5 pixel image as a NumPy array as follows:

tpf.flux[0].value
array([[          nan, 8.0390711e+00, 4.8509899e+01, 8.0933449e+01,
        3.7914341e+01],
       [4.9503891e+01, 7.3099373e+01, 1.1294020e+03, 3.2421128e+03,
        4.6083792e+02],
       [2.3193569e+01, 2.1991617e+02, 9.3725166e+03, 2.3602078e+04,
        1.2132692e+03],
       [3.1846043e+01, 8.9215948e+02, 1.7038822e+03, 2.6247312e+03,
        7.1924988e+02],
       [1.5339867e+02, 8.3342633e+02, 5.1096500e+02, 1.1593601e+03,
        1.7446196e+02]], dtype='>f4')

At each cadence the TPF has four different flux-related data properties:

  • tpf.flux: the stellar brightness after the background is removed.

  • tpf.flux_err: the statistical uncertainty on the stellar flux after background removal.

  • tpf.flux_bkg: the astronomical background brightness of the image.

  • tpf.flux_bkg_err: the statistical uncertainty on the background flux.

All four of these data arrays are in units of electrons per second.

Note: for Kepler, the flux background isn’t a measurement made using the local TPF data. Instead, at each cadence, the Kepler pipeline fits a model to thousands of empty pixels across each CCD in order to estimate a continuum background across the the CCD. For more details read the Kepler Instrument Handbook, Section 2.6.2.4. In the case of TESS, local background pixels contained within a TPF are used instead.

Note: The tpf.flux values seen above have been quality-masked. This means that cadences of observations that violated the quality_bitmask parameter are removed, and so tpf.flux represents the data that you probably want to use to do your science. The quality_bitmask can also be accessed as a property of a KeplerTargetPixelFile. For specific details on the quality flags, read the Kepler Archive Manual, Section 2.3.1.1.

If you want to access flux and background flux measurements that have not been quality masked, you can pass a custom quality_bitmask parameter to the download() or read() method as follows:

search = lk.search_targetpixelfile("Kepler-8", mission="Kepler", quarter=4)
tpf = search.download(quality_bitmask=0)
/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/lightkurve/search.py:424: LightkurveWarning: Warning: 4 files available to download. Only the first file has been downloaded. Please use `download_all()` or specify additional criteria (e.g. quarter, campaign, or sector) to limit your search.
  warnings.warn(

You can see that the flux array of this object now has more cadences (4397) than the original one above (4116):

tpf.flux.shape
(45600, 5, 5)

Alternatively, we can access the unmasked contents of the original TPF FITS file at any time using the hdu property:

tpf.hdu[1].data['FLUX'].shape
(45600, 5, 5)

About this Notebook#

Authors: Oliver Hall (oliver.hall@esa.int), Geert Barentsen

Updated On: 2020-09-15

Citing Lightkurve and Astropy#

If you use lightkurve or astropy for published research, please cite the authors. Click the buttons below to copy BibTeX entries to your clipboard.

lk.show_citation_instructions()

When using Lightkurve, we kindly request that you cite the following packages:

  • lightkurve
  • astropy
  • astroquery — if you are using search_lightcurve() or search_targetpixelfile().
  • tesscut — if you are using search_tesscut().

Space Telescope Logo