structured_domain.py 3.75 KB
Newer Older
1
2
3
4
# 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.
5
#
6
7
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
8
9
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
11
# You should have received a copy of the GNU General Public License
12
# 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.
Marco Selig's avatar
Marco Selig committed
18

19
import abc
Martin Reinecke's avatar
Martin Reinecke committed
20
21
from .domain import Domain
import numpy as np
Theo Steininger's avatar
Theo Steininger committed
22

23

Martin Reinecke's avatar
Martin Reinecke committed
24
25
class StructuredDomain(Domain):
    """The abstract base class for all structured NIFTy domains.
26

Martin Reinecke's avatar
Martin Reinecke committed
27
    An instance of a space contains information about the manifold's
Martin Reinecke's avatar
Martin Reinecke committed
28
    geometry and enhances the functionality of Domain by methods that
Martin Reinecke's avatar
Martin Reinecke committed
29
    are needed for power spectrum analysis and smoothing.
30
    """
31

32
    def __init__(self):
Martin Reinecke's avatar
Martin Reinecke committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
        super(StructuredDomain, self).__init__()

    @abc.abstractmethod
    def scalar_dvol(self):
        """Returns the volume factors of this domain as a floating
        point scalar, if the volume factors are all identical, otherwise
        returns None.

        Returns
        -------
        float or None: Volume factor
        """
        raise NotImplementedError

    def dvol(self):
        """Returns the volume factors of this domain, either as a floating
        point scalar (if the volume factors are all identical) or as a
        floating point array with a shape of `self.shape`.

        Returns
        -------
        float or numpy.ndarray(dtype=float): Volume factors
        """
        return self.scalar_dvol()

    def total_volume(self):
        tmp = self.dvol()
        return self.size * tmp if np.isscalar(tmp) else np.sum(tmp)
61

62
63
    @abc.abstractproperty
    def harmonic(self):
Martin Reinecke's avatar
Martin Reinecke committed
64
        """ Returns True iff this domain is a harmonic domain."""
65
        raise NotImplementedError
66

67
    def get_k_length_array(self):
Martin Reinecke's avatar
Martin Reinecke committed
68
        """The length of the k vector for every pixel.
Martin Reinecke's avatar
Martin Reinecke committed
69
        This method is only implemented for harmonic domains.
Theo Steininger's avatar
Theo Steininger committed
70

71
72
        Returns
        -------
73
        Field
74
            An array containing the k vector lengths
75
        """
Martin Reinecke's avatar
Martin Reinecke committed
76
        raise NotImplementedError
77

78
    def get_unique_k_lengths(self):
Martin Reinecke's avatar
Martin Reinecke committed
79
        """ Returns an array of floats containing the unique k vector lengths
Martin Reinecke's avatar
Martin Reinecke committed
80
81
        for this domain.
        This method is only implemented for harmonic domains.
Martin Reinecke's avatar
Martin Reinecke committed
82
        """
Martin Reinecke's avatar
Martin Reinecke committed
83
84
        raise NotImplementedError

85
    def get_fft_smoothing_kernel_function(self, sigma):
Martin Reinecke's avatar
Martin Reinecke committed
86
        """This method returns a smoothing kernel function.
Theo Steininger's avatar
Theo Steininger committed
87

Martin Reinecke's avatar
Martin Reinecke committed
88
89
90
91
92
93
        This method, which is only implemented for harmonic domains, helps
        smoothing fields that live on a domain that has this domain as
        its harmonic partner. The returned function multiplies field values of
        a field with a zero centered Gaussian which corresponds to a
        convolution with a Gaussian kernel and sigma standard deviation in
        position space.
Theo Steininger's avatar
Theo Steininger committed
94

95
96
        Parameters
        ----------
Theo Steininger's avatar
Theo Steininger committed
97
98
        sigma : float
            A real number representing a physical scale on which the smoothing
Martin Reinecke's avatar
Martin Reinecke committed
99
            takes place. Mathematically sigma is the standard
Theo Steininger's avatar
Theo Steininger committed
100
101
102
            deviation of a convolution with a normalized, zero-centered
            Gaussian that takes place in position space.

103
104
        Returns
        -------
Theo Steininger's avatar
Theo Steininger committed
105
106
107
        function (array-like -> array-like)
            A smoothing operation that multiplies values with a Gaussian
            kernel.
108
        """
Martin Reinecke's avatar
Martin Reinecke committed
109
        raise NotImplementedError