def find_CF(snapshot, snapnum, grid, MAS, do_RSD, axis, threads, ptype, fcf, save_multipoles): if os.path.exists(fcf): return 0 # read header head = readgadget.header(snapshot) BoxSize = head.boxsize / 1e3 #Mpc/h Nall = head.nall #Total number of particles Masses = head.massarr * 1e10 #Masses of the particles in Msun/h Omega_m = head.omega_m Omega_l = head.omega_l redshift = head.redshift Hubble = 100.0 * np.sqrt(Omega_m * (1.0 + redshift)**3 + Omega_l) #km/s/(Mpc/h) h = head.hubble # read snapshot pos = readgadget.read_block(snapshot, "POS ", ptype) / 1e3 #Mpc/h # move particles to redshift-space if do_RSD: vel = readgadget.read_block(snapshot, "VEL ", ptype) #km/s RSL.pos_redshift_space(pos, vel, BoxSize, Hubble, redshift, axis) # calculate CF delta = np.zeros((grid, grid, grid), dtype=np.float32) if len(ptype) > 1: #for multiple particles read masses mass = np.zeros(pos.shape[0], dtype=np.float32) offset = 0 for j in ptype: mass[offset:offset + Nall[j]] = Masses[j] offset += Nall[j] MASL.MA(pos, delta, BoxSize, MAS, W=mass) else: MASL.MA(pos, delta, BoxSize, MAS) delta /= np.mean(delta, dtype=np.float64) delta -= 1.0 CF = PKL.Xi(delta, BoxSize, MAS, axis, threads) # save results to file if save_multipoles: np.savetxt(fcf, np.transpose( [CF.r3D, CF.xi[:, 0], CF.xi[:, 1], CF.xi[:, 2]]), delimiter='\t') else: np.savetxt(fcf, np.transpose([CF.r3D, CF.xi[:, 0]]), delimiter='\t')
import Pk_library as PKL import numpy as np import h5py import sys test_cube = np.load('../dat/processed/test_cube_target.npy') pred_cube = np.load('../dat/processed/test_cube_final_prediction.npy') benchmark_cube = np.load('../dat/processed/benchmark_cube.npy') BoxSize = 31.82373046875 #Size of the density field in Mpc/h MAS = None threads = 16 axis = 0 # compute the correlation function CF = PKL.Xi(test_cube, BoxSize, MAS, axis, threads) r = CF.r3D #radii in Mpc/h xi0 = CF.xi[:, 0] #correlation function (monopole) #xi2 = CF.xi[:,1] #correlation function (quadrupole) #xi4 = CF.xi[:,2] #correlation function (hexadecapole) # save correlation function and r np.save('../processed/target_r_values.npy', r) np.save('../processed/target_xi0_values.npy', xi0) # compute dm2gal corr func CF = PKL.Xi(pred_cube, BoxSize, MAS, axis, threads) r = CF.r3D #radii in Mpc/h xi0 = CF.xi[:, 0] #correlation function (monopole) #xi2 = CF.xi[:,1] #correlation function (quadrupole) #xi4 = CF.xi[:,2] #correlation function (hexadecapole)
print '\nREADING SNAPSHOTS PROPERTIES' head = readsnap.snapshot_header(snapshot_fname) BoxSize = head.boxsize / 1e3 #Mpc/h Nall = head.nall Masses = head.massarr * 1e10 #Msun/h Omega_m = head.omega_m Omega_l = head.omega_l redshift = head.redshift Hubble = 100.0 * np.sqrt(Omega_m * (1.0 + redshift)**3 + Omega_l) #km/s/(Mpc/h) h = head.hubble fout = 'CF_CDM_z=%.3f.txt' % redshift # read the positions and masses of the CDM particles pos = readsnap.read_block(snapshot_fname, "POS ", parttype=1) / 1e3 #Mpc/h # compute delta_CDM delta = np.zeros((dims, dims, dims), dtype=np.float32) MASL.MA(pos, delta, BoxSize, MAS) print '%.6e should be equal to\n%.6e'\ %(np.sum(delta,dtype=np.float64),len(pos)) delta /= np.mean(delta, dtype=np.float64) delta -= 1.0 #compute the correlation function CF = PKL.Xi(delta, BoxSize, MAS, threads=8) #save results to file np.savetxt(fout, np.transpose([CF.r3D, CF.xi]))
# do the lognormal transformation if do_lognormal: sigma_G = np.sqrt(np.mean(delta_r**2, dtype=np.float64)) print('sigma_G =', sigma_G) delta_r = np.exp(delta_r - sigma_G**2 / 2.0) - 1.0 print('<delta_NL(r)> =', np.mean(delta_r, dtype=np.float64)) print(np.min(delta_r), '< delta_NL(r) <', np.max(delta_r)) # save density and velocity field to file np.save(fout_df, [delta_r, Vx_r, Vy_r, Vz_r]) ############ Final checks ########### # Compute power spectrum & correlation function of the density field Pk = PKL.Pk(delta_r, BoxSize, axis, MAS, threads) CF = PKL.Xi(delta_r, BoxSize, MAS, axis, threads) np.savetxt(f_Pk, np.transpose([Pk.k3D, Pk.Pk[:, 0]])) np.savetxt(f_CF, np.transpose([CF.r3D, CF.xi[:, 0]])) del delta_r """ #compute the power spectrum of the theta=i\grad V Vx_r = np.reshape(Vx_r,(dims,dims,dims)) Vy_r = np.reshape(Vy_r,(dims,dims,dims)) Vz_r = np.reshape(Vz_r,(dims,dims,dims)) Vx_k = scipy.fftpack.ifftn(Vx_r,overwrite_x=True); del Vx_r Vy_k = scipy.fftpack.ifftn(Vy_r,overwrite_x=True); del Vy_r Vz_k = scipy.fftpack.ifftn(Vz_r,overwrite_x=True); del Vz_r theta_k = DFL.theta(Vx_k,Vy_k,Vz_k,dims)*2.0*np.pi/BoxSize del Vx_k, Vy_k, Vz_k