Commit cb5ac9c6 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

comment cleanup

parent c8928a36
Pipeline #19541 passed with stage
in 4 minutes and 11 seconds
...@@ -20,6 +20,7 @@ from builtins import range ...@@ -20,6 +20,7 @@ from builtins import range
from .linear_operator import LinearOperator from .linear_operator import LinearOperator
from .. import DomainTuple from .. import DomainTuple
class ComposedOperator(LinearOperator): class ComposedOperator(LinearOperator):
""" NIFTY class for composed operators. """ NIFTY class for composed operators.
...@@ -46,27 +47,6 @@ class ComposedOperator(LinearOperator): ...@@ -46,27 +47,6 @@ class ComposedOperator(LinearOperator):
Raised if Raised if
* an element of the operator list is not an instance of the * an element of the operator list is not an instance of the
LinearOperator base class. LinearOperator base class.
Notes
-----
Very useful in case one has to transform a Field living over a product
space (see example below).
Examples
--------
Minimal example of transforming a Field living on two domains into its
harmonic space.
>>> x1 = RGSpace(5)
>>> x2 = RGSpace(10)
>>> k1 = RGRGTransformation.get_codomain(x1)
>>> k2 = RGRGTransformation.get_codomain(x2)
>>> FFT1 = FFTOperator(domain=(x1,x2), target=(k1,x2), space=0)
>>> FFT2 = FFTOperator(domain=(k1,x2), target=(k1,k2), space=1)
>>> FFT = ComposedOperator((FFT1, FFT2)
>>> f = Field.from_random('normal', domain=(x1,x2))
>>> FFT.times(f)
""" """
# ---Overwritten properties and methods--- # ---Overwritten properties and methods---
......
...@@ -31,7 +31,6 @@ class DiagonalOperator(EndomorphicOperator): ...@@ -31,7 +31,6 @@ class DiagonalOperator(EndomorphicOperator):
EndomorphicOperator. It multiplies an input field pixel-wise with its EndomorphicOperator. It multiplies an input field pixel-wise with its
diagonal. diagonal.
Parameters Parameters
---------- ----------
diagonal : Field diagonal : Field
...@@ -55,14 +54,15 @@ class DiagonalOperator(EndomorphicOperator): ...@@ -55,14 +54,15 @@ class DiagonalOperator(EndomorphicOperator):
self_adjoint : boolean self_adjoint : boolean
Indicates whether the operator is self_adjoint or not. Indicates whether the operator is self_adjoint or not.
NOTE: the fields given to __init__ and returned from .diagonal() are
considered to be bare, i.e. during operator application, the colume factors
are applied explicitly.
See Also See Also
-------- --------
EndomorphicOperator EndomorphicOperator
""" """
# ---Overwritten properties and methods---
def __init__(self, diagonal, domain=None, spaces=None): def __init__(self, diagonal, domain=None, spaces=None):
super(DiagonalOperator, self).__init__() super(DiagonalOperator, self).__init__()
...@@ -113,12 +113,9 @@ class DiagonalOperator(EndomorphicOperator): ...@@ -113,12 +113,9 @@ class DiagonalOperator(EndomorphicOperator):
------- -------
out : Field out : Field
The diagonal of the Operator. The diagonal of the Operator.
""" """
return self._diagonal.weight(-1) return self._diagonal.weight(-1)
# ---Mandatory properties and methods---
@property @property
def domain(self): def domain(self):
return self._domain return self._domain
...@@ -138,8 +135,6 @@ class DiagonalOperator(EndomorphicOperator): ...@@ -138,8 +135,6 @@ class DiagonalOperator(EndomorphicOperator):
self._unitary = (abs(self._diagonal.val) == 1.).all() self._unitary = (abs(self._diagonal.val) == 1.).all()
return self._unitary return self._unitary
# ---Added properties and methods---
def _times_helper(self, x, operation): def _times_helper(self, x, operation):
if self._spaces is None: if self._spaces is None:
return operation(self._diagonal)(x) return operation(self._diagonal)(x)
......
...@@ -71,7 +71,6 @@ class DirectSmoothingOperator(EndomorphicOperator): ...@@ -71,7 +71,6 @@ class DirectSmoothingOperator(EndomorphicOperator):
wgt[i] is an array with nval[i] entries containing the wgt[i] is an array with nval[i] entries containing the
normalized smoothing weights. normalized smoothing weights.
""" """
dxmax = self._effective_smoothing_width*self._sigma dxmax = self._effective_smoothing_width*self._sigma
x = np.asarray(x) x = np.asarray(x)
......
...@@ -38,17 +38,8 @@ class EndomorphicOperator(LinearOperator): ...@@ -38,17 +38,8 @@ class EndomorphicOperator(LinearOperator):
Indicates whether the Operator is unitary or not. Indicates whether the Operator is unitary or not.
self_adjoint : boolean self_adjoint : boolean
Indicates whether the operator is self_adjoint or not. Indicates whether the operator is self_adjoint or not.
Raises
------
NotImplementedError
Raised if
* self_adjoint is not defined
""" """
# ---Overwritten properties and methods---
def inverse_times(self, x): def inverse_times(self, x):
if self.self_adjoint and self.unitary: if self.self_adjoint and self.unitary:
return self.times(x) return self.times(x)
...@@ -73,17 +64,11 @@ class EndomorphicOperator(LinearOperator): ...@@ -73,17 +64,11 @@ class EndomorphicOperator(LinearOperator):
else: else:
return super(EndomorphicOperator, self).inverse_adjoint_times(x) return super(EndomorphicOperator, self).inverse_adjoint_times(x)
# ---Mandatory properties and methods---
@property @property
def target(self): def target(self):
return self.domain return self.domain
# ---Added properties and methods---
@abc.abstractproperty @abc.abstractproperty
def self_adjoint(self): def self_adjoint(self):
""" States whether the Operator is self_adjoint or not. """ States whether the Operator is self_adjoint or not."""
"""
raise NotImplementedError raise NotImplementedError
...@@ -91,8 +91,6 @@ class FFTOperator(LinearOperator): ...@@ -91,8 +91,6 @@ class FFTOperator(LinearOperator):
(LMSpace, GLSpace): LMGLTransformation (LMSpace, GLSpace): LMGLTransformation
} }
# ---Overwritten properties and methods---
def __init__(self, domain, target=None, space=None): def __init__(self, domain, target=None, space=None):
super(FFTOperator, self).__init__() super(FFTOperator, self).__init__()
...@@ -141,8 +139,6 @@ class FFTOperator(LinearOperator): ...@@ -141,8 +139,6 @@ class FFTOperator(LinearOperator):
def _adjoint_times(self, x): def _adjoint_times(self, x):
return self._times_helper(x, self.domain, self._backward_transformation) return self._times_helper(x, self.domain, self._backward_transformation)
# ---Mandatory properties and methods---
@property @property
def domain(self): def domain(self):
return self._domain return self._domain
......
...@@ -32,7 +32,6 @@ class FFTSmoothingOperator(EndomorphicOperator): ...@@ -32,7 +32,6 @@ class FFTSmoothingOperator(EndomorphicOperator):
return self._smooth(x) return self._smooth(x)
# ---Mandatory properties and methods---
@property @property
def domain(self): def domain(self):
return self._transformator.domain return self._transformator.domain
...@@ -45,8 +44,6 @@ class FFTSmoothingOperator(EndomorphicOperator): ...@@ -45,8 +44,6 @@ class FFTSmoothingOperator(EndomorphicOperator):
def unitary(self): def unitary(self):
return False return False
# ---Added properties and methods---
def _smooth(self, x): def _smooth(self, x):
# transform to the (global-)default codomain and perform all remaining # transform to the (global-)default codomain and perform all remaining
# steps therein # steps therein
......
...@@ -24,18 +24,17 @@ from ..field import Field ...@@ -24,18 +24,17 @@ from ..field import Field
class InvertibleOperatorMixin(object): class InvertibleOperatorMixin(object):
""" Mixin class to invert implicit defined operators. """ Mixin class to invert implicit defined operators.
To invert the application of a given implicitly defined operator on a This class provides the functionality necessary to invert the application
field, this class gives the necessary functionality. Inheriting of a given implicitly defined operator on a field. Inheriting
functionality from this class provides the derived class with the inverse functionality from this class provides the derived class with the
to the given implicitly definied application of the operator on a field. operations inverse to the defined operator applications
(e.g. .inverse_times vs. .times and (e.g. .inverse_times if .times is defined and
.adjoint_times vs. .adjoint_inverse_times) .adjoint_times if .adjoint_inverse_times is defined)
Parameters Parameters
---------- ----------
inverter : Inverter inverter : Inverter
An instance of an Inverter class. An instance of an Inverter class.
""" """
def __init__(self, inverter, preconditioner=None, def __init__(self, inverter, preconditioner=None,
......
...@@ -28,7 +28,7 @@ class LaplaceOperator(EndomorphicOperator): ...@@ -28,7 +28,7 @@ class LaplaceOperator(EndomorphicOperator):
"""An irregular LaplaceOperator with free boundary and excluding monopole. """An irregular LaplaceOperator with free boundary and excluding monopole.
This LaplaceOperator implements the second derivative of a Field in This LaplaceOperator implements the second derivative of a Field in
PowerSpace on logarithmic or linear scale with vanishing curvature at the PowerSpace on logarithmic or linear scale with vanishing curvature at the
boundary, starting at the second entry of the Field. The second derivative boundary, starting at the second entry of the Field. The second derivative
of the Field on the irregular grid is calculated using finite differences. of the Field on the irregular grid is calculated using finite differences.
...@@ -37,6 +37,8 @@ class LaplaceOperator(EndomorphicOperator): ...@@ -37,6 +37,8 @@ class LaplaceOperator(EndomorphicOperator):
logarithmic : boolean, logarithmic : boolean,
Whether smoothness is calculated on a logarithmic scale or linear scale Whether smoothness is calculated on a logarithmic scale or linear scale
default : True default : True
space : int
The index of the domain on which the operator acts
""" """
def __init__(self, domain, space=None, logarithmic=True): def __init__(self, domain, space=None, logarithmic=True):
...@@ -70,10 +72,6 @@ class LaplaceOperator(EndomorphicOperator): ...@@ -70,10 +72,6 @@ class LaplaceOperator(EndomorphicOperator):
self._dposc[1:] += self._dpos self._dposc[1:] += self._dpos
self._dposc *= 0.5 self._dposc *= 0.5
@property
def target(self):
return self._domain
@property @property
def domain(self): def domain(self):
return self._domain return self._domain
......
...@@ -40,14 +40,6 @@ class LinearOperator(with_metaclass( ...@@ -40,14 +40,6 @@ class LinearOperator(with_metaclass(
The domain in which the Operators result lives. The domain in which the Operators result lives.
unitary : boolean unitary : boolean
Indicates whether the Operator is unitary or not. Indicates whether the Operator is unitary or not.
Raises
------
NotImplementedError
Raised if
* domain is not defined
* target is not defined
* unitary is not set to (True/False)
""" """
def __init__(self): def __init__(self):
...@@ -56,7 +48,7 @@ class LinearOperator(with_metaclass( ...@@ -56,7 +48,7 @@ class LinearOperator(with_metaclass(
@abc.abstractproperty @abc.abstractproperty
def domain(self): def domain(self):
""" """
domain : tuple of DomainObjects, i.e. Spaces and FieldTypes domain : DomainTuple
The domain on which the Operator's input Field lives. The domain on which the Operator's input Field lives.
Every Operator which inherits from the abstract LinearOperator Every Operator which inherits from the abstract LinearOperator
base class must have this attribute. base class must have this attribute.
...@@ -66,7 +58,7 @@ class LinearOperator(with_metaclass( ...@@ -66,7 +58,7 @@ class LinearOperator(with_metaclass(
@abc.abstractproperty @abc.abstractproperty
def target(self): def target(self):
""" """
target : tuple of DomainObjects, i.e. Spaces and FieldTypes target : DomainTuple
The domain on which the Operator's output Field lives. The domain on which the Operator's output Field lives.
Every Operator which inherits from the abstract LinearOperator Every Operator which inherits from the abstract LinearOperator
base class must have this attribute. base class must have this attribute.
...@@ -89,35 +81,31 @@ class LinearOperator(with_metaclass( ...@@ -89,35 +81,31 @@ class LinearOperator(with_metaclass(
def times(self, x): def times(self, x):
""" Applies the Operator to a given Field. """ Applies the Operator to a given Field.
Operator and Field have to live over the same domain.
Parameters Parameters
---------- ----------
x : Field x : Field
The input Field. The input Field, living on the Operator's domain.
Returns Returns
------- -------
out : Field out : Field
The processed Field living on the target-domain. The processed Field living on the Operator's target domain.
""" """
self._check_input_compatibility(x) self._check_input_compatibility(x)
return self._times(x) return self._times(x)
def inverse_times(self, x): def inverse_times(self, x):
""" Applies the inverse-Operator to a given Field. """Applies the inverse Operator to a given Field.
Operator and Field have to live over the same domain.
Parameters Parameters
---------- ----------
x : Field x : Field
The input Field. The input Field, living on the Operator's target domain
Returns Returns
------- -------
out : Field out : Field
The processed Field living on the target-domain. The processed Field living on the Operator's domain.
""" """
self._check_input_compatibility(x, inverse=True) self._check_input_compatibility(x, inverse=True)
try: try:
...@@ -130,21 +118,18 @@ class LinearOperator(with_metaclass( ...@@ -130,21 +118,18 @@ class LinearOperator(with_metaclass(
return y return y
def adjoint_times(self, x): def adjoint_times(self, x):
""" Applies the adjoint-Operator to a given Field. """Applies the adjoint-Operator to a given Field.
Operator and Field have to live over the same domain.
Parameters Parameters
---------- ----------
x : Field x : Field
applies the Operator to the given Field The input Field, living on the Operator's target domain
Returns Returns
------- -------
out : Field out : Field
The processed Field living on the target-domain. The processed Field living on the Operator's domain.
""" """
if self.unitary: if self.unitary:
return self.inverse_times(x) return self.inverse_times(x)
...@@ -161,17 +146,15 @@ class LinearOperator(with_metaclass( ...@@ -161,17 +146,15 @@ class LinearOperator(with_metaclass(
def adjoint_inverse_times(self, x): def adjoint_inverse_times(self, x):
""" Applies the adjoint-inverse Operator to a given Field. """ Applies the adjoint-inverse Operator to a given Field.
Operator and Field have to live over the same domain.
Parameters Parameters
---------- ----------
x : Field x : Field
applies the Operator to the given Field The input Field, living on the Operator's domain.
Returns Returns
------- -------
out : Field out : Field
The processed Field living on the target-domain. The processed Field living on the Operator's target domain.
Notes Notes
----- -----
......
...@@ -27,8 +27,6 @@ class SmoothnessOperator(EndomorphicOperator): ...@@ -27,8 +27,6 @@ class SmoothnessOperator(EndomorphicOperator):
default : True default : True
""" """
# ---Overwritten properties and methods---
def __init__(self, domain, strength=1., logarithmic=True, space=None): def __init__(self, domain, strength=1., logarithmic=True, space=None):
super(SmoothnessOperator, self).__init__() super(SmoothnessOperator, self).__init__()
self._laplace = LaplaceOperator(domain, self._laplace = LaplaceOperator(domain,
...@@ -38,8 +36,6 @@ class SmoothnessOperator(EndomorphicOperator): ...@@ -38,8 +36,6 @@ class SmoothnessOperator(EndomorphicOperator):
raise ValueError("ERROR: invalid sigma.") raise ValueError("ERROR: invalid sigma.")
self._strength = strength self._strength = strength
# ---Mandatory properties and methods---
@property @property
def domain(self): def domain(self):
return self._laplace._domain return self._laplace._domain
...@@ -64,8 +60,6 @@ class SmoothnessOperator(EndomorphicOperator): ...@@ -64,8 +60,6 @@ class SmoothnessOperator(EndomorphicOperator):
result = Field.zeros_like(x) result = Field.zeros_like(x)
return result return result
# ---Added properties and methods---
@property @property
def logarithmic(self): def logarithmic(self):
return self._laplace.logarithmic return self._laplace.logarithmic
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment