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

Martin Reinecke's avatar
Martin Reinecke committed
19
from .scaling_operator import ScalingOperator
Martin Reinecke's avatar
Martin Reinecke committed
20
from .fft_operator import FFTOperator
21
from ..utilities import infer_space
22
from .diagonal_operator import DiagonalOperator
Martin Reinecke's avatar
Martin Reinecke committed
23
from ..domain_tuple import DomainTuple
24

25

Martin Reinecke's avatar
Martin Reinecke committed
26
def FFTSmoothingOperator(domain, sigma, space=None):
Martin Reinecke's avatar
Martin Reinecke committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    """ This function returns an operator that carries out a smoothing with
    a Gaussian kernel of width `sigma` on the part of `domain` given by
    `space`.

    Parameters
    ----------
    domain : Domain, tuple of Domains, or DomainTuple
       The total domain of the operator's input and output fields

    sigma : float>=0
       The sigma of the Gaussian used for smoothing. It has the same units as
       the RGSpace the operator is working on.
       If `sigma==0`, an identity operator will be returned.

    space: integer, *optional*
       The index of the sub-domain on which the smoothing is performed.
       Can be omitted if `domain` only has one sub-domain.

    Notes
    -----
       The sub-domain on which the smoothing is carried out *must* be a
       non-harmonic `RGSpace`.
    """

Martin Reinecke's avatar
Martin Reinecke committed
51
52
53
54
55
56
57
58
    sigma = float(sigma)
    if sigma < 0.:
        raise ValueError("sigma must be nonnegative")
    if sigma == 0.:
        return ScalingOperator(1., domain)

    domain = DomainTuple.make(domain)
    space = infer_space(domain, space)
59
60
    if domain[space].harmonic:
        raise TypeError("domain must not be harmonic")
Martin Reinecke's avatar
Martin Reinecke committed
61
    FFT = FFTOperator(domain, space=space)
Martin Reinecke's avatar
Martin Reinecke committed
62
63
64
65
66
67
68
    codomain = FFT.domain[space].get_default_codomain()
    kernel = codomain.get_k_length_array()
    smoother = codomain.get_fft_smoothing_kernel_function(sigma)
    kernel = smoother(kernel)
    ddom = list(domain)
    ddom[space] = codomain
    diag = DiagonalOperator(kernel, ddom, space)
69
    return FFT.inverse*diag*FFT