From 15fc7b6d00497e9ab3361a61667b7ca4447c19ab Mon Sep 17 00:00:00 2001 From: Martin Reinecke <martin@mpa-garching.mpg.de> Date: Tue, 22 Aug 2017 14:10:19 +0200 Subject: [PATCH] remove factory method; create the proper operators directly --- demos/paper_demos/cartesian_wiener_filter.py | 2 +- .../response_operator/response_operator.py | 4 +-- .../operators/smoothing_operator/__init__.py | 3 +- .../smoothing_operator/smoothing_operator.py | 28 ------------------- .../test_operators/test_smoothing_operator.py | 17 +++++------ 5 files changed, 14 insertions(+), 40 deletions(-) diff --git a/demos/paper_demos/cartesian_wiener_filter.py b/demos/paper_demos/cartesian_wiener_filter.py index 89c5e4f48..4a932bdee 100644 --- a/demos/paper_demos/cartesian_wiener_filter.py +++ b/demos/paper_demos/cartesian_wiener_filter.py @@ -130,7 +130,7 @@ if __name__ == "__main__": plotter.plot.zmin = 0. plotter.plot.zmax = 3. - sm = ift.SmoothingOperator.make(plot_space, sigma=0.03) + sm = ift.FFTSmoothingOperator(plot_space, sigma=0.03) plotter(ift.log(ift.sqrt(sm(ift.Field(plot_space, val=variance.val.real)))), path='uncertainty.html') plotter.plot.zmin = np.real(mock_signal.min()); diff --git a/nifty/operators/response_operator/response_operator.py b/nifty/operators/response_operator/response_operator.py index f331d351f..78cb905d6 100644 --- a/nifty/operators/response_operator/response_operator.py +++ b/nifty/operators/response_operator/response_operator.py @@ -3,7 +3,7 @@ import numpy as np from nifty import Field,\ FieldArray from nifty.operators.linear_operator import LinearOperator -from nifty.operators.smoothing_operator import SmoothingOperator +from nifty.operators.smoothing_operator import FFTSmoothingOperator from nifty.operators.composed_operator import ComposedOperator from nifty.operators.diagonal_operator import DiagonalOperator @@ -81,7 +81,7 @@ class ResponseOperator(LinearOperator): "exposure do not match") for ii in range(len(kernel_smoothing)): - kernel_smoothing[ii] = SmoothingOperator.make(self._domain[ii], + kernel_smoothing[ii] = FFTSmoothingOperator(self._domain[ii], sigma=sigma[ii]) kernel_exposure[ii] = DiagonalOperator(self._domain[ii], diagonal=exposure[ii]) diff --git a/nifty/operators/smoothing_operator/__init__.py b/nifty/operators/smoothing_operator/__init__.py index c0eb24343..05acc9449 100644 --- a/nifty/operators/smoothing_operator/__init__.py +++ b/nifty/operators/smoothing_operator/__init__.py @@ -16,4 +16,5 @@ # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik # and financially supported by the Studienstiftung des deutschen Volkes. -from .smoothing_operator import SmoothingOperator +from .fft_smoothing_operator import FFTSmoothingOperator +from .direct_smoothing_operator import DirectSmoothingOperator diff --git a/nifty/operators/smoothing_operator/smoothing_operator.py b/nifty/operators/smoothing_operator/smoothing_operator.py index 3a16ae24b..a7b17e697 100644 --- a/nifty/operators/smoothing_operator/smoothing_operator.py +++ b/nifty/operators/smoothing_operator/smoothing_operator.py @@ -83,34 +83,6 @@ class SmoothingOperator(EndomorphicOperator): """ - @staticmethod - def make(domain, sigma, log_distances=False, default_spaces=None): - _fft_smoothing_spaces = [RGSpace, - GLSpace, - HPSpace] - _direct_smoothing_spaces = [PowerSpace] - - domain = SmoothingOperator._parse_domain(domain) - - if len(domain) != 1: - raise ValueError("SmoothingOperator only accepts exactly one " - "space as input domain.") - - if np.any([isinstance(domain[0], sp) - for sp in _fft_smoothing_spaces]): - from .fft_smoothing_operator import FFTSmoothingOperator - return FFTSmoothingOperator (domain, sigma, default_spaces) - - elif np.any([isinstance(domain[0], sp) - for sp in _direct_smoothing_spaces]): - from .direct_smoothing_operator import DirectSmoothingOperator - return DirectSmoothingOperator (domain, sigma, log_distances,\ - default_spaces) - - else: - raise NotImplementedError("For the given Space smoothing " - " is not available.") - # ---Overwritten properties and methods--- def __init__(self, domain, sigma, log_distances=False, default_spaces=None): diff --git a/test/test_operators/test_smoothing_operator.py b/test/test_operators/test_smoothing_operator.py index 8c632ccaf..6869ebe96 100644 --- a/test/test_operators/test_smoothing_operator.py +++ b/test/test_operators/test_smoothing_operator.py @@ -23,7 +23,8 @@ from numpy.testing import assert_equal, assert_allclose from nifty import Field,\ RGSpace,\ PowerSpace,\ - SmoothingOperator + FFTSmoothingOperator,\ + DirectSmoothingOperator from itertools import product from test.common import expand @@ -40,7 +41,7 @@ class SmoothingOperator_Tests(unittest.TestCase): @expand(product(spaces, [0., .5, 5.])) def test_property(self, space, sigma): - op = SmoothingOperator.make(space, sigma=sigma) + op = FFTSmoothingOperator(space, sigma=sigma) if op.domain[0] != space: raise TypeError if op.unitary != False: @@ -54,7 +55,7 @@ class SmoothingOperator_Tests(unittest.TestCase): @expand(product(spaces, [0., .5, 5.])) def test_adjoint_times(self, space, sigma): - op = SmoothingOperator.make(space, sigma=sigma) + op = FFTSmoothingOperator(space, sigma=sigma) rand1 = Field.from_random('normal', domain=space) rand2 = Field.from_random('normal', domain=space) tt1 = rand1.vdot(op.times(rand2)) @@ -63,7 +64,7 @@ class SmoothingOperator_Tests(unittest.TestCase): @expand(product(spaces, [0., .5, 5.])) def test_times(self, space, sigma): - op = SmoothingOperator.make(space, sigma=sigma) + op = FFTSmoothingOperator(space, sigma=sigma) rand1 = Field(space, val=0.) rand1.val[0] = 1. tt1 = op.times(rand1) @@ -74,7 +75,7 @@ class SmoothingOperator_Tests(unittest.TestCase): def test_smooth_regular1(self, sz, d, sigma, tp): tol = _get_rtol(tp) sp = RGSpace(sz, harmonic=True, distances=d) - smo = SmoothingOperator.make(sp, sigma=sigma) + smo = FFTSmoothingOperator(sp, sigma=sigma) inp = Field.from_random(domain=sp, random_type='normal', std=1, mean=4, dtype=tp) out = smo(inp) @@ -86,7 +87,7 @@ class SmoothingOperator_Tests(unittest.TestCase): def test_smooth_regular2(self, sz1, sz2, d1, d2, sigma, tp): tol = _get_rtol(tp) sp = RGSpace([sz1, sz2], distances=[d1, d2], harmonic=True) - smo = SmoothingOperator.make(sp, sigma=sigma) + smo = FFTSmoothingOperator(sp, sigma=sigma) inp = Field.from_random(domain=sp, random_type='normal', std=1, mean=4, dtype=tp) out = smo(inp) @@ -99,7 +100,7 @@ class SmoothingOperator_Tests(unittest.TestCase): tol = _get_rtol(tp) sp = RGSpace(sz, harmonic=True) ps = PowerSpace(sp, nbin=sz, logarithmic=log) - smo = SmoothingOperator.make(ps, sigma=sigma) + smo = DirectSmoothingOperator(ps, sigma=sigma) inp = Field.from_random(domain=ps, random_type='normal', std=1, mean=4, dtype=tp) out = smo(inp) @@ -112,7 +113,7 @@ class SmoothingOperator_Tests(unittest.TestCase): tol = _get_rtol(tp) sp = RGSpace([sz1, sz2], harmonic=True) ps = PowerSpace(sp, logarithmic=log) - smo = SmoothingOperator.make(ps, sigma=sigma) + smo = DirectSmoothingOperator(ps, sigma=sigma) inp = Field.from_random(domain=ps, random_type='normal', std=1, mean=4, dtype=tp) out = smo(inp) -- GitLab