def lightcone_stats(s='',ht=''): infile = setup_dirs.resultsdir()+'dbt_lightcone_smooth'+ht+'.bin' zfile = open(setup_dirs.resultsdir()+'dbt_lightcone_redshifts.bin','rb') meanfile = open(setup_dirs.resultsdir()+s+'_'+'mean'+'_'+ht+'lightcone.dat','w') skewnessfile = open(setup_dirs.resultsdir()+s+'_'+'skewness'+'_'+ht+'lightcone.dat','w') kurtosisfile = open(setup_dirs.resultsdir()+s+'_'+'kurtosis'+'_'+ht+'lightcone.dat','w') rmsfile = open(setup_dirs.resultsdir()+s+'_'+'rms'+'_'+ht+'lightcone.dat','w') redshiftfile = open(setup_dirs.resultsdir()+s+'_'+'zs'+'_'+ht+'.dat','w') lc = np.load(infile) zs = np.load(zfile) ratio=4. #smoothing ratio Lbox=244./0.7 #boxsize in cMpc SLbox=Lbox/ratio #size of smoothing box Nbox=250 #number of cells SNbox=int(Nbox/ratio)+1 #new number of cells print Lbox, SLbox, Nbox, SNbox for i in range(len(zs)-SNbox/2-2,SNbox/2,-1): mapfile=setup_dirs.resultsdir()+s+'_map_'+ht+str('%.3f'%zs[i])+'.bin' print "Doing redshift: " + str(zs[i]) data,dims = c2t.get_lightcone_subvolume(lc,zs,zs[i],depth_mpc=SLbox,subtract_mean=False) IO.writebin(data,mapfile) redshiftfile.write(str(zs[i])+'\n') meanfile.write(str(np.mean(data))+'\n') rmsfile.write(str(np.sqrt(np.var(data)))+'\n') skewnessfile.write(str(c2t.statistics.skewness(data.flatten()))+'\n') kurtosisfile.write(str(c2t.statistics.kurtosis(data.flatten()))+'\n') print "Written statistics"
def smoothed_lightcone_dbt(id="", ht=""): infile = open(setup_dirs.resultsdir() + "dbt_lightcone" + ht + ".bin", "rb") outfile = setup_dirs.resultsdir() + "dbt_lightcone_smooth" + ht + ".bin" zfile = open(setup_dirs.resultsdir() + "dbt_lightcone_redshifts.bin", "rb") dT_box = np.load(infile) log = open("stats.dat", "w") zs = np.load(zfile) dT_box3 = np.zeros((len(dT_box[:, 1, 1]) / 2, len(dT_box[1, :, 1]) / 2, len(dT_box[1, 1, :]))) dT_box2 = np.zeros((len(dT_box[:, 1, 1]) / 2, len(dT_box[1, :, 1]) / 2, len(dT_box[1, 1, :]))) for z in range(len(dT_box[1, 1, :]) - 1, -1, -1): wl = 0.21 * (1 + zs[z]) c = 299792.458 omm = 0.27 oml = 0.73 omr = 0.0 omk = 1.0 - omm - oml - omr H0 = 70.0 def integrand(x, omm, oml, omr, omk): return 1.0 / np.sqrt(omr * ((1 + x) ** 4) + omm * ((1 + x) ** 3) + oml + omk * ((1 + x) ** 2)) def dc(z, omm, oml, omr, omk): return quad(integrand, 0, z, args=(omm, oml, omr, omk))[0] # /(1.0+z) vec_dc = np.vectorize(dc) bw_r = wl / (2.0e3) # radians bw = bw_r * 3437.74677 # arcminutesi log.write("Wavelength of 21-cm from redshift " + str(zs[z]) + " is " + str(wl) + "m\n") log.write("At redshift: " + str(zs[z]) + " smoothing with a " + str(bw) + " arc minute beam.\n") rc = bw_r * c / H0 * vec_dc(zs[z], omm, oml, omr, omk) # comoving Mpc Hz = H0 * np.sqrt(omr * (1 + zs[z]) ** 4 + omm * (1 + zs[z]) ** 3 + oml + omk * (1 + zs[z]) ** 2) log.write("rc = " + str(rc) + "\n") # dnu=nu0*Hz*rc/(c*(1+zs[z])**2) dz = rc * Hz / c log.write("$\Delta$ z = " + str(dz) + "\n") ncs = rc * 250.0 * 0.7 / 244.0 log.write(str(ncs) + " cells in the z direction\n") log.write("\n") # rc_h=rc/0.7 # comoving Mpc/h # print "This corresponds to "+str(rc_h)+"Mpc/h on the sky" dT_box2[:, :, z] = c2t.beam_convolve(dT_box[:, :, z], zs[z], 244.0, beam_w=bw) if z > ncs and z + ncs < zs[len(zs) - 1]: for x in range(len(dT_box2)): for y in range(len(dT_box2)): dT_box3[x, y, z] = np.mean(dT_box2[x, y, z - ncs / 2.0 : z + ncs / 2.0]) else: print "..." dT_box3[:, :, z] = dT_box2[:, :, z] IO.writebin(dT_box3[:, :, z], setup_dirs.resultsdir() + "smoothed_map_dbt_" + ht + str("%.3f" % zs[z]) + ".bin") IO.writebin(dT_box3, outfile) print "Written map to " + outfile
def dbt_lightcone(ht=""): filenames = ["" for x in range(len(redshifts))] for i in range(0, len(redshifts)): filenames[i] = setup_dirs.resultsdir() + "dbt" + ht + "/map_dbt_" + ht + str("%.3f" % redshifts[i]) + ".bin" output = setup_dirs.resultsdir() + "dbt_lightcone" + ht + ".bin" output2 = setup_dirs.resultsdir() + "dbt_lightcone_redshifts.bin" lightcone, z = c2t.make_lightcone(filenames, redshifts[len(redshifts) - 1], redshifts[0], interpolation="linear") lightcone2 = np.asarray(lightcone) z2 = np.asarray(z) IO.writebin(lightcone2, output) IO.writebin(z2, output2) print "written lightcone to " + output
def blurtemp(): for z in range(start,len(redshifts)): print "Doing redshift " + str(redshifts[z])+"..." temp_filename = setup_dirs.path() + 'Temper3D_'+str('%.3f' % redshifts[z]) + '.bin' T = c2t.TemperFile(temp_filename).temper Tb=np.zeros(10**3).reshape(10,10,10) nobins=20 for i in range(len(T[:,1,1])): for j in range(len(T[:,1,1])): for k in range(len(T[:,1,1])): Tb[i/20,j/20,k/20]=Tb[i/20,j/20,k/20]+T[i,j,k] Tb=Tb/20**3 IO.writebin(Tb,"tests/blurred/temp_"+str(redshifts[z])+".bin") print "written to tests/blurred/temp_"+str(redshifts[z])+".bin"
def smoothed_lightcone_dbt2(id="", ht=""): print "hello" infile = open(setup_dirs.resultsdir() + "dbt_lightcone" + ht + ".bin", "rb") outfile = setup_dirs.resultsdir() + "dbt_lightcone_smooth" + ht + ".bin" zfile = open(setup_dirs.resultsdir() + "dbt_lightcone_redshifts.bin", "rb") dT_box = np.load(infile) log = open("stats.dat", "w") zs = np.load(zfile) dT_box3 = np.zeros((len(dT_box[:, 1, 1]) / 2, len(dT_box[1, :, 1]) / 2, len(dT_box[1, 1, :]))) dT_box2 = np.zeros((len(dT_box[:, 1, 1]) / 2, len(dT_box[1, :, 1]) / 2, len(dT_box[1, 1, :]))) for z in range(len(dT_box[1, 1, :])): wl = 0.21 * (1 + zs[z]) c = 299792.458 omm = 0.27 oml = 0.73 omr = 0.0 omk = 1.0 - omm - oml - omr H0 = 70.0 print 1 def integrand(x, omm, oml, omr, omk): return 1.0 / np.sqrt(omr * ((1 + x) ** 4) + omm * ((1 + x) ** 3) + oml + omk * ((1 + x) ** 2)) def dc(z, omm, oml, omr, omk): return quad(integrand, 0, z, args=(omm, oml, omr, omk))[0] # /(1.0+z) vec_dc = np.vectorize(dc) print 2 bw_r = wl / (2.0e3) # radians bw = bw_r * 3437.74677 # arcminutesi stats.write("Wavelength of 21-cm from redshift " + str(zs[z]) + " is " + str(wl) + "m") stats.write("At redshift: " + str(zs[z]) + " smoothing with a " + str(bw_r) + " radian beam") stats.write("At redshift: " + str(zs[z]) + " smoothing with a " + str(bw) + " arc minute beam") stats.write("\n") print 3 dT_box2[:, :, z] = c2t.beam_convolve(dT_box[:, :, z], zs[z], 244.0, beam_w=bw) print 4 dT_box3 = lightcone_smooth.frequency_direction_same(dT_box2, zs[0], 244.0, 2) print 5 IO.writebin(dT_box3[:, :, z], setup_dirs.resultsdir() + "smoothed_map_dbt_" + ht + str("%.3f" % zs[z]) + ".bin") IO.writebin(dT_box3, outfile) print "Written map to " + outfile
def map_dbt(): for i in range(start, len(redshifts)): filename = setup_dirs.resultsdir() + "map_dbt_" + str("%.3f" % redshifts[i]) + ".bin" temp_filename = setup_dirs.path() + "Temper3D_" + str("%.3f" % redshifts[i]) + ".bin" xfrac_filename = setup_dirs.path() + "xfrac3d_" + str("%.3f" % redshifts[i]) + ".bin" if i % 2 == 0: density_filename = ( "/research/prace/244Mpc_RT/244Mpc_f2_8.2pS_250/coarser_densities/" + str("%.3f" % redshifts[i]) + "n_all.dat" ) else: density_filename = ( "/research/prace/244Mpc_RT/244Mpc_f2_8.2pS_250/coarser_densities/" + str("%.3f" % redshifts[i - 1]) + "n_all.dat" ) tfile = c2t.TemperFile(temp_filename) xfile = c2t.XfracFile(xfrac_filename).xi if ss != " ": abu_he = 0.074 G_grav = 6.674e-11 pc = 3.086e16 Mpc = 1e6 * pc H0 = 0.7 * 100.0 * 1.0e5 / Mpc rho_crit_0 = 3.0 * H0 * H0 / (8.0 * np.pi * G_grav) Omega_B = 0.044 mu = (1.0 - abu_he) + 4.0 * abu_he m_p = 1.672661e-24 dfile = np.ones(ss ** 3).reshape(ss, ss, ss) dfile = dfile * rho_crit_0 * Omega_B / (mu * m_p) * (1.0 + redshifts[i]) ** 3 dfile = dfile * 1.23581719037e-35 else: dfile = c2t.DensityFile(density_filename).cgs_density dT_box = c2t.calc_dt_full(xfile, tfile, dfile, redshifts[i]) # IO.writemap(dT_box,filename) IO.writebin(dT_box, filename) print "Written map to " + filename
def smoothed_coeval_box(ht=""): log2 = open("coeval_stats.dat", "w") for z in range(len(redshifts)): infile = "map_dbt_" + ht + str("%0.3f" % redshifts[z]) + ".bin" dT_box = IO.readbin(infile) dT_box3 = np.zeros((len(dT_box[:, 1, 1]) / 2, len(dT_box[1, :, 1]) / 2, len(dT_box[1, 1, :]))) dT_box2 = np.zeros((len(dT_box[:, 1, 1]) / 2, len(dT_box[1, :, 1]) / 2, len(dT_box[1, 1, :]))) wl = 0.21 * (1 + redshifts[z]) c = 299792.458 omm = 0.27 oml = 0.73 omr = 0.0 omk = 1.0 - omm - oml - omr H0 = 70.0 def integrand(x, omm, oml, omr, omk): return 1.0 / np.sqrt(omr * ((1 + x) ** 4) + omm * ((1 + x) ** 3) + oml + omk * ((1 + x) ** 2)) def dc(z, omm, oml, omr, omk): return quad(integrand, 0, z, args=(omm, oml, omr, omk))[0] # /(1.0+z) vec_dc = np.vectorize(dc) bw_r = wl / (2.0e3) # radians bw = bw_r * 3437.74677 # arcminutesi log2.write("Wavelength of 21-cm from redshift " + str(redshifts[z]) + " is " + str(wl) + "m\n") log2.write("At redshift: " + str(redshifts[z]) + " smoothing with a " + str(bw) + " arc minute beam.\n") rc = bw_r * c / H0 * vec_dc(redshifts[z], omm, oml, omr, omk) # comoving Mpc Hz = H0 * np.sqrt( omr * (1 + redshifts[z]) ** 4 + omm * (1 + redshifts[z]) ** 3 + oml + omk * (1 + redshifts[z]) ** 2 ) log2.write("rc = " + str(rc) + "\n") dz = rc * Hz / c log2.write("$\Delta$ z = " + str(dz) + "\n") ncs = rc * 250.0 * 0.7 / 244.0 log2.write(str(ncs) + " cells in the z direction\n") log2.write("\n") for k in range(len(dT_box2[1, 1, :])): dT_box2[:, :, k] = c2t.beam_convolve(dT_box[:, :, k], redshifts[z], 244.0, beam_w=bw) for i in range(0): # len(dT_box2[:,1,1])): for j in range(0): # len(dT_box2[1,:,1])): for k in range(0): # len(dT_box2[1,1,:])): L = len(dT_box2[1, 1, :]) if k - ncs / 2 > 0 and k + ncs / 2 < L: dT_box3[i, j, k] = np.mean(dT_box2[i, j, k - ncs / 2.0 : k + ncs / 2.0]) if k + ncs / 2.0 - k + ncs / 2.0 != ncs: print "Wrong smoothing width for tophat function!!" elif (k - ncs) / 2 < 0: if k + ncs / 2.0 + k - ncs / 2 != ncs: print "Wrong smoothing width for tophat function!!" dT_box3[i, j, k] = ( np.sum(dT_box2[i, j, 0 : (k + ncs / 2.0)]) + np.sum(dT_box2[i, j, L - ncs / 2 + k : L]) ) / ncs elif (k + ncs) / 2 > 10: if L - k + ncs / 2 + L - k + ncs / 2 != ncs: print "Wrong smoothing width for tophat function!!" dT_box3[i, j, k] = ( np.sum(dT_box2[i, j, k - ncs / 2 : L]) + np.sum(dT_box2[i, j, L - k + ncs / 2 : L]) ) / ncs IO.writebin( dT_box2, setup_dirs.resultsdir() + "smooth_coevalmap_dbt_" + ht + str("%.3f" % redshifts[z]) + ".bin" ) print np.mean(dT_box2) print "Written map"