cosmotool/python_sample/test_bispectrum.py

26 lines
738 B
Python
Raw Normal View History

2016-11-26 21:30:44 +01:00
import timeit
2016-11-22 06:56:12 +01:00
import numpy as np
import cosmotool as ct
2016-11-26 21:30:44 +01:00
def myfun(N):
f=0.10
d=np.random.normal(size=(N,)*3)
rho = d + f *(d*d - np.average(d*d))
B = ct.bispectrum(rho, 1, N, fourier=False)
P = ct.powerspectrum(rho, 1, N, fourier=False)
PP = P[1]/P[0]/N**3
x = PP[:,None,None] * PP[None,:,None] + PP[:,None,None]*PP[None,None,:] + PP[None,:,None]*PP[None,None,:]
BB = B[1]/B[0]/N**6
y = BB/x
2016-11-22 06:56:12 +01:00
np.savez("bispec_%d.npz" % N, y=y, B_nt=B[0], B_r=B[1], P_n=P[0], P=P[1], rho=rho);
2016-11-26 21:30:44 +01:00
print( timeit.timeit('from __main__ import myfun; myfun(16)', number=1) )
print( timeit.timeit('from __main__ import myfun; myfun(32)', number=1) )
print( timeit.timeit('from __main__ import myfun; myfun(64)', number=1) )