From 34c70dcafd17143197e30c73063ec9f396069931 Mon Sep 17 00:00:00 2001
From: Sylvia Biscoveanu <violinasb@yahoo.com>
Date: Fri, 15 May 2020 20:18:43 -0700
Subject: [PATCH 1/2] Fix multinest temporary directory functionality

---
 bilby/core/sampler/pymultinest.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/bilby/core/sampler/pymultinest.py b/bilby/core/sampler/pymultinest.py
index 55c3ac1af..055d4e14a 100644
--- a/bilby/core/sampler/pymultinest.py
+++ b/bilby/core/sampler/pymultinest.py
@@ -181,11 +181,15 @@ class Pymultinest(NestedSampler):
                 self.outputfiles_basename, self.temporary_outputfiles_basename
             )
         )
-        if os.path.islink(self.outputfiles_basename.strip("/")):
-            os.unlink(self.outputfiles_basename.strip("/"))
-        elif os.path.isdir(self.outputfiles_basename):
-            shutil.rmtree(self.outputfiles_basename, ignore_errors=True)
-        shutil.move(self.temporary_outputfiles_basename, self.outputfiles_basename)
+        if self.outputfiles_basename.endswith('/'):
+            outputfiles_basename_stripped = self.outputfiles_basename[:-1]
+        else:
+            outputfiles_basename_stripped = self.outputfiles_basename
+        if os.path.islink(outputfiles_basename_stripped):
+            os.unlink(outputfiles_basename_stripped)
+        elif os.path.isdir(outputfiles_basename_stripped):
+            shutil.rmtree(outputfiles_basename_stripped)
+        shutil.move(self.temporary_outputfiles_basename, outputfiles_basename_stripped)
 
     def run_sampler(self):
         import pymultinest
-- 
GitLab


From 93444f57c639bb6bbf6baf2158db0f1ad16e276a Mon Sep 17 00:00:00 2001
From: Sylvia Biscoveanu <violinasb@yahoo.com>
Date: Wed, 3 Jun 2020 14:11:43 -0700
Subject: [PATCH 2/2] Time-saving changes to the time reconstruction

---
 bilby/gw/likelihood.py | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/bilby/gw/likelihood.py b/bilby/gw/likelihood.py
index 25d0c37ee..0b6ea7d51 100644
--- a/bilby/gw/likelihood.py
+++ b/bilby/gw/likelihood.py
@@ -399,20 +399,32 @@ class GravitationalWaveTransient(Likelihood):
             signal_polarizations = \
                 self.waveform_generator.frequency_domain_strain(self.parameters)
 
+        times = create_time_series(
+            sampling_frequency=16384,
+            starting_time=self.parameters['geocent_time'] - self.waveform_generator.start_time,
+            duration=self.waveform_generator.duration)
+        times = times % self.waveform_generator.duration
+        times += self.waveform_generator.start_time
+
+        prior = self.priors["geocent_time"]
+        in_prior = (times >= prior.minimum) & (times < prior.maximum)
+        times = times[in_prior]
+
         n_time_steps = int(self.waveform_generator.duration * 16384)
-        d_inner_h = np.zeros(n_time_steps, dtype=np.complex)
+        d_inner_h = np.zeros(len(times), dtype=np.complex)
         psd = np.ones(n_time_steps)
         signal_long = np.zeros(n_time_steps, dtype=np.complex)
         data = np.zeros(n_time_steps, dtype=np.complex)
         h_inner_h = np.zeros(1)
         for ifo in self.interferometers:
             ifo_length = len(ifo.frequency_domain_strain)
+            mask = ifo.frequency_mask
             signal = ifo.get_detector_response(
                 signal_polarizations, self.parameters)
             signal_long[:ifo_length] = signal
             data[:ifo_length] = np.conj(ifo.frequency_domain_strain)
-            psd[:ifo_length] = ifo.power_spectral_density_array
-            d_inner_h += np.fft.fft(signal_long * data / psd)
+            psd[:ifo_length][mask] = ifo.power_spectral_density_array[mask]
+            d_inner_h += np.fft.fft(signal_long * data / psd)[in_prior]
             h_inner_h += ifo.optimal_snr_squared(signal=signal).real
 
         if self.distance_marginalization:
@@ -424,13 +436,6 @@ class GravitationalWaveTransient(Likelihood):
         else:
             time_log_like = (d_inner_h.real - h_inner_h.real / 2)
 
-        times = create_time_series(
-            sampling_frequency=16384,
-            starting_time=self.parameters['geocent_time'] - self.waveform_generator.start_time,
-            duration=self.waveform_generator.duration)
-        times = times % self.waveform_generator.duration
-        times += self.waveform_generator.start_time
-
         time_prior_array = self.priors['geocent_time'].prob(times)
         time_post = (
             np.exp(time_log_like - max(time_log_like)) * time_prior_array)
-- 
GitLab