Commit 20a1e800 authored by Theo Steininger's avatar Theo Steininger
Browse files

Made module import for plotting modular and infer backend for matplotlib dynamically.

parent 01fea702
Pipeline #11723 failed with stage
in 8 minutes and 34 seconds
...@@ -8,7 +8,8 @@ RUN \ ...@@ -8,7 +8,8 @@ RUN \
libopenmpi-dev libatlas-base-dev libfftw3-bin libfftw3-dev \ libopenmpi-dev libatlas-base-dev libfftw3-bin libfftw3-dev \
libfftw3-double3 libfftw3-long3 libfftw3-mpi-dev libfftw3-mpi3 \ libfftw3-double3 libfftw3-long3 libfftw3-mpi-dev libfftw3-mpi3 \
libfftw3-quad3 libfftw3-single3 libhdf5-10 libhdf5-dev \ 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 # python dependencies
ADD ci/requirements.txt /tmp/requirements.txt ADD ci/requirements.txt /tmp/requirements.txt
......
...@@ -2,6 +2,7 @@ numpy ...@@ -2,6 +2,7 @@ numpy
cython cython
mpi4py mpi4py
matplotlib matplotlib
plotly
ipython==5.3.0 ipython==5.3.0
nose nose
parameterized parameterized
......
...@@ -50,6 +50,8 @@ from spaces import * ...@@ -50,6 +50,8 @@ from spaces import *
from operators import * from operators import *
from plotting import *
from probing import * from probing import *
from sugar import * from sugar import *
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import os import os
from distutils.version import LooseVersion as lv
import numpy as np import numpy as np
import keepers import keepers
...@@ -28,13 +27,12 @@ __all__ = ['dependency_injector', 'nifty_configuration'] ...@@ -28,13 +27,12 @@ __all__ = ['dependency_injector', 'nifty_configuration']
dependency_injector = keepers.DependencyInjector( dependency_injector = keepers.DependencyInjector(
[('mpi4py.MPI', 'MPI'), [('mpi4py.MPI', 'MPI'),
'pyHealpix', 'pyHealpix',
'plotly']) 'plotly',
'pylab',
'healpy'])
dependency_injector.register('pyfftw', lambda z: hasattr(z, 'FFTW_MPI')) 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 # Initialize the variables
variable_fft_module = keepers.Variable( variable_fft_module = keepers.Variable(
'fft_module', 'fft_module',
......
from matplotlib_init import *
from descriptors import * from descriptors import *
from plots import * from plots import *
from figures import * from figures import *
......
...@@ -2,15 +2,19 @@ ...@@ -2,15 +2,19 @@
import numpy as np import numpy as np
from plotly.tools import make_subplots from nifty import dependency_injector as gdi
from figure_base import FigureBase from figure_base import FigureBase
from figure_3D import Figure3D from figure_3D import Figure3D
plotly = gdi.get('plotly')
class MultiFigure(FigureBase): class MultiFigure(FigureBase):
def __init__(self, rows, columns, subfigures=None, def __init__(self, rows, columns, subfigures=None,
title=None, width=None, height=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) super(MultiFigure, self).__init__(title, width, height)
self.subfigures = np.empty((rows, columns), dtype=np.object) self.subfigures = np.empty((rows, columns), dtype=np.object)
self.subfigures[:] = subfigures self.subfigures[:] = subfigures
...@@ -36,7 +40,8 @@ class MultiFigure(FigureBase): ...@@ -36,7 +40,8 @@ class MultiFigure(FigureBase):
specs_setter = \ specs_setter = \
lambda z: {'is_3d': True} if isinstance(z, Figure3D) else {} lambda z: {'is_3d': True} if isinstance(z, Figure3D) else {}
sub_specs = np.vectorize(specs_setter)(sub_specs) 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, self.columns,
subplot_titles=sub_titles, subplot_titles=sub_titles,
specs=sub_specs) specs=sub_specs)
......
# -*- 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')
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import pylab from nifty import dependency_injector as gdi
import healpy.projaxes as PA
import healpy.pixelfunc as pixelfunc
from heat_map import HeatMap from heat_map import HeatMap
pylab = gdi.get('pylab')
healpy = gdi.get('healpy')
class Mollweide(HeatMap): class Mollweide(HeatMap):
def __init__(self, data, label='', line=None, marker=None, webgl=False, def __init__(self, data, label='', line=None, marker=None, webgl=False,
smoothing=False): # smoothing 'best', 'fast', 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) data = self._mollview(data)
super(Mollweide, self).__init__(data, label, line, marker, webgl, super(Mollweide, self).__init__(data, label, line, marker, webgl,
smoothing) smoothing)
def _mollview(self, x, xsize=800): 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)) f = pylab.figure(None, figsize=(8.5, 5.4))
extent = (0.02, 0.05, 0.96, 0.9) 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) img = ax.projmap(x, nest=False, xsize=xsize)
return img return img
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment