qht_operator.py 2.63 KB
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
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/>.
#
14
# Copyright(C) 2013-2019 Max-Planck-Society
Martin Reinecke's avatar
Martin Reinecke committed
15
#
16
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
17
18

from .. import dobj
19
from .. import fft
20
21
from ..domain_tuple import DomainTuple
from ..field import Field
22
from ..utilities import infer_space
23
24
25
26
from .linear_operator import LinearOperator


class QHTOperator(LinearOperator):
Reimar H Leike's avatar
Reimar H Leike committed
27
28
29
30
31
32
33
34
35
    """
    Does a Hartley transform on LogRGSpace

    This operator takes a field on a LogRGSpace and transforms it
    according to the Hartley transform. The zero modes are not transformed
    because they are infinitely far away.

    Parameters
    ----------
Martin Reinecke's avatar
Martin Reinecke committed
36
37
    target : domain, tuple of domains or DomainTuple
        The full output domain
Martin Reinecke's avatar
Martin Reinecke committed
38
39
    space : int
        The index of the domain on which the operator acts.
Martin Reinecke's avatar
Martin Reinecke committed
40
        target[space] must be a nonharmonic LogRGSpace.
Reimar H Leike's avatar
Reimar H Leike committed
41
    """
Philipp Arras's avatar
Philipp Arras committed
42

Martin Reinecke's avatar
Martin Reinecke committed
43
44
45
    def __init__(self, target, space=0):
        self._target = DomainTuple.make(target)
        self._space = infer_space(self._target, space)
46

Martin Reinecke's avatar
fixes    
Martin Reinecke committed
47
        from ..domains.log_rg_space import LogRGSpace
Martin Reinecke's avatar
Martin Reinecke committed
48
49
        if not isinstance(self._target[self._space], LogRGSpace):
            raise ValueError("target[space] has to be a LogRGSpace!")
50

Martin Reinecke's avatar
Martin Reinecke committed
51
        if self._target[self._space].harmonic:
52
            raise TypeError("target[space] must be a nonharmonic space")
Martin Reinecke's avatar
Martin Reinecke committed
53

Martin Reinecke's avatar
Martin Reinecke committed
54
55
56
57
        self._domain = [dom for dom in self._target]
        self._domain[self._space] = \
            self._target[self._space].get_default_codomain()
        self._domain = DomainTuple.make(self._domain)
Martin Reinecke's avatar
Martin Reinecke committed
58
        self._capability = self.TIMES | self.ADJOINT_TIMES
59
60
61

    def apply(self, x, mode):
        self._check_input(x, mode)
Martin Reinecke's avatar
Martin Reinecke committed
62
        dom = self._domain[self._space]
Martin Reinecke's avatar
Martin Reinecke committed
63
        v = x.val * dom.scalar_dvol
Martin Reinecke's avatar
Martin Reinecke committed
64
65
        n = self._domain.axes[self._space]
        rng = n if mode == self.TIMES else reversed(n)
66
67
        for i in rng:
            sl = (slice(None),)*i + (slice(1, None),)
Martin Reinecke's avatar
Martin Reinecke committed
68
            v, tmp = dobj.ensure_not_distributed(v, (i,))
69
            tmp[sl] = fft.hartley(tmp[sl], axes=(i,))
Martin Reinecke's avatar
Martin Reinecke committed
70
        return Field(self._tgt(mode), dobj.ensure_default_distributed(v))