From 0bc4642148ee5f256b549ce610598ae320f46f0f Mon Sep 17 00:00:00 2001 From: Gregory Ashton <gregory.ashton@ligo.org> Date: Thu, 31 Jan 2019 17:16:41 -0600 Subject: [PATCH] Resolve "Consistency of constants between bilby and lalsuite" --- CHANGELOG.md | 2 +- bilby/core/utils.py | 10 +++++----- test/gw_likelihood_test.py | 4 ++-- test/utils_test.py | 16 ++++++++++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9809cb44a..593e16b10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - ### Changed -- +- Updates the bilby.core.utils constants to match those of Astropy v3.0.4 ### Removed - diff --git a/bilby/core/utils.py b/bilby/core/utils.py index b23872827..ce634a6e1 100644 --- a/bilby/core/utils.py +++ b/bilby/core/utils.py @@ -13,12 +13,12 @@ from scipy.interpolate import interp2d logger = logging.getLogger('bilby') -# Constants -speed_of_light = 299792458.0 # speed of light in m/s -parsec = 3.085677581 * 1e16 -solar_mass = 1.98855 * 1e30 -radius_of_earth = 6371 * 1e3 # metres +# Constants: values taken from astropy v3.0.4 +speed_of_light = 299792458.0 # m/s +parsec = 3.0856775814671916e+16 # m +solar_mass = 1.9884754153381438e+30 # Kg +radius_of_earth = 6378100.0 # m def infer_parameters_from_function(func): diff --git a/test/gw_likelihood_test.py b/test/gw_likelihood_test.py index 4d343a04f..b2d9a8128 100644 --- a/test/gw_likelihood_test.py +++ b/test/gw_likelihood_test.py @@ -42,7 +42,7 @@ class TestBasicGWTransient(unittest.TestCase): """Test log likelihood matches precomputed value""" self.likelihood.log_likelihood() self.assertAlmostEqual(self.likelihood.log_likelihood(), - -4055.2526551677647, 3) + -4055.236283345252, 3) def test_log_likelihood_ratio(self): """Test log likelihood ratio returns the correct value""" @@ -111,7 +111,7 @@ class TestGWTransient(unittest.TestCase): """Test log likelihood matches precomputed value""" self.likelihood.log_likelihood() self.assertAlmostEqual(self.likelihood.log_likelihood(), - -4055.2526551677647, 3) + -4055.236283345252, 3) def test_log_likelihood_ratio(self): """Test log likelihood ratio returns the correct value""" diff --git a/test/utils_test.py b/test/utils_test.py index 9b3abf941..ad1d22783 100644 --- a/test/utils_test.py +++ b/test/utils_test.py @@ -2,11 +2,27 @@ from __future__ import absolute_import, division import unittest import numpy as np +from astropy import constants import bilby from bilby.core import utils +class TestConstants(unittest.TestCase): + + def test_speed_of_light(self): + self.assertTrue(bilby.core.utils.speed_of_light, constants.c.value) + + def test_parsec(self): + self.assertTrue(bilby.core.utils.parsec, constants.pc.value) + + def test_solar_mass(self): + self.assertTrue(bilby.core.utils.solar_mass, constants.M_sun.value) + + def test_radius_of_earth(self): + self.assertTrue(bilby.core.utils.radius_of_earth, constants.R_earth.value) + + class TestFFT(unittest.TestCase): def setUp(self): -- GitLab