Skip to content

Commit

Permalink
Merge branch 'bugfix-cbc-waveform-generator' into 'master'
Browse files Browse the repository at this point in the history
BUGFIX: CBCWaveformGenerator: don't access hidden enum

See merge request lscsoft/bilby!1140
  • Loading branch information
ColmTalbot committed Aug 22, 2022
2 parents 69ccfdf + 027a3d4 commit 9c89194
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
6 changes: 4 additions & 2 deletions bilby/gw/waveform_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,16 @@ def __parameters_from_source_model(self):

class LALCBCWaveformGenerator(WaveformGenerator):
""" A waveform generator with specific checks for LAL CBC waveforms """
LAL_SIM_INSPIRAL_SPINS_FLOW = 1

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.validate_reference_frequency()

def validate_reference_frequency(self):
from lalsimulation import SimInspiralGetSpinFreqFromApproximant, LAL_SIM_INSPIRAL_SPINS_FLOW
from lalsimulation import SimInspiralGetSpinFreqFromApproximant
waveform_approximant = self.waveform_arguments["waveform_approximant"]
waveform_approximant_number = lalsim_GetApproximantFromString(waveform_approximant)
if SimInspiralGetSpinFreqFromApproximant(waveform_approximant_number) == LAL_SIM_INSPIRAL_SPINS_FLOW:
if SimInspiralGetSpinFreqFromApproximant(waveform_approximant_number) == self.LAL_SIM_INSPIRAL_SPINS_FLOW:
if self.waveform_arguments["reference_frequency"] != self.waveform_arguments["minimum_frequency"]:
raise ValueError(f"For {waveform_approximant}, reference_frequency must equal minimum_frequency")
65 changes: 65 additions & 0 deletions test/gw/waveform_generator_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import unittest
from unittest import mock

import bilby
import lalsimulation
import numpy as np


Expand Down Expand Up @@ -159,6 +161,69 @@ def test_waveform_arguments_init_setting(self):
)


class TestLALCBCWaveformArgumentsSetting(unittest.TestCase):
def setUp(self):
self.kwargs = dict(
duration=4,
frequency_domain_source_model=bilby.gw.source.lal_binary_black_hole,
sampling_frequency=2048,
)

def tearDown(self):
del self.kwargs

def test_spin_reference_enumeration(self):
"""
Verify that the value of the reference enumerator hasn't changed by comparing
against a known approximant.
"""
self.assertEqual(
lalsimulation.SimInspiralGetSpinFreqFromApproximant(lalsimulation.SEOBNRv3),
bilby.gw.waveform_generator.LALCBCWaveformGenerator.LAL_SIM_INSPIRAL_SPINS_FLOW,
)

def test_create_waveform_generator_non_precessing(self):
self.kwargs["waveform_arguments"] = dict(
minimum_frequency=20.0,
reference_frequency=50.0,
waveform_approximant="TaylorF2",
)
wfg = bilby.gw.waveform_generator.LALCBCWaveformGenerator(**self.kwargs)
self.assertDictEqual(
wfg.waveform_arguments,
dict(
minimum_frequency=20.0,
reference_frequency=50.0,
waveform_approximant="TaylorF2",
),
)

def test_create_waveform_generator_eob_succeeds(self):
self.kwargs["waveform_arguments"] = dict(
minimum_frequency=20.0,
reference_frequency=20.0,
waveform_approximant="SEOBNRv3",
)
wfg = bilby.gw.waveform_generator.LALCBCWaveformGenerator(**self.kwargs)
self.assertDictEqual(
wfg.waveform_arguments,
dict(
minimum_frequency=20.0,
reference_frequency=20.0,
waveform_approximant="SEOBNRv3",
),
)

def test_create_waveform_generator_eob_fails(self):
self.kwargs["waveform_arguments"] = dict(
minimum_frequency=20.0,
reference_frequency=50.0,
waveform_approximant="SEOBNRv3",
)
with self.assertRaises(ValueError):
_ = bilby.gw.waveform_generator.LALCBCWaveformGenerator(**self.kwargs)


class TestSetters(unittest.TestCase):
def setUp(self):
self.waveform_generator = bilby.gw.waveform_generator.WaveformGenerator(
Expand Down

0 comments on commit 9c89194

Please sign in to comment.