hpmollweide.py 1.02 KB
Newer Older
1
2
3
4
5
6
# -*- coding: utf-8 -*-

from nifty import dependency_injector as gdi
from heatmap import Heatmap
import numpy as np

7
8
from .mollweide_helper import mollweide_helper

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
pyHealpix = gdi.get('pyHealpix')


class HPMollweide(Heatmap):
    def __init__(self, data, color_map=None, webgl=False,
                 smoothing=False):  # smoothing 'best', 'fast', False
        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(HPMollweide, self).__init__(data, color_map, webgl, smoothing)

Martin Reinecke's avatar
Martin Reinecke committed
24
    def _mollview(self, x, xsize=800):
25
        res, mask, theta, phi = mollweide_helper(xsize)
Martin Reinecke's avatar
Martin Reinecke committed
26

Martin Reinecke's avatar
Martin Reinecke committed
27
28
29
30
        ptg = np.empty((phi.size, 2), dtype=np.float64)
        ptg[:, 0] = theta
        ptg[:, 1] = phi
        base = pyHealpix.Healpix_Base(int(np.sqrt(x.size/12)), "RING")
Martin Reinecke's avatar
PEP8    
Martin Reinecke committed
31
        res[mask] = x[base.ang2pix(ptg)]
Martin Reinecke's avatar
Martin Reinecke committed
32
        return res