Fixed CIC errors. Added support for CosmoPower in _cosmotool.pyx
This commit is contained in:
parent
0a28eb3e04
commit
302ed9a912
8 changed files with 230 additions and 110 deletions
|
@ -15,6 +15,40 @@ def gen_posgrid(N, L):
|
|||
|
||||
return x.flatten(), y.flatten(), z.flatten()
|
||||
|
||||
def bin_power(P, L, bins=20, range=(0,1.)):
|
||||
|
||||
N = P.shape[0]
|
||||
ik = np.fft.fftfreq(N, d=L/N)*2*np.pi
|
||||
|
||||
k = np.sqrt(ik[:,None,None]**2 + ik[None,:,None]**2 + ik[None,None,:(N/2+1)]**2)
|
||||
|
||||
H,b = np.histogram(k, bins=bins, range=range)
|
||||
Hw,b = np.histogram(k, bins=bins, weights=P, range=range)
|
||||
|
||||
return Hw/H, 0.5*(b[1:]+b[0:bins])
|
||||
|
||||
def compute_power_from_borg(input_borg, a_borg, cosmo, bins=10, range=(0,1)):
|
||||
borg_vol = ct.read_borg_vol(input_borg)
|
||||
N = borg_vol.density.shape[0]
|
||||
|
||||
cgrowth = CosmoGrowth(**cosmo)
|
||||
D1 = cgrowth.D(1)
|
||||
D1_0 = D1/cgrowth.D(a_borg)
|
||||
|
||||
density_hat, L = ba.half_pixel_shift(borg_vol)
|
||||
|
||||
return bin_power(D1_0**2*np.abs(density_hat)**2/L**3, L, bins=bins, range=range)
|
||||
|
||||
def compute_ref_power(L, N, cosmo, bins=10, range=(0,1), func='HU_WIGGLES'):
|
||||
ik = np.fft.fftfreq(N, d=L/N)*2*np.pi
|
||||
|
||||
k = np.sqrt(ik[:,None,None]**2 + ik[None,:,None]**2 + ik[None,None,:(N/2+1)]**2)
|
||||
p = ct.CosmologyPower(**cosmo)
|
||||
p.setFunction(func)
|
||||
p.normalize(cosmo['SIGMA8'])
|
||||
|
||||
return bin_power(p.compute(k)*cosmo['h']**3, L, bins=bins, range=range)
|
||||
|
||||
def run_generation(input_borg, a_borg, a_ic, **cosmo):
|
||||
""" Generate particles and velocities from a BORG snapshot. Returns a tuple of
|
||||
(positions,velocities,N,BoxSize,scale_factor)."""
|
||||
|
@ -26,7 +60,6 @@ def run_generation(input_borg, a_borg, a_ic, **cosmo):
|
|||
|
||||
density_hat, L = ba.half_pixel_shift(borg_vol)
|
||||
|
||||
|
||||
lpt = LagrangianPerturbation(density_hat, L, fourier=True)
|
||||
|
||||
# Generate grid
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
import cosmotool as ct
|
||||
import borgicgen as bic
|
||||
|
||||
cosmo={'omega_M_0':0.3175, 'h':0.6711}
|
||||
cosmo['omega_lambda_0']=1-cosmo['omega_M_0']
|
||||
cosmo['omega_k_0'] = 0
|
||||
cosmo['omega_B_0']=0.049
|
||||
cosmo['SIGMA8']=0.8344
|
||||
|
||||
zstart=50
|
||||
zstart=0
|
||||
astart=1/(1.+zstart)
|
||||
|
||||
if __name__=="__main__":
|
||||
bic.write_icfiles(*bic.run_generation("initial_condition_borg.dat", 0.001, astart, **cosmo), **cosmo)
|
||||
#if __name__=="__main__":
|
||||
# bic.write_icfiles(*bic.run_generation("initial_condition_borg.dat", 0.001, astart, **cosmo), **cosmo)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue