From a95bf50d8d7dbe0062302ee3da37696588dd1b6c Mon Sep 17 00:00:00 2001
From: Gregory Ashton <gregory.ashton@ligo.org>
Date: Wed, 16 May 2018 16:04:46 +1000
Subject: [PATCH] Closes #70

If DISPLAY environ not found, then default to the Agg matplotlib
backend. Useful for running on clusters etc.
---
 tupak/__init__.py | 5 +++--
 tupak/utils.py    | 8 ++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/tupak/__init__.py b/tupak/__init__.py
index 285c2c448..251b7fca7 100644
--- a/tupak/__init__.py
+++ b/tupak/__init__.py
@@ -1,10 +1,11 @@
 from __future__ import print_function, division
 
-# import local files
+# import local files, utils should be imported first
 from . import utils
 from . import detector
 from . import prior
 from . import source
 from . import likelihood
 from . import waveform_generator
-from . import sampler
\ No newline at end of file
+from . import sampler
+
diff --git a/tupak/utils.py b/tupak/utils.py
index 866d8e89d..cd1530208 100644
--- a/tupak/utils.py
+++ b/tupak/utils.py
@@ -543,6 +543,14 @@ def set_up_command_line_arguments():
 
 command_line_args = set_up_command_line_arguments()
 
+if 'DISPLAY' in os.environ:
+    pass
+else:
+    logging.info('No $DISPLAY environment variable found, so importing \
+                  matplotlib.pyplot with non-interactive "Agg" backend.')
+    import matplotlib
+    matplotlib.use('Agg')
+
 
 
 
-- 
GitLab