<jupyter_start><jupyter_text>What are `LightCurve` objects? [`LightCurve`](https://docs.lightkurve.org/api/lightkurve.lightcurve.LightCurve.htmllightkurve.lightcurve.LightCurve) objects are data objects which encapsulate the brightness of a star over time. They provide a series of common operations, for example folding, binning, plotting, etc. There are a range of subclasses of `LightCurve` objects specific to telescopes, including [`TESSLightCurve`](https://docs.lightkurve.org/api/lightkurve.lightcurve.TessLightCurve.htmllightkurve.lightcurve.TessLightCurve) for TESS data.You can create a `LightCurve` object from a `TargetPixelFile` object using Simple Aperture Photometry (see our tutorial for more information on Target Pixel Files [here](x). Aperture Photometry is the simple act of summing up the values of all the pixels in a pre-defined aperture, as a function of time. By carefully choosing the shape of the aperture mask, you can avoid nearby contaminants or improve the strength of the specific signal you are trying to measure relative to the background.To demonstrate, lets create a `TESSLightCurve` from a `TESSTargetPixelFile`. First we open a Target Pixel File from [MAST](https://archive.stsci.edu/kepler/), this one is already cached from our previous [tutorial](https://docs.lightkurve.org/tutorials/01-what-are-lightcurves.html)!:<jupyter_code>import numpy as np
import pandas as pd

from lightkurve import search_targetpixelfile

tpf = search_targetpixelfile('TIC 307210830 c', sector=2).download()<jupyter_output><empty_output><jupyter_text>Then we convert the target pixel file into a light curve using the [`to_lightcurve`](https://docs.lightkurve.org/api/lightkurve.targetpixelfile.KeplerTargetPixelFile.htmllightkurve.targetpixelfile.KeplerTargetPixelFile.to_lightcurve) command and the pipeline-defined aperture mask (look [here](https://keplerscience.arc.nasa.gov/pipeline.htmlpixel-response-function) for more information about aperture photometry and the optimal aperture mask definition).<jupyter_code>lc = tpf.to_lightcurve(aperture_mask=tpf.pipeline_mask)<jupyter_output><empty_output><jupyter_text>We've built a new `TESSLightCurve` object called `lc`. Note in this case we've passed an **aperture_mask** to the `to_lightcurve` method. The default is to use the `SPOC` pipeline aperture. (You can pass your own aperture, which is a boolean `numpy` array.) By summing all the pixels in the aperture we have created a Simple Aperture Photometry (SAP) lightcurve.`TESSLightCurve` has many useful functions that you can use. As with Target Pixel Files you can access the meta data very simply:<jupyter_code>lc.mission
lc.sector<jupyter_output><empty_output><jupyter_text>And you still have access to time and flux attributes. In a light curve, there is only one flux point for every time stamp. The data can be displayed as a table using `Pandas`:<jupyter_code>info = pd.DataFrame(data={'Time (BKJD)': lc.time, 'Flux (e-/s)': lc.flux})
info<jupyter_output><empty_output><jupyter_text>You can also check the Combined Differential Photometric Precision (CDPP) RMS per transit duration noise metric (see [Gilliland et al., 2011](https://iopscience.iop.org/article/10.1088/0067-0049/197/1/6/pdf) for more details) of the lightcurve using the built in method [`estimate_cdpp`](https://docs.lightkurve.org/api/lightkurve.lightcurve.FoldedLightCurve.htmllightkurve.lightcurve.FoldedLightCurve.estimate_cdpp):<jupyter_code>lc.estimate_cdpp()<jupyter_output><empty_output><jupyter_text>The above is the Savitzky-Golay CDPP noise metric in units parts-per-million (ppm) Now we can use the built in `plot` function on the `TESSLightCurve` object to plot the time series. You can pass `plot` any keywords you would normally pass to [`matplotlib.pyplot.plot`](https://matplotlib.org/3.1.3/api/_as_gen/matplotlib.pyplot.plot.html).<jupyter_code>%matplotlib inline
lc.plot();<jupyter_output><empty_output><jupyter_text>There are a set of useful functions in [`LightCurve`](https://docs.lightkurve.org/api/lightkurve.lightcurve.LightCurve.htmllightkurve.lightcurve.LightCurve) objects which you can use to work with the data. These include:* [`flatten()`](https://docs.lightkurve.org/api/lightkurve.lightcurve.LightCurve.htmllightkurve.lightcurve.LightCurve.flatten): Remove long term trends using a [Savitzky–Golay filter](https://en.wikipedia.org/wiki/Savitzky%E2%80%93Golay_filter)* [`remove_outliers()`](https://docs.lightkurve.org/api/lightkurve.lightcurve.LightCurve.htmllightkurve.lightcurve.LightCurve.remove_outliers): Remove outliers using simple sigma clipping* [`remove_nans()`](https://docs.lightkurve.org/api/lightkurve.lightcurve.LightCurve.htmllightkurve.lightcurve.LightCurve.remove_nans): Remove infinite or NaN values (these can occur during thruster firings)* [`fold()`](https://docs.lightkurve.org/api/lightkurve.lightcurve.LightCurve.htmllightkurve.lightcurve.LightCurve.fold): Fold the data at a particular period* [`bin()`](https://docs.lightkurve.org/api/lightkurve.lightcurve.LightCurve.htmllightkurve.lightcurve.LightCurve.bin): Reduce the time resolution of the array, taking the average value in each bin.We can use these simply on a light curve object<jupyter_code>flat_lc = lc.flatten(window_length=401)
flat_lc.plot();
folded_lc = flat_lc.fold(period=3.690621)
folded_lc.plot();
binned_lc = folded_lc.bin(binsize=10)
binned_lc.plot();<jupyter_output><empty_output><jupyter_text>Or we can do these all in a single (long) line!<jupyter_code>lc.remove_nans().flatten(window_length=401).fold(period=3.690621).bin(binsize=20).plot();<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10140794867225093, 'fraction_numerical': 0.011940830511495278, 'mean_word_length': 6.698216735253772, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 16, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '506096', 'license': 'MIT', 'n_tokens_mistral': 1883, 'n_tokens_neox': 1745, 'n_words': 495, 'path': 'docs/source/tutorials/01-what-are-lightcurvesv2.ipynb', 'repo_name': 'rebekah9969/lightkurve', 'size': '5611'}