# Define the cubic Grid
x,dr = fr.create1DGrid(ngrid,boxlength)

# Create Wavenumbers
k = fr.constructWavenumbers(ngrid, boxlength, dr)

# Compute a 3D power spectrum (power law k^-npower)
powerspec = fr.compute1DPowerLawPowerSpectrum(npower, ngrid, k)

# The power spectrum has no phase data - must generate it before Fourier Transform
# Use random phases to reconstruct the Fourier Transform of the density

rho_fft = fr.PowerSpectrumToFT(seed, powerspec)
            
# Compute the inverse fourier transform of rho_fft

rho = fr.InverseFFT(rho_fft)

# Scale density by rhozero

print "Scaling Density"

rho = np.real(rho)
rho = np.real(np.exp(rho/rhozero))

# Test the density to check its PDF is lognormal (optional - feel free to comment out)
nbins = ngrid/10
fr.testForLognormalPDF(rho, nbins)


ky = fr.constructWavenumbers(ngrid, ylength, dy, distkey)
kz = fr.constructWavenumbers(ngrid, zlength, dz, distkey)

# Compute a 3D power spectrum (power law k^-npower)
powerspec = fr.computePowerLawPowerSpectrum(npower, ngrid, ngrid, ngrid, kx,
                                            ky, kz)

# The power spectrum has no phase data - must generate it before Fourier Transform
# Use random phases to reconstruct the Fourier Transform of the density

rho_fft = fr.PowerSpectrumToFT(seed, powerspec)

# Compute the inverse fourier transform of rho_fft

rho = fr.InverseFFTN(rho_fft)

# Scale density by rhozero

print "Scaling Density"

rho = np.real(rho)
rho = rhozero * np.real(np.exp(rho * deltarho))

# Test the density to check its PDF is lognormal (optional - feel free to comment out)
fr.testForLognormalPDF(rho, ngrid)

# Write density grid to file

fr.writeCuboidGridToFile(x, y, z, ngrid, ngrid, ngrid, rho, dx, dy, dz,
                         massunit, distunit, masskey, distkey, filename)
kx = fr.constructWavenumbers(ngrid, xlength, dx,distkey)
ky = fr.constructWavenumbers(ngrid, ylength, dy,distkey)
kz = fr.constructWavenumbers(ngrid, zlength, dz,distkey)

# Compute a 3D power spectrum (power law k^-npower)
powerspec = fr.computePowerLawPowerSpectrum(npower, ngrid, ngrid, ngrid, kx, ky, kz)

# The power spectrum has no phase data - must generate it before Fourier Transform
# Use random phases to reconstruct the Fourier Transform of the density

rho_fft = fr.PowerSpectrumToFT(seed, powerspec)
            
# Compute the inverse fourier transform of rho_fft

rho = fr.InverseFFTN(rho_fft)

# Scale density by rhozero

print "Scaling Density"

rho = np.real(rho)
rho = rhozero*np.real(np.exp(rho*deltarho))

# Test the density to check its PDF is lognormal (optional - feel free to comment out)
fr.testForLognormalPDF(rho, ngrid)

# Write density grid to file

fr.writeCuboidGridToFile(x,y,z,ngrid,ngrid,ngrid,rho,dx,dy,dz,massunit,distunit,masskey,distkey,filename)

Ejemplo n.º 4
0
)

# Define the cubic Grid
x, dr = fr.create1DGrid(ngrid, boxlength)

# Create Wavenumbers
k = fr.constructWavenumbers(ngrid, boxlength, dr)

# Compute a 3D power spectrum (power law k^-npower)
powerspec = fr.compute1DPowerLawPowerSpectrum(npower, ngrid, k)

# The power spectrum has no phase data - must generate it before Fourier Transform
# Use random phases to reconstruct the Fourier Transform of the density

rho_fft = fr.PowerSpectrumToFT(seed, powerspec)

# Compute the inverse fourier transform of rho_fft

rho = fr.InverseFFT(rho_fft)

# Scale density by rhozero

print "Scaling Density"

rho = np.real(rho)
rho = np.real(np.exp(rho / rhozero))

# Test the density to check its PDF is lognormal (optional - feel free to comment out)
nbins = ngrid / 10
fr.testForLognormalPDF(rho, nbins)