diff --git a/nifty/field.py b/nifty/field.py index 5fbc74ec97158d8162c72d693ef09a0faddb175c..9de78717f1fbaa64dda386430cc6f5cb5cebf882 100644 --- a/nifty/field.py +++ b/nifty/field.py @@ -234,8 +234,9 @@ class Field(object): power_spectrum = dobj.bincount_axis(pindex, weights=field.val, axis=axes) new_rho_shape = [1] * len(power_spectrum.shape) - new_rho_shape[axes[0]] = len(power_domain.rho) - power_spectrum /= power_domain.rho.reshape(new_rho_shape) + new_rho_shape[axes[0]] = power_domain.dim + power_spectrum /= power_domain.dvol().reshape(new_rho_shape) + power_spectrum *= field.domain[idx].scalar_dvol() result_domain = list(field.domain) result_domain[idx] = power_domain return Field(result_domain, power_spectrum) diff --git a/nifty/operators/linear_operator.py b/nifty/operators/linear_operator.py index e1af3e810816ddd5ae78b901effb375a058a0bec..822ff62c6ef7276334a78cc8694af9a53ece070d 100644 --- a/nifty/operators/linear_operator.py +++ b/nifty/operators/linear_operator.py @@ -60,7 +60,6 @@ class LinearOperator(with_metaclass( The domain on which the Operator's input Field lives. Every Operator which inherits from the abstract LinearOperator base class must have this attribute. - """ raise NotImplementedError diff --git a/test/test_field.py b/test/test_field.py index e74d404daee8d0053b7f731cdd7a1913c7880c14..d88c10992461afd114c835e7eaa665fe97cee22a 100644 --- a/test/test_field.py +++ b/test/test_field.py @@ -80,8 +80,8 @@ class Test_Functionality(unittest.TestCase): sk = fp.power_synthesize(spaces=(0, 1), real_signal=True) sp = sk.power_analyze(spaces=(0, 1), keep_phase_information=False) - ps1 += sp.integrate(spaces=1)/fp2.sum() - ps2 += sp.integrate(spaces=0)/fp1.sum() + ps1 += sp.sum(spaces=1)/fp2.sum() + ps2 += sp.sum(spaces=0)/fp1.sum() assert_allclose(ps1.val/samples, fp1.val, rtol=0.2) assert_allclose(ps2.val/samples, fp2.val, rtol=0.2) @@ -117,8 +117,8 @@ class Test_Functionality(unittest.TestCase): rand_k = Field.from_random('normal', domain=fulldomain) sk = S_1.times(S_2.times(rand_k)) sp = sk.power_analyze(spaces=(0, 1), keep_phase_information=False) - ps1 += sp.integrate(spaces=1)/fp2.sum() - ps2 += sp.integrate(spaces=0)/fp1.sum() + ps1 += sp.sum(spaces=1)/fp2.sum() + ps2 += sp.sum(spaces=0)/fp1.sum() assert_allclose(ps1.val/samples, fp1.val, rtol=0.2) assert_allclose(ps2.val/samples, fp2.val, rtol=0.2) diff --git a/test/test_spaces/test_power_space.py b/test/test_spaces/test_power_space.py index 83ba48c91f50e750b1804fc2ffe4ae4c240a6c3d..add6d5d06c6c078894a8e3bed1014524fdcfba4e 100644 --- a/test/test_spaces/test_power_space.py +++ b/test/test_spaces/test_power_space.py @@ -56,7 +56,6 @@ CONSTRUCTOR_CONFIGS = [ 'binbounds': None, 'pindex': np.array([0, 1, 2, 3, 4, 3, 2, 1]), 'k_lengths': np.array([0., 1., 2., 3., 4.]), - 'rho': np.array([1, 2, 2, 2, 1]), }], [RGSpace((8,), harmonic=True), True, None, None, { 'harmonic': True, @@ -66,7 +65,6 @@ CONSTRUCTOR_CONFIGS = [ 'binbounds': (0.5, 1.3228756555322954, 3.5), 'pindex': np.array([0, 1, 2, 2, 3, 2, 2, 1]), 'k_lengths': np.array([0., 1., 2.5, 4.]), - 'rho': np.array([1, 2, 4, 1]), }], ] @@ -84,7 +82,6 @@ class PowerSpaceInterfaceTest(unittest.TestCase): ['binbounds', type(None)], ['pindex', np.ndarray], ['k_lengths', np.ndarray], - ['rho', np.ndarray], ]) def test_property_ret_type(self, attribute, expected_type): r = RGSpace((4, 4), harmonic=True) @@ -99,7 +96,7 @@ class PowerSpaceConsistencyCheck(unittest.TestCase): bb = PowerSpace.useful_binbounds(harmonic_partner, logarithmic, nbin) p = PowerSpace(harmonic_partner=harmonic_partner, binbounds=bb) - assert_equal(np.bincount(p.pindex.ravel()), p.rho, + assert_equal(np.bincount(p.pindex.ravel()), p.dvol(), err_msg='rho is not equal to pindex degeneracy') @@ -128,5 +125,11 @@ class PowerSpaceFunctionalityTest(unittest.TestCase): assert_almost_equal(p.get_k_length_array(), expected) def test_dvol(self): - p = PowerSpace(harmonic_partner=RGSpace(10,harmonic=True)) - assert_almost_equal(p.dvol(),1.) + hp = RGSpace(10,harmonic=True) + p = PowerSpace(harmonic_partner=hp) + v1 = hp.dvol() + v1 = hp.dim*v1 if np.isscalar(v1) else np.sum(v1) + v2 = p.dvol() + v2 = p.dim*v2 if np.isscalar(v2) else np.sum(v2) + print v1, v2 + assert_almost_equal(v1, v2)