KeplerTargetPixelFile

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

Bases: lightkurve.targetpixelfile.TargetPixelFile

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

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

Parameters
pathstr or astropy.io.fits.HDUList

Path to a Kepler Target Pixel (FITS) File or a HDUList object.

quality_bitmaskstr or int

Bitmask (integer) which identifies the quality flag bitmask that should be used to mask out bad cadences. If a string is passed, it has the following meaning:

  • “none”: no cadences will be ignored (quality_bitmask=0).

  • “default”: cadences with severe quality issues will be ignored (quality_bitmask=1130799).

  • “hard”: more conservative choice of flags to ignore (quality_bitmask=1664431). This is known to remove good data.

  • “hardest”: removes all data that has been flagged (quality_bitmask=2096639). This mask is not recommended.

See the KeplerQualityFlags class for details on the bitmasks.

kwargsdict

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

References

R59afa7b5afd4-1

Kepler: A Search for Terrestrial Planets. Kepler Archive Manual. http://archive.stsci.edu/kepler/manuals/archive_manual.pdf

Attributes Summary

astropy_time

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

cadenceno

Return the cadence number for all good-quality cadences.

campaign

K2 Campaign number.

channel

Kepler CCD channel number.

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

‘Kepler’ or ‘K2’.

module

Kepler CCD module number.

nan_time_mask

Returns a boolean mask flagging cadences whose time is nan.

obsmode

‘short cadence’ or ‘long cadence’.

output

Kepler CCD module output number.

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.

quarter

Kepler quarter number.

ra

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

row

CCD pixel row number (‘2CRV5P’ 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

create_threshold_mask(self[, threshold, …])

Returns an aperture mask creating using the thresholding method.

cutout(self[, center, size])

Cut a rectangle out of the Target Pixel File.

estimate_centroids(self[, aperture_mask])

Returns centroid positions estimated using sample moments.

extract_aperture_photometry(self[, …])

Returns a LightCurve obtained using aperture photometry.

extract_prf_photometry(self[, cadences, …])

Returns the results of PRF photometry applied to the pixel file.

from_fits_images(images, position[, size, …])

Creates a new Target Pixel File from a set of images.

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.

get_model(self[, star_priors])

Returns a default TPFModel object for PRF fitting.

get_prf_model(self)

Returns an object of KeplerPRF initialized using the necessary metadata in the tpf object.

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

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

interact_sky(self[, notebook_url, …])

Display a Jupyter Notebook widget showing Gaia DR2 positions on top of the pixels.

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

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

prf_lightcurve(self, \*\*kwargs)

show_properties(self)

Prints a description of all non-callable attributes.

to_corrector(self[, method])

Returns a Corrector instance to remove systematics.

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.

cadenceno

Return the cadence number for all good-quality cadences.

campaign

K2 Campaign number. (‘CAMPAIGN’ header keyword)

channel

Kepler CCD channel number. (‘CHANNEL’ 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

‘Kepler’ or ‘K2’. (‘MISSION’ header keyword)

module

Kepler CCD module number. (‘MODULE’ header keyword)

nan_time_mask

Returns a boolean mask flagging cadences whose time is nan.

obsmode

‘short cadence’ or ‘long cadence’. (‘OBSMODE’ header keyword)

output

Kepler CCD module output number. (‘OUTPUT’ header keyword)

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.

quarter

Kepler quarter number. (‘QUARTER’ header keyword)

ra

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

row

CCD pixel row number (‘2CRV5P’ 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

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.

cutout(self, center=None, size=5)

Cut a rectangle out of the Target Pixel File.

This methods returns a new TargetPixelFile object containing a rectangle of a given size cut out around a given center.

Parameters
center(int, int) tuple or astropy.SkyCoord

Center of the cutout. If an (int, int) tuple is passed, it will be interpreted as the (column, row) coordinates relative to the bottom-left corner of the TPF. If an astropy.SkyCoord is passed then the sky coordinate will be used instead. If None (default) then the center of the TPF will be used.

sizeint or (int, int) tuple

Number of pixels to cut out. If a single integer is passed then a square of that size will be cut. If a tuple is passed then a rectangle with dimensions (column_size, row_size) will be cut.

Returns
tpflightkurve.TargetPixelFile object

New and smaller Target Pixel File object containing only the data cut out.

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')

Returns a LightCurve obtained using aperture photometry.

Parameters
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.

Returns
lcKeplerLightCurve object

Array containing the summed flux within the aperture for each cadence.

extract_prf_photometry(self, cadences=None, parallel=True, **kwargs)

Returns the results of PRF photometry applied to the pixel file.

Parameters
cadenceslist of int

Cadences to fit. If None (default) then all cadences will be fit.

parallelbool

If True, fitting cadences will be distributed across multiple cores using Python’s multiprocessing module.

**kwargsdict

Keywords to be passed to tpf.get_model() to create the TPFModel object that will be fit.

Returns
resultsPRFPhotometry object

Object that provides access to PRF-fitting photometry results and various diagnostics.

static from_fits_images(images, position, size=(11, 11), extension=1, target_id='unnamed-target', hdu0_keywords=None, **kwargs)

Creates a new Target Pixel File from a set of images.

This method is intended to make it easy to cut out targets from Kepler/K2 “superstamp” regions or TESS FFI images.

Parameters
imageslist of str, or list of fits.ImageHDU objects

Sorted list of FITS filename paths or ImageHDU objects to get the data from.

positionastropy.SkyCoord

Position around which to cut out pixels.

size(int, int)

Dimensions (cols, rows) to cut out around position.

extensionint or str

If images is a list of filenames, provide the extension number or name to use. Default: 0.

target_idint or str

Unique identifier of the target to be recorded in the TPF.

hdu0_keywordsdict

Additional keywords to add to the first header file.

**kwargsdict

Extra arguments to be passed to the KeplerTargetPixelFile constructor.

Returns
tpfKeplerTargetPixelFile

A new Target Pixel File assembled from the images.

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.

get_model(self, star_priors=None, **kwargs)

Returns a default TPFModel object for PRF fitting.

The default model only includes one star and only allows its flux and position to change. A different set of stars can be added using the star_priors parameter.

Parameters
**kwargsdict

Arguments to be passed to the TPFModel constructor, e.g. star_priors.

Returns
modelTPFModel object

Model with appropriate defaults for this Target Pixel File.

get_prf_model(self)

Returns an object of KeplerPRF initialized using the necessary metadata in the tpf object.

Returns
prfinstance of SimpleKeplerPRF
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.

interact_sky(self, notebook_url='localhost:8888', magnitude_limit=18)

Display a Jupyter Notebook widget showing Gaia DR2 positions on top of the pixels.

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.

magnitude_limitfloat

A value to limit the results in based on Gaia Gmag. Default, 18.

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.

prf_lightcurve(self, **kwargs)
show_properties(self)

Prints a description of all non-callable attributes.

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

to_corrector(self, method='pld')

Returns a Corrector instance to remove systematics.

Parameters
methodsstring

Currently, only “pld” is supported. This will return a PLDCorrector class instance.

Returns
correcterlightkurve.Correcter

Instance of a Corrector class, which typically provides correct() and diagnose() methods.

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.