From 51c6d01aa079581446c090471c12f9eb878c9d1d Mon Sep 17 00:00:00 2001 From: Martin Reinecke <martin@mpa-garching.mpg.de> Date: Wed, 30 Aug 2017 12:10:02 +0200 Subject: [PATCH] PEP8 --- nifty/field.py | 1 - nifty/spaces/power_space/power_space.py | 13 ++++++------- nifty/spaces/rg_space/rg_space.py | 14 ++++++++++---- nifty/spaces/space/space.py | 12 +++--------- test/common.py | 7 ++++--- test/test_operators/test_laplace_operator.py | 2 +- test/test_spaces/test_power_space.py | 16 +++++++++------- 7 files changed, 33 insertions(+), 32 deletions(-) diff --git a/nifty/field.py b/nifty/field.py index 1fbd7c3b5..d50061709 100644 --- a/nifty/field.py +++ b/nifty/field.py @@ -18,7 +18,6 @@ from __future__ import division from builtins import zip -#from builtins import str from builtins import range import ast diff --git a/nifty/spaces/power_space/power_space.py b/nifty/spaces/power_space/power_space.py index 92aff50ee..0f5793225 100644 --- a/nifty/spaces/power_space/power_space.py +++ b/nifty/spaces/power_space/power_space.py @@ -16,7 +16,6 @@ # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik # and financially supported by the Studienstiftung des deutschen Volkes. -#from builtins import str import ast import numpy as np @@ -87,7 +86,7 @@ class PowerSpace(Space): # ---Overwritten properties and methods--- @staticmethod - def linear_binbounds (nbin, first_bound, last_bound): + def linear_binbounds(nbin, first_bound, last_bound): """ nbin: integer the number of bins @@ -100,11 +99,11 @@ class PowerSpace(Space): values equidistantly spaced (in linear scale) between these two. """ nbin = int(nbin) - assert nbin>=3, "nbin must be at least 3" - return np.linspace(float(first_bound),float(last_bound),nbin-1) + assert nbin >= 3, "nbin must be at least 3" + return np.linspace(float(first_bound), float(last_bound), nbin-1) @staticmethod - def logarithmic_binbounds (nbin, first_bound, last_bound): + def logarithmic_binbounds(nbin, first_bound, last_bound): """ nbin: integer the number of bins @@ -118,7 +117,7 @@ class PowerSpace(Space): between these two. """ nbin = int(nbin) - assert nbin>=3, "nbin must be at least 3" + assert nbin >= 3, "nbin must be at least 3" return np.logspace(np.log(float(first_bound)), np.log(float(last_bound)), nbin-1, base=np.e) @@ -153,7 +152,7 @@ class PowerSpace(Space): binbounds=binbounds, distribution_strategy=distribution_strategy) temp_rho = temp_pindex.bincount().get_full_data() - assert not np.any(temp_rho==0), "empty bins detected" + assert not np.any(temp_rho == 0), "empty bins detected" temp_kindex = \ (temp_pindex.bincount(weights=distance_array).get_full_data() / temp_rho) diff --git a/nifty/spaces/rg_space/rg_space.py b/nifty/spaces/rg_space/rg_space.py index d24e1ef97..b405f9890 100644 --- a/nifty/spaces/rg_space/rg_space.py +++ b/nifty/spaces/rg_space/rg_space.py @@ -125,6 +125,8 @@ class RGSpace(Space): # return fixed_points def hermitianize_inverter(self, x, axes): + if (not self.harmonic): + raise NotImplementedError if nifty_configuration['harmonic_rg_base'] == 'real': return x else: @@ -210,7 +212,8 @@ class RGSpace(Space): """ - if (not self.harmonic): raise NotImplementedError + if (not self.harmonic): + raise NotImplementedError shape = self.shape # prepare the distributed_data_object nkdict = distributed_data_object( @@ -258,7 +261,8 @@ class RGSpace(Space): return dists def get_unique_distances(self): - if (not self.harmonic): raise NotImplementedError + if (not self.harmonic): + raise NotImplementedError dimensions = len(self.shape) if dimensions == 1: # extra easy maxdist = self.shape[0]//2 @@ -285,12 +289,14 @@ class RGSpace(Space): return tmp[np.diff(np.r_[tmp, 2*tmp[-1]]) > tol] def get_natural_binbounds(self): - if (not self.harmonic): raise NotImplementedError + if (not self.harmonic): + raise NotImplementedError tmp = self.get_unique_distances() return 0.5*(tmp[:-1]+tmp[1:]) def get_fft_smoothing_kernel_function(self, sigma): - if (not self.harmonic): raise NotImplementedError + if (not self.harmonic): + raise NotImplementedError return lambda x: np.exp(-2. * np.pi*np.pi * x*x * sigma*sigma) # ---Added properties and methods--- diff --git a/nifty/spaces/space/space.py b/nifty/spaces/space/space.py index a57d24706..4e2900755 100644 --- a/nifty/spaces/space/space.py +++ b/nifty/spaces/space/space.py @@ -51,21 +51,18 @@ class Space(DomainObject): 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`. + the methods `total_volume` and `copy` must be implemented as well as the + abstract methods inherited from `DomainObject`. """ def __init__(self): - super(Space, self).__init__() @abc.abstractproperty def harmonic(self): """ Returns True if this space is a harmonic space. """ - raise NotImplementedError @abc.abstractproperty @@ -76,9 +73,7 @@ class Space(DomainObject): ------- float A real number representing the sum of all pixel volumes. - """ - raise NotImplementedError( "There is no generic volume for the Space base class.") @@ -90,9 +85,7 @@ class Space(DomainObject): ------- Space A copy of this instance. - """ - return self.__class__() def get_distance_array(self, distribution_strategy): @@ -165,6 +158,7 @@ class Space(DomainObject): def hermitianize_inverter(self, x, axes): """ Inverts/flips x in the context of Hermitian decomposition. + This method is only implemented for harmonic spaces. This method is mainly used for power-synthesizing and -analyzing Fields. diff --git a/test/common.py b/test/common.py index cb7a67797..5ae8c1200 100644 --- a/test/common.py +++ b/test/common.py @@ -47,7 +47,8 @@ def generate_harmonic_spaces(): spaces = [RGSpace(4, harmonic=True), LMSpace(5)] return spaces -def marco_binbounds (space, logarithmic, nbin=None): + +def marco_binbounds(space, logarithmic, nbin=None): """Only for testing purposes. DO NOT USE IN REAL LIFE!""" if logarithmic is None and nbin is None: return None @@ -55,8 +56,8 @@ def marco_binbounds (space, logarithmic, nbin=None): raise ValueError("space must be a harmonic space.") logarithmic = bool(logarithmic) if nbin is not None: - nbin=int(nbin) - assert nbin>=3, "nbin must be at least 3" + nbin = int(nbin) + assert nbin >= 3, "nbin must be at least 3" # equidistant binning (linear or log) # MR FIXME: this needs to improve kindex = space.get_unique_distances() diff --git a/test/test_operators/test_laplace_operator.py b/test/test_operators/test_laplace_operator.py index 6a9181a2e..ba4a49986 100644 --- a/test/test_operators/test_laplace_operator.py +++ b/test/test_operators/test_laplace_operator.py @@ -28,7 +28,7 @@ class LaplaceOperatorTests(unittest.TestCase): @expand(product([None, False, True], [False, True], [10, 100, 1000])) def test_Laplace(self, log1, log2, sz): s = ift.RGSpace(sz, harmonic=True) - p = ift.PowerSpace(s, binbounds=marco_binbounds(s,logarithmic=log1)) + p = ift.PowerSpace(s, binbounds=marco_binbounds(s, logarithmic=log1)) L = ift.LaplaceOperator(p, logarithmic=log2) arr = np.random.random(p.shape[0]) fp = ift.Field(p, val=arr) diff --git a/test/test_spaces/test_power_space.py b/test/test_spaces/test_power_space.py index b099dd08a..c99217a88 100644 --- a/test/test_spaces/test_power_space.py +++ b/test/test_spaces/test_power_space.py @@ -41,8 +41,8 @@ HARMONIC_SPACES = [RGSpace((8,), harmonic=True), LMSpace(9)] -#Try all sensible kinds of combinations of spaces, distribution strategy and -#binning parameters +# Try all sensible kinds of combinations of spaces, distribution strategy and +# binning parameters CONSISTENCY_CONFIGS_IMPLICIT = product(HARMONIC_SPACES, ["not", "equal", "fftw"], [None], [None, 3, 4], [True, False]) @@ -123,18 +123,20 @@ class PowerSpaceInterfaceTest(unittest.TestCase): class PowerSpaceConsistencyCheck(unittest.TestCase): @expand(CONSISTENCY_CONFIGS) - def test_rhopindexConsistency(self, harmonic_partner, distribution_strategy, + def test_rhopindexConsistency(self, harmonic_partner, + distribution_strategy, binbounds, nbin, logarithmic): if distribution_strategy == "fftw": if not hasattr(gdi.get('fftw'), 'FFTW_MPI'): raise SkipTest p = PowerSpace(harmonic_partner=harmonic_partner, - distribution_strategy=distribution_strategy, - binbounds=marco_binbounds(harmonic_partner, - logarithmic, nbin)) + distribution_strategy=distribution_strategy, + binbounds=marco_binbounds(harmonic_partner, + logarithmic, nbin)) assert_equal(p.pindex.flatten().bincount(), p.rho, - err_msg='rho is not equal to pindex degeneracy') + err_msg='rho is not equal to pindex degeneracy') + class PowerSpaceFunctionalityTest(unittest.TestCase): @expand(CONSTRUCTOR_CONFIGS) -- GitLab