space.py 5.06 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
20
import abc

Martin Reinecke's avatar
Martin Reinecke committed
21
from ...domain_object import DomainObject
Ultimanet's avatar
Ultimanet committed
22

23

24
class Space(DomainObject):
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
51
52
53
54
55
56
57
58
    """ 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.
    total_volume : np.float
        The total volume of the 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
    the methods `get_distance_array`, `total_volume` and `copy` must be
    implemented as well as the abstract methods inherited from
    `DomainObject`.

    """
59

60
    def __init__(self):
Theo Steininger's avatar
Theo Steininger committed
61

Martin Reinecke's avatar
Martin Reinecke committed
62
        super(Space, self).__init__()
theos's avatar
theos committed
63

64
65
    @abc.abstractproperty
    def harmonic(self):
Theo Steininger's avatar
Theo Steininger committed
66
        """ Returns True if this space is a harmonic space.
67
        """
Theo Steininger's avatar
Theo Steininger committed
68

69
        raise NotImplementedError
70

71
    @abc.abstractproperty
72
    def total_volume(self):
Theo Steininger's avatar
Theo Steininger committed
73
74
        """ Returns the total volume of the space.

75
76
        Returns
        -------
Theo Steininger's avatar
Theo Steininger committed
77
78
79
        float
            A real number representing the sum of all pixel volumes.

80
        """
81

82
83
        raise NotImplementedError(
            "There is no generic volume for the Space base class.")
84

85
86
    @abc.abstractmethod
    def copy(self):
Theo Steininger's avatar
Theo Steininger committed
87
88
        """ Returns a copy of this Space instance.

89
90
        Returns
        -------
Theo Steininger's avatar
Theo Steininger committed
91
92
93
        Space
            A copy of this instance.

94
        """
Theo Steininger's avatar
Theo Steininger committed
95

Martin Reinecke's avatar
Martin Reinecke committed
96
        return self.__class__()
97

Martin Reinecke's avatar
stage1    
Martin Reinecke committed
98
    def get_distance_array(self):
Theo Steininger's avatar
Theo Steininger committed
99
100
101
102
103
        """ The distances of the pixel to zero.

        This returns an array that gives for each pixel its distance to the
        center of the manifolds grid.

104
105
        Returns
        -------
Martin Reinecke's avatar
stage1    
Martin Reinecke committed
106
107
        numpy.ndarray
            An array containing the distances
Theo Steininger's avatar
Theo Steininger committed
108

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

111
        raise NotImplementedError(
112
113
            "There is no generic distance structure for Space base class.")

Martin Reinecke's avatar
Martin Reinecke committed
114
115
116
117
118
119
120
121
    def get_unique_distances(self):
        raise NotImplementedError

    def get_natural_binbounds(self):
        """ The boundaries for natural power spectrum binning.

        Returns
        -------
Martin Reinecke's avatar
stage1    
Martin Reinecke committed
122
        np.ndarray
Martin Reinecke's avatar
Martin Reinecke committed
123
124
125
126
127
            A numpy array containing the binbounds

        """
        raise NotImplementedError

128
    def get_fft_smoothing_kernel_function(self, sigma):
Theo Steininger's avatar
Theo Steininger committed
129
130
131
132
133
134
135
136
        """ 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.

137
138
        Parameters
        ----------
Theo Steininger's avatar
Theo Steininger committed
139
140
141
142
143
144
145
146
        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.

147
148
        Returns
        -------
Theo Steininger's avatar
Theo Steininger committed
149
150
151
152
        function (array-like -> array-like)
            A smoothing operation that multiplies values with a Gaussian
            kernel.

153
        """
Theo Steininger's avatar
Theo Steininger committed
154

155
156
        raise NotImplementedError(
            "There is no generic co-smoothing kernel for Space base class.")
157

158
159
160
161
162
    def hermitianize_inverter(self, x, axes):
        """ Inverts/flips x in the context of Hermitian decomposition.

        This method is mainly used for power-synthesizing and -analyzing
        Fields.
Theo Steininger's avatar
Theo Steininger committed
163

164
165
        Parameters
        ----------
Theo Steininger's avatar
Theo Steininger committed
166
167
168
        axes : tuple of ints
            Specifies the axes of x which correspond to this space.

169
170
        Returns
        -------
Martin Reinecke's avatar
stage1    
Martin Reinecke committed
171
        numpy.ndarray
172
            The Hermitian-flipped of x.
173
        """
Theo Steininger's avatar
Theo Steininger committed
174

175
        return x