This commit is contained in:
Guilhem Lavaux 2014-07-18 15:54:12 +02:00
parent b3fee145d4
commit 087ab69ff3
3 changed files with 43 additions and 30 deletions

View file

@ -103,7 +103,7 @@ def run_generation(input_borg, a_borg, a_ic, cosmo, supersample=1, do_lpt2=True,
@ct.timeit_quiet
def whitify(density, L, cosmo, supergenerate=1, func='HU_WIGGLES'):
def whitify(density, L, cosmo, supergenerate=1, zero_fill=False, func='HU_WIGGLES'):
N = density.shape[0]
p = ct.CosmologyPower(**cosmo)
@ -141,18 +141,22 @@ def whitify(density, L, cosmo, supergenerate=1, func='HU_WIGGLES'):
if supergenerate > 1:
cond=np.isnan(density_hat_super)
print np.where(np.isnan(density_hat_super))[0].size
Nz = np.count_nonzero(cond)
density_hat_super.real[cond] = np.random.randn(Nz)
density_hat_super.imag[cond] = np.random.randn(Nz)
density_hat_super[cond] /= np.sqrt(2.0)
print np.where(np.isnan(density_hat_super))[0].size
if zero_fill:
density_hat_super[cond] = 0
else:
print np.where(np.isnan(density_hat_super))[0].size
Nz = np.count_nonzero(cond)
density_hat_super.real[cond] = np.random.randn(Nz)
density_hat_super.imag[cond] = np.random.randn(Nz)
density_hat_super[cond] /= np.sqrt(2.0)
print np.where(np.isnan(density_hat_super))[0].size
# Now we have to fix the Nyquist plane
hNs = Ns/2
nyquist = density_hat_super[:, :, hNs]
Nplane = nyquist.size
nyquist.flat[:Nplane/2] = np.sqrt(2.0)*nyquist.flat[Nplane:Nplane/2:-1].conj()
hNs = Ns/2
nyquist = density_hat_super[:, :, hNs]
Nplane = nyquist.size
nyquist.flat[:Nplane/2] = np.sqrt(2.0)*nyquist.flat[Nplane:Nplane/2:-1].conj()
print np.where(np.isnan(density_hat_super))[0].size
@ -166,8 +170,8 @@ def write_icfiles(*generated_ic, **kwargs):
"""Write the initial conditions from the tuple returned by run_generation"""
supergenerate=1
if 'supergenerate' in kwargs:
supergenerate=kwargs['supergenerate']
supergenerate=kwargs.get('supergenerate', 1)
zero_fill=kwargs.get('zero_fill', False)
posx,vel,density,N,L,a_ic,cosmo = generated_ic
ct.simpleWriteGadget("Data/borg.gad", posx, velocities=vel, boxsize=L, Hubble=cosmo['h'], Omega_M=cosmo['omega_M_0'], time=a_ic)
@ -176,7 +180,7 @@ def write_icfiles(*generated_ic, **kwargs):
ct.writeGrafic("Data/ic_deltab", density, L, a_ic, **cosmo)
ct.writeWhitePhase("Data/white.dat", whitify(density, L, cosmo, supergenerate=supergenerate))
ct.writeWhitePhase("Data/white.dat", whitify(density, L, cosmo, supergenerate=supergenerate,zero_fill=zero_fill))
with file("Data/white_params", mode="w") as f:
f.write("4\n%lg, %lg, %lg\n" % (cosmo['omega_M_0'], cosmo['omega_lambda_0'], 100*cosmo['h']))

View file

@ -9,10 +9,11 @@ cosmo['omega_B_0']=0.049
cosmo['SIGMA8']=0.8344
cosmo['ns']=0.9624
supergen=1
supergen=2
zstart=50
astart=1/(1.+zstart)
astart=1/69.#1/(1.+zstart)
halfPixelShift=False
zero_fill=True
if __name__=="__main__":
bic.write_icfiles(*bic.run_generation("initial_density_988.dat", 0.001, astart, cosmo, supersample=1, shiftPixel=halfPixelShift, do_lpt2=False), supergenerate=supergen)
bic.write_icfiles(*bic.run_generation("initial_density_1380.dat", 0.001, astart, cosmo, supersample=1, shiftPixel=halfPixelShift, do_lpt2=False), supergenerate=supergen, zero_fill=zero_fill)