コード例 #1
0
ファイル: run.py プロジェクト: j-faria/OPEN
		def get_rv(self):
			self.vel_full = np.zeros_like(self.times_full)  # rv at oversampled times
			self.vel_full_each = np.zeros_like(self.times_full)  # rv at oversampled times for each planet
			self.vel_all = np.zeros((len(self.times), self.nplanets))  # rv at sample times for each planet
			self.vel_each = np.zeros_like(self.times)  # rv at sample times for each planet (temporary)
			self.vel_total = np.zeros_like(self.times)  # rv at sample times

			# if self.nplanets == 0:
			# 	self.get_noise(self.types_noise)
				# return

			for planet in range(self.nplanets):
				if self.periods is None: 
					P = np.random.rand()*998. + 2.  # random period, U(2, 998)
				else: 
					P = self.periods[planet]  # user-provided period

				if self.eccentricities is None:
					ecc = np.random.beta(0.867, 3.03)  # from Kipping 2013
				else:
					ecc = self.eccentricities[planet]  # user-provided eccentricity

				if self.semi_amplitudes is None:
					K = np.random.rand()*50. + 2.
				else:
					K = self.semi_amplitudes[planet]  # user-provided semi-amplitude

				if self.omegas is None:
					omega = np.random.rand()*2.*np.pi 
				else:
					omega = self.omegas[planet]  # user-provided omega

				if self.times_periastron is None:
					# random starting at around 2010-01-01, ending 1000 days later
					time_periastron = np.random.randint(2455197, 2456197) 
				else:
					time_periastron = self.times_periastron[planet]  # user-provided time of periastron

				# log
				# temp.write(output % (planet+1, P, K, ecc, omega, 2452000))

				# get RVs for this planet
				get_rvn(self.times, P, K, ecc, omega, time_periastron, 0., self.vel_each)

				# get RVs for this planet at oversampled times
				get_rvn(self.times_full, P, K, ecc, omega, time_periastron, 0., self.vel_full_each)

				# store
				self.vel_all[:,planet] = self.vel_each
				self.vel_total += self.vel_each
				self.vel_full += self.vel_full_each

			# self.get_noise(self.types_noise)
			self.vel_total += self.noise  # add noise
コード例 #2
0
ファイル: plot_best_solution.py プロジェクト: j-faria/OPEN
vel = np.zeros_like(tt)

## best solution found
best_ind = np.argmax(m.chains[1, :])
par_best = m.chains[2:, best_ind]

f = plt.figure()
gs = gridspec.GridSpec(2, 1, height_ratios=[2,1])
ax = [plt.subplot(gs[0])]
ax.append(plt.subplot(gs[1], sharex=ax[0]))
# , ax = plt.subplots(nrows=2, sharex=True)


#### plot best solution
args = [tt] + list(par_best) + [vel]
get_rvn(*args)
ax[0].plot(tt, (vel - par_best[5])*1e3, '-', lw=1.5, color='k')
limits = ax[0].axis()

#### plot posterior predictive
# n_posterior_samples = 1000
# par_samples = sample(m.chains[2:, :].T, n_posterior_samples)
# for p in par_samples:
#     # if abs(p[4] - 2493817.60) > 1000: continue
#     args = [tt] + list(p) + [vel]
#     get_rvn(*args)
#     ax[0].plot(tt, (vel - p[5])*1e3, '-', lw=1.5, alpha=0.05)

# we have to do it again...
args = [tt] + list(par_best) + [vel]
get_rvn(*args)