TessTargetPixelFile

class lightkurve.targetpixelfile.TessTargetPixelFile(path, quality_bitmask='default', **kwargs)

Bases: lightkurve.targetpixelfile.TargetPixelFile

Represents pixel data products created by NASA’s TESS pipeline.

This class enables extraction of custom light curves and centroid positions.

Parameters
pathstr

Path to a Kepler Target Pixel (FITS) File.

quality_bitmaskstr or int

Bitmask specifying quality flags of cadences that should be ignored.

kwargsdict

Keyword arguments passed to astropy.io.fits.open().

Attributes Summary

astropy_time

Returns an AstroPy Time object for all good-quality cadences.

background_mask

Returns the background mask used by the TESS pipeline.

cadenceno

Return the cadence number for all good-quality cadences.

camera

TESS Camera number (‘CAMERA’ header keyword).

ccd

TESS CCD number (‘CCD’ header keyword).

column

CCD pixel column number (‘1CRV5P’ header keyword).

dec

Declination of target (‘DEC_OBJ’ header keyword).

flux

Returns the flux for all good-quality cadences.

flux_bkg

Returns the background flux for all good-quality cadences.

flux_bkg_err

flux_err

Returns the flux uncertainty for all good-quality cadences.

hdu

header

Returns the header of the primary extension.

mission

nan_time_mask

Returns a boolean mask flagging cadences whose time is nan.

pipeline_mask

Returns the optimal aperture mask used by the pipeline.

pos_corr1

Returns the column position correction.

pos_corr2

Returns the row position correction.

quality

Returns the quality flag integer of every good cadence.

ra

Right Ascension of target (‘RA_OBJ’ header keyword).

row

CCD pixel row number (‘2CRV5P’ header keyword).

sector

TESS Sector number (‘SECTOR’ header keyword).

shape

Return the cube dimension shape.

time

Returns the time for all good-quality cadences.

wcs

Returns an astropy.wcs.WCS object with the World Coordinate System solution for the target pixel file.

Methods Summary

centroids(self, \*\*kwargs)

DEPRECATED: use estimate_cdpp() instead.

create_threshold_mask(self[, threshold, …])

Returns an aperture mask creating using the thresholding method.

estimate_centroids(self[, aperture_mask])

Returns centroid positions estimated using sample moments.

extract_aperture_photometry(self[, …])

Performs aperture photometry.

from_fits(path_or_url, \*\*kwargs)

WARNING: THIS FUNCTION IS DEPRECATED AND WILL BE REMOVED VERY SOON.

get_bkg_lightcurve(self[, aperture_mask])

get_coordinates(self[, cadence])

Returns two 3D arrays of RA and Dec values in decimal degrees.

get_keyword(self, keyword[, hdu, default])

Returns a header keyword value.

interact(self[, notebook_url, max_cadences, …])

Display an interactive Jupyter Notebook widget to inspect the pixel data.

plot(self[, ax, frame, cadenceno, bkg, …])

