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

adjust to new PowerSpace

parent e8ffa519
Pipeline #19436 failed with stage
in 4 minutes and 12 seconds
......@@ -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)
......
......@@ -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
......
......@@ -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)
......
......@@ -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)
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