gl_space.py 3.55 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
# 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
Theo Steininger's avatar
Theo Steininger committed
21

Martin Reinecke's avatar
Martin Reinecke committed
22

Martin Reinecke's avatar
Martin Reinecke committed
23
class GLSpace(StructuredDomain):
Martin Reinecke's avatar
Martin Reinecke committed
24
    """Represents a 2-sphere with Gauss-Legendre pixelization.
Martin Reinecke's avatar
Martin Reinecke committed
25

Martin Reinecke's avatar
Martin Reinecke committed
26
    Its harmonic partner domain is the
Martin Reinecke's avatar
Martin Reinecke committed
27
    :class:`~nifty7.domains.lm_space.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
        Number of longitudinal bins that are used for this pixelization.
Martin Reinecke's avatar
Martin Reinecke committed
36
        Default value is 2*nlat - 1.
csongor's avatar
csongor committed
37
38
    """

Martin Reinecke's avatar
Martin Reinecke committed
39
40
    _needed_for_hash = ["_nlat", "_nlon"]

Martin Reinecke's avatar
Martin Reinecke committed
41
    def __init__(self, nlat, nlon=None):
Martin Reinecke's avatar
Martin Reinecke committed
42
43
44
45
46
47
48
49
50
        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.")
51
        self._dvol = None
csongor's avatar
csongor committed
52

53
    def __repr__(self):
Martin Reinecke's avatar
Martin Reinecke committed
54
        return "GLSpace(nlat={}, nlon={})".format(self.nlat, self.nlon)
55

56
57
58
    @property
    def harmonic(self):
        return False
csongor's avatar
csongor committed
59
60
61

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

64
    @property
Martin Reinecke's avatar
Martin Reinecke committed
65
    def size(self):
66
        return np.int((self.nlat * self.nlon))
67

Martin Reinecke's avatar
Martin Reinecke committed
68
    @property
69
    def scalar_dvol(self):
70
71
        return None

Martin Reinecke's avatar
Martin Reinecke committed
72
73
    # MR FIXME: this is potentially wasteful, since the return array is
    #           blown up by a factor of self.nlon
Martin Reinecke's avatar
Martin Reinecke committed
74
    @property
75
    def dvol(self):
76
        from ducc0.misc import GL_weights
77
78
79
        if self._dvol is None:
            self._dvol = GL_weights(self.nlat, self.nlon)
        return np.repeat(self._dvol, self.nlon)
80

Martin Reinecke's avatar
Martin Reinecke committed
81
    @property
Martin Reinecke's avatar
Martin Reinecke committed
82
83
84
    def total_volume(self):
        return 4*np.pi

85
86
    @property
    def nlat(self):
Martin Reinecke's avatar
Martin Reinecke committed
87
        """int : number of rings in this domain"""
88
89
90
91
        return self._nlat

    @property
    def nlon(self):
Martin Reinecke's avatar
Martin Reinecke committed
92
        """int : pixels per ring in this domain"""
93
94
        return self._nlon

Martin Reinecke's avatar
Martin Reinecke committed
95
    def get_default_codomain(self):
Martin Reinecke's avatar
Martin Reinecke committed
96
97
98
99
100
101
102
        """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
Martin Reinecke's avatar
Martin Reinecke committed
103
            The partner domain
Martin Reinecke's avatar
Martin Reinecke committed
104
        """
Martin Reinecke's avatar
fixes    
Martin Reinecke committed
105
        from ..domains.lm_space import LMSpace
Martin Reinecke's avatar
fix    
Martin Reinecke committed
106
107
108
        mmax = self._nlon//2
        lmax = max(mmax, self._nlat-1)
        return LMSpace(lmax=lmax, mmax=mmax)
Martin Reinecke's avatar
Martin Reinecke committed
109
110

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