How to use the celerite.plot_setup.setup function in celerite

To help you get started, we’ve selected a few celerite examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dfm / celerite / papers / paper1 / figures / transit_plot.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import division, print_function

import corner
import emcee3
import pickle
import numpy as np

from celerite.plot_setup import setup

setup(auto=True)

gp, y, true_params = pickle.load(open("transit.pkl", "rb"))
f = emcee3.backends.HDFBackend("transit.h5")

# Plot the parameter constraints
names = gp.get_parameter_names()
cols = ["log_period", "log_ror", "log_duration", "t0"]
inds = [names.index("mean:{0}".format(c)) for c in cols]
samples = np.array(f.get_coords(discard=5000, flat=True, thin=13))
samples = samples[:, inds]
samples[:, :-1] = np.exp(samples[:, :-1])
truths = np.array([true_params[k] for k in cols])
truths[:-1] = np.exp(truths[:-1])
fig = corner.corner(samples, truths=truths, smooth=0.5,
                    labels=[r"period", r"$R_\mathrm{P}/R_\star$", r"duration",
                            r"$t_0$"])
github dfm / celerite / paper / figures / astero_plot.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import division, print_function

import pickle
import corner
import numpy as np
import matplotlib.pyplot as plt
from scipy.ndimage.filters import gaussian_filter

import emcee3

from celerite.plot_setup import setup, get_figsize, COLORS

setup(auto=True)
np.random.seed(42)

# Helpers
def format_filename(name):
    base = "astero-{0}-".format(kicid)
    return base + name + ".pdf"

kicid = 11615890
uHz_conv = 1e-6 * 24 * 60 * 60

# Save the current state of the GP and data
with open("astero-{0}.pkl".format(kicid), "rb") as f:
    gp, fit_y, freq, power_all, power_some, n_tot = pickle.load(f)
freq_uHz = freq / uHz_conv
measurement_var = np.median(gp._yerr**2)
white_noise_all = measurement_var * uHz_conv / n_tot
github dfm / celerite / paper / figures / sho.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import division, print_function

import numpy as np
import matplotlib.pyplot as plt
from celerite.plot_setup import setup, get_figsize

np.random.seed(42)
setup(auto=True)

def sho_psd(Q, x):
    x2 = x*x
    return 1.0 / ((x2 - 1)**2 + x2 / Q**2)

def sho_acf(Q, tau):
    t = np.abs(tau)
    if np.allclose(Q, 0.5):
        return np.exp(-t) * (1.0 + t)
    b = 1.0 / np.sqrt(4*Q**2 - 1)
    c = 0.5 / Q
    d = 0.5 * np.sqrt(4*Q**2 - 1) / Q
    return np.exp(-c * t) * (np.cos(d*t)+b*np.sin(d*t))

def lorentz_psd(Q, x):
    return Q**2 * (1.0 / ((x - 1)**2 * (2*Q)**2 + 1) +
github dfm / celerite / examples / benchmark / plot.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import division, print_function

import os
import argparse
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

from celerite.plot_setup import setup, get_figsize, COLOR_CYCLE
setup(auto=True)

parser = argparse.ArgumentParser()
parser.add_argument("platform")
parser.add_argument("--suffix", default=None)
parser.add_argument("--directory",
                    default=os.path.dirname(os.path.abspath(__file__)))
args = parser.parse_args()

# Compile into a matrix
suffix = ""
if args.suffix is not None:
    suffix = "_" + args.suffix

fn = "benchmark_{0}{1}.csv".format(args.platform, suffix)
fn = os.path.join(args.directory, fn)
data = pd.read_csv(fn, comment="#")
github dfm / celerite / paper / figures / rotation.py View on Github external
from __future__ import division, print_function

import kplr
import emcee3
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import minimize

from celerite.plot_setup import setup, get_figsize, COLORS

import celerite
from celerite import terms

np.random.seed(123)
setup(auto=True)

# Define the custom kernel
class RotationTerm(terms.Term):
    parameter_names = ("log_amp", "log_timescale", "log_period", "log_factor")

    def get_real_coefficients(self):
        f = np.exp(self.log_factor)
        return (
            np.exp(self.log_amp) * (1.0 + f) / (2.0 + f),
            np.exp(-self.log_timescale),
        )

    def get_complex_coefficients(self):
        f = np.exp(self.log_factor)
        return (
            np.exp(self.log_amp) / (2.0 + f),