From 593249521cbcb9f519ae630d0954f5a49cb73eed Mon Sep 17 00:00:00 2001
From: Gregory Ashton <gregory.ashton@ligo.org>
Date: Tue, 15 Mar 2022 15:58:41 +0000
Subject: [PATCH 1/3] Use a local copy of the lookup table

---
 bilby_pipe/input.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/bilby_pipe/input.py b/bilby_pipe/input.py
index f3fed170..3c397e8a 100644
--- a/bilby_pipe/input.py
+++ b/bilby_pipe/input.py
@@ -7,6 +7,7 @@ import inspect
 import itertools
 import json
 import os
+import shutil
 import subprocess
 from importlib import import_module
 
@@ -783,7 +784,11 @@ class Input(object):
             fname = f"{prior_file_str}_distance_marginalization_lookup_phase.npz"
         else:
             fname = f"{prior_file_str}_distance_marginalization_lookup.npz"
-        return os.path.join(direc, fname)
+        lookup_file_source = os.path.join(direc, fname)
+        lookup_file_dest = os.path.join(self.outdir, "." + fname)
+        if os.path.isfile(lookup_file_source):
+            shutil.copyfile(lookup_file_source, lookup_file_dest)
+        return lookup_file_dest
 
     @property
     def prior_file(self):
-- 
GitLab


From 4f1edaa1cced048cb50857ec6e7e9f4bd8fcb3f5 Mon Sep 17 00:00:00 2001
From: Gregory Ashton <gregory.ashton@ligo.org>
Date: Tue, 15 Mar 2022 16:25:31 +0000
Subject: [PATCH 2/3] Improve lookup file handling

---
 bilby_pipe/input.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/bilby_pipe/input.py b/bilby_pipe/input.py
index 3c397e8a..9bdba8d8 100644
--- a/bilby_pipe/input.py
+++ b/bilby_pipe/input.py
@@ -779,16 +779,20 @@ class Input(object):
         return {os.path.basename(ff).rstrip(".prior"): ff for ff in filenames}
 
     def get_distance_file_lookup_table(self, prior_file_str):
+        lookup_file_source = self.get_source_distance_file_lookup_table(prior_file_str)
+        fname = os.path.basename(lookup_file_source)
+        lookup_file_dest = os.path.join(self.outdir, "." + fname)
+        if os.path.isfile(lookup_file_source):
+            shutil.copyfile(lookup_file_source, lookup_file_dest)
+        return lookup_file_dest
+
+    def get_source_distance_file_lookup_table(self, prior_file_str):
         direc = os.path.dirname(self.default_prior_files[prior_file_str])
         if self.phase_marginalization:
             fname = f"{prior_file_str}_distance_marginalization_lookup_phase.npz"
         else:
             fname = f"{prior_file_str}_distance_marginalization_lookup.npz"
-        lookup_file_source = os.path.join(direc, fname)
-        lookup_file_dest = os.path.join(self.outdir, "." + fname)
-        if os.path.isfile(lookup_file_source):
-            shutil.copyfile(lookup_file_source, lookup_file_dest)
-        return lookup_file_dest
+        return os.path.join(direc, fname)
 
     @property
     def prior_file(self):
-- 
GitLab


From d1563cf52729d3cf0d0ce33627f54fd23b174e77 Mon Sep 17 00:00:00 2001
From: Gregory Ashton <gregory.ashton@ligo.org>
Date: Tue, 15 Mar 2022 17:06:58 +0000
Subject: [PATCH 3/3] Clean up input tests

---
 tests/input_test.py | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tests/input_test.py b/tests/input_test.py
index 130780b5..53ce1ea1 100644
--- a/tests/input_test.py
+++ b/tests/input_test.py
@@ -1,6 +1,6 @@
 import os
 import unittest
-from shutil import copyfile
+from shutil import copyfile, rmtree
 
 import pandas as pd
 
@@ -16,9 +16,11 @@ class TestInput(unittest.TestCase):
             "tests/lalinference_test_injection_standard.json"
         )
         self.test_injection_file_dat = "tests/lalinference_test_injection_standard.dat"
+        self.test_outdir = "test_outdir"
 
     def tearDown(self):
-        pass
+        if os.path.exists(self.test_outdir):
+            rmtree(self.test_outdir)
 
     def test_idx(self):
         inputs = bilby_pipe.main.Input(None, None)
@@ -173,9 +175,9 @@ class TestInput(unittest.TestCase):
 
     def test_default_webdir(self):
         inputs = bilby_pipe.main.Input(None, None)
-        inputs.outdir = "results"
+        inputs.outdir = self.test_outdir
         inputs.webdir = None
-        self.assertEqual(inputs.webdir, "results/results_page")
+        self.assertEqual(inputs.webdir, f"{self.test_outdir}/results_page")
 
     def test_default_start_time(self):
         inputs = bilby_pipe.main.Input(None, None)
@@ -411,6 +413,7 @@ class TestInput(unittest.TestCase):
 
     def test_default_prior_files_lookups(self):
         inputs = bilby_pipe.main.Input(None, None)
+        inputs.outdir = self.test_outdir
         for phase_marginalization in [True, False]:
             inputs.phase_marginalization = phase_marginalization
             for prior in inputs.default_prior_files:
@@ -440,6 +443,7 @@ class TestInput(unittest.TestCase):
 
     def test_prior_file_set_from_default(self):
         inputs = bilby_pipe.main.Input(None, None)
+        inputs.outdir = self.test_outdir
         filename = inputs.default_prior_files["4s"]
         inputs.phase_marginalization = False
         inputs.prior_file = "4s"
-- 
GitLab