lightkurve.KeplerTargetPixelFile.interact#

KeplerTargetPixelFile.interact(notebook_url=None, max_cadences=200000, aperture_mask='default', exported_filename=None, transform_func=None, ylim_func=None, **kwargs)#

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_urlstr

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. For use with JupyterHub, set the environment variable LK_JUPYTERHUB_EXTERNAL_URL to the public hostname of your JupyterHub and notebook_url will be defined appropriately automatically.

max_cadencesint

Print an error message if the number of cadences shown is larger than this value. This limit helps keep browsers from becoming unresponsive.

aperture_maskarray-like, ‘pipeline’, ‘threshold’, ‘default’, 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. If ‘default’ is passed, ‘pipeline’ mask will be used when available, with ‘threshold’ as the fallback.

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.

transform_func: function

A function that transforms the lightcurve. The function takes in a LightCurve object as input and returns a LightCurve object as output. The function can be complex, such as detrending the lightcurve. In this way, the interactive selection of aperture mask can be evaluated after inspection of the transformed lightcurve. The transform_func is applied before saving a fits file. Default: None (no transform is applied).

ylim_func: function

A function that returns ylimits (low, high) given a LightCurve object. The default is to return a window approximately around 5 sigma-clipped lightcurve flux values.

Examples

To select an aperture mask for V827 Tau:

>>> import lightkurve as lk
>>> tpf = lk.search_targetpixelfile("V827 Tau", mission="K2").download()  
>>> tpf.interact()  

To see the full y-axis dynamic range of your lightcurve and normalize the lightcurve after each pixel selection:

>>> ylim_func = lambda lc: (0.0, lc.flux.max())  
>>> transform_func = lambda lc: lc.normalize()  
>>> tpf.interact(ylim_func=ylim_func, transform_func=transform_func)