Exemplo n.º 1
0
def lnlike(theta, x, y, yerr):
    P1, tau1, k1, w1, e1, P2, tau2, k2, w2, e2, P3, tau3, k3, w3, e3, offset = theta
    fit_curve   = Model(P1=P1, tau1=tau1, k1=k1, w1=w1, e1=e1, 
                        P2=P2, tau2=tau2, k2=k2, w2=w2, e2=e2, 
                        P3=P3, tau3=tau3, k3=k3, w3=w3, e3=e3, offset=offset)
    y_fit       = fit_curve.get_value(x)
    return -0.5*(np.sum( ((y-y_fit)/yerr)**2))
Exemplo n.º 2
0
def lnlike(theta, x, y, yerr):
    P1, tau1, k1, w1, e1, offset1, alpha = theta
    fit_curve = Model(P1=P1,
                      tau1=tau1,
                      k1=k1,
                      w1=w1,
                      e1=e1,
                      offset1=offset1,
                      alpha=alpha)
    y_fit = fit_curve.get_value(x)
    return -0.5 * (np.sum(((y - y_fit) / yerr)**2))
Exemplo n.º 3
0
def lnlike(theta, x, y, yerr):
    P, tau, k, w, e0, offset1, offset2 = theta
    fit_curve = Model(P=P,
                      tau=tau,
                      k=k,
                      w=w,
                      e0=e0,
                      offset1=offset1,
                      offset2=offset2)
    y_fit = fit_curve.get_value(np.array(x))
    return -0.5 * (np.sum(((y - y_fit) / yerr)**2.))
Exemplo n.º 4
0
def lnlike(theta, x, y, yerr):
    P, tau, k, w, e0, off_aat, off_chiron, off_feros, off_mj1, off_mj3 = theta
    fit_curve = Model(P=P,
                      tau=tau,
                      k=k,
                      w=w,
                      e0=e0,
                      off_aat=off_aat,
                      off_chiron=off_chiron,
                      off_feros=off_feros,
                      off_mj1=off_mj1,
                      off_mj3=off_mj3)
    y_fit = fit_curve.get_value(np.array(x))
    return -0.5 * (np.sum(((y - y_fit) / yerr)**2.))
Exemplo n.º 5
0
def lnlike(theta, x, y, yerr):
    P1, tau1, k1, w1, e1, P2, tau2, k2, w2, e2, offset, alpha = theta
    model = Model(P1=P1,
                  tau1=tau1,
                  k1=k1,
                  w1=w1,
                  e1=e1,
                  P2=P2,
                  tau2=tau2,
                  k2=k2,
                  w2=w2,
                  e2=e2,
                  offset=offset,
                  alpha=alpha)
    return -0.5 * (np.sum(((y - model.get_value(np.array(x))) / yerr)**2.))
Exemplo n.º 6
0
def lnlike(theta, x, y, yerr):
    P1, tau1, k1, w1, e1, P2, tau2, k2, w2, e2, offset, alpha = theta
    fit_curve = Model(P1=P1,
                      tau1=tau1,
                      k1=k1,
                      w1=w1,
                      e1=e1,
                      P2=P2,
                      tau2=tau2,
                      k2=k2,
                      w2=w2,
                      e2=e2,
                      offset=offset,
                      alpha=alpha)
    y_fit = fit_curve.get_value(x)
    return -0.5 * (np.sum(((y - y_fit) / yerr)**2))
Exemplo n.º 7
0
aa[5, :] = [a5[i] for i in range(3)]
aa[6, :] = [a6[i] for i in range(3)]
aa[7, :] = [a7[i] for i in range(3)]
aa[8, :] = [a8[i] for i in range(3)]
aa[9, :] = [a9[i] for i in range(3)]
aa[10, :] = [a10[i] for i in range(3)]
aa[11, :] = [a11[i] for i in range(3)]
np.savetxt('HD85390_fit.txt', aa, fmt='%.6f')

P1, tau1, k1, w1, e1, P2, tau2, k2, w2, e2, offset, alpha = aa[:, 0]
fit_curve = Model(P1=np.log(P1) / 10,
                  tau1=tau1 / 100,
                  k1=k1 / 100,
                  w1=w1,
                  e1=e1,
                  P2=np.log(P2) / 10,
                  tau2=tau2 / 100,
                  k2=k2 / 100,
                  w2=w2,
                  e2=e2,
                  offset=offset,
                  alpha=alpha)
y_fit = fit_curve.get_value(x)

fit_curve2 = Model2(P1=np.log(P1) / 10,
                    tau1=tau1 / 100,
                    k1=k1 / 100,
                    w1=w1,
                    e1=e1,
                    P2=np.log(P2) / 10,
                    tau2=tau2 / 100,
                    k2=k2 / 100,
Exemplo n.º 8
0
a0, a1, a2, a3, a4, a5, a6 = map(
    lambda v: (v[1], v[2] - v[1], v[1] - v[0]),
    zip(*np.percentile(real_samples, [16, 50, 84], axis=0)))
aa = np.zeros((len(guess), 3))
aa[0, :] = [a0[i] for i in range(3)]
aa[1, :] = [a1[i] for i in range(3)]
aa[2, :] = [a2[i] for i in range(3)]
aa[3, :] = [a3[i] for i in range(3)]
aa[4, :] = [a4[i] for i in range(3)]
aa[5, :] = [a5[i] for i in range(3)]
aa[6, :] = [a6[i] for i in range(3)]
np.savetxt('../../output/HD103720/103720pj_MCMC_result.txt', aa, fmt='%.6f')

P, tau, k, w, e0, offset, m = aa[:, 0]
fit_curve = Model(P=P, tau=tau, k=k, w=w, e0=e0, offset=offset, m=m)
y_fit = fit_curve.get_value(np.array(x))

plt.figure()
plt.errorbar(x, y_fit, yerr=yerr, fmt=".", capsize=0, label='MCMC fit')
plt.errorbar(x, y, yerr=yerr, fmt=".", capsize=0, label='HARPS')
plt.ylabel("RV [m/s]")
plt.xlabel("MJD")
plt.legend(loc="upper center")
plt.savefig('../../output/HD103720/103720pj_MCMC_fit.png')
plt.show()

residual = np.array(y) - fit_curve.get_value(np.array(x))
chi2 = sum(residual**2 / np.array(yerr)**2) / (len(x) - len(guess))
rms = np.sqrt(np.mean(residual**2))
wrms = np.sqrt(sum((residual / yerr)**2) / sum(1 / yerr**2))
Exemplo n.º 9
0
aa[5, :] = [a5[i] for i in range(3)]
aa[6, :] = [a6[i] for i in range(3)]
aa[7, :] = [a7[i] for i in range(3)]
aa[8, :] = [a8[i] for i in range(3)]
aa[9, :] = [a9[i] for i in range(3)]
aa[10, :] = [a10[i] for i in range(3)]
aa[11, :] = [a11[i] for i in range(3)]
np.savetxt('HD85390_fit.txt', aa, fmt='%.6f')

P1, tau1, k1, w1, e1, P2, tau2, k2, w2, e2, offset, alpha = aa[:, 0]
fit_curve = Model(P1=np.log(P1) / 10,
                  tau1=np.log(tau1),
                  k1=np.log(k1),
                  w1=w1,
                  e1=e1,
                  P2=np.log(P2) / 10,
                  tau2=np.log(tau2),
                  k2=np.log(k2),
                  w2=w2,
                  e2=e2,
                  offset=offset,
                  alpha=0)
t_fit = np.linspace(min(x), max(x), num=10001, endpoint=True)
y_fit = fit_curve.get_value(np.array(x))

residual = y_fit - y
chi2 = sum(residual**2 / yerr**2)
rms = np.sqrt(np.mean(residual**2))

fig = plt.figure(figsize=(10, 7))
frame1 = fig.add_axes((.15, .3, .8, .6))
frame1.axhline(y=0, color='k', ls='--', alpha=.3)
Exemplo n.º 10
0
P1, tau1, k1, w1, e1, offset1, alpha = aa[:,0]
fig         = plt.figure(figsize=(10, 7))
frame1      = fig.add_axes((.15,.3,.8,.6))
frame1.axhline(y=0, color='k', ls='--', alpha=.3)
t_sample    = np.linspace(min(t), max(t), num=10001, endpoint=True)

# Planet 1 #
Planet1     = Model2(P1=P1/1000, tau1=tau1/1000, k1=k1/100, w1=w1, e1=e1, offset1=offset1)
y1          = Planet1.get_value(t_sample)
plt.plot(t_sample, y1, 'b-.', alpha=.3, label='Planet1')
plt.errorbar(t, xx, yerr=yerr, fmt=".k", capsize=0, label='HARPS RV')
plt.legend()
plt.ylabel("Radial velocity [m/s]")
# Jitter#
Jitter      = Model(P1=P1/1000, tau1=tau1/1000, k1=0, w1=w1, e1=e1, offset1=0, alpha=alpha)
y_jitter    = Jitter.get_value(t)
plt.plot(t, y_jitter, 'ro', alpha=.5, label='smoothed jitter')

Fit         = Model(P1=P1/1000, tau1=tau1/1000, k1=k1/100, w1=w1, e1=e1, offset1=offset1, alpha=alpha)
y_fit       = Fit.get_value(t)
plt.plot(t, y_fit, 'bo', alpha=.5, label='Planet 1 + smoothed jitter')
# plt.plot(x[x<57300], alpha*jitter_smooth, 'ro', alpha=.5, label='smoothed jitter')
plt.legend()
plt.ylabel("Radial velocity [m/s]")

residual    = y_fit - xx
chi2        = sum(residual**2 / yerr**2)
rms         = np.sqrt(np.mean(residual**2))
wrms        = np.sqrt(sum((residual/yerr)**2) / sum(1/yerr**2))
Exemplo n.º 11
0
#==============================================================================

a0, a1, a2, a3, a4, a5 = map(
    lambda v: (v[1], v[2] - v[1], v[1] - v[0]),
    zip(*np.percentile(real_samples, [16, 50, 84], axis=0)))
aa = np.zeros((len(guess), 3))
aa[0, :] = [a0[i] for i in range(3)]
aa[1, :] = [a1[i] for i in range(3)]
aa[2, :] = [a2[i] for i in range(3)]
aa[3, :] = [a3[i] for i in range(3)]
aa[4, :] = [a4[i] for i in range(3)]
aa[5, :] = [a5[i] for i in range(3)]
np.savetxt('../../output/HD103720/103720_MCMC_result.txt', aa, fmt='%.6f')

P, tau, k, w, e0, offset = aa[:, 0]
fit_curve = Model(P=P, tau=tau, k=k, w=w, e0=e0, offset=offset)
t_fit = np.linspace(min(x) - 20, max(x), num=10001, endpoint=True)
y_fit = fit_curve.get_value(np.array(t_fit))

plt.figure()
plt.plot(t_fit, y_fit, label='MCMC fit')
plt.errorbar(x, y, yerr=yerr, fmt=".", capsize=0, label='HARPS')
plt.ylabel("RV [m/s]")
plt.xlabel("MJD")
plt.legend(loc="upper center")
plt.savefig('../../output/HD103720/103720_MCMC_fit.png')
plt.show()

companion = fit_curve.get_value(np.array(x))
residual = np.array(y) - companion
chi2 = sum(residual**2 / np.array(yerr)**2) / (len(x) - len(guess))
Exemplo n.º 12
0
                               self.e2 * np.cos(self.w2))

        offset = np.zeros(len(t))
        idx = t < 57300
        offset[idx] = self.offset1
        offset[~idx] = self.offset2

        return rv1 + rv2 + offset


