gl_space.py 3.71 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
# 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# 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.
18

csongor's avatar
csongor committed
19
20
from __future__ import division
import numpy as np
Martin Reinecke's avatar
Martin Reinecke committed
21
from .structured_domain import StructuredDomain
Theo Steininger's avatar
Theo Steininger committed
22

Martin Reinecke's avatar
Martin Reinecke committed
23

Martin Reinecke's avatar
Martin Reinecke committed
24
class GLSpace(StructuredDomain):
Martin Reinecke's avatar
Martin Reinecke committed
25
26
27
    """NIFTy subclass for Gauss-Legendre pixelizations of the two-sphere.

    Its harmonic partner is the :class:`LMSpace`
csongor's avatar
csongor committed
28

Martin Reinecke's avatar
Martin Reinecke committed
29
30
31
32
33
    Parameters
    ----------
    nlat : int
        Number of latitudinal bins (or rings) that are used for this
        pixelization.
Martin Reinecke's avatar
Martin Reinecke committed
34
    nlon : int, optional
Martin Reinecke's avatar
Martin Reinecke committed
35
36
37
38
39
40
41
        Number of longitudinal bins that are used for this pixelization.
        Default value is 2*nlat + 1.

    Raises
    ------
    ValueError
        If input `nlat` or `nlon` is invalid.
csongor's avatar
csongor committed
42
43
    """

Martin Reinecke's avatar
Martin Reinecke committed
44
45
    def __init__(self, nlat, nlon=None):
        super(GLSpace, self).__init__()
46
        self._needed_for_hash += ["_nlat", "_nlon"]
csongor's avatar
csongor committed
47

Martin Reinecke's avatar
Martin Reinecke committed
48
49
50
51
52
53
54
55
56
        self._nlat = int(nlat)
        if self._nlat < 1:
            raise ValueError("nlat must be a positive number.")
        if nlon is None:
            self._nlon = 2*self._nlat - 1
        else:
            self._nlon = int(nlon)
            if self._nlon < 1:
                raise ValueError("nlon must be a positive number.")
57
        self._dvol = None
csongor's avatar
csongor committed
58

59
60
61
    def __repr__(self):
        return ("GLSpace(nlat=%r, nlon=%r)" % (self.nlat, self.nlon))

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

    @property
    def shape(self):
68
        return (np.int((self.nlat * self.nlon)),)
csongor's avatar
csongor committed
69

70
    @property
Martin Reinecke's avatar
Martin Reinecke committed
71
    def size(self):
72
        return np.int((self.nlat * self.nlon))
73

74
    def scalar_dvol(self):
75
76
        return None

Martin Reinecke's avatar
Martin Reinecke committed
77
78
    # MR FIXME: this is potentially wasteful, since the return array is
    #           blown up by a factor of self.nlon
79
    def dvol(self):
80
        from pyHealpix import GL_weights
81
82
83
        if self._dvol is None:
            self._dvol = GL_weights(self.nlat, self.nlon)
        return np.repeat(self._dvol, self.nlon)
84

Martin Reinecke's avatar
Martin Reinecke committed
85
86
87
    def total_volume(self):
        return 4*np.pi

88
89
    @property
    def nlat(self):
Theo Steininger's avatar
Theo Steininger committed
90
91
        """ Number of latitudinal bins (or rings) that are used for this
        pixelization.
92
        """
93
94
95
96
        return self._nlat

    @property
    def nlon(self):
Martin Reinecke's avatar
Martin Reinecke committed
97
        """Number of longitudinal bins that are used for this pixelization."""
98
99
        return self._nlon

Martin Reinecke's avatar
Martin Reinecke committed
100
    def get_default_codomain(self):
Martin Reinecke's avatar
Martin Reinecke committed
101
102
103
104
105
106
107
108
109
        """Returns a :class:`LMSpace` object, which is capable of storing an
        accurate representation of data residing on `self` (if this data is
        band-limited).

        Returns
        -------
        LMSpace
            The parter domain
        """
Martin Reinecke's avatar
Martin Reinecke committed
110
        from .. import LMSpace
111
        return LMSpace(lmax=self._nlat-1, mmax=self._nlon//2)
Martin Reinecke's avatar
Martin Reinecke committed
112
113

    def check_codomain(self, codomain):
Martin Reinecke's avatar
Martin Reinecke committed
114
115
116
117
118
119
120
121
        """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
Martin Reinecke committed
122
123
124
        from .. import LMSpace
        if not isinstance(codomain, LMSpace):
            raise TypeError("codomain must be a LMSpace.")