Skip to main content
v2026.11,986 entries · CC-BY 4.0

Lightkurve Python: Kepler and TESS Workflow

Use Lightkurve to select Kepler and TESS data, extract a light curve, inspect time and flux, and document processing choices.

Written and maintained by CASRAI Editorial Board

Published

On this page

Lightkurve is a Python package for working with astronomical brightness time series, especially Kepler, K2 and TESS observations. It can retrieve prepared light curves or pixel data from MAST, extract flux through an aperture, and plot, fold and bin the result. A useful research workflow starts by choosing the data product deliberately, then preserving the aperture, time representation and processing parameters alongside the analysis.

What Lightkurve is used for in research

Lightkurve connects archive discovery with analysis of how an object’s measured brightness changes over time. The official searching and downloading tutorial distinguishes two principal products: light-curve files contain flux measurements at observation times, while target pixel files contain a sequence of small images. That distinction determines whether you start with prepared photometry or make an extraction from pixels.

The package also accesses community-produced High Level Science Products and TESS Full Frame Image cutouts. A cutout is a selected pixel region obtained through MAST’s TESSCut service; it is not a download of an entire full-frame image. These routes give researchers different starting material, even when the target name is identical. The wider discipline context is covered in CASRAI’s guide to astronomy research.

A LightCurve holds brightness against time and provides plotting, folding and binning operations. The documented mission-specific subclasses include KeplerLightCurve for Kepler and K2 and TessLightCurve for TESS. The objects can also represent other astronomical data. Their convenience does not remove the need to distinguish an archive product, an extracted measurement and a transformed display.

How to install or access Lightkurve

Install Lightkurve using the command in its official installation instructions. Run this in a terminal associated with the Python environment you intend to use:

python -m pip install lightkurve --upgrade

The documentation says that --upgrade is optional and recommends it when upgrading an existing installation. Depending on the environment, the interpreter command may be python3. Check the installed package version with the documented command:

python -c "import lightkurve; print(lightkurve.__version__)"

The installation page lists Astropy, NumPy, SciPy, Matplotlib, Astroquery, Bokeh and pandas as dependencies, which pip installs automatically when needed. Bokeh supports interactive widgets. Record the version returned by the check as part of the analysis record; an installation command alone does not identify the software that subsequently generated a figure.

The same documentation provides a GitHub development-install route for people changing the package itself. For a first analysis, the pip route above is the documented starting point. If you work in notebooks, CASRAI’s Anaconda and Jupyter Notebook setup guide explains that surrounding environment. Keep installation and analysis associated with the same chosen interpreter.

How to extract and inspect a Kepler light curve step by step

The following walkthrough follows the official LightCurve objects tutorial, using its KIC 6922244 example. The supplied period and processing settings belong to that demonstration. They are not estimates produced by running a period search on a new target.

  1. Search for a specified pixel product. Import the documented search function and request the Kepler author, long cadence and quarter 4. These constraints make the intended example explicit.

    from lightkurve import search_targetpixelfile
    tpf = search_targetpixelfile('KIC 6922244', author="Kepler", cadence="long", quarter=4).download()

    For an unfamiliar target, inspect the search result before calling download(). The archive tutorial shows that results can contain multiple products and that a single download selects only the first when more than one remains.

  2. Inspect the pixels before extraction. The official quickstart demonstrates plotting a frame before summing pixels. Apply that inspection to the downloaded object:

    tpf.plot(frame=1);

    The quickstart’s separate Tabby’s Star example uses all pixels after describing the object as isolated. The LightCurve tutorial explains that aperture shape can avoid nearby contaminants or improve the signal relative to background. An all-pixel aperture is therefore a specific extraction choice.

  3. Extract with the pipeline aperture. Use the tutorial’s explicit mask:

    lc = tpf.to_lightcurve(aperture_mask=tpf.pipeline_mask)

    This sums the pixels selected by the mask at each time and creates a Simple Aperture Photometry light curve. Keep a record of the mask choice. Changing the selected pixels changes the measurement you ask the software to construct.

  4. Check identity, time and flux. The tutorial accesses lc.meta['MISSION'], lc.meta['QUARTER'], lc.time and lc.flux. Examine these before further processing. Plot the extracted series with lc.plot() so you retain a view of the starting measurement.

  5. Inspect a flattened series. The tutorial removes long-term trends with the following call:

    flat_lc = lc.flatten(window_length=401)
    flat_lc.plot();

    Lightkurve documents flatten() as using a Savitzky–Golay filter. Keep this output separate from lc, and compare the two plots. The example’s window setting is a recorded processing parameter, not a universal recommendation for astronomical variability.

  6. Fold at the demonstration period. The next documented operation is:

    folded_lc = flat_lc.fold(period=3.5225)
    folded_lc.plot();

    Folding arranges the measurements relative to a supplied period. This call supplies that period directly; it does not search a range of periods or establish the physical cause of a recurring feature.

  7. Bin the folded curve. The tutorial then reduces its time resolution:

    binned_lc = folded_lc.bin(time_bin_size=0.01)
    binned_lc.plot();

    Retain the folded and binned objects separately so the effect of averaging is visible. Record the bin size together with the period and flattening setting when documenting this demonstration.

