Commit 8d76a2cb authored by Martin Reinecke's avatar Martin Reinecke
Browse files

remove healpy dependency; add GL plotting. NOTE: update of pyHealpix is required!

parent 76133243
Pipeline #12506 passed with stage
in 6 minutes and 2 seconds
......@@ -30,8 +30,7 @@ dependency_injector = keepers.DependencyInjector(
[('mpi4py.MPI', 'MPI'),
'pyHealpix',
'plotly',
'pylab',
'healpy'])
'pylab'])
dependency_injector.register('pyfftw', lambda z: hasattr(z, 'FFTW_MPI'))
......
# -*- coding: utf-8 -*-
from figure_from_plot import FigureFromPlot
from nifty.plotting.plots import Heatmap, Mollweide
from nifty.plotting.plots import Heatmap, HPMollweide, GLMollweide
class Figure2D(FigureFromPlot):
......@@ -19,7 +19,8 @@ class Figure2D(FigureFromPlot):
else:
height = 500
width = int(500 * y / x)
if isinstance(plots[0], Mollweide):
if isinstance(plots[0], GLMollweide) or isinstance(plots[0],
HPMollweide):
if not xaxis:
xaxis = False
if not yaxis:
......
# -*- coding: utf-8 -*-
from mollweide import Mollweide
from hpmollweide import HPMollweide
from glmollweide import GLMollweide
from heatmap import Heatmap
# -*- coding: utf-8 -*-
from nifty import dependency_injector as gdi
from heatmap import Heatmap
import numpy as np
pylab = gdi.get('pylab')
pyHealpix = gdi.get('pyHealpix')
class GLMollweide(Heatmap):
def __init__(self, data, nlat, nlon, color_map=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 'pyHealpix' not in gdi:
raise ImportError(
"The module pyHealpix is needed but not available.")
if isinstance(data, list):
data = [self._mollview(d) for d in data]
else:
data = self._mollview(data, nlat, nlon)
super(GLMollweide, self).__init__(data, color_map, webgl, smoothing)
def _find_closest(A, target):
# A must be sorted
idx = A.searchsorted(target)
idx = np.clip(idx, 1, len(A)-1)
left = A[idx-1]
right = A[idx]
idx -= target - left < right - target
return idx
def _mollview(self, x, nlat, nlon, xsize=800):
f = pylab.figure(None, figsize=(8.5, 5.4))
extent = (0.02, 0.05, 0.96, 0.9)
x = np.reshape(x, (nlon, nlat))
ra = np.linspace(-np.pi, np.pi, xsize)
dec = np.linspace(-np.pi/2, np.pi/2, xsize/2)
X, Y = np.meshgrid(ra, dec)
gllat = pyHealpix.GL_thetas(nlat)-0.5*np.pi
gllon = np.arange(nlon+1)*(2*np.pi/nlon)
ilat = _find_closest(gllat, dec-0.5*np.pi)
ilon = _find_closest(gllon, np.pi+ra)
for i in range(ilon.size):
if (ilon[i] == nlon):
ilon[i] = 0
Z = np.empty((xsize/2, xsize), dtype=np.float64)
for i in range(xsize/2):
Z[i, :] = x[ilon, ilat[i]]
ax = f.add_subplot(111, projection='mollweide')
ax.pcolormesh(X, Y, Z, rasterized=True)
return f
......@@ -2,28 +2,39 @@
from nifty import dependency_injector as gdi
from heatmap import Heatmap
import numpy as np
pylab = gdi.get('pylab')
healpy = gdi.get('healpy')
pyHealpix = gdi.get('pyHealpix')
class Mollweide(Heatmap):
class HPMollweide(Heatmap):
def __init__(self, data, color_map=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.")
if 'pyHealpix' not in gdi:
raise ImportError(
"The module pyHealpix is needed but not available.")
if isinstance(data, list):
data = [self._mollview(d) for d in data]
else:
data = self._mollview(data)
super(Mollweide, self).__init__(data, color_map, webgl, smoothing)
super(HPMollweide, self).__init__(data, color_map, webgl, smoothing)
def _mollview(self, x, xsize=800):
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 = healpy.projaxes.HpxMollweideAxes(f, extent)
img = ax.projmap(x, nest=False, xsize=xsize)
return img
nside = int(np.sqrt(x.size//12))
base = pyHealpix.Healpix_Base(nside, "RING")
ra = np.linspace(-np.pi, np.pi, xsize)
dec = np.linspace(-np.pi/2, np.pi/2, xsize/2)
X, Y = np.meshgrid(ra, dec)
dims = X.shape+(2,)
ptg = np.empty(dims, dtype=np.float64)
ptg[:, :, 0] = 0.5*np.pi-Y
ptg[:, :, 1] = X+np.pi
Z = x[base.ang2pix(ptg)]
ax = f.add_subplot(111, projection='mollweide')
ax.pcolormesh(X, Y, Z, rasterized=True)
return f
from healpix_plotter import HealpixPlotter
from gl_plotter import GLPlotter
from power_plotter import PowerPlotter
from nifty.spaces import GLSpace
from nifty.plotting.figures import Figure2D
from nifty.plotting.plots import GLMollweide
from .plotter import Plotter
class GLPlotter(Plotter):
def __init__(self, interactive=False, path='.', title="", color_map=None):
super(GLPlotter, self).__init__(interactive, path, title)
self.color_map = color_map
@property
def domain_classes(self):
return (GLSpace, )
def _create_individual_figure(self, plots):
return Figure2D(plots)
def _create_individual_plot(self, data, plot_domain):
result_plot = GLMollweide(data=data, nlat=plot_domain.nlat,
nlon=plot_domain.nlon,
color_map=self.color_map)
return result_plot
from nifty.spaces import HPSpace
from nifty.plotting.figures import Figure2D
from nifty.plotting.plots import Mollweide
from nifty.plotting.plots import HPMollweide
from .plotter import Plotter
......@@ -18,6 +18,6 @@ class HealpixPlotter(Plotter):
return Figure2D(plots)
def _create_individual_plot(self, data, plot_domain):
result_plot = Mollweide(data=data,
color_map=self.color_map)
result_plot = HPMollweide(data=data,
color_map=self.color_map)
return result_plot
Markdown is supported
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