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,
tau2=1., k2=np.std(y) / 100, w2=0., e2=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.8), tau2=(-50, 50), k2=(0, 0.2), w2=(-2 * np.pi, 2 * np.pi), e2=(0, 0.8)) mean_model = Model(**kwargs) # 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 #============================================================================== 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(2), log_omega0=np.log(5)) gp = celerite.GP(kernel, mean=mean_model, fit_mean=True)
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)
# 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]')
aa[10, :] = [a10[i] for i in range(3)] aa[11, :] = [a11[i] for i in range(3)] np.savetxt('76920_MCMC_5sets_result.txt', aa, fmt='%.6f') 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)) if 0: # I need to add the offset into the data before plotting P1, tau1, k1, w1, e1, P2, tau2, k2, w2, e2, m, offset = aa[:, 0] fit_curve = Model(P1=np.log(P1), tau1=np.log(tau1), k1=np.log(k1), w1=w1, e1=e1, P2=np.log(P2), tau2=np.log(tau2), k2=np.log(k2), w2=w2, e2=e2, m=m, offset=offset) y_fit = fit_curve.get_value(x) plt.figure() plt.plot(x, y_fit, 'o', label='MCMC fit') plt.errorbar(BJD, RV_HARPS, yerr=RV_HARPS_err, fmt=".", capsize=0, label='HARPS') plt.title("RV time series")
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.8)) 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 / 3000)) gp = celerite.GP(kernel, mean=mean_model, fit_mean=True)
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)
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)) 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)
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, 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, yerr=yerr, fmt=".", capsize=0, label='HARPS') plt.errorbar(x, y_fit, yerr=yerr, fmt=".", capsize=0, label='MCMC fit') 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))
def lnlike(theta, x, y, yerr): P, tau, k, w, e0, offset, alpha = theta model = Model(P=P, tau=tau, k=k, w=w, e0=e0, offset=offset, alpha=alpha) return -0.5*(np.sum( ((y-model.get_value(np.array(x)))/yerr)**2. ))
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')
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))
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))
P1, tau1, k1, w1, e1, offset1, offset2, 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=np.log(P1)/10, 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) 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))
#============================================================================== 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))
def lnlike(theta, x, y, yerr): P1, tau1, k1, w1, e1, offset1, offset2, alpha = theta fit_curve = Model(P1=P1, tau1=tau1, k1=k1, w1=w1, e1=e1, offset1=offset1, offset2=offset2, alpha=alpha) y_fit = fit_curve.get_value(x) return -0.5*(np.sum( ((y-y_fit)/yerr)**2))
def lnlike(theta, x, y, yerr): P, tau, k, w, e0, offset = theta fit_curve = Model(P=P, tau=tau, k=k, w=w, e0=e0, offset=offset) y_fit = fit_curve.get_value(np.array(x)) return -0.5 * (np.sum(((y - y_fit) / yerr)**2.))
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,
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=alpha) y_fit = fit_curve.get_value(x) fit_curve2 = Model2(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),