gllmtransformation.py 2.98 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

19
import numpy as np
20

Martin Reinecke's avatar
Martin Reinecke committed
21
from .... import GLSpace, LMSpace
Martin Reinecke's avatar
Martin Reinecke committed
22
23
from .slicing_transformation import SlicingTransformation
from . import lm_transformation_helper
24

Martin Reinecke's avatar
Martin Reinecke committed
25
import pyHealpix
26

27

28
29
class GLLMTransformation(SlicingTransformation):

Martin Reinecke's avatar
Martin Reinecke committed
30
31
    def __init__(self, domain, codomain=None):
        super(GLLMTransformation, self).__init__(domain, codomain)
32

33
34
35
36
    @property
    def unitary(self):
        return False

37
38
    @classmethod
    def get_codomain(cls, domain):
Jait Dixit's avatar
Jait Dixit committed
39
40
        """
            Generates a compatible codomain to which transformations are
Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
41
            reasonable, i.e.\  an instance of the :py:class:`LMSpace` class.
Jait Dixit's avatar
Jait Dixit committed
42
43
44
45
46
47
48
49
50
51
52
53
54

            Parameters
            ----------
            domain: GLSpace
                Space for which a codomain is to be generated

            Returns
            -------
            codomain : LMSpace
                A compatible codomain.
        """

        if not isinstance(domain, GLSpace):
55
            raise TypeError("domain needs to be a GLSpace")
Jait Dixit's avatar
Jait Dixit committed
56

Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
57
        return LMSpace(lmax=domain.nlat-1,mmax=(domain.nlon-1)//2)
Jait Dixit's avatar
Jait Dixit committed
58

59
60
    @classmethod
    def check_codomain(cls, domain, codomain):
Jait Dixit's avatar
Jait Dixit committed
61
        if not isinstance(domain, GLSpace):
62
            raise TypeError("domain is not a GLSpace")
Jait Dixit's avatar
Jait Dixit committed
63
        if not isinstance(codomain, LMSpace):
64
65
            raise TypeError("codomain must be a LMSpace.")
        super(GLLMTransformation, cls).check_codomain(domain, codomain)
66

Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
67
    def _transformation_of_slice(self, inp):
68
69
70
71
        nlat = self.domain.nlat
        nlon = self.domain.nlon
        lmax = self.codomain.lmax
        mmax = self.codomain.mmax
72

73
74
75
        sjob = pyHealpix.sharpjob_d()
        sjob.set_Gauss_geometry(nlat, nlon)
        sjob.set_triangular_alm_info(lmax, mmax)
76
        if issubclass(inp.dtype.type, np.complexfloating):
Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
77
78
79
80
81
            return self._combine_complex_result(
                lm_transformation_helper.buildIdx(sjob.map2alm(inp.real),
                                                  lmax=lmax),
                lm_transformation_helper.buildIdx(sjob.map2alm(inp.imag),
                                                  lmax=lmax))
82
        else:
Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
83
84
            return lm_transformation_helper.buildIdx(sjob.map2alm(inp),
                                                     lmax=lmax)