def test_convolutional_model_log_gaussain_kernel_circular(self): """ Test ck-motion w/ log gaussian kernel for circular orbit. """ # Arbitrary circular orbit. windy_star.configure_params( period=1000, eccentricity=0, rv_semi_amplitude=50, argument_of_periastron=270, rv_offset=0, log_sigma_time=0.5, mean_emissivity=30, stellar_radius_a=1, wind_velocity_a=500) windy_star.configure_epochs( epochs=np.linspace(0, 2, 1000)) windy_star.configure_kernel( kernel_mode='LogGaussian') res_df = windy_star.convolutional_model_centroid_velocity # Sanity checks. self.assertNotAlmostEqual( res_df['ConvolvedVelocity'].max(), 50, places=0, msg='Convolutional velocity unexpected max value.') self.assertNotAlmostEqual( res_df['ConvolvedVelocity'].min(), -50, places=0, msg='Convolutional velocity unexpected min value.') self.assertNotAlmostEqual( res_df['ConvolvedVelocity'].iloc[0], 0, places=0, msg='Convolutional velocity unexpected value at phase 0.') self.assertNotAlmostEqual( res_df['ConvolvedVelocity'].iloc[124], 50, places=0, msg='Convolutional velocity unexpected value at phase 0.25') self.assertNotAlmostEqual( res_df['ConvolvedVelocity'].iloc[249], 0, places=0, msg='Convolutional velocity unexpected value at phase 0.5') self.assertNotAlmostEqual( res_df['ConvolvedVelocity'].iloc[374], -50, places=0, msg='Convolutional velocity unexpected value at phase 0.75')
def test_convolutional_model_top_hat_kernel_eccentric(self): """ Test ck-motion w/ top hat kernel for eccentric orbit. """ # Arbitrary circular orbit. windy_star.configure_params( period=1000, eccentricity=0.9, rv_semi_amplitude=50, argument_of_periastron=270, rv_offset=0, ionisation_radius=50, photospheric_radius=5, stellar_radius_a=1, wind_velocity_a=500) windy_star.configure_epochs( epochs=np.linspace(0, 2, 1000)) windy_star.configure_kernel( kernel_mode='TopHat') res_df = windy_star.convolutional_model_centroid_velocity # Sanity checks. self.assertNotAlmostEqual( res_df['ConvolvedVelocity'].max(), 50, places=0, msg='Convolutional velocity unexpected max value.') self.assertNotAlmostEqual( res_df['ConvolvedVelocity'].min(), -50, places=0, msg='Convolutional velocity unexpected min value.') self.assertNotAlmostEqual( res_df['ConvolvedVelocity'].iloc[0], 0, places=0, msg='Convolutional velocity unexpected value at phase 0.') self.assertNotAlmostEqual( res_df['ConvolvedVelocity'].iloc[124], 50, places=0, msg='Convolutional velocity unexpected value at phase 0.25') self.assertNotAlmostEqual( res_df['ConvolvedVelocity'].iloc[249], 0, places=0, msg='Convolutional velocity unexpected value at phase 0.5') self.assertNotAlmostEqual( res_df['ConvolvedVelocity'].iloc[374], -50, places=0, msg='Convolutional velocity unexpected value at phase 0.75')
def test_convolutional_model_rt_interp_kernel_eccentric(self): """ Test ck-motion w/ RT interp kernel for eccentric orbit. """ # Arbitrary eccentric orbit. emissivity = Emissivity(setup_mode=False, pickle_dir='test_jar') windy_star.configure_params( period=2022.7, eccentricity=0.9, rv_semi_amplitude=100, argument_of_periastron=270, rv_offset=0, m_dot_a=5e-4, wind_velocity_a=500) windy_star.configure_epochs(epochs=np.linspace(0, 2, 1000)) windy_star.configure_kernel(kernel_mode='RTInterp', kernel_line=3, interp_dims='Grid', emissivity_interpolators=emissivity) res_df = windy_star.convolutional_model_centroid_velocity
def _mcmc_lnlike_kepler_model(self, theta): """ Logarithmic likelihood. """ # Current position of walkers in each dimension of parameter space. t0, e, k, w, c = theta # Configure params and epochs. windy_star.__init__() windy_star.configure_params(period=self.fixed_params['Period'], eccentricity=e, rv_semi_amplitude=k, argument_of_periastron=w, rv_offset=c) windy_star.configure_epochs(epochs=self.observations['JD'].values, time_of_periastron=t0) # Calculate centroid velocity of a binary Keplerian orbit. res_df = windy_star.keplerian_model_centroid_velocity # Log likelihood: Chi-squared + ln(2 * pi * sigma^2). ln_like = -0.5 * ( (((res_df['KeplerVelocity'] - self.observations['Velocity'])**2) / (self.observations['VelocityError']**2)) + np.log(2 * np.pi * (self.observations['VelocityError']**2))).sum() if self.debug: plt.scatter(windy_star.epochs, self.observations['Velocity'], c='red', s=2) plt.scatter(res_df['Phase'], res_df['KeplerVelocity'], c='blue', s=2) plt.title('ln(likelihood)={}'.format(round(ln_like, 5)), fontsize=10) plt.xlabel('Orbital Phase $\phi$', fontsize=10) plt.ylabel('Velocity / $\\rm{km\,s^{-1}}$', fontsize=10) plt.tight_layout() plt.show() return ln_like
def test_keplerian_eccentric_orbit_model(self): """ Test Keplerian eccentric orbit model. """ # Arbitrary eccentric orbit. windy_star.configure_params(period=1000, eccentricity=0.9, rv_semi_amplitude=50, argument_of_periastron=270, rv_offset=0) windy_star.configure_epochs(epochs=np.linspace(0, 2, 1000)) res_df = windy_star.keplerian_model_centroid_velocity # Sanity checks. self.assertAlmostEqual(res_df['KeplerVelocity'].max(), 50, places=0, msg='Keplerian velocity unexpected max value.') self.assertAlmostEqual(res_df['KeplerVelocity'].min(), -50, places=0, msg='Keplerian velocity unexpected min value.') self.assertAlmostEqual( res_df['KeplerVelocity'].iloc[0], 0, places=0, msg='Keplerian velocity unexpected value at phase 0.') self.assertNotAlmostEqual( res_df['KeplerVelocity'].iloc[124], 50, places=0, msg='Keplerian velocity unexpected value at phase 0.25') self.assertAlmostEqual( res_df['KeplerVelocity'].iloc[249], 0, places=0, msg='Keplerian velocity unexpected value at phase 0.5') self.assertNotAlmostEqual( res_df['KeplerVelocity'].iloc[374], -50, places=0, msg='Keplerian velocity unexpected value at phase 0.75')
obs = unpickle_observations(OBSERVATIONS_PATH, OBSERVATIONS, time_of_periastron=2555555, period=1000, n_periods=2) # Load interpolation objects. emissivity = Emissivity(setup_mode=False, pickle_dir='interp_jar/rt_code_v1') # Configure params and epochs and kernel. windy_star.configure_params(period=1000, eccentricity=0.7, rv_semi_amplitude=60, argument_of_periastron=250, rv_offset=-20) windy_star.configure_epochs(epochs=np.linspace(0, 2, 1000)) windy_star.configure_kernel(kernel_mode='RTInterp', kernel_line=4, interp_dims='Point', emissivity_interpolators=emissivity) # Calculate centroid velocity of convolved/time averaged Keplerian orbit res_df = windy_star.convolutional_model_centroid_velocity # Plot. fig = plt.figure(figsize=(15, 6)) ax1 = fig.add_subplot(1, 1, 1) ax1.scatter(obs['Phase'], obs['Velocity'], s=2, c='#000000') ax1.plot(res_df['Phase'], res_df['ConvolvedVelocity'], linewidth=2) ax1.set_xlabel('Orbital Phase $\phi$', fontsize=14) ax1.set_ylabel('Velocity / $\\rm{km\,s^{-1}}$', fontsize=14)
label='Observations') [bar.set_alpha(0.2) for bar in bars] [cap.set_alpha(0.2) for cap in caps] # Plot model samples. count = 0 for t0, e, k, w, c in sample_chain[ np.random.randint(len(sample_chain), size=N_CHAIN_SAMPLES), :]: try: windy_star.__init__() windy_star.configure_params(period=fixed_params['Period'], eccentricity=e, rv_semi_amplitude=k, argument_of_periastron=w, rv_offset=c) windy_star.configure_epochs(epochs=np.linspace(0, N_PERIODS, 2000 * N_PERIODS)) res_df = windy_star.keplerian_model_centroid_velocity adjusted_phase = res_df['Phase'] + ( (t0 - REFERENCE_PERIASTRON) / PERIOD) if count == 0: ax1.plot([], [], color='#4891dc', alpha=1, linewidth=1, label='MCMC Kepler solution samples') ax1.legend(loc='upper right', fontsize=10) else: ax1.plot(adjusted_phase, res_df['KeplerVelocity'], color='#4891dc', alpha=0.2,
# Plot model samples. count = 0 for t0, e, k, w in sample_chain[ np.random.randint(len(sample_chain), size=N_CHAIN_SAMPLES), :]: try: windy_star.__init__() windy_star.configure_params( period=fixed_params['Period'], eccentricity=e, rv_semi_amplitude=k, argument_of_periastron=w, rv_offset=systemic[line_index - 1], m_dot_a=fixed_params['MassLossRate'], wind_velocity_a=fixed_params['WindTerminalVelocity']) windy_star.configure_epochs( epochs=np.linspace(0, N_PERIODS, EPOCH_DENSITY)) windy_star.configure_kernel(kernel_mode='RTInterp', kernel_line=line, interp_dims='Point', emissivity_interpolators=emissivity) res_df = windy_star.convolutional_model_centroid_velocity adjusted_phase = res_df['Phase'] + ( (t0 - REFERENCE_PERIASTRON) / PERIOD) if count == 0: ax.plot([], [], color='#4891dc', alpha=1, linewidth=1, label='MCMC CK (RTInterp) solution samples') ax.legend(loc='upper right', fontsize=8) else: