Skip to content
Snippets Groups Projects
Commit 024e079f authored by Gregory Ashton's avatar Gregory Ashton
Browse files

Small simplification of waveform generator / likelihood interaction

This allows the waveform generator to be given None for the sampling
frequency and duration (in this state, it therefore can't be used to
generate an injection). Then, when passed to the likelihood, a check if
performed to see if those attributes are set. If they are None, they are
set from the data, and if they disagree with the data, an error is raised.
parent 240b2b2b
No related branches found
No related tags found
1 merge request!99Allow waveform_generator to not have to be initialised with the duration and sampling frequency
......@@ -36,9 +36,7 @@ prior = tupak.gw.prior.BBHPriorSet(filename='GW150914.prior')
# creates the frequency-domain strain. In this instance, we are using the
# `lal_binary_black_hole model` source model. We also pass other parameters:
# the waveform approximant and reference frequency.
waveform_generator = tupak.WaveformGenerator(duration=interferometers.duration,
sampling_frequency=interferometers.sampling_frequency,
frequency_domain_source_model=tupak.gw.source.lal_binary_black_hole,
waveform_generator = tupak.WaveformGenerator(frequency_domain_source_model=tupak.gw.source.lal_binary_black_hole,
waveform_arguments={'waveform_approximant': 'IMRPhenomPv2',
'reference_frequency': 50})
......
......@@ -62,6 +62,7 @@ class GravitationalWaveTransient(likelihood.Likelihood):
self.distance_marginalization = distance_marginalization
self.phase_marginalization = phase_marginalization
self.prior = prior
self._check_set_duration_and_sampling_frequency_of_waveform_generator()
if self.distance_marginalization:
self.check_prior_is_set()
......@@ -80,6 +81,24 @@ class GravitationalWaveTransient(likelihood.Likelihood):
if self.time_marginalization:
self.check_prior_is_set()
def _check_set_duration_and_sampling_frequency_of_waveform_generator(self):
""" Check the waveform_generator has the same duration and
sampling_frequency as the interferometers. If they are unset, then
set them, if they differ, raise an error
"""
attributes = ['duration', 'sampling_frequency', 'start_time']
for attr in attributes:
wfg_attr = getattr(self.waveform_generator, attr)
ifo_attr = getattr(self.interferometers, attr)
if wfg_attr is None:
setattr(self.waveform_generator, attr, ifo_attr)
elif wfg_attr != ifo_attr:
logging.debug(
"The waveform_generator {} is not equal to that of the "
"provided interferometers. Overwriting the "
"waveform_generator.".format(attr))
def check_prior_is_set(self):
if self.prior is None:
raise ValueError("You can't use a marginalized likelihood without specifying a prior")
......
......@@ -6,7 +6,7 @@ import numpy as np
class WaveformGenerator(object):
def __init__(self, duration, sampling_frequency, start_time=0, frequency_domain_source_model=None,
def __init__(self, duration=None, sampling_frequency=None, start_time=0, frequency_domain_source_model=None,
time_domain_source_model=None, parameters=None, parameter_conversion=None,
non_standard_sampling_parameter_keys=None,
waveform_arguments=None):
......@@ -14,9 +14,9 @@ class WaveformGenerator(object):
Parameters
----------
sampling_frequency: float
sampling_frequency: float, optional
The sampling frequency
duration: float
duration: float, optional
Time duration of data
start_time: float, optional
Starting time of the time array
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment