structured_domain.py 3.94 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
#
Martin Reinecke's avatar
Martin Reinecke committed
14
# Copyright(C) 2013-2018 Max-Planck-Society
Theo Steininger's avatar
Theo Steininger committed
15
16
17
#
# 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
from __future__ import absolute_import, division, print_function
from ..compat import *
21
import abc
Martin Reinecke's avatar
Martin Reinecke committed
22
23
from .domain import Domain
import numpy as np
Theo Steininger's avatar
Theo Steininger committed
24

25

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

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

Martin Reinecke's avatar
Martin Reinecke committed
34
    @abc.abstractproperty
Martin Reinecke's avatar
Martin Reinecke committed
35
    def scalar_dvol(self):
Martin Reinecke's avatar
Martin Reinecke committed
36
37
38
        """float or None : uniform cell volume, if applicable

        Returns the volume factors of this domain as a floating
Martin Reinecke's avatar
Martin Reinecke committed
39
40
41
42
43
        point scalar, if the volume factors are all identical, otherwise
        returns None.
        """
        raise NotImplementedError

Martin Reinecke's avatar
Martin Reinecke committed
44
    @property
Martin Reinecke's avatar
Martin Reinecke committed
45
    def dvol(self):
Martin Reinecke's avatar
Martin Reinecke committed
46
47
48
        """float or numpy.ndarray(dtype=float): Volume factors

        Returns the volume factors of this domain, either as a floating
Martin Reinecke's avatar
Martin Reinecke committed
49
50
51
        point scalar (if the volume factors are all identical) or as a
        floating point array with a shape of `self.shape`.
        """
Martin Reinecke's avatar
Martin Reinecke committed
52
        return self.scalar_dvol
Martin Reinecke's avatar
Martin Reinecke committed
53

Martin Reinecke's avatar
Martin Reinecke committed
54
    @property
Martin Reinecke's avatar
Martin Reinecke committed
55
    def total_volume(self):
Martin Reinecke's avatar
Martin Reinecke committed
56
        """float : Total domain volume
Martin Reinecke's avatar
Martin Reinecke committed
57

Martin Reinecke's avatar
Martin Reinecke committed
58
        Returns the sum over all the domain's pixel volumes.
Martin Reinecke's avatar
Martin Reinecke committed
59
        """
Martin Reinecke's avatar
Martin Reinecke committed
60
        tmp = self.dvol
Martin Reinecke's avatar
Martin Reinecke committed
61
        return self.size * tmp if np.isscalar(tmp) else np.sum(tmp)
62

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

68
    def get_k_length_array(self):
Martin Reinecke's avatar
Martin Reinecke committed
69
70
71
        """k vector lengths, if applicable,

        Returns the length of the k vector for every pixel.
Martin Reinecke's avatar
Martin Reinecke committed
72
        This method is only implemented for harmonic domains.
Theo Steininger's avatar
Theo Steininger committed
73

74
75
        Returns
        -------
76
        Field
77
            An array containing the k vector lengths
78
        """
Martin Reinecke's avatar
Martin Reinecke committed
79
        raise NotImplementedError
80

81
    def get_unique_k_lengths(self):
Martin Reinecke's avatar
Martin Reinecke committed
82
83
84
        """Sorted unique k-vector lengths, if applicable.

        Returns an array of floats containing the unique k vector lengths
Martin Reinecke's avatar
Martin Reinecke committed
85
86
        for this domain.
        This method is only implemented for harmonic domains.
Martin Reinecke's avatar
Martin Reinecke committed
87
        """
Martin Reinecke's avatar
Martin Reinecke committed
88
89
        raise NotImplementedError

90
    def get_fft_smoothing_kernel_function(self, sigma):
Martin Reinecke's avatar
Martin Reinecke committed
91
        """Helper for Gaussian smoothing.
Theo Steininger's avatar
Theo Steininger committed
92

Martin Reinecke's avatar
Martin Reinecke committed
93
94
95
96
97
98
        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
99

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

108
109
        Returns
        -------
Theo Steininger's avatar
Theo Steininger committed
110
111
112
        function (array-like -> array-like)
            A smoothing operation that multiplies values with a Gaussian
            kernel.
113
        """
Martin Reinecke's avatar
Martin Reinecke committed
114
        raise NotImplementedError