Starting with a prepared curve or TESS cutout

Import the package as import lightkurve as lk for the following routes. To skip pixel extraction, the archive tutorial searches lk.search_lightcurve('KIC 3733346', author='Kepler', quarter=2) and downloads the resulting prepared light curve. This is a different starting product from the pipeline-mask extraction above. When several observing segments are required, download_all() returns a collection that can be plotted together or iterated over; the tutorial demonstrates normalizing individual curves while labeling their quarters.

For a TESS full-frame target, the documented route begins with lk.search_tesscut('Pi Men'). The tutorial selects a result and calls download(cutout_size=10), returning a target pixel file. The cutout size describes its side length in pixels and may also be a tuple. Choose the observing sector deliberately before downloading: the cutout supplies pixel data for subsequent extraction, rather than a prepared flux column.

How to read the output

Read each output according to its object type. A SearchResult describes products available for download. A target pixel file contains images at successive cadences. A LightCurve contains a flux point for each time stamp. A folded or binned curve has undergone an additional operation and should be interpreted with its parameters attached.

Search metadata identifies the observation

The archive-search tutorial displays mission, year, author, exposure time, target name and angular distance. Exposure time is shown in seconds and distance in arcseconds. The fuller search_result.table exposes additional fields, including product filenames and identifiers. A row count is a count of matching products, not a count of independent astronomical detections.

For prepared light curves, the tutorial shows a downloaded object’s summary with FLUX_ORIGIN=pdcsap_flux, as well as separate sap_flux and pdcsap_flux columns. Check the selected flux origin instead of assuming that an archive-downloaded series is identical to your own pipeline-mask pixel sum. The table is also the place to retain the observation and product identity.

Time format and time scale are separate

In the quickstart, lc.time is an Astropy Time object displayed with format bkjd and scale tdb; flux is an Astropy Quantity in electrons per second. Preserve those attributes when moving between analysis tools. A bare numerical time array loses the visible explanation of what the numbers represent.

The Astropy time-series documentation demonstrates the distinction directly: the same time object can be displayed in formats such as modified Julian date or Unix time, while its scale is inspected separately. Its Kepler example identifies TDB as Barycentric Dynamical Time. Format conversion and scale identification answer different questions.

Folding and estimating a period are different operations

The Lightkurve walkthrough supplies a period before folding. Astropy’s separate demonstration instead constructs a BoxLeastSquares model, evaluates a periodogram, selects a period and transit time, and then folds the series. That ordering shows where estimation happens. Keep a supplied demonstration period distinct from a period inferred from your observations.

Troubleshooting Lightkurve

An installation reports PermissionError

The installation documentation says that PermissionError indicates insufficient administrative access to the chosen Python installation and suggests considering pip’s --user option. Check which interpreter the installation command uses and run the documented version check in the environment intended for analysis before changing the notebook code.

A download returns only one product

Calling download() on multiple matches downloads only the first and produces a warning. Narrow the search or select a particular row. Use download_all() when you deliberately want a collection; light-curve searches then return a LightCurveCollection, while pixel searches return a TargetPixelFileCollection.

The mission-specific selectors are quarter for Kepler, campaign for K2 and sector for TESS. The tutorial also demonstrates exptime filtering. These controls address different parts of product selection, so check the displayed metadata after applying them.

A search includes nearby objects

A cone search intentionally includes targets within an angular radius. Lightkurve’s tutorial states that a numeric radius is interpreted in arcseconds and that the distance column reports separation from the requested position. Inspect target identifiers and distances before extracting photometry from every match.

Be especially careful when switching interfaces: Astroquery’s direct MAST observation queries interpret a numeric positional-query radius in degrees. Explicit angular quantities avoid carrying an implicit unit from one API into another.

Cleaning changes the feature being inspected

The LightCurve tutorial distinguishes remove_nans() for invalid values, remove_outliers() for sigma clipping, flatten() for long-term trends and bin() for reduced time resolution. Treat these as separate operations. As a practical review step, keep intermediate plots and parameters so you can identify which operation changed a feature, rather than inspecting only the final curve.

Recording a reproducible Lightkurve analysis

A practical analysis record can follow the objects already inspected: save the search expression, selected product identifiers, installed Lightkurve version, aperture choice, flux origin, time format and time scale. Add the flattening, folding and binning parameters where those operations are used. These recommendations connect documented package fields to the information needed to explain a particular result.

Retain the starting product alongside the analysis code and distinguish raw extraction from later transformations. CASRAI’s guide to reproducible workflows and software environments develops the broader preservation approach. For software attribution, the archive tutorial provides lk.show_citation_instructions() after importing lightkurve as lk, and requests citations for Lightkurve and relevant dependencies, including Astroquery or TESSCut when used.

Free alternatives to Lightkurve

Astropy and Astroquery offer alternatives for particular stages of this workflow. They are also part of the ecosystem Lightkurve uses. Choose according to whether the task is archive retrieval or time-series manipulation; neither row implies that the entire pixel-to-plot workflow is replaced by a single call.

Alternative Documented role Workflow implication
Astropy timeseries Read a Kepler FITS time series, manipulate time-aware tables, estimate a BLS period, fold and downsample. Useful for explicit table and analysis control; its example points to Astroquery for retrieving other scientific light curves.
Astroquery mast Query observation metadata, retrieve associated product lists, filter them and download archive files. Useful for direct archive selection; subsequent photometry or time-series analysis is a separate stage.

Astroquery’s documentation describes its database-query role and BSD-style license; Astropy’s project page also specifies a three-clause BSD license. Astropy’s worked example demonstrates the analysis route. The data table below compiles a separate crosswalk between Lightkurve operations and related lower-level interfaces, with the official documentation behind each pairing.

Sources

Data: Lightkurve and Astropy workflow operation crosswalk

Original compilation pairing documented Lightkurve operations with related Astropy or Astroquery interfaces. The entries compare the role and returned representation at four stages; they do not claim identical algorithms or interchangeable defaults.

Lightkurve and Astropy workflow operation crosswalk
TaskLightkurve interfaceRelated lower-level interfaceOutput distinctionDocumentation sources
Discover archive datasearch_lightcurve(target)astroquery.mast.Observations.query_object(objectname)Lightkurve SearchResult lists downloadable products; direct MAST observation queries return an observation metadata Table.Lightkurve: Searching and downloading data; Astroquery: Observation Queries
Load Kepler photometrySearchResult.download()astropy.timeseries.TimeSeries.read(filename, format="kepler.fits")The documented Lightkurve example returns KeplerLightCurve; the Astropy reader returns TimeSeries from an existing FITS file.Lightkurve: Searching and downloading data; Astropy: Time Series
Fold measurementsLightCurve.fold(period=...)TimeSeries.fold(period=..., epoch_time=...)Both document folding with a supplied period; the Astropy example also supplies a transit epoch derived in a preceding BLS step.Lightkurve: What are LightCurve objects?; Astropy: Time Series
Reduce time resolutionLightCurve.bin(time_bin_size=...)astropy.timeseries.aggregate_downsample(time_series, time_bin_size=...)Lightkurve documents averaging into bins; Astropy demonstrates a BinnedTimeSeries result. Defaults are not asserted to be equivalent.Lightkurve: What are LightCurve objects?; Astropy: Time Series

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · full access

Ask about Lightkurve Python: Kepler and TESS Workflow

Full access: large monthly usage, up to 10 source passages behind each answer, and MCP and API access for Claude Code, Codex and other CLIs. Cancel any time.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →