hp_space.py 2.71 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
# Copyright(C) 2013-2019 Max-Planck-Society
Theo Steininger's avatar
Theo Steininger committed
15
#
16
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
Philipp Arras's avatar
Philipp Arras committed
17

csongor's avatar
csongor committed
18
import numpy as np
Philipp Arras's avatar
Philipp Arras committed
19

Martin Reinecke's avatar
Martin Reinecke committed
20
from .structured_domain import StructuredDomain
21

Theo Steininger's avatar
Theo Steininger committed
22

Martin Reinecke's avatar
Martin Reinecke committed
23
class HPSpace(StructuredDomain):
24
    """Represents 2-sphere with HEALPix discretization.
Martin Reinecke's avatar
Martin Reinecke committed
25
26

    Its harmonic partner domain is the
Martin Reinecke's avatar
5->6    
Martin Reinecke committed
27
    :class:`~nifty6.domains.lm_space.LMSpace`.
Martin Reinecke's avatar
Martin Reinecke committed
28
29
30
31
32
33

    Parameters
    ----------
    nside : int
        The corresponding HEALPix Nside parameter. Must be a positive integer
        and typically is a power of 2.
csongor's avatar
csongor committed
34
    """
35

Martin Reinecke's avatar
Martin Reinecke committed
36
37
    _needed_for_hash = ["_nside"]

Martin Reinecke's avatar
Martin Reinecke committed
38
    def __init__(self, nside):
Martin Reinecke's avatar
Martin Reinecke committed
39
40
41
        self._nside = int(nside)
        if self._nside < 1:
            raise ValueError("nside must be >=1.")
42

43
    def __repr__(self):
Martin Reinecke's avatar
Martin Reinecke committed
44
        return "HPSpace(nside={})".format(self.nside)
45

46
47
48
    @property
    def harmonic(self):
        return False
csongor's avatar
csongor committed
49
50
51

    @property
    def shape(self):
Martin Reinecke's avatar
Martin Reinecke committed
52
        return (self.size,)
csongor's avatar
csongor committed
53
54

    @property
Martin Reinecke's avatar
Martin Reinecke committed
55
    def size(self):
56
        return np.int(12 * self.nside * self.nside)
csongor's avatar
csongor committed
57

Martin Reinecke's avatar
Martin Reinecke committed
58
    @property
59
    def scalar_dvol(self):
60
        return np.pi / (3*self._nside*self._nside)
61
62
63

    @property
    def nside(self):
Martin Reinecke's avatar
Martin Reinecke committed
64
        """int : HEALPix Nside parameter of this domain"""
65
66
        return self._nside

Martin Reinecke's avatar
Martin Reinecke committed
67
    def get_default_codomain(self):
Martin Reinecke's avatar
Martin Reinecke committed
68
69
70
71
72
73
        """Returns a :class:`LMSpace` object, which is capable of storing a
        fairly accurate representation of data residing on `self`

        Returns
        -------
        LMSpace
Martin Reinecke's avatar
Martin Reinecke committed
74
            The partner domain
Martin Reinecke's avatar
Martin Reinecke committed
75
76
77
78
79
80

        Notes
        -----
        The `lmax` and `mmax` parameters of the returned :class:`LMSpace` are
        set to `2*self.nside`.
        """
Martin Reinecke's avatar
fixes    
Martin Reinecke committed
81
        from ..domains.lm_space import LMSpace
Martin Reinecke's avatar
bug fix    
Martin Reinecke committed
82
        return LMSpace(lmax=2*self.nside)
Martin Reinecke's avatar
Martin Reinecke committed
83
84

    def check_codomain(self, codomain):
Martin Reinecke's avatar
Martin Reinecke committed
85
86
87
88
89
90
91
92
        """Raises `TypeError` if `codomain` is not a matching partner domain
        for `self`.

        Notes
        -----
        This function only checks whether `codomain` is of type
        :class:`LMSpace`.
        """
Martin Reinecke's avatar
fixes    
Martin Reinecke committed
93
        from ..domains.lm_space import LMSpace
Martin Reinecke's avatar
Martin Reinecke committed
94
95
        if not isinstance(codomain, LMSpace):
            raise TypeError("codomain must be a LMSpace.")