gl_space.py 4.75 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 ..space import Space
Theo Steininger's avatar
Theo Steininger committed
22

Martin Reinecke's avatar
Martin Reinecke committed
23

Theo Steininger's avatar
Theo Steininger committed
24
class GLSpace(Space):
csongor's avatar
csongor committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
    """
        ..                 __
        ..               /  /
        ..     ____ __  /  /
        ..   /   _   / /  /
        ..  /  /_/  / /  /_
        ..  \___   /  \___/  space class
        .. /______/

        NIFTY subclass for Gauss-Legendre pixelizations [#]_ of the two-sphere.

        Parameters
        ----------
        nlat : int
39
40
            Number of latitudinal bins (or rings) that are used for this
            pixelization.
41
        nlon : int, *optional*
42
            Number of longitudinal bins that are used for this pixelization.
43

44
        Attributes
csongor's avatar
csongor committed
45
        ----------
46
47
48
49
        dim : np.int
            Total number of dimensionality, i.e. the number of pixels.
        harmonic : bool
            Specifies whether the space is a signal or harmonic space.
csongor's avatar
csongor committed
50
        nlat : int
51
52
            Number of latitudinal bins (or rings) that are used for this
            pixelization.
53
        nlon : int
54
            Number of longitudinal bins that are used for this pixelization.
55
56
57
58
        total_volume : np.float
            The total volume of the space.
        shape : tuple of np.ints
            The shape of the space's data array.
csongor's avatar
csongor committed
59

Theo Steininger's avatar
Theo Steininger committed
60
61
62
63
64
        Raises
        ------
        ValueError
            If input `nlat` or `nlon` is invalid.

csongor's avatar
csongor committed
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
        See Also
        --------
        hp_space : A class for the HEALPix discretization of the sphere [#]_.
        lm_space : A class for spherical harmonic components.

        References
        ----------
        .. [#] M. Reinecke and D. Sverre Seljebotn, 2013, "Libsharp - spherical
               harmonic transforms revisited";
               `arXiv:1303.4945 <http://www.arxiv.org/abs/1303.4945>`_
        .. [#] 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.

    """

81
82
    # ---Overwritten properties and methods---

Martin Reinecke's avatar
Martin Reinecke committed
83
84
    def __init__(self, nlat, nlon=None):
        super(GLSpace, self).__init__()
csongor's avatar
csongor committed
85

86
87
        self._nlat = self._parse_nlat(nlat)
        self._nlon = self._parse_nlon(nlon)
csongor's avatar
csongor committed
88

89
    # ---Mandatory properties and methods---
csongor's avatar
csongor committed
90

91
92
93
    def __repr__(self):
        return ("GLSpace(nlat=%r, nlon=%r)" % (self.nlat, self.nlon))

94
95
96
    @property
    def harmonic(self):
        return False
csongor's avatar
csongor committed
97
98
99

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

102
    @property
103
    def dim(self):
104
        return np.int((self.nlat * self.nlon))
105
106
107
108

    @property
    def total_volume(self):
        return 4 * np.pi
109

110
    def copy(self):
111
        return self.__class__(nlat=self.nlat, nlon=self.nlon)
112

113
114
115
    def scalar_weight(self):
        return None

116
    def weight(self):
117
        from pyHealpix import GL_weights
118
        vol = GL_weights(self.nlat, self.nlon)
Martin Reinecke's avatar
Martin Reinecke committed
119
        return np.outer(vol, np.ones(self.nlon,dtype=np.float64)).ravel()
120
121
122
123
124

    # ---Added properties and methods---

    @property
    def nlat(self):
Theo Steininger's avatar
Theo Steininger committed
125
126
        """ Number of latitudinal bins (or rings) that are used for this
        pixelization.
127
        """
128
129
130
131
        return self._nlat

    @property
    def nlon(self):
132
        """ Number of longitudinal bins that are used for this pixelization.
133
        """
134
135
136
137
        return self._nlon

    def _parse_nlat(self, nlat):
        nlat = int(nlat)
138
        if nlat < 1:
139
            raise ValueError("nlat must be a positive number.")
140
141
142
143
144
145
146
        return nlat

    def _parse_nlon(self, nlon):
        if nlon is None:
            nlon = 2 * self.nlat - 1
        else:
            nlon = int(nlon)
147
148
            if nlon < 1:
                raise ValueError("nlon must be a positive number.")
149
        return nlon
Martin Reinecke's avatar
Martin Reinecke committed
150
151
152

    def get_default_codomain(self):
        from .. import LMSpace
Martin Reinecke's avatar
Martin Reinecke committed
153
        return LMSpace(lmax=self.nlat-1, mmax=(self.nlon-1)//2)
Martin Reinecke's avatar
Martin Reinecke committed
154
155
156
157
158

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