<jupyter_start><jupyter_text>Appending light curves (stitching Kepler quarters) The Kepler mission took 17 quarters of continuous observations on the same targets. For applications such as finding long period planets or asteroseismology it is useful to be able to turn these quarters into one long light curve. We can do this using lightkurve's `append` function. The append function is called by doing    stitched_lc = lc1.append(lc2)    It works in the same way as appending a list in python.Below is an example of how to stitch together all the quarters for the exoplanet target Kepler-8b. (*Note: We'll use the jupyter notebook magic command `%%capture` to supress the output for the cell so that it doesn't print a long download message*)<jupyter_code>from lightkurve import KeplerLightCurveFile
target = 'Kepler-8b'
%%capture
lc = KeplerLightCurveFile.from_archive(target, quarter=1).PDCSAP_FLUX
for q in range(2,17):
    lc = lc.append(KeplerLightCurveFile.from_archive(target, quarter=q).PDCSAP_FLUX)<jupyter_output><empty_output><jupyter_text>Above we have created a `KeplerLightCurve` object from the first quarter of the data, choosing to use the PDCSAP_FLUX. Then we have looped through all the quarters, appending each new light curve to the fist one. We can plot this new `KeplerLightCurve` using the `plot` function (and all the other functions from previous tutorials will work too!)<jupyter_code>lc.plot();<jupyter_output><empty_output><jupyter_text>Unfortunately, as the light fell on difference pixels in each quarter and the spacecraft changed temperature during observation, these light curves all have difference offsets. We can remove them by normalizing each light curve before we append it. We can do this with the lightkurve function `normalize`.<jupyter_code>%%capture
lc = KeplerLightCurveFile.from_archive(target, quarter=1).PDCSAP_FLUX.normalize()
for q in range(2,8):
    lc = lc.append(KeplerLightCurveFile.from_archive(target, quarter=q).PDCSAP_FLUX.normalize())
lc.plot();<jupyter_output><empty_output><jupyter_text>Now that the light curves are normalized they don't have significant offsets. However, there are clear long term trends in some of the early quarters of the data. We can remove this using lightkurve's `flatten` method before appending each object.<jupyter_code>%%capture
lc = KeplerLightCurveFile.from_archive(target, quarter=1).PDCSAP_FLUX.normalize().flatten(window_length=401)
for q in range(2,8):
    lc = lc.append(KeplerLightCurveFile.from_archive(target, quarter=q).PDCSAP_FLUX.normalize().flatten(window_length=401))
lc.plot();<jupyter_output><empty_output><jupyter_text>Now all of the light curves stitch together with no visible join. We can use the `fold` and `bin` methods to form a planet transit out of all of the data for Kepler-8b.<jupyter_code>lc.fold(3.52254, phase=0.38).bin().plot();<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup