space.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
from ..domain_object import DomainObject
Theo Steininger's avatar
Theo Steininger committed
21

22

23
class Space(DomainObject):
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    """ The abstract base class for all NIFTy spaces.

    An instance of a space contains information about the manifolds
    geometry and enhances the functionality of DomainObject by methods that
    are needed for powerspectrum analysis and smoothing.

    Parameters
    ----------
    None

    Attributes
    ----------
    dim : np.int
        Total number of dimensionality, i.e. the number of pixels.
    harmonic : bool
        Specifies whether the space is a signal or harmonic space.
    shape : tuple of np.ints
        The shape of the space's data array.

    Raises
    ------
    TypeError
        Raised if instantiated directly.

    Notes
    -----
    `Space` is an abstract base class. In order to allow for instantiation
Martin Reinecke's avatar
Martin Reinecke committed
51
52
    the method `copy` must be implemented as well as the abstract methods
    inherited from `DomainObject`.
53
54

    """
55

56
    def __init__(self):
Martin Reinecke's avatar
Martin Reinecke committed
57
        super(Space, self).__init__()
58

59
60
    @abc.abstractproperty
    def harmonic(self):
Theo Steininger's avatar
Theo Steininger committed
61
        """ Returns True if this space is a harmonic space.
62
        """
63
        raise NotImplementedError
64

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

69
70
        Returns
        -------
Martin Reinecke's avatar
stage1    
Martin Reinecke committed
71
        numpy.ndarray
Martin Reinecke's avatar
Martin Reinecke committed
72
            An array containing the  k vector lengths
Theo Steininger's avatar
Theo Steininger committed
73

74
        """
Martin Reinecke's avatar
Martin Reinecke committed
75
        raise NotImplementedError
76

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

84
    def get_fft_smoothing_kernel_function(self, sigma):
Theo Steininger's avatar
Theo Steininger committed
85
86
87
88
89
90
91
92
        """ This method returns a smoothing kernel function.

        This method, which is only implemented for harmonic spaces, helps
        smoothing fields that live in a position space that has this space as
        its harmonic space. 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.

93
94
        Parameters
        ----------
Theo Steininger's avatar
Theo Steininger committed
95
96
97
98
99
100
101
102
        sigma : float
            A real number representing a physical scale on which the smoothing
            takes place. The smoothing is defined with respect to the real
            physical field and points that are closer together than one sigma
            are blurred together. Mathematically sigma is the standard
            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
108
        function (array-like -> array-like)
            A smoothing operation that multiplies values with a Gaussian
            kernel.

109
        """
Theo Steininger's avatar
Theo Steininger committed
110

111
112
        raise NotImplementedError(
            "There is no generic co-smoothing kernel for Space base class.")