diff --git a/Dockerfile b/Dockerfile index 2991b39589a75576bac3251b394e954619af1030..d070c4dabc58c545e7f25dea0ef660dc6e4820cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,8 @@ RUN \ libopenmpi-dev libatlas-base-dev libfftw3-bin libfftw3-dev \ libfftw3-double3 libfftw3-long3 libfftw3-mpi-dev libfftw3-mpi3 \ libfftw3-quad3 libfftw3-single3 libhdf5-10 libhdf5-dev \ - libhdf5-openmpi-10 libhdf5-openmpi-dev hdf5-tools + libhdf5-openmpi-10 libhdf5-openmpi-dev hdf5-tools \ + python-tk # python dependencies ADD ci/requirements.txt /tmp/requirements.txt diff --git a/ci/requirements.txt b/ci/requirements.txt index c691ef3455b84370e74ebbfcd6cb0fd8b44a198b..424f78f5a6757773b236896f08586eead7ed6c8a 100644 --- a/ci/requirements.txt +++ b/ci/requirements.txt @@ -2,6 +2,7 @@ numpy cython mpi4py matplotlib +plotly ipython==5.3.0 nose parameterized diff --git a/nifty/__init__.py b/nifty/__init__.py index 12ca828b06d1a71d7e12ad14c67edc4887342d5e..60e6385946cfafafbadfaefd8e5f8f05461cf471 100644 --- a/nifty/__init__.py +++ b/nifty/__init__.py @@ -50,6 +50,8 @@ from spaces import * from operators import * +from plotting import * + from probing import * from sugar import * diff --git a/nifty/config/nifty_config.py b/nifty/config/nifty_config.py index 70b7ea4177418e8a9a4ef1a054c5bf8e62be6a1a..adb0be372d82bd1b2a9e6a59a199030b9ba7d03b 100644 --- a/nifty/config/nifty_config.py +++ b/nifty/config/nifty_config.py @@ -17,7 +17,6 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import os -from distutils.version import LooseVersion as lv import numpy as np import keepers @@ -28,13 +27,12 @@ __all__ = ['dependency_injector', 'nifty_configuration'] dependency_injector = keepers.DependencyInjector( [('mpi4py.MPI', 'MPI'), 'pyHealpix', - 'plotly']) + 'plotly', + 'pylab', + 'healpy']) dependency_injector.register('pyfftw', lambda z: hasattr(z, 'FFTW_MPI')) -dependency_injector.register('healpy', - lambda z: lv(z.__version__) >= lv('1.8.1')) - # Initialize the variables variable_fft_module = keepers.Variable( 'fft_module', diff --git a/nifty/plotting/__init__.py b/nifty/plotting/__init__.py index 8d586c62e8d0ea294fb392ecdee980b5262d3e05..cb85e11d0a1e25ef6893918b552c0e1aa8eeeb9e 100644 --- a/nifty/plotting/__init__.py +++ b/nifty/plotting/__init__.py @@ -1,3 +1,5 @@ +from matplotlib_init import * + from descriptors import * from plots import * from figures import * diff --git a/nifty/plotting/figures/multi_figure.py b/nifty/plotting/figures/multi_figure.py index 2b0411feb7c82cfbee1aa96a8d96aa607146d29d..30c0a82f43925239d6b9b29a93a9137287a839a8 100644 --- a/nifty/plotting/figures/multi_figure.py +++ b/nifty/plotting/figures/multi_figure.py @@ -2,15 +2,19 @@ import numpy as np -from plotly.tools import make_subplots +from nifty import dependency_injector as gdi from figure_base import FigureBase from figure_3D import Figure3D +plotly = gdi.get('plotly') + class MultiFigure(FigureBase): def __init__(self, rows, columns, subfigures=None, title=None, width=None, height=None): + if 'plotly' not in gdi: + raise ImportError("The module plotly is needed but not available.") super(MultiFigure, self).__init__(title, width, height) self.subfigures = np.empty((rows, columns), dtype=np.object) self.subfigures[:] = subfigures @@ -36,7 +40,8 @@ class MultiFigure(FigureBase): specs_setter = \ lambda z: {'is_3d': True} if isinstance(z, Figure3D) else {} sub_specs = np.vectorize(specs_setter)(sub_specs) - multi_figure_plotly_object = make_subplots(self.rows, + multi_figure_plotly_object = plotly.tools.make_subplots( + self.rows, self.columns, subplot_titles=sub_titles, specs=sub_specs) diff --git a/nifty/plotting/matplotlib_init.py b/nifty/plotting/matplotlib_init.py new file mode 100644 index 0000000000000000000000000000000000000000..734963ae8f8ed75cb1ce581f485a78bacbc4ab10 --- /dev/null +++ b/nifty/plotting/matplotlib_init.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +import os + +__all__ = [] + +try: + import matplotlib +except ImportError: + pass +else: + try: + display = os.environ['DISPLAY'] + except KeyError: + matplotlib.use('Agg') + else: + if display == '': + matplotlib.use('Agg') diff --git a/nifty/plotting/plots/heatmaps/mollweide.py b/nifty/plotting/plots/heatmaps/mollweide.py index 9111f92e6dc531d862633672aebd5560676fdd08..f718160be2c8008c9b99dea9dcc64c3f08612261 100644 --- a/nifty/plotting/plots/heatmaps/mollweide.py +++ b/nifty/plotting/plots/heatmaps/mollweide.py @@ -1,24 +1,28 @@ # -*- coding: utf-8 -*- -import pylab - -import healpy.projaxes as PA -import healpy.pixelfunc as pixelfunc - +from nifty import dependency_injector as gdi from heat_map import HeatMap +pylab = gdi.get('pylab') +healpy = gdi.get('healpy') + class Mollweide(HeatMap): def __init__(self, data, label='', line=None, marker=None, webgl=False, smoothing=False): # smoothing 'best', 'fast', False + if 'pylab' not in gdi: + raise ImportError("The module pylab is needed but not available.") + if 'healpy' not in gdi: + raise ImportError("The module healpy is needed but not available.") + data = self._mollview(data) super(Mollweide, self).__init__(data, label, line, marker, webgl, smoothing) def _mollview(self, x, xsize=800): - x = pixelfunc.ma_to_array(x) + x = healpy.pixelfunc.ma_to_array(x) f = pylab.figure(None, figsize=(8.5, 5.4)) extent = (0.02, 0.05, 0.96, 0.9) - ax = PA.HpxMollweideAxes(f, extent) + ax = healpy.projaxes.HpxMollweideAxes(f, extent) img = ax.projmap(x, nest=False, xsize=xsize) return img