harmonic_transform_operator.py 2.96 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
# 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/>.
#
Martin Reinecke's avatar
Martin Reinecke committed
14
# Copyright(C) 2013-2018 Max-Planck-Society
15
16
17
18
19
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.

from ..domain_tuple import DomainTuple
Martin Reinecke's avatar
Martin Reinecke committed
20
from ..domains.rg_space import RGSpace
21
from .linear_operator import LinearOperator
22
23
from .fft_operator import FFTOperator
from .sht_operator import SHTOperator
24
25
26
27
from .. import utilities


class HarmonicTransformOperator(LinearOperator):
Martin Reinecke's avatar
Martin Reinecke committed
28
    """Transforms between a harmonic domain and a position domain counterpart.
29
30
31

    Built-in domain pairs are
      - a harmonic and a non-harmonic RGSpace (with matching distances)
32
      - an LMSpace and a HPSpace
33
34
35
36
37
38
      - an LMSpace and a GLSpace

    The supported operations are times() and adjoint_times().

    Parameters
    ----------
Martin Reinecke's avatar
Martin Reinecke committed
39
    domain : Domain, tuple of Domain or DomainTuple
40
41
        The domain of the data that is input by "times" and output by
        "adjoint_times".
Martin Reinecke's avatar
Martin Reinecke committed
42
43
44
45
    target : Domain, optional
        The target domain of the transform operation.
        If omitted, a domain will be chosen automatically.
        Whenever the input domain of the transform is an RGSpace, the codomain
46
47
        (and its parameters) are uniquely determined.
        For LMSpace, a GLSpace of sufficient resolution is chosen.
Martin Reinecke's avatar
Martin Reinecke committed
48
49
50
51
    space : int, optional
        The index of the domain on which the operator should act
        If None, it is set to 0 if domain contains exactly one subdomain.
        domain[space] must be a harmonic domain.
52
53
54
55
56
    """

    def __init__(self, domain, target=None, space=None):
        super(HarmonicTransformOperator, self).__init__()

57
58
        domain = DomainTuple.make(domain)
        space = utilities.infer_space(domain, space)
59

60
        hspc = domain[space]
61
62
63
64
        if not hspc.harmonic:
            raise TypeError(
                "HarmonicTransformOperator only works on a harmonic space")
        if isinstance(hspc, RGSpace):
65
            self._op = FFTOperator(domain, target, space)
66
        else:
67
            self._op = SHTOperator(domain, target, space)
68
69
70

    def apply(self, x, mode):
        self._check_input(x, mode)
71
        return self._op.apply(x, mode)
72
73
74

    @property
    def domain(self):
75
        return self._op.domain
76
77
78

    @property
    def target(self):
79
        return self._op.target
80
81
82
83

    @property
    def capability(self):
        return self.TIMES | self.ADJOINT_TIMES