hp_space.py 2.65 KB
Newer Older
csongor's avatar
csongor committed
1
2
3
4
5
6
7
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
8
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
csongor's avatar
csongor committed
10
11
#
# You should have received a copy of the GNU General Public License
12
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Theo Steininger's avatar
Theo Steininger committed
13
14
15
16
17
#
# Copyright(C) 2013-2017 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
csongor's avatar
csongor committed
18

Martin Reinecke's avatar
Martin Reinecke committed
19
from __future__ import division
csongor's avatar
csongor committed
20
import numpy as np
Martin Reinecke's avatar
Martin Reinecke committed
21
from .space import Space
22

Theo Steininger's avatar
Theo Steininger committed
23

Theo Steininger's avatar
Theo Steininger committed
24
class HPSpace(Space):
Martin Reinecke's avatar
Martin Reinecke committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    """NIFTY subclass for HEALPix discretizations of the two-sphere [#]_.

    Parameters
    ----------
    nside : int
        The corresponding HEALPix Nside parameter. Must be a positive integer
        and typically is a power of 2.

    Raises
    ------
    ValueError
        If given `nside` < 1.

    See Also
    --------
Martin Reinecke's avatar
Martin Reinecke committed
40
    GLSpace, LMSpace
Martin Reinecke's avatar
Martin Reinecke committed
41
42
43
44
45
46
47
48
49

    References
    ----------
    .. [#] K.M. Gorski et al., 2005, "HEALPix: A Framework for
           High-Resolution Discretization and Fast Analysis of Data
           Distributed on the Sphere", *ApJ* 622..759G.
    .. [#] M. Reinecke and D. Sverre Seljebotn, 2013, "Libsharp - spherical
           harmonic transforms revisited";
           `arXiv:1303.4945 <http://www.arxiv.org/abs/1303.4945>`_
csongor's avatar
csongor committed
50
    """
51

Martin Reinecke's avatar
Martin Reinecke committed
52
53
    def __init__(self, nside):
        super(HPSpace, self).__init__()
54
        self._needed_for_hash += ["_nside"]
Martin Reinecke's avatar
Martin Reinecke committed
55
56
57
        self._nside = int(nside)
        if self._nside < 1:
            raise ValueError("nside must be >=1.")
58

59
60
61
    def __repr__(self):
        return ("HPSpace(nside=%r)" % self.nside)

62
63
64
    @property
    def harmonic(self):
        return False
csongor's avatar
csongor committed
65
66
67

    @property
    def shape(self):
68
        return (self.dim,)
csongor's avatar
csongor committed
69
70

    @property
Jait Dixit's avatar
Jait Dixit committed
71
    def dim(self):
72
        return np.int(12 * self.nside * self.nside)
csongor's avatar
csongor committed
73

74
    def scalar_dvol(self):
75
        return np.pi / (3*self._nside*self._nside)
76
77
78

    @property
    def nside(self):
Martin Reinecke's avatar
Martin Reinecke committed
79
        """Returns the nside of the corresponding HEALPix pixelization."""
80
81
        return self._nside

Martin Reinecke's avatar
Martin Reinecke committed
82
83
    def get_default_codomain(self):
        from .. import LMSpace
Martin Reinecke's avatar
bug fix    
Martin Reinecke committed
84
        return LMSpace(lmax=2*self.nside)
Martin Reinecke's avatar
Martin Reinecke committed
85
86
87
88
89

    def check_codomain(self, codomain):
        from .. import LMSpace
        if not isinstance(codomain, LMSpace):
            raise TypeError("codomain must be a LMSpace.")