<jupyter_start><jupyter_text>Simple Trapezoid Fit ExampleThis is basically the unit test modified for an interactive session in a notebook format, so you can play with the API.A development version of `exovetter` is required to be installed, along with all the required and optional dependencies. Refer to package documentation for more information.<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
from astropy.utils.compat.context import nullcontext
from astropy.utils.misc import NumpyRNGContext

from exovetter.trapezoid_fit import TrapezoidFitParameters, TrapezoidOriginalEstimates, TrapezoidFit, phase_data

%matplotlib inline<jupyter_output><empty_output><jupyter_text>Set the random seed for reproducibility. Set it to `None` if you want a truly random behavior.<jupyter_code>seed = 1234
if seed is None:
    rand_ctx = nullcontext()
else:
    rand_ctx = NumpyRNGContext(seed)<jupyter_output><empty_output><jupyter_text>Adjust the values here according to your science case. Please be mindful of the units.<jupyter_code>data_span = 80.0  # in Days
exposure_length = 1.0 / 48.0  # in Days, 48 cadences per day
signal_depth = 300.0  # signal depth in ppm
signal_duration = 5.0 / 24.0  # in Days
signal_period = 10.4203  # in Days
signal_epoch = 5.1  # in Days
noise_level = 40.0  # noise per observation in ppm
samplen = 15
fitregion = 4.0<jupyter_output><empty_output><jupyter_text>These are computed parameters based on your inputs above.<jupyter_code>n_data = int(data_span / exposure_length)
signal_duration_hours = signal_duration * 24.0

time_series = np.linspace(0, int(data_span), n_data)

with rand_ctx:
    data_series = 1.0 + np.random.randn(n_data) / 1e6 * noise_level

error_series = np.full_like(data_series, noise_level / 1e6)<jupyter_output><empty_output><jupyter_text>Pass the parameters into classes that hold fit parameters and original estimates, respectively.<jupyter_code>trp_parm = TrapezoidFitParameters(exposure_length, samplen=samplen, fitregion=fitregion)
trp_origests = TrapezoidOriginalEstimates(
    period=signal_period, epoch=signal_epoch,
    duration=signal_duration_hours, depth=signal_depth)<jupyter_output><empty_output><jupyter_text>Instantiate the class to do the trapezoid fitting.<jupyter_code>ioblk = TrapezoidFit(
    time_series, data_series, error_series,
    trp_parameters=trp_parm, trp_originalestimates=trp_origests,
    t_ratio=0.1)<jupyter_output><empty_output><jupyter_text>Make a model trapezoid light curve.<jupyter_code>ioblk.trapezoid_model()<jupyter_output><empty_output><jupyter_text>Insert signal.<jupyter_code>data_series *= ioblk.modellc<jupyter_output><empty_output><jupyter_text>Some values need to be readjusted before fitting.<jupyter_code>new_signal_epoch = signal_epoch + 0.001
new_signal_duration_hours = signal_duration_hours * 0.9
new_signal_depth = signal_depth * 1.1
fit_trial_n = 2
error_scale = 1.0<jupyter_output><empty_output><jupyter_text>Perform the fitting.<jupyter_code>ioblk = TrapezoidFit.trapezoid_fit(
    time_series, data_series, error_series,
    signal_period, new_signal_epoch,
    new_signal_duration_hours, new_signal_depth,
    fit_trial_n=fit_trial_n, fit_region=fitregion,
    error_scale=error_scale, sample_n=samplen, seed=seed)<jupyter_output><empty_output><jupyter_text>Print the planet model estimates.<jupyter_code>print(ioblk.planetests)<jupyter_output><empty_output><jupyter_text>Plot the fitting result.<jupyter_code>ioblk.plot_likehood()<jupyter_output><empty_output><jupyter_text>More plots.<jupyter_code>phased_series = phase_data(time_series, signal_period, signal_epoch)
plt.plot(phased_series, data_series, '.');
plt.plot(time_series, data_series, '.');<jupyter_output><empty_output><jupyter_text>Encore: Other Ways to Generate ModelsThis is the other unit test for alternative ways to general models without doing the fitting part.<jupyter_code>newioblk = TrapezoidFit.trapezoid_model_onemodel(
    time_series, signal_period,
    signal_epoch, signal_depth, signal_duration_hours,
    signal_duration_hours * 0.1, samplen)
newioblk2 = newioblk.trapezoid_model_raw(
    signal_epoch + 0.05, signal_depth * 1.5,
    signal_duration_hours * 2.0,
    signal_duration_hours * 2.0 * 0.2)
fig = plt.figure()
ax = fig.subplots()
ax.plot(phased_series, newioblk.modellc, '.b')
ax.plot(phased_series, newioblk2.modellc, '.r')
ax.set_xlim(-0.05, 0.05);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08607767431296844, 'fraction_numerical': 0.018623665682489212, 'mean_word_length': 6.963833634719711, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '96211', 'license': 'MIT', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1535, 'n_words': 328, 'path': 'example_notebooks/trapezoid_fit_simple.ipynb', 'repo_name': 'spacetelescope/exovetter', 'size': '4403'}