<jupyter_start><jupyter_text>Recovering weak signals<jupyter_code>import numpy as np
import corner
import pandas as pd
import matplotlib.pyplot as plt
import exoplanet as xo
import pymc3 as pm
import lightkurve as lk
%config IPython.matplotlib.backend = "retina"
from matplotlib import rcParams
rcParams["figure.dpi"] = 150
rcParams["savefig.dpi"] = 150<jupyter_output><empty_output><jupyter_text>Sometimes a signal is too weak to be obvious in the `first_look`. There are a few ways to dig deeper. One of those is the time delay periodogram module, which essentially brute forces a model for a range of orbital periods. The likelihood of the model can then be plotted against the orbital periods, and should peak at the correct value. Let's try this out for a short period binary, KIC~6780873<jupyter_code>lc = lk.search_lightcurvefile('KIC 6780873', mission='Kepler').download_all().PDCSAP_FLUX.stitch().remove_nans()
lc.plot();
from maelstrom import Maelstrom

ms = Maelstrom(lc.time, lc.flux, max_peaks=2, fmin=10)
ms.first_look(segment_size=5);<jupyter_output><empty_output><jupyter_text>It does look like there's something there.. but it's hard to tell. Let's create the periodogram searcher:<jupyter_code>pg = ms.period_search()<jupyter_output><empty_output><jupyter_text>We'll search between 5 and 15 days<jupyter_code>periods = np.linspace(5,15,100)
res = pg.fit(periods)
pg.diagnose();<jupyter_output><empty_output><jupyter_text>Cool, there's a peak at the orbital period of ~9 days! This is almost exactly where we know it to be. The contents of the pg.fit results are a list of optimisation dict results. If we want to make these plots manually, we can do the following:<jupyter_code>ys = np.array([[r[0] for r in row] for row in res])
sm = np.sum(ys, axis=0)
plt.plot(periods, sm)
period = periods[np.argmax(sm)]
plt.xlabel('Period [day]')
plt.ylabel('Model likelihood')

print(f"Expected orbital period at {period:.2f} days")<jupyter_output>Expected orbital period at 9.14 days
{'fraction_non_alphanumeric': 0.09593169261677549, 'fraction_numerical': 0.02059266700150678, 'mean_word_length': 6.217391304347826, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '522131', 'license': 'MIT', 'n_tokens_mistral': 708, 'n_tokens_neox': 657, 'n_words': 227, 'path': 'docs/notebooks/Recovering weak signals.ipynb', 'repo_name': 'danielhey/Maelstrom', 'size': '1991'}