print 'The critical baryon density of the universe is: ', c2t.rho_crit_0*c2t.OmegaB, ' g/cm^3' #You can also access the density in simulation units print 'The raw density at point (0,0,0) is ', dfile.raw_density[0,0,0] #Read an ionized fractions file and store it as an XfracFile object xfile = c2t.XfracFile(xfrac_filename) #The most important property of an XfracFile object is xi, which #is a numpy array containing the ionized fraction print 'The ionized fraction in point (10,223,45) is: ', xfile.xi[10,223,45] print 'The volume-averaged mean ionized fraction is: ', xfile.xi.mean() #c2raytools has several methods to calculate useful statistics, such as #mass-weighted mean ionized fraction print 'The mass-averaged mean ionized fraction is:', c2t.mass_weighted_mean_xi(xfile.xi, dfile.raw_density) #Read a velocity data file and store it as a VelocityFile object vfile = c2t.VelocityFile(velocity_filename) #Since the velocity data is actually momentum, we need the density to convert it to km/s kms = vfile.get_kms_from_density(dfile) print 'Gas velocity at cell (100,100,100) is ', kms[:,100,100,100], 'km/s' #Calculate neutral hydrogen number density n_hi = dfile.cgs_density*xfile.xi/c2t.m_p #Calculate differential brightness temperature #The calc_dt method can also take names of files so you don't have to load the #files yourself in advance. dT = c2t.calc_dt(xfile, dfile, z=xfile.z)
density_file = ''.join(glob.glob(density_path+'%.3fn_all.dat'%(z_arr[i-1]))) print 'Desnity file = %s' % density_file dfile = c2t.DensityFile(density_file) #Delta = dfile.raw_density/np.mean(dfile.raw_density.astype('float64')) xfrac_file = ''.join(glob.glob(xfrac_path+'xfrac3d_%.3f.bin' % (z_arr[i]))) print 'Ionized fraction file = %s' % xfrac_file xfile = c2t.XfracFile(xfrac_file) irate_file = ''.join(glob.glob(xfrac_path+'IonRates3_%.3f.bin'%(z_arr[i]))) print 'Ionization rate file = %s' % irate_file ifile = c2t.IonRateFile(irate_file) avg_vG = ifile.irate.mean() avg_mG = c2t.mass_weighted_mean_xi(ifile.irate,dfile.raw_density) avg_xIIG = c2t.mass_weighted_mean_xi(ifile.irate,xfile.xi) median_vG = np.median(ifile.irate) ilist = np.reshape(ifile.irate,(ifile.mesh_x*ifile.mesh_y*ifile.mesh_z,1)) Dlist = np.reshape(dfile.raw_density/np.mean(dfile.raw_density.astype('float64')),(ifile.mesh_x*ifile.mesh_y*ifile.mesh_z,1)) avg_dG = 0. count = 0 for index,Delta in enumerate(Dlist): if (Delta < 1. - thresh): continue elif (Delta > 1. + thresh): continue else: #print 'index = ',index, 'and Delta = ',Delta avg_dG += ilist[index] count += 1
#We are using the 114/h Mpc simulation box, so set all the proper conversion factors c2t.set_sim_constants(boxsize_cMpc=114.) #Read a density file and print some statistics dfile = c2t.DensityFile(density_filename) print 'The redshift is ', dfile.z print 'The size of the mesh is (', dfile.mesh_x, dfile.mesh_y, dfile.mesh_z, ')' print 'The mean baryon density is ', dfile.cgs_density.mean(), ' g/cm^3' #Read an ionized fractions file xfile = c2t.XfracFile(xfrac_filename) print 'The volume-averaged mean ionized fraction is: ', xfile.xi.mean() print 'The mass-averaged mean ionized fraction is:', c2t.mass_weighted_mean_xi( xfile.xi, dfile.raw_density) #Read a velocity data file vfile = c2t.VelocityFile(velocity_filename) #Since the velocity data is actually momentum, we need the density to convert it to km/s kms = vfile.get_kms_from_density(dfile) print 'Gas velocity at cell (100,100,100) is ', kms[:, 100, 100, 100], 'km/s' #Calculate neutral hydrogen number density n_hi = dfile.cgs_density * xfile.xi / c2t.m_p #Calculate differential brightness temperature dT = c2t.calc_dt(xfile, dfile) #Get a slice through the center
z_filename = "../reds_full.dat" # Read in z file to get snap and redshift and set mesh z_arr = np.loadtxt(z_filename) z_min = 10 out = open(output_filename, "w") # Loop over z for i in range(z_min, len(z_arr)): print "z = %.3f" % (z_arr[i]) density_file = "".join(glob.glob(density_path + "%.3fn_all.dat" % (z_arr[i]))) if not density_file: density_file = "".join(glob.glob(density_path + "%.3fn_all.dat" % (z_arr[i - 1]))) print "Density file = %s" % density_file dfile = c2t.DensityFile(density_file) # dens_arr = np.reshape(dfile.raw_density,box_vol) xfrac_file = "".join(glob.glob(xfrac_path + "xfrac3d_%.3f.bin" % (z_arr[i]))) print "Ionized fraction file = %s" % xfrac_file xfile = c2t.XfracFile(xfrac_file) # xfrac_arr = np.reshape(xfile.xi,box_vol) avg_nHII = xfile.xi.mean() avg_mHII = c2t.mass_weighted_mean_xi(xfile.xi, dfile.raw_density) print "z, avg_nHII, avg_mHII = %.3f %.4e %.4e" % (z_arr[i], avg_nHII, avg_mHII) out.write("%.3f %.4e %.4e \n" % (z_arr[i], avg_nHII, avg_mHII)) out.close()