From 024e079f9a155798d9daf73c59fd5970241374fb Mon Sep 17 00:00:00 2001
From: Gregory Ashton <gregory.ashton@ligo.org>
Date: Wed, 4 Jul 2018 08:21:12 +1000
Subject: [PATCH 1/2] 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.
---
 examples/open_data_examples/GW150914.py |  4 +---
 tupak/gw/likelihood.py                  | 19 +++++++++++++++++++
 tupak/gw/waveform_generator.py          |  6 +++---
 3 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/examples/open_data_examples/GW150914.py b/examples/open_data_examples/GW150914.py
index bac83cf66..07a31db02 100644
--- a/examples/open_data_examples/GW150914.py
+++ b/examples/open_data_examples/GW150914.py
@@ -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})
 
diff --git a/tupak/gw/likelihood.py b/tupak/gw/likelihood.py
index 5c87f0d5e..19b42cb41 100644
--- a/tupak/gw/likelihood.py
+++ b/tupak/gw/likelihood.py
@@ -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")
diff --git a/tupak/gw/waveform_generator.py b/tupak/gw/waveform_generator.py
index e5618ac4d..fdee84a20 100644
--- a/tupak/gw/waveform_generator.py
+++ b/tupak/gw/waveform_generator.py
@@ -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
-- 
GitLab


From e481d05d4c4cc9ed5c1e8f6f6011574fd696e70e Mon Sep 17 00:00:00 2001
From: Gregory Ashton <gregory.ashton@ligo.org>
Date: Wed, 4 Jul 2018 12:24:31 +1000
Subject: [PATCH 2/2] Improve warning messages when overwriting the WFG

---
 tupak/gw/likelihood.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tupak/gw/likelihood.py b/tupak/gw/likelihood.py
index 19b42cb41..3b197d9f1 100644
--- a/tupak/gw/likelihood.py
+++ b/tupak/gw/likelihood.py
@@ -92,9 +92,12 @@ class GravitationalWaveTransient(likelihood.Likelihood):
             wfg_attr = getattr(self.waveform_generator, attr)
             ifo_attr = getattr(self.interferometers, attr)
             if wfg_attr is None:
+                logging.debug(
+                    "The waveform_generator {} is None. Setting from the "
+                    "provided interferometers.".format(attr))
                 setattr(self.waveform_generator, attr, ifo_attr)
             elif wfg_attr != ifo_attr:
-                logging.debug(
+                logging.warning(
                     "The waveform_generator {} is not equal to that of the "
                     "provided interferometers. Overwriting the "
                     "waveform_generator.".format(attr))
-- 
GitLab