コード例 #1
0
ファイル: test_box.py プロジェクト: philbull/FastBox
def test_box_builtin_tests():
    """Run the built-in tests in the CosmoBox object."""
    box = CosmoBox(cosmo=default_cosmo,
                   box_scale=(1e2, 1e2, 1e2),
                   nsamp=16,
                   realise_now=True)

    # Test Parseval's theorem (integrals of power in real and Fourier space are
    # equal)
    s1, s2 = box.test_parseval()
    assert np.isclose(s1, s2)
コード例 #2
0
sys.exit(0)


# Log-normal box
delta_ln = box.lognormal(box.delta_x)
lnre_k, lnre_pk, lnre_stddev \
    = box.binned_power_spectrum(delta_k=fft.fftn(delta_ln))

plt.matshow(delta_ln[0], vmin=-1., vmax=2., cmap='cividis')
plt.title("Log-normal density")
plt.colorbar()


# Tests
box.test_sampling_error()
box.test_parseval()


# Plot some stuff
fig = plt.figure()
plt.plot(th_k, th_pk, 'b-', label="Theoretical P(k)")
#plt.errorbar(re_k, re_pk, yerr=re_stddev, fmt=".", color='r')
plt.plot(re_k, re_pk, 'r.', label="P(k) from density field")
plt.plot(lnre_k, lnre_pk, 'gx', label="P(k) from log-normal")
plt.xscale('log')
plt.yscale('log')
plt.legend(loc='lower left', frameon=False)

"""
plt.subplot(212)