Responsive Code Snippet

            
            Copied to clipboard!
            import lightkurve as lk
                import numpy as np
                import matplotlib.pyplot as plt

# Download the data for the Estrella Tabby
  target = "KIC 8462852"
                search_result = lk.search_lightcurvefile(target)

                # Download all the light curve files
                lc_collection = search_result.download_all()

                # Stitch all the light curves together
                lc = lc_collection.stitch()

                # Remove NaN values and normalize the light curve
                lc = lc.remove_nans().normalize()

                # Apply a Savitzky-Golay filter to remove long-term trends
                lc_detrended = lc.flatten(window_length=401)

                # Plot the processed light curve
                lc_detrended.plot()

                # Apply the Fourier Transform
                fft = np.fft.fft(lc_detrended.flux)
                frequencies = np.fft.fftfreq(len(fft), lc_detrended.time[1].value - lc_detrended.time[0].value)

                # Filter positive frequencies
                positive_frequencies = frequencies[frequencies > 0]
                positive_fft = np.abs(fft[frequencies > 0])

                # Plot the Fourier Transform
                plt.figure(figsize=(10, 6))
                plt.plot(positive_frequencies, positive_fft)
                plt.xlabel("Frequency (cycles per day)")
                plt.ylabel("Amplitude")
                plt.title("Fourier Transform of the Estrella Tabby")
                plt.show()

                # Zoom in on the 0-5 cycles per day range
                plt.figure(figsize=(10, 6))
                mask = (positive_frequencies > 0) & (positive_frequencies <= 5)
                plt.plot(positive_frequencies[mask], positive_fft[mask])
                plt.xlabel("Frequency (cycles per day)")
                plt.ylabel("Amplitude")
                plt.title("Fourier Transform (0-5 cycles per day)")
                plt.show()