mean_model = Model(P1=8.,
                   tau1=1.,
                   k1=np.std(y) / 100,
                   w1=0.,
                   e1=0.4,
                   P2=100,
                   tau2=1.,
                   k2=np.std(y) / 100,
                   w2=0.,
                   e2=0.4,
                   offset1=0.,
                   offset2=0.)

#==============================================================================
# The fit
#==============================================================================
import celerite
from celerite import terms

# Set up the GP model
kernel = terms.RealTerm(log_a=np.log(np.var(y)), log_c=-np.log(10.0))
gp = celerite.GP(kernel, mean=mean_model, fit_mean=True)
Exemplo n.º 13
0
#==============================================================================

a0, a1, a2, a3, a4, a5 = map(
    lambda v: (v[1], v[2] - v[1], v[1] - v[0]),
    zip(*np.percentile(real_samples, [16, 50, 84], axis=0)))
aa = np.zeros((len(guess), 3))
aa[0, :] = [a0[i] for i in range(3)]
aa[1, :] = [a1[i] for i in range(3)]
aa[2, :] = [a2[i] for i in range(3)]
aa[3, :] = [a3[i] for i in range(3)]
aa[4, :] = [a4[i] for i in range(3)]
aa[5, :] = [a5[i] for i in range(3)]
np.savetxt('103720_MCMC_result.txt', aa, fmt='%.6f')

P, tau, k, w, e0, offset = aa[:, 0]
fit_curve = Model(P=P, tau=tau, k=k, w=w, e0=e0, offset=offset)
y_fit = fit_curve.get_value(np.array(x))

plt.figure()
plt.errorbar(x, y_fit, yerr=yerr, fmt=".", capsize=0, label='MCMC fit')
plt.errorbar(x, y, yerr=yerr, fmt=".", capsize=0, label='HARPS')
plt.ylabel("RV [m/s]")
plt.xlabel("MJD")
plt.legend(loc="upper center")
plt.savefig('../../103720_MCMC_fit.png')
plt.show()

companion = fit_curve.get_value(np.array(x))
residual = np.array(y) - companion
chi2 = sum(residual**2 / np.array(yerr)**2) / (len(x) - len(guess))
rms = np.sqrt(np.mean(residual**2))
Exemplo n.º 14
0
    zip(*np.percentile(real_samples, [16, 50, 84], axis=0)))
aa = np.zeros((len(guess), 3))
aa[0, :] = [a0[i] for i in range(3)]
aa[1, :] = [a1[i] for i in range(3)]
aa[2, :] = [a2[i] for i in range(3)]
aa[3, :] = [a3[i] for i in range(3)]
aa[4, :] = [a4[i] for i in range(3)]
aa[5, :] = [a5[i] for i in range(3)]
aa[6, :] = [a6[i] for i in range(3)]
np.savetxt('../../output/HD36051/36051_MCMC_result.txt', aa, fmt='%.6f')

P, tau, k, w, e0, offset1, offset2 = aa[:, 0]
fit_curve = Model(P=P / 100,
                  tau=tau,
                  k=k,
                  w=w,
                  e0=e0,
                  offset1=offset1,
                  offset2=offset2)
y_fit = fit_curve.get_value(np.array(x))

plt.figure()
plt.errorbar(x, y_fit, yerr=yerr, fmt=".", capsize=0, label='MCMC fit')
plt.errorbar(x, y, yerr=yerr, fmt=".", capsize=0, label='HARPS')
plt.ylabel("RV [m/s]")
plt.xlabel("MJD")
plt.legend(loc="upper center")
plt.savefig('../../output/HD36051/36051_MCMC_fit.png')
plt.show()

companion = fit_curve.get_value(np.array(x))
Exemplo n.º 15
0
    # plt.rcParams.update({'font.size': 20})
    # fig, axes = plt.subplots(figsize=(16, 5))
    plt.rcParams.update({'font.size': 24})
    fig = plt.figure(figsize=(15, 7))
    plt.subplots_adjust(left=left,
                        bottom=bottom,
                        right=right,
                        top=top,
                        wspace=wspace,
                        hspace=hspace)

    fig.suptitle(r'$\epsilon$ Eridani time series', y=0.95)
    axes_1 = plt.subplot(211)
    axes_1.axhline(color="gray", ls='--')
    fit_curve = Model(P=P, tau=tau, k=k, w0=w0, e0=e0, offset=offset)
    plot_x = np.linspace(min(MJD), max(MJD), num=10000)
    plot_y = fit_curve.get_value(plot_x)
    wrms1 = np.sqrt(
        sum(((x - np.mean(x)) / RV_noise)**2) / sum(1 / RV_noise**2))
    rms1 = np.var(x)**0.5
    plt.errorbar(MJD,
                 x + 7,
                 yerr=RV_noise,
                 fmt="k.",
                 capsize=0,
                 alpha=alpha,
                 label=r'$RV_{HARPS}$')
    plt.plot(plot_x, plot_y, 'g-', linewidth=2.0, label='Model')
    plt.ylim(-21, 21)
    plt.ylabel('RV [m/s]')
Exemplo n.º 16
0
aa[9, :] = [a9[i] for i in range(3)]
aa[10, :] = [a10[i] for i in range(3)]
np.savetxt('HD85390_fit.txt', aa, fmt='%.6f')

P1, tau1, k1, w1, e1, P2, tau2, k2, w2, e2, offset = aa[:, 0]
fig = plt.figure(figsize=(10, 7))
frame1 = fig.add_axes((.15, .3, .8, .6))
frame1.axhline(y=0, color='k', ls='--', alpha=.3)
t_sample = np.linspace(min(x), max(x), num=10001, endpoint=True)
# Planet 1 #
Planet1 = Model(P1=P1 / 100,
                tau1=tau1 / 100,
                k1=k1 / 100,
                w1=w1,
                e1=e1,
                P2=P2 / 100,
                tau2=tau2 / 100,
                k2=0,
                w2=w2,
                e2=e2,
                offset=0)
y1 = Planet1.get_value(t_sample)
plt.plot(t_sample, y1, 'b-.', alpha=.3, label='Planet1')
# Planet 2 #
Planet2 = Model(P1=P1 / 100,
                tau1=tau1 / 100,
                k1=0,
                w1=w1,
                e1=e1,
                P2=P2 / 100,
                tau2=tau2 / 100,
Exemplo n.º 17
0
OFFSET_CHIRON   = -70./100
OFFSET_FEROS    = -8.4/100
OFFSET_MJ1      = -12.8/100
OFFSET_MJ3      = -54.4/100
OFFSET_FIDEOS   = -83.2/100

truth   = dict(log_P=np.log(415.9), log_tau=np.log(4812), log_k=np.log(186.8), w=-0.06, e0=0.856,
                off_aat=OFFSET_AAT, off_chiron=OFFSET_CHIRON, off_feros=OFFSET_FEROS, 
                off_mj1=OFFSET_MJ1, off_mj3=OFFSET_MJ3, off_fideos=OFFSET_FIDEOS)


kernel  = terms.SHOTerm(log_S0=np.log(2), log_Q=np.log(2), log_omega0=np.log(5))
kernel.freeze_parameter("log_Q")

# mean: An object (following the modeling protocol) that specifies the mean function of the GP.
gp  = celerite.GP(kernel, mean=Model(**truth), fit_mean = True)

# compute(x, yerr=0.0, **kwargs). Pre-compute the covariance matrix and factorize it for a set of times and uncertainties.
gp.compute(t, yerr)                                                             



#==============================================================================
# log likelihood
#==============================================================================

def lnprob2(p):
    
    # Trivial uniform prior.
    _, _, P, tau, k, w, e0, off_aat, off_chiron, off_feros, off_mj1, off_mj3, off_fideos = p
    if (5.8 < P < 6.1) and (4.6 < k < 5.7) and (-np.pi < w < np.pi) and (0.7 < e0 < 0.99):
Exemplo n.º 18
0
aa[7,:] = [a7[i] for i in range(3)]
aa[8,:] = [a8[i] for i in range(3)]
aa[9,:] = [a9[i] for i in range(3)]
aa[10,:]= [a10[i] for i in range(3)]
aa[11,:]= [a11[i] for i in range(3)]
aa[12,:]= [a12[i] for i in range(3)]
aa[13,:]= [a13[i] for i in range(3)]
aa[14,:]= [a14[i] for i in range(3)]
aa[15,:]= [a15[i] for i in range(3)]
np.savetxt('HD85390_fit.txt', aa, fmt='%.6f')



P1, tau1, k1, w1, e1, P2, tau2, k2, w2, e2, P3, tau3, k3, w3, e3, offset = aa[:,0]
fit_curve   = Model(P1=np.log(P1)/10, tau1=np.log(tau1), k1=np.log(k1), w1=w1, e1=e1, 
                    P2=np.log(P2)/10, tau2=np.log(tau2), k2=np.log(k2), w2=w2, e2=e2, 
                    P3=np.log(P3)/10, tau3=np.log(tau3), k3=np.log(k3), w3=w3, e3=e3, offset=offset)
t_fit       = np.linspace(min(x), max(x), num=10001, endpoint=True)
y_fit       = fit_curve.get_value(np.array(t_fit))

residual    = fit_curve.get_value(x) - y
chi2        = sum(residual**2 / yerr**2)
rms         = np.sqrt(np.mean(residual**2))


fig = plt.figure(figsize=(10, 7))
frame1 = fig.add_axes((.15,.3,.8,.6))
frame1.axhline(y=0, color='k', ls='--', alpha=.3)
plt.plot(t_fit, y_fit, alpha=.5)
plt.errorbar(x, y, yerr=yerr, fmt=".k", capsize=0)
plt.ylabel("Radial velocity [m/s]")
Exemplo n.º 19
0
        return rv1 + offset


truth = dict(P1=8.,
             tau1=1.,
             k1=np.std(y) / 100,
             w1=0.,
             e1=0.4,
             offset1=0.,
             offset2=0.)
kwargs = dict(**truth)
kwargs["bounds"] = dict(P1=(7.5, 8.5),
                        k1=(0, 0.1),
                        w1=(-2 * np.pi, 2 * np.pi),
                        e1=(0, 0.9))
mean_model = Model(**kwargs)

#==============================================================================
# The fit
#==============================================================================
from scipy.optimize import minimize

import celerite
from celerite import terms

# Set up the GP model
# kernel = terms.RealTerm(log_a=np.log(np.var(y)), log_c=-np.log(10.0))
kernel = terms.SHOTerm(log_S0=np.log(2),
                       log_Q=np.log(20),
                       log_omega0=np.log(1))
gp = celerite.GP(kernel, mean=mean_model, fit_mean=True)
Exemplo n.º 20
0
celerite.__version__
from celerite import terms

# bounds = dict(P=(350,400), k=(100,300), w=(-2*np.pi, 2*np.pi), e0=(0.8, 0.95), offset=(-100,100))
# bounds = dict(log_S0 = (0,2), log_Q=(0,2), log_omega0=(0,2), P=(350,400), k=(100,300), w=(-2*np.pi, 2*np.pi), e0=(0.8, 0.95), offset=(-100,100))
# bounds[3] = (350,400)
# bounds[4] = (0, 10000)
# bounds[5] = (100,300)
# bounds[6] = (-2*np.pi, 2*np.pi)
# bounds[7] = (0.8, 0.95)
# bounds[8] = (-100,100)

kernel = terms.SHOTerm(np.log(2), np.log(2), np.log(5))
# kernel  = terms.SHOTerm(np.log(2), np.log(2), np.log(5), 415.4, 4867, 186.8, 0, 0.856, 0, bounds=bounds)
# mean: An object (following the modeling protocol) that specifies the mean function of the GP.
gp = celerite.GP(kernel, mean=Model(**truth), fit_mean=True)

# compute(x, yerr=0.0, **kwargs). Pre-compute the covariance matrix and factorize it for a set of times and uncertainties.
gp.compute(t, yerr)

####################################################################

if 0:

    from scipy.optimize import minimize

    def neg_log_like(params, y, gp):
        gp.set_parameter_vector(params)
        return -gp.log_likelihood(y)

    initial_params = gp.get_parameter_vector()
Exemplo n.º 21
0
from astropy.io import fits
from scipy.interpolate import CubicSpline

os.chdir(DIR + 'fits')
FILE = glob.glob('*fits')
N = 3 * len(FILE)
v = np.linspace(-20, 20, 401)
CCF = np.zeros([401, N])
v_new = np.linspace(-10, 10, 201)
CCF_new = np.zeros([201, N])

for n in range(N):
    i = n % 25
    hdulist = fits.open(FILE[i])
    CCF[:, n] = hdulist[0].data
    v_planet = Model(**truth).get_value(n)
    cs = CubicSpline(v + v_planet, CCF[:, n])
    CCF_new[:, n] = cs(v_new)

#plt.plot(np.arange(N), CCF_new[70, :])
plt.plot(v_new, CCF[100:301, n], v_new, CCF_new[:, n], '--', v_new,
         CCF[100:301, n] - CCF_new[:, n], '-.')
plt.plot(v_new[-50], CCF[301 - 50, n], 'ro')
plt.plot(v_new[-60], CCF[301 - 60, n], 'bo')
plt.plot(v_new[-70], CCF[301 - 70, n], 'mo')
plt.plot(v_new[-70], CCF[301 - 70, n] - CCF_new[-70, n], 'mo')
plt.plot(v_new[-60], CCF[301 - 60, n] - CCF_new[-60, n], 'bo')
plt.plot(v_new[-50], CCF[301 - 50, n] - CCF_new[-50, n], 'ro')
plt.ylabel("Normalized flux")
plt.xlabel("Wavelength [km/s]")
plt.legend(['static line profile', 'shifted line profile', 'variation'])
Exemplo n.º 22
0
aa[0,:] = [a0[i] for i in range(3)]
aa[1,:] = [a1[i] for i in range(3)]
aa[2,:] = [a2[i] for i in range(3)]
aa[3,:] = [a3[i] for i in range(3)]
aa[4,:] = [a4[i] for i in range(3)]
aa[5,:] = [a5[i] for i in range(3)]
aa[6,:] = [a6[i] for i in range(3)]
aa[7,:] = [a7[i] for i in range(3)]
aa[8,:] = [a8[i] for i in range(3)]
aa[9,:] = [a9[i] for i in range(3)]
aa[10,:]= [a10[i] for i in range(3)]
np.savetxt('HD85390_fit.txt', aa, fmt='%.6f')


P1, tau1, k1, w1, e1, P2, tau2, k2, w2, e2, offset = aa[:,0]
fit_curve   = Model(P1=P1/100, tau1=tau1/100, k1=k1/100, w1=w1, e1=e1, 
                    P2=P2/100, tau2=tau2/100, k2=k2/100, w2=w2, e2=e2, offset=offset)
y_fit       = fit_curve.get_value(x)

residual    = y_fit - y
chi2        = sum(residual**2 / yerr**2)
rms         = np.sqrt(np.mean(residual**2))

t_sample    = np.linspace(min(x), max(x), num=10001, endpoint=True)
y_sample    = fit_curve.get_value(np.array(t_sample))
fig = plt.figure(figsize=(10, 7))
frame1 = fig.add_axes((.15,.3,.8,.6))
frame1.axhline(y=0, color='k', ls='--', alpha=.3)
plt.plot(t_sample, y_sample, 'b-', alpha=.5, label='two planets + smoothed jitter')
plt.errorbar(x, y, yerr=yerr, fmt=".k", capsize=0, label='HARPS RV')
plt.legend()
plt.ylabel("Radial velocity [m/s]")
Exemplo n.º 23
0
#==============================================================================
# Inject a planet
#==============================================================================

from celerite.modeling import Model


class Model(Model):
    parameter_names = ("amp", "P", "phase")

    def get_value(self, t):
        return self.amp * np.sin(2 * np.pi * t / self.P + self.phase)


truth = dict(amp=5, P=25 * 0.31, phase=0.1)
y_planet = Model(**truth).get_value(t)
y = y + y_planet

if 0:
    plt.errorbar(t, y, yerr=yerr, fmt=".k", capsize=0)
    plt.ylabel('RV' r"$[m/s]$")
    plt.xlabel(r"$t$")
    plt.title("Simulated data -- planet and jitter")
    plt.show()

#==============================================================================
# Modelling
#==============================================================================

import celerite
Exemplo n.º 24
0
a0, a1, a2, a3, a4, a5 = map(
    lambda v: (v[1], v[2] - v[1], v[1] - v[0]),
    zip(*np.percentile(real_samples, [16, 50, 84], axis=0)))
aa = np.zeros((6, 3))
aa[0, :] = [a0[i] for i in range(3)]
aa[1, :] = [a1[i] for i in range(3)]
aa[2, :] = [a2[i] for i in range(3)]
aa[3, :] = [a3[i] for i in range(3)]
aa[4, :] = [a4[i] for i in range(3)]
aa[5, :] = [a5[i] for i in range(3)]
np.savetxt('76920_MCMC_result.txt', aa, fmt='%.6f')

P, tau, k, w, e0, offset = aa[:, 0]
fit_curve = Model(P=np.log(P),
                  tau=np.log(tau),
                  k=np.log(k),
                  w=w,
                  e0=e0,
                  offset=offset)
t_fit = np.linspace(min(RV_ALL[:, 0]),
                    max(RV_ALL[:, 0]),
                    num=10001,
                    endpoint=True)
y_fit = fit_curve.get_value(np.array(t_fit))
plt.figure()
plt.plot(t_fit, y_fit, label='MCMC fit')
plt.errorbar(RV_AAT[:, 0],
             RV_AAT[:, 1],
             yerr=RV_AAT[:, 2],
             fmt=".",
             capsize=0,
             label='AAT')
Exemplo n.º 25
0
aa[2, :] = [a2[i] for i in range(3)]
aa[3, :] = [a3[i] for i in range(3)]
aa[4, :] = [a4[i] for i in range(3)]
aa[5, :] = [a5[i] for i in range(3)]
aa[6, :] = [a6[i] for i in range(3)]
aa[7, :] = [a7[i] for i in range(3)]
aa[8, :] = [a8[i] for i in range(3)]
aa[9, :] = [a9[i] for i in range(3)]
np.savetxt('76920_MCMC_5sets_result.txt', aa, fmt='%.6f')

P, tau, k, w, e0, off_aat, off_chiron, off_feros, off_mj1, off_mj3 = aa[:, 0]
fit_curve = Model(P=np.log(P),
                  tau=np.log(tau),
                  k=np.log(k),
                  w=w,
                  e0=e0,
                  off_aat=off_aat / 100,
                  off_chiron=off_chiron / 100,
                  off_feros=off_feros / 100,
                  off_mj1=off_mj1 / 100,
                  off_mj3=off_mj3 / 100)
t_fit = np.linspace(min(RV_ALL[:, 0]) - 20,
                    max(RV_ALL[:, 0] + 20),
                    num=10001,
                    endpoint=True)
y_fit = fit_curve.get_value(np.array(t_fit))

# I need to add the offset into the data before plotting
RV_AAT[:, 1] -= off_aat
RV_CHIRON[:, 1] -= off_chiron
RV_FEROS[:, 1] -= off_feros
RV_MJ1[:, 1] -= off_mj1
Exemplo n.º 26
0
aa[12, :] = [a12[i] for i in range(3)]
aa[13, :] = [a13[i] for i in range(3)]
aa[14, :] = [a14[i] for i in range(3)]
aa[15, :] = [a15[i] for i in range(3)]
np.savetxt('HD85390_fit.txt', aa, fmt='%.6f')

P1, tau1, k1, w1, e1, P2, tau2, k2, w2, e2, P3, tau3, k3, w3, e3, offset = aa[:,
                                                                              0]
fit_curve = Model(P1=P1 / 100,
                  tau1=tau1 / 100,
                  k1=k1 / 100,
                  w1=w1,
                  e1=e1,
                  P2=P2 / 100,
                  tau2=tau2 / 100,
                  k2=k2 / 100,
                  w2=w2,
                  e2=e2,
                  P3=P3 / 100,
                  tau3=tau3 / 100,
                  k3=k3 / 100,
                  w3=w3,
                  e3=e3,
                  offset=offset)
t_fit = np.linspace(min(x), max(x), num=10001, endpoint=True)
y_fit = fit_curve.get_value(np.array(t_fit))

residual = fit_curve.get_value(x) - y
chi2 = sum(residual**2 / yerr**2)
rms = np.sqrt(np.mean(residual**2))
wrms = np.sqrt(sum((residual / yerr)**2) / sum(1 / yerr**2))
Exemplo n.º 27
0
aa[6,:] = [a6[i] for i in range(3)]
aa[7,:] = [a7[i] for i in range(3)]
aa[8,:] = [a8[i] for i in range(3)]
aa[9,:] = [a9[i] for i in range(3)]
aa[10,:]= [a10[i] for i in range(3)]
aa[11,:]= [a11[i] for i in range(3)]
np.savetxt('HD85390_fit.txt', aa, fmt='%.6f')


P1, tau1, k1, w1, e1, P2, tau2, k2, w2, e2, offset1, offset2 = aa[:,0]
fig = plt.figure(figsize=(10, 7))
frame1 = fig.add_axes((.15,.3,.8,.6))
frame1.axhline(y=0, color='k', ls='--', alpha=.3)
t_sample    = np.linspace(min(x), max(x), num=10001, endpoint=True)
# Planet 1 #
Planet1     = Model(P1=P1/100, tau1=tau1/1000, k1=k1/100, w1=w1, e1=e1, 
                    P2=P2/100, tau2=tau2/1000, k2=0, w2=w2, e2=e2, offset1=offset1, offset2=0)
y1          = Planet1.get_value(t_sample)
plt.plot(t_sample, y1, 'b-.', alpha=.3, label='Planet1')
# Planet 2 #
Planet2     = Model(P1=P1/100, tau1=tau1/1000, k1=0, w1=w1, e1=e1, 
                    P2=P2/100, tau2=tau2/1000, k2=k2/100, w2=w2, e2=e2, offset1=0, offset2=offset2)
y2          = Planet2.get_value(t_sample)
plt.plot(t_sample, y2, 'b--', alpha=.3, label='Planet2')
# Planet1 + Planet2 #
y12         = y1 + y2
plt.plot(t_sample, y12, 'b-', alpha=.5, label='Planet1+Planet2')
plt.errorbar(x, y, yerr=yerr, fmt=".k", capsize=0, label='HARPS RV')
plt.legend()
plt.ylabel("Radial velocity [m/s]")

fit_curve   = Model(P1=P1/100, tau1=tau1/1000, k1=k1/100, w1=w1, e1=e1, 
Exemplo n.º 28
0
y2 = Planet2.get_value(t_sample)
plt.plot(t_sample, y2, 'b--', alpha=.3, label='Planet2')
# Planet1 + Planet2 #
y12 = y1 + y2
plt.plot(t_sample, y12, 'b-', alpha=.5, label='Planet1+Planet2')
plt.errorbar(x, y, yerr=yerr, fmt=".k", capsize=0, label='HARPS RV')
plt.legend()
plt.ylabel("Radial velocity [m/s]")

fit_curve = Model(P1=P1 / 100,
                  tau1=tau1 / 1000,
                  k1=k1 / 100,
                  w1=w1,
                  e1=e1,
                  P2=P2 / 100,
                  tau2=tau2 / 1000,
                  k2=k2 / 100,
                  w2=w2,
                  e2=e2,
                  offset1=offset1,
                  offset2=offset2,
                  alpha=alpha)
y_fit = fit_curve.get_value(x)
plt.plot(x, y_fit, 'bo', alpha=.5, label='two planets + smoothed jitter')
plt.plot(x[x < 57300],
         alpha * jitter_smooth,
         'ro',
         alpha=.5,
         label='smoothed jitter')
plt.errorbar(x, y, yerr=yerr, fmt=".k", capsize=0, label='HARPS RV')
plt.legend()
Exemplo n.º 29
0
                     tau1=tau1 / 1000,
                     k1=k1 / 100,
                     w1=w1,
                     e1=e1,
                     offset1=offset1,
                     offset2=offset2)
    y1 = Planet1.get_value(t_sample)
    plt.plot(t_sample, y1, 'b-.', alpha=.3, label='Planet1')
    plt.errorbar(t, xx, yerr=yerr, fmt=".k", capsize=0, label='HARPS RV')
    plt.legend()
    plt.ylabel("Radial velocity [m/s]")
    # Jitter#
    Jitter = Model(P1=np.log(P1) / 10,
                   tau1=tau1 / 1000,
                   k1=0,
                   w1=w1,
                   e1=e1,
                   offset1=0,
                   offset2=0,
                   alpha=np.log(alpha))
    y_jitter = Jitter.get_value(t)
    plt.plot(t, y_jitter, 'ro', alpha=.5, label='smoothed jitter')

    Fit = Model(P1=np.log(P1) / 10,
                tau1=tau1 / 1000,
                k1=k1 / 100,
                w1=w1,
                e1=e1,
                offset1=offset1,
                offset2=offset1,
                alpha=np.log(alpha))
    y_fit = Fit.get_value(t)
Exemplo n.º 30
0
aa[7, :] = [a7[i] for i in range(3)]
aa[8, :] = [a8[i] for i in range(3)]
aa[9, :] = [a9[i] for i in range(3)]
aa[10, :] = [a10[i] for i in range(3)]
np.savetxt('76920_MCMC_6sets_result.txt', aa, fmt='%.6f')

# aa = np.genfromtxt('76920_MCMC_6sets_5MJ_removed_0710/76920_MCMC_6sets_result-5MJ_removed.txt', dtype = None)
aa = np.genfromtxt('76920_MCMC_6sets_result.txt', dtype=None)
P, tau, k, w, e0, off_aat, off_chiron, off_feros, off_mj1, off_mj3, off_fideos = aa[:,
                                                                                    0]
fit_curve = Model(P=np.log(P),
                  tau=np.log(tau),
                  k=np.log(k),
                  w=w,
                  e0=e0,
                  off_aat=off_aat / 100,
                  off_chiron=off_chiron / 100,
                  off_feros=off_feros / 100,
                  off_mj1=off_mj1 / 100,
                  off_mj3=off_mj3 / 100,
                  off_fideos=off_fideos / 100)
t_fit = np.linspace(min(RV_ALL[:, 0]) - 300,
                    max(RV_ALL[:, 0] + 300),
                    num=10001,
                    endpoint=True)
y_fit = fit_curve.get_value(np.array(t_fit))

residual = fit_curve.get_value(np.array(x)) - np.array(y)
chi2 = sum(residual**2 / np.array(yerr)**2)
rms = np.sqrt(np.mean(residual**2))
yerr = np.array(yerr)