diff --git a/refactored/da/ct/tools.py b/refactored/da/ct/tools.py index 20cb223b8c4aa8d2930d9c070bbce845bcad5c1f..103e89fe3bf162b106aee70e804f8297c821a4a5 100755 --- a/refactored/da/ct/tools.py +++ b/refactored/da/ct/tools.py @@ -96,8 +96,3 @@ if __name__ == "__main__": show() - - - - - diff --git a/refactored/da/tools/general.py b/refactored/da/tools/general.py index e519db3581ce97ff2fca0cc0d8f934d779faf654..77f948d081734e2868dea3426dc974ecb44dd644 100755 --- a/refactored/da/tools/general.py +++ b/refactored/da/tools/general.py @@ -120,6 +120,7 @@ def ToDectime(dd): """ convert a datetime object to a decimal date """ import datetime import calendar + from matplotlib.pylab import date2num Days0=date2num(datetime.datetime(dd.year,1,1)) diff --git a/refactored/das.py b/refactored/das.py index 6a89735b475b1402bc736bfa040027a0809c7307..20085f82a4a8e686faeb2720c447de3aa3592a09 100644 --- a/refactored/das.py +++ b/refactored/das.py @@ -4,6 +4,19 @@ # First order of business is always to make all other python modules accessible through the path ################################################################################################# +__realimport__ = __import__ +def _printimport(*args, **kwds): + """print each import.""" + print "importing:", args[:1] + if args[0] == "matplotlib": + print args, kwds + raise Exception("Imported matplotlib here!") + return __realimport__(*args, **kwds) + +# debugging info to get the actual import order. +#import __builtin__ +#__builtin__.__import__ = _printimport + import sys import os import logging @@ -13,6 +26,14 @@ dummy = sys.path.append(os.getcwd()) # Next, import the tools needed to initialize a data assimilation cycle ################################################################################################# +# without X11 use Agg as matplotlib backend. +from subprocess import call +def hasWorkingX11(): + return not call(["python", "-c", "import pylab as pl; pl.ion(); pl.plot((0,0))"]) +if not "DISPLAY" in os.environ or not hasWorkingX11(): + import matplotlib + matplotlib.use("Agg") + from da.tools.initexit import StartLogger from da.tools.initexit import ValidateOptsArgs from da.tools.initexit import ParseOptions