Plot the pixel data for a single frame (i.e.

show_properties(self)

Prints a description of all non-callable attributes.

to_fits(self[, output_fn, overwrite])

Writes the TPF to a FITS file on disk.

to_lightcurve(self[, method])

Performs photometry on the pixel data and returns a LightCurve object.

Attributes Documentation

astropy_time

Returns an AstroPy Time object for all good-quality cadences.

background_mask

Returns the background mask used by the TESS pipeline.

cadenceno

Return the cadence number for all good-quality cadences.

camera

TESS Camera number (‘CAMERA’ header keyword).

ccd

TESS CCD number (‘CCD’ header keyword).

column

CCD pixel column number (‘1CRV5P’ header keyword).

dec

Declination of target (‘DEC_OBJ’ header keyword).

flux

Returns the flux for all good-quality cadences.

flux_bkg

Returns the background flux for all good-quality cadences.

flux_bkg_err
flux_err

Returns the flux uncertainty for all good-quality cadences.

hdu
header

Returns the header of the primary extension.

mission
nan_time_mask

Returns a boolean mask flagging cadences whose time is nan.

pipeline_mask

Returns the optimal aperture mask used by the pipeline.

pos_corr1

Returns the column position correction.

pos_corr2

Returns the row position correction.

quality

Returns the quality flag integer of every good cadence.

ra

Right Ascension of target (‘RA_OBJ’ header keyword).

row

CCD pixel row number (‘2CRV5P’ header keyword).

sector

TESS Sector number (‘SECTOR’ header keyword).

shape

Return the cube dimension shape.

time

Returns the time for all good-quality cadences.

wcs

Returns an astropy.wcs.WCS object with the World Coordinate System solution for the target pixel file.

Returns
wastropy.wcs.WCS object

WCS solution

Methods Documentation

centroids(self, **kwargs)

DEPRECATED: use estimate_cdpp() instead.

create_threshold_mask(self, threshold=3, reference_pixel='center')

Returns an aperture mask creating using the thresholding method.

This method will identify the pixels in the TargetPixelFile which show a median flux that is brighter than threshold times the standard deviation above the overall median. The standard deviation is estimated in a robust way by multiplying the Median Absolute Deviation (MAD) with 1.4826.

If the thresholding method yields multiple contiguous regions, then only the region closest to the (col, row) coordinate specified by reference_pixel is returned. For exmaple, reference_pixel=(0, 0) will pick the region closest to the bottom left corner. By default, the region closest to the center of the mask will be returned. If reference_pixel=None then all regions will be returned.

Parameters
thresholdfloat

A value for the number of sigma by which a pixel needs to be brighter than the median flux to be included in the aperture mask.

reference_pixel: (int, int) tuple, ‘center’, or None

(col, row) pixel coordinate closest to the desired region. For example, use reference_pixel=(0,0) to select the region closest to the bottom left corner of the target pixel file. If ‘center’ (default) then the region closest to the center pixel will be selected. If None then all regions will be selected.

Returns
aperture_maskndarray

2D boolean numpy array containing True for pixels above the threshold.

estimate_centroids(self, aperture_mask='pipeline')

Returns centroid positions estimated using sample moments.

Parameters
aperture_maskarray-like, ‘pipeline’, or ‘all’

A boolean array describing the aperture such that True means that the pixel will be used. If None or ‘all’ are passed, all pixels will be used. If ‘pipeline’ is passed, the mask suggested by the official pipeline will be returned. If ‘threshold’ is passed, all pixels brighter than 3-sigma above the median flux will be used.

Returns
col_centr, row_centrtuple

Arrays containing centroids for column and row at each cadence

extract_aperture_photometry(self, aperture_mask='pipeline')

Performs aperture photometry.

Parameters
aperture_maskarray-like, ‘pipeline’, or ‘all’

A boolean array describing the aperture such that False means that the pixel will be masked out. If the string ‘all’ is passed, all pixels will be used. The default behaviour is to use the TESS pipeline mask.

Returns
——-
lcTessLightCurve object

Contains the summed flux within the aperture for each cadence.

classmethod from_fits(path_or_url, **kwargs)

WARNING: THIS FUNCTION IS DEPRECATED AND WILL BE REMOVED VERY SOON.

Please use lightkurve.open() instead.

get_bkg_lightcurve(self, aperture_mask=None)
get_coordinates(self, cadence='all')

Returns two 3D arrays of RA and Dec values in decimal degrees.

If cadence number is given, returns 2D arrays for that cadence. If cadence is ‘all’ returns one RA, Dec value for each pixel in every cadence. Uses the WCS solution and the POS_CORR data from TPF header.

Parameters
cadence‘all’ or int

Which cadences to return the RA Dec coordinates for.

Returns
ranumpy array, same shape as tpf.flux[cadence]

Array containing RA values for every pixel, for every cadence.

decnumpy array, same shape as tpf.flux[cadence]

Array containing Dec values for every pixel, for every cadence.

get_keyword(self, keyword, hdu=0, default=None)

Returns a header keyword value.

If the keyword is Undefined or does not exist, then return default instead.

interact(self, notebook_url='localhost:8888', max_cadences=30000, aperture_mask='pipeline', exported_filename=None)

Display an interactive Jupyter Notebook widget to inspect the pixel data.

The widget will show both the lightcurve and pixel data. By default, the lightcurve shown is obtained by calling the to_lightcurve() method, unless the user supplies a custom LightCurve object. This feature requires an optional dependency, bokeh (v0.12.15 or later). This dependency can be installed using e.g. conda install bokeh.

At this time, this feature only works inside an active Jupyter Notebook, and tends to be too slow when more than ~30,000 cadences are contained in the TPF (e.g. short cadence data).

Parameters
notebook_url: str

Location of the Jupyter notebook page (default: “localhost:8888”) When showing Bokeh applications, the Bokeh server must be explicitly configured to allow connections originating from different URLs. This parameter defaults to the standard notebook host and port. If you are running on a different location, you will need to supply this value for the application to display properly. If no protocol is supplied in the URL, e.g. if it is of the form “localhost:8888”, then “http” will be used.

max_cadencesint

Raise a RuntimeError if the number of cadences shown is larger than this value. This limit helps keep browsers from becoming unresponsive.

aperture_maskarray-like, ‘pipeline’, ‘threshold’ or ‘all’

A boolean array describing the aperture such that True means that the pixel will be used. If None or ‘all’ are passed, all pixels will be used. If ‘pipeline’ is passed, the mask suggested by the official pipeline will be returned. If ‘threshold’ is passed, all pixels brighter than 3-sigma above the median flux will be used.

exported_filename: str

An optional filename to assign to exported fits files containing the custom aperture mask generated by clicking on pixels in interact. The default adds a suffix ‘-custom-aperture-mask.fits’ to the TargetPixelFile basename.

plot(self, ax=None, frame=0, cadenceno=None, bkg=False, aperture_mask=None, show_colorbar=True, mask_color='pink', style='lightkurve', **kwargs)

Plot the pixel data for a single frame (i.e. at a single time).

The time can be specified by frame index number (frame=0 will show the first frame) or absolute cadence number (cadenceno).

Parameters
axmatplotlib.axes._subplots.AxesSubplot

A matplotlib axes object to plot into. If no axes is provided, a new one will be generated.

frameint

Frame number. The default is 0, i.e. the first frame.

cadencenoint, optional

Alternatively, a cadence number can be provided. This argument has priority over frame number.

bkgbool

If True, background will be added to the pixel values.

aperture_maskndarray or str

Highlight pixels selected by aperture_mask.

show_colorbarbool

Whether or not to show the colorbar

mask_colorstr

Color to show the aperture mask

stylestr

Path or URL to a matplotlib style file, or name of one of matplotlib’s built-in stylesheets (e.g. ‘ggplot’). Lightkurve’s custom stylesheet is used by default.

kwargsdict

Keywords arguments passed to lightkurve.utils.plot_image.

Returns
axmatplotlib.axes._subplots.AxesSubplot

The matplotlib axes object.

show_properties(self)

Prints a description of all non-callable attributes.

Prints in order of type (ints, strings, lists, arrays, others).

to_fits(self, output_fn=None, overwrite=False)

Writes the TPF to a FITS file on disk.

to_lightcurve(self, method='aperture', **kwargs)

Performs photometry on the pixel data and returns a LightCurve object.

See the docstring of aperture_photometry() for valid arguments if the method is ‘aperture’. Otherwise, see the docstring of prf_photometry() for valid arguments if the method is ‘prf’.

Parameters
method‘aperture’ or ‘prf’.

Photometry method to use.

**kwargsdict

Extra arguments to be passed to the aperture_photometry or the prf_photometry method of this class.

Returns
lcLightCurve object

Object containing the resulting lightcurve.


Created with ♥ by the Lightkurve collaboration. Please cite us or join us on GitHub.