CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-lightkurve

A friendly package for Kepler & TESS time series analysis in Python.

Pending
Overview
Eval results
Files

core-data.mddocs/

Core Data Objects

Light curves and target pixel files are the fundamental data containers in lightkurve, providing comprehensive functionality for time series analysis and visualization.

Capabilities

Light Curve Classes

Generic Light Curve

class LightCurve:
    """
    Time series data with time, flux, and flux_err columns.
    
    Subclass of astropy TimeSeries with guaranteed time, flux, and flux_err columns.
    """
    
    def __init__(self, time=None, flux=None, flux_err=None, **kwargs):
        """
        Initialize a light curve.
        
        Parameters:
        - time: astropy.time.Time or array-like - Time values
        - flux: astropy.units.Quantity or array-like - Flux values  
        - flux_err: astropy.units.Quantity or array-like - Flux uncertainties
        - **kwargs: Additional columns and metadata
        """
    
    # Time series operations
    def normalize(self, unit="unscaled"):
        """Normalize flux to relative units"""
        
    def remove_nans(self):
        """Remove NaN values from the light curve"""
        
    def remove_outliers(self, sigma=5, **kwargs):
        """Remove statistical outliers using sigma clipping"""
        
    def flatten(self, window_length=101, **kwargs):
        """Remove long-term trends using Savitzky-Golay filter"""
        
    def fold(self, period, epoch_time=None, **kwargs):
        """Fold the light curve at a given period"""
        
    def bin(self, time_bin_size, **kwargs):
        """Bin the light curve to lower time resolution"""
        
    def append(self, others, **kwargs):
        """Append other light curves to this one"""
        
    # Analysis methods
    def to_periodogram(self, method='lombscargle', **kwargs):
        """Create a periodogram from the light curve"""
        
    def to_corrector(self, method='pld', **kwargs):
        """Create corrector object for systematics removal"""
        
    def estimate_cdpp(self, transit_duration=13, savgol_window=101, sigma=5):
        """Estimate Combined Differential Photometric Precision"""
        
    def search_neighbors(self, limit=None, radius=None):
        """Search for nearby targets in the same observations"""
        
    def query_solar_system_objects(self, **kwargs):
        """Identify potential solar system object contamination"""
        
    # Visualization
    def plot(self, **kwargs):
        """Plot the light curve"""
        
    def scatter(self, **kwargs):
        """Create a scatter plot of the light curve"""
        
    def errorbar(self, **kwargs):
        """Create error bar plot of the light curve"""
        
    def interact(self, **kwargs):
        """Create an interactive plot widget"""

Mission-Specific Light Curves

class KeplerLightCurve(LightCurve):
    """Kepler light curve with mission-specific methods and metadata"""
        
    @classmethod
    def read(cls, filename, **kwargs):
        """Read Kepler light curve from FITS file"""

class TessLightCurve(LightCurve):
    """TESS light curve with mission-specific methods and metadata"""
        
    @classmethod  
    def read(cls, filename, **kwargs):
        """Read TESS light curve from FITS file"""

class FoldedLightCurve(LightCurve):
    """Light curve folded at a specific period for phase analysis"""
    
    def plot_river(self, **kwargs):
        """Create a river plot showing phase evolution"""

Target Pixel File Classes

Generic Target Pixel File

class TargetPixelFile:
    """
    Abstract base class for pixel-level time series data.
    Contains 3D array of pixels over time plus metadata.
    """
    
    # Data access properties
    @property
    def time(self):
        """Time array for the observations"""
        
    @property
    def flux(self):
        """3D flux array (time, row, column)"""
        
    @property
    def flux_err(self):
        """3D flux error array (time, row, column)"""
        
    @property
    def pos_corr1(self):
        """Position correction in first axis"""
        
    @property
    def pos_corr2(self):
        """Position correction in second axis"""
        
    # Light curve extraction
    def to_lightcurve(self, aperture_mask=None, **kwargs):
        """
        Extract light curve using specified aperture.
        
        Parameters:
        - aperture_mask: array-like, str, or callable - Pixel selection method
        
        Returns:
        LightCurve object
        """
        
    # Visualization
    def plot(self, ax=None, frame=0, **kwargs):
        """Plot a single frame of the target pixel file"""
        
    def animate(self, **kwargs):
        """Create an animation of the pixel data over time"""
        
    def interact(self, **kwargs):
        """Create interactive pixel selection widget"""
        
    # Analysis
    def create_threshold_mask(self, threshold=3, reference_pixel=None):
        """Create aperture mask based on flux threshold"""
        
    def estimate_centroids(self, **kwargs):
        """Estimate centroid positions for each frame"""
        
    def estimate_background(self, **kwargs):
        """Estimate background flux for each frame"""
        
    def cutout(self, size=5, **kwargs):
        """Create smaller cutout from target pixel file"""
        
    def extract_aperture_photometry(self, aperture_mask, **kwargs):
        """Perform aperture photometry with specified mask"""
        
    def to_corrector(self, method='pld', **kwargs):
        """Create corrector object for systematics removal"""

Mission-Specific Target Pixel Files

class KeplerTargetPixelFile(TargetPixelFile):
    """Kepler target pixel file with mission-specific functionality"""
    
    @property
    def quality_bitmask(self):
        """Kepler quality flags bitmask"""
        
    def correct(self, method='sff', **kwargs):
        """Apply systematics correction to pixel data"""
        
    @classmethod
    def read(cls, filename, **kwargs):
        """Read Kepler target pixel file from FITS"""

class TessTargetPixelFile(TargetPixelFile):
    """TESS target pixel file with mission-specific functionality"""
    
    @property  
    def quality_bitmask(self):
        """TESS quality flags bitmask"""
        
    def interact_sky(self, **kwargs):
        """Interactive sky view with Gaia overlay"""
        
    @classmethod
    def read(cls, filename, **kwargs):
        """Read TESS target pixel file from FITS"""

Data Collections

class LightCurveCollection:
    """Collection of multiple light curves with batch operations"""
    
    def __init__(self, lightcurves):
        """Initialize collection from list of LightCurve objects"""
        
    def stitch(self, **kwargs):
        """Combine multiple light curves into single LightCurve"""
        
    def normalize(self, **kwargs):
        """Normalize all light curves in the collection"""
        
    def remove_outliers(self, **kwargs):
        """Remove outliers from all light curves"""
        
    def plot(self, **kwargs):
        """Plot all light curves together"""

class TargetPixelFileCollection:
    """Collection of multiple target pixel files with batch operations"""
    
    def __init__(self, tpfs):
        """Initialize collection from list of TargetPixelFile objects"""
        
    def to_lightcurve(self, **kwargs):
        """Extract light curves from all TPFs"""
        
    def plot(self, **kwargs):
        """Plot all target pixel files"""

Usage Examples

Basic Light Curve Operations

import lightkurve as lk
import astropy.units as u

# Create light curve from arrays
import numpy as np
time = np.linspace(0, 10, 1000)
flux = 1 + 0.01 * np.sin(2 * np.pi * time / 2.5)  # 2.5-day period
lc = lk.LightCurve(time=time, flux=flux)

# Basic processing
lc = lc.normalize().remove_outliers()

# Fold at known period
folded = lc.fold(period=2.5 * u.day)
folded.plot()

Target Pixel File Analysis

# Download TPF and create custom apertures
search = lk.search_targetpixelfile('Kepler-10')
tpf = search[0].download()

# Visualize pixels
tpf.plot()

# Create different aperture masks
threshold_mask = tpf.create_threshold_mask(threshold=5)
custom_mask = tpf.flux[0] > 1000  # Custom threshold

# Extract light curves with different apertures
lc_threshold = tpf.to_lightcurve(aperture_mask=threshold_mask)
lc_custom = tpf.to_lightcurve(aperture_mask=custom_mask)

Working with Collections

# Download multiple quarters/sectors
search = lk.search_lightcurve('KIC 11904151', quarter=[4, 5, 6, 7])
collection = search.download_all()

# Process entire collection
collection = collection.normalize().remove_outliers()

# Stitch together into single light curve
long_lc = collection.stitch()

# Plot all quarters together
collection.plot()

Quality Filtering

# Apply different quality filters
lc_default = search[0].download(quality_bitmask='default')
lc_hard = search[0].download(quality_bitmask='hard')
lc_custom = search[0].download(quality_bitmask=1024)  # Custom bitmask

Install with Tessl CLI

npx tessl i tessl/pypi-lightkurve

docs

asteroseismology.md

core-data.md

data-search.md

index.md

prf-modeling.md

systematics-correction.md

time-series-analysis.md

tile.json