lmhptransformation.py 3.54 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# NIFTy
# Copyright (C) 2017  Theo Steininger
#
# Author: Theo Steininger
#
# 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/>.

Jait Dixit's avatar
Jait Dixit committed
19
import numpy as np
20
from nifty.config import dependency_injector as gdi
Jait Dixit's avatar
Jait Dixit committed
21
from nifty import HPSpace, LMSpace
22
from slicing_transformation import SlicingTransformation
23
24
import lm_transformation_factory as ltf

25
pyHealpix = gdi.get('pyHealpix')
Jait Dixit's avatar
Jait Dixit committed
26
27


28
29
30
31
class LMHPTransformation(SlicingTransformation):

    # ---Overwritten properties and methods---

Jait Dixit's avatar
Jait Dixit committed
32
    def __init__(self, domain, codomain=None, module=None):
33
        if gdi.get('pyHealpix') is None:
34
            raise ImportError(
35
                "The module pyHealpix is needed but not available.")
Jait Dixit's avatar
Jait Dixit committed
36

37
38
        super(LMHPTransformation, self).__init__(domain, codomain,
                                                 module=module)
Jait Dixit's avatar
Jait Dixit committed
39

40
41
42
43
    # ---Mandatory properties and methods---

    @classmethod
    def get_codomain(cls, domain):
Jait Dixit's avatar
Jait Dixit committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
        """
            Generates a compatible codomain to which transformations are
            reasonable, i.e.\  a pixelization of the two-sphere.

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

            Returns
            -------
            codomain : HPSpace
                A compatible codomain.

            References
            ----------
            .. [#] 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.
        """
        if not isinstance(domain, LMSpace):
65
66
            raise TypeError(
                'ERROR: domain needs to be a LMSpace')
Jait Dixit's avatar
Jait Dixit committed
67

68
        nside = np.max(domain.lmax // 2,1)
69
70
71
        result = HPSpace(nside=nside)
        cls.check_codomain(domain, result)
        return result
Jait Dixit's avatar
Jait Dixit committed
72

Jait Dixit's avatar
Jait Dixit committed
73
74
75
    @staticmethod
    def check_codomain(domain, codomain):
        if not isinstance(domain, LMSpace):
76
77
            raise TypeError(
                'ERROR: domain is not a LMSpace')
Jait Dixit's avatar
Jait Dixit committed
78
79

        if not isinstance(codomain, HPSpace):
80
81
            raise TypeError(
                'ERROR: codomain must be a HPSpace.')
82

83
84
        nside = codomain.nside
        lmax = domain.lmax
Jait Dixit's avatar
Jait Dixit committed
85

86
        return None
Jait Dixit's avatar
Jait Dixit committed
87

88
89
90
    def _transformation_of_slice(self, inp, **kwargs):
        nside = self.codomain.nside
        lmax = self.domain.lmax
91
        mmax = lmax
Jait Dixit's avatar
Jait Dixit committed
92

93
94
95
        sjob=pyHealpix.sharpjob_d()
        sjob.set_Healpix_geometry(nside)
        sjob.set_triangular_alm_info(lmax,mmax)
96
97
98
99
        if issubclass(inp.dtype.type, np.complexfloating):
            [resultReal, resultImag] = [ltf.buildLm(x, lmax=lmax)
                                        for x in (inp.real, inp.imag)]

100
            [resultReal, resultImag] = [sjob.alm2map(x)
101
102
103
                                        for x in [resultReal, resultImag]]

            result = self._combine_complex_result(resultReal, resultImag)
Jait Dixit's avatar
Jait Dixit committed
104
105

        else:
106
            result = ltf.buildLm(inp, lmax=lmax)
107
            result = sjob.alm2map(result)
Jait Dixit's avatar
Jait Dixit committed
108

109
        return result