Commit ff879f9c authored by Martin Reinecke's avatar Martin Reinecke

lots of simplifications

parent d4a9bd66
Pipeline #25104 passed with stages
in 6 minutes and 43 seconds
......@@ -28,10 +28,7 @@ if __name__ == "__main__":
sh = ift.power_synthesize(sp, real_signal=True)
# Choose the measurement instrument
# Instrument = SmoothingOperator(s_space, sigma=0.01)
Instrument = ift.ScalingOperator(1., s_space)
# Instrument._diagonal.val[200:400, 200:400] = 0
# Instrument._diagonal.val[64:512-64, 64:512-64] = 0
# Add a harmonic transformation to the instrument
R = Instrument*HT
......@@ -40,10 +37,7 @@ if __name__ == "__main__":
signal_to_noise = 1.
noise_amplitude = noiseless_data.val.std()/signal_to_noise
N = ift.ScalingOperator(noise_amplitude**2, s_space)
n = ift.Field.from_random(domain=s_space,
random_type='normal',
std=noise_amplitude,
mean=0)
n = ift.Field.from_random("normal", s_space, std=noise_amplitude, mean=0)
# Create mock data
d = noiseless_data + n
......@@ -54,7 +48,6 @@ if __name__ == "__main__":
binbounds=p_space.binbounds))
data_power = ift.log(ift.power_analyze(HT.adjoint_times(d),
binbounds=p_space.binbounds))
d_data = d.val
plotdict = {"colormap": "Planck-like"}
ift.plot(d, name="data.png", **plotdict)
ift.plot(HT(sh), name="mock_signal.png", **plotdict)
......
......@@ -34,7 +34,7 @@ if __name__ == "__main__":
else:
raise NotImplementedError
diag = ift.Field.from_global_data(s_space, diag).lock()
diag = ift.Field.from_global_data(s_space, diag)
Instrument = ift.DiagonalOperator(diag)
# Add harmonic transformation to the instrument
......
......@@ -17,13 +17,11 @@
# and financially supported by the Studienstiftung des deutschen Volkes.
import abc
from ..utilities import NiftyMeta
from future.utils import with_metaclass
from ..utilities import NiftyMetaBase
import numpy as np
class Domain(with_metaclass(
NiftyMeta, type('NewBase', (object,), {}))):
class Domain(NiftyMetaBase()):
"""The abstract class repesenting a (structured or unstructured) domain.
"""
......
......@@ -16,11 +16,10 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from ..utilities import memo, NiftyMeta
from future.utils import with_metaclass
from ..utilities import memo, NiftyMetaBase
class Energy(with_metaclass(NiftyMeta, type('NewBase', (object,), {}))):
class Energy(NiftyMetaBase()):
""" Provides the functional used by minimization schemes.
The Energy object is an implementation of a scalar function including its
......
......@@ -18,12 +18,10 @@
from builtins import range
import abc
from ..utilities import NiftyMeta
from future.utils import with_metaclass
from ..utilities import NiftyMetaBase
class IterationController(with_metaclass(NiftyMeta, type('NewBase',
(object,), {}))):
class IterationController(NiftyMetaBase()):
"""The abstract base class for all iteration controllers.
An iteration controller is an object that monitors the progress of a
minimization iteration. At the begin of the minimization, its start()
......
......@@ -17,13 +17,10 @@
# and financially supported by the Studienstiftung des deutschen Volkes.
import abc
from future.utils import with_metaclass
from ..utilities import NiftyMetaBase
class LineSearch(with_metaclass(abc.ABCMeta,
with_metaclass(abc.ABCMeta,
type('NewBase',
(object,), {})))):
class LineSearch(NiftyMetaBase()):
"""Class for determining the optimal step size along some descent direction.
Initialize the line search procedure which can be used by a specific line
......
......@@ -17,11 +17,10 @@
# and financially supported by the Studienstiftung des deutschen Volkes.
import abc
from ..utilities import NiftyMeta
from future.utils import with_metaclass
from ..utilities import NiftyMetaBase
class Minimizer(with_metaclass(NiftyMeta, type('NewBase', (object,), {}))):
class Minimizer(NiftyMetaBase()):
""" A base class used by all minimizers."""
@abc.abstractmethod
......
......@@ -64,12 +64,10 @@ class InversionEnabler(LinearOperator):
if self._op.capability & mode:
return self._op.apply(x, mode)
tdom = self._tgt(mode)
x0 = Field.zeros(tdom, dtype=x.dtype)
def func(x):
return self._op.apply(x, self._inverseMode[mode])
x0 = Field.zeros(self._tgt(mode), dtype=x.dtype)
energy = QuadraticEnergy(A=func, b=x, position=x0)
r, stat = self._inverter(energy, preconditioner=self._preconditioner)
if stat != IterationController.CONVERGED:
......
......@@ -17,14 +17,12 @@
# and financially supported by the Studienstiftung des deutschen Volkes.
import abc
from ..utilities import NiftyMeta
from ..utilities import NiftyMetaBase
from ..field import Field
from future.utils import with_metaclass
import numpy as np
class LinearOperator(with_metaclass(
NiftyMeta, type('NewBase', (object,), {}))):
class LinearOperator(NiftyMetaBase()):
"""NIFTY base class for linear operators.
The base NIFTY operator class is an abstract class from which
......
......@@ -20,8 +20,12 @@ from builtins import next, range
import numpy as np
from itertools import product
import abc
from future.utils import with_metaclass
__all__ = ["get_slice_list", "safe_cast", "parse_spaces", "infer_space",
"memo", "NiftyMetaBase", "hartley", "my_fftn_r2c"]
def get_slice_list(shape, axes):
"""
Helper function which generates slice list(s) to traverse over all
......@@ -150,6 +154,10 @@ class NiftyMeta(_DocStringInheritor, abc.ABCMeta):
pass
def NiftyMetaBase():
return with_metaclass(NiftyMeta, type('NewBase', (object,), {}))
def hartley(a, axes=None):
# Check if the axes provided are valid given the shape
if axes is not None and \
......
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