<jupyter_start><jupyter_text>---<jupyter_code>import exoplanet as xo
import exoplanet.units as xu
import pymc3 as pm
import thejoker as tj
from twobody import KeplerOrbit, KeplerElements
true_orbit = KeplerOrbit(
    P=12.5234*u.day,
    e=0.,
    i=90*u.deg,
    K=100*u.km/u.s,
    M0=0.8384*u.rad,
    omega=2.424*u.rad,
    t0=Time(55524., format='mjd', scale='tcb'))

ts = true_orbit.t0 + 645 + np.random.uniform(10, 200, size=30)
rvs = true_orbit.radial_velocity(ts)
rv_errs = np.ones_like(rvs)
rv_data = tj.RVData(
    ts,
    rvs,
    rv_errs
)
with pm.Model() as model:
    # Allow extra error to account for under-estimated error bars
    s = xu.with_unit(pm.Lognormal('s', 0, 1),
                     u.km/u.s)

    prior = tj.JokerPrior.default(
        P_min=4*u.day, P_max=20*u.day,
        sigma_K0=30*u.km/u.s,
        sigma_v=50*u.km/u.s,
        s=s)

joker = tj.TheJoker(prior)
samples = joker.rejection_sample(rv_data, 
                                 prior_samples=100_000)
len(samples)
mean_sample = samples
rv_data.t0
mean_sample['M0'][0]
(2*np.pi * (rv_data.t0 - true_orbit.t0).jd * u.day / true_orbit.P) % (2*np.pi)
mean_sample['M0'][0].value / (2*np.pi)
# t0 = mean_sample.t0 - mean_sample['P'][0] * mean_sample['M0'][0].to_value(u.rad) / (2*np.pi)
t0 = rv_data.t0 + (mean_sample['P'][0]/(2*np.pi)*mean_sample['M0'][0]).to(u.day, u.dimensionless_angles())
t0
(t0.mjd - true_orbit.t0.mjd) / true_orbit.P.value<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16928327645051194, 'fraction_numerical': 0.0552901023890785, 'mean_word_length': 3.2247838616714697, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '299420', 'license': 'MIT', 'n_tokens_mistral': 701, 'n_tokens_neox': 655, 'n_words': 103, 'path': 'notebooks/Find-asteroseismic.ipynb', 'repo_name': 'adrn/apogee-koi-984', 'size': '1465'}