<jupyter_start><jupyter_text>TTV Retrieval for TOI-216 (a partially-sampled dynamically-interacting system from *TESS*)In this notebook, we will perform a dynamical retrieval for TOI-216. This is one of the first TTV systems from *TESS*, verified by two independent groups (Dawson et al. 2019, Kipping et al. 2019). Since Dawson et al. (2019) had follow-up data, I'll use their times here. First, let's import packages and download data:<jupyter_code>%matplotlib inline
import ttvnest
import numpy as np
import pandas as pd

data = []
errs = []
epochs = []

fname = 'toi_216.dat'
df = pd.read_csv(fname, sep=',')
arr = np.array(df)
for planet in [1, 2]:
    subarr = arr[np.where(arr[:,0] == planet)]
    data.append(np.array(subarr[:,2], dtype = 'float'))
    errs.append(np.array(subarr[:,3], dtype = 'float'))
    epochs.append(np.array(subarr[:,1], dtype = 'int'))<jupyter_output><empty_output><jupyter_text>Now, let's set up the ttvnest system:<jupyter_code>toi216_b = ttvnest.TTVPlanet(data[0], errs[0], epochs[0], mass_prior = ('Uniform', 0, 500.), 
                               period_prior = ('Normal', 17.09, 0.01)
                              )

toi216_c = ttvnest.TTVPlanet(data[1], errs[1], epochs[1], mass_prior = ('Uniform', 0, 500.), 
                               period_prior = ('Normal', 34.56, 0.01)
                              )

toi216 = ttvnest.TTVSystem(toi216_b, toi216_c)<jupyter_output>Simulation start/reference time:  1323.0
ttvnest timestep:  0.6836
Simulation length:  218.0
Simulation end time:  1541.0<jupyter_text>Before retrieval, let's plot the data alone to see what they look like:<jupyter_code>ttvnest.plot_utils.plot_ttv_data(toi216)<jupyter_output><empty_output><jupyter_text>Let's retrieve:<jupyter_code>results = toi216.retrieve()<jupyter_output>23567it [14:36, 18.68it/s, batch: 0 | bound: 111 | nc: 25 | ncall: 473199 | eff(%):  4.970 | loglstar:   -inf < -103.027 <    inf | logz: -130.527 +/-    nan | dlogz: 179.842 >  0.010]      /usr/local/lib/python3.7/site-packages/dynesty/sampling.py:238: UserWarning: Random walk proposals appear to be extremely inefficient. Adjusting the scale-factor accordingly.
  warnings.warn("Random walk proposals appear to be "
25465it [16:46,  2.96it/s, batch: 0 | bound: 128 | nc: 827 | ncall: 532858 | eff(%):  4.770 | loglstar:   -inf < -19.328 <    inf | logz: -48.161 +/-    nan | dlogz: 105.795 >  0.010]   /usr/local/lib/python3.7/site-packages/dynesty/sampling.py:238: UserWarning: Random walk proposals appear to be extremely inefficient. Adjusting the scale-factor accordingly.
  warnings.warn("Random walk proposals appear to be "
26058it [17:25,  2.90it/s, batch: 0 | bound: 133 | nc: 836 | ncall: 551296 | eff(%):  4.718 | loglstar:   -inf < -1.769 <    inf | logz: -31.140 +/-    nan | dlogz: 8[...]<jupyter_text>Dawson et al. (2019) got a bimodal solution for planets {b, c} with mode peaks at {20.7, 107} and {41.3, 236} in dynamical mass. Kipping et al. (2019) got {33.8, 247} with larger error bars (and fitting only the *TESS*, nott the ground-based transits). Let's see what we get.<jupyter_code>toi216.posterior_summary()
ttvnest.plot_utils.plot_results(toi216, uncertainty_curves = 100, 
                                sim_length = 365.25*3, outname = 'toi216')<jupyter_output>Summary (middle 95 percentile): 
$M_1/M_\star/3\times10^{-6}$: $32.40569^{+26.480366}_{-14.944147}$
$P_1\ [\mathrm{days}]$: $17.093725^{+0.005424}_{-0.007549}$
$\sqrt{e}_1\cos(\omega_1)$: $0.052098^{+0.171954}_{-0.397521}$
$\sqrt{e}_1\sin(\omega_1)$: $-0.284014^{+0.369713}_{-0.107045}$
$T_{0,1}\ [\mathrm{days}]$: $2.325885^{+0.00535}_{-0.006074}$
$M_2/M_\star/3\times10^{-6}$: $233.905727^{+250.787841}_{-115.507431}$
$P_2\ [\mathrm{days}]$: $34.546407^{+0.004326}_{-0.00381}$
$\sqrt{e}_2\cos(\omega_2)$: $0.114376^{+0.217997}_{-0.213084}$
$\sqrt{e}_2\sin(\omega_2)$: $0.084404^{+0.067307}_{-0.110083}$
$T_{0,2}\ [\mathrm{days}]$: $8.285478^{+0.001315}_{-0.00119}$<jupyter_text>Awesome! Seems like we agree well with the high-mass mode of Dawson+19 and the Kipping+19 fit (the latter one matches particularly well). From the saved TTV plots, it looks like the constraints from TESS three years out will be extremely useful in nailing down the masses. Let's make the dynesty plots for good measure:<jupyter_code>ttvnest.plot_utils.dynesty_plots(toi216, outname = 'toi216')<jupyter_output>Axis limits error on runplot; internal to dynesty<jupyter_text>And, let's save our results for later:<jupyter_code>ttvnest.io_utils.save_results(toi216, 'toi216.p')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15776805251641138, 'fraction_numerical': 0.11969365426695842, 'mean_word_length': 4.084538375973303, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 27, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '159637', 'license': 'MIT', 'n_tokens_mistral': 2068, 'n_tokens_neox': 1688, 'n_words': 418, 'path': 'examples/toi-216/TOI-216.ipynb', 'repo_name': 'astroshrey/ttvnest', 'size': '4570'}