def read_HMF_data(snapdir, snapnum, bins_HMF, dN, BoxSize): FoF = readfof.FoF_catalog(snapdir,snapnum,long_ids=False, swap=False,SFR=False,read_IDs=False) mass = FoF.GroupMass*1e10 #Msun/h part = FoF.GroupLen #number of particles in the halo p_mass = mass[0]/part[0] #mass of a single particle in Msun/h mass = p_mass*(part*(1.0-part**(-0.6))) #corect FoF masses return np.histogram(part, bins=bins_HMF)[0]/(dN*BoxSize**3)*1e12
def FoF_halo_positions(groups_fname, groups_number, mass_interval, min_mass, max_mass): #read FoF halos information halos = readfof.FoF_catalog(groups_fname, groups_number, long_ids=True, swap=False) Pos = halos.GroupPos / 1e3 #Mpc/h if mass_interval: a = halos.GroupMass > min_mass b = halos.GroupMass < max_mass c = a * b halos_indexes = np.where(c == True)[0] del a, b, c, halos Pos = Pos[halos_indexes] return Pos
def find_Pk(folder, snapdir, snapnum, grid, MAS, do_RSD, axis, threads, fixed_Mmin, Mmin, Nhalos, fpk, save_multipoles): if os.path.exists(fpk): return 0 # read header head = readgadget.header(snapdir) BoxSize = head.boxsize/1e3 #Mpc/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 halo catalogue FoF = readfof.FoF_catalog(folder, snapnum, long_ids=False, swap=False, SFR=False, read_IDs=False) pos_h = FoF.GroupPos/1e3 #Mpc/h mass = FoF.GroupMass*1e10 #Msun/h vel_h = FoF.GroupVel*(1.0+redshift) #km/s if fixed_Mmin: indexes = np.where(mass>Mmin)[0] pos_h = pos_h[indexes]; vel_h = vel_h[indexes]; del indexes else: indexes = np.argsort(mass)[-Nhalos:] #take the Nhalos most massive halos pos_h = pos_h[indexes]; vel_h = vel_h[indexes]; del indexes # move halos to redshift-space if do_RSD: RSL.pos_redshift_space(pos_h, vel_h, BoxSize, Hubble, redshift, axis) # calculate Pk delta = np.zeros((grid,grid,grid), dtype=np.float32) MASL.MA(pos_h, delta, BoxSize, MAS) delta /= np.mean(delta, dtype=np.float64); delta -= 1.0 Pk = PKL.Pk(delta, BoxSize, axis, MAS, threads) # save results to file hdr = ('Nhalos=%i BoxSize=%.3f'%(pos_h.shape[0],BoxSize)) if save_multipoles: np.savetxt(fpk, np.transpose([Pk.k3D, Pk.Pk[:,0], Pk.Pk[:,1], Pk.Pk[:,2]]), delimiter='\t', header=hdr) else: np.savetxt(fpk, np.transpose([Pk.k3D, Pk.Pk[:,0]]), delimiter='\t', header=hdr)
def mass_function_fsigma(groups_fname, groups_number, f_out, min_mass, max_mass, bins, BoxSize, obj, Omega_M, k, Pk): rhoM = rho_crit * Omega_M bins_mass = np.logspace(np.log10(min_mass), np.log10(max_mass), bins + 1) mass_mean = 10**(0.5 * (np.log10(bins_mass[1:]) + np.log10(bins_mass[:-1]))) if obj == 'FoF': #read FoF halos information fof = readfof.FoF_catalog(groups_fname, groups_number, long_ids=True, swap=False) F_pos = fof.GroupPos / 1e3 #positions in Mpc/h F_mass = fof.GroupMass * 1e10 #masses in Msun/h F_part = fof.GroupLen #number particles belonging to the group F_Mpart = F_mass[0] / F_part[0] #mass of a single particle in Msun/h del fof #Correct the masses of the FoF halos F_mass = F_Mpart * (F_part * (1.0 - F_part**(-0.6))) #some verbose print 'Number of FoF halos=', len(F_pos) print np.min(F_pos[:, 0]), '< X_fof <', np.max(F_pos[:, 0]) print np.min(F_pos[:, 1]), '< Y_fof <', np.max(F_pos[:, 1]) print np.min(F_pos[:, 2]), '< Z_fof <', np.max(F_pos[:, 2]) print np.min(F_mass), '< M_fof <', np.max(F_mass) number = np.histogram(F_mass, bins=bins_mass)[0] print number print np.sum(number, dtype=np.float64) elif obj == 'halos_m200': #read CDM halos information halos = readsubf.subfind_catalog(groups_fname, groups_number, group_veldisp=True, masstab=True, long_ids=True, swap=False) H_pos = halos.group_pos / 1e3 #positions in Mpc/h H_mass = halos.group_m_mean200 * 1e10 #masses in Msun/h H_radius_m = halos.group_r_mean200 / 1e3 #radius in Mpc/h del halos #some verbose print 'Number of halos=', len(H_pos) print np.min(H_pos[:, 0]), '< X_fof <', np.max(H_pos[:, 0]) print np.min(H_pos[:, 1]), '< Y_fof <', np.max(H_pos[:, 1]) print np.min(H_pos[:, 2]), '< Z_fof <', np.max(H_pos[:, 2]) print np.min(H_mass), '< M_fof <', np.max(H_mass) number = np.histogram(H_mass, bins=bins_mass)[0] print number print np.sum(number, dtype=np.float64) else: print 'bad object type selected' sys.exit() sigma_mean = np.empty(bins) f_sigma = np.empty(bins) delta_f_sigma = np.empty(bins) for i in range(bins): R1 = (3.0 * bins_mass[i] / (4.0 * pi * rhoM))**(1.0 / 3.0) sigma1 = sigma(k, Pk, R1) R2 = (3.0 * bins_mass[i + 1] / (4.0 * pi * rhoM))**(1.0 / 3.0) sigma2 = sigma(k, Pk, R2) sigma_mean[i] = 0.5 * (sigma2 + sigma1) f_sigma[i] = (number[i] / np.log(sigma2 / sigma1)) / BoxSize**3 f_sigma[i] = -(mass_mean[i] / rhoM) * f_sigma[i] delta_f_sigma[i] = (np.sqrt(number[i]) / np.log(sigma2 / sigma1)) / BoxSize**3 delta_f_sigma[i] = -(mass_mean[i] / rhoM) * delta_f_sigma[i] f = open(f_out, 'w') for i in range(bins): f.write( str(sigma_mean[i]) + ' ' + str(f_sigma[i]) + ' ' + str(delta_f_sigma[i]) + ' ' + str(mass_mean[i]) + '\n') f.close()
def mass_function(groups_fname, groups_number, obj, BoxSize, bins, f_out, min_mass=None, max_mass=None, long_ids_flag=True, SFR_flag=False): #bins_mass=np.logspace(np.log10(min_mass),np.log10(max_mass),bins+1) #mass_mean=10**(0.5*(np.log10(bins_mass[1:])+np.log10(bins_mass[:-1]))) #dM=bins_mass[1:]-bins_mass[:-1] if obj == 'FoF': #read FoF halos information fof = readfof.FoF_catalog(groups_fname, groups_number, long_ids=long_ids_flag, swap=False, SFR=SFR_flag) F_pos = fof.GroupPos / 1e3 #positions in Mpc/h F_mass = fof.GroupMass * 1e10 #masses in Msun/h F_part = fof.GroupLen #number particles belonging to the group F_Mpart = F_mass[0] / F_part[0] #mass of a single particle in Msun/h del fof #some verbose print '\nNumber of FoF halos=', len(F_pos) print '%f < X_fof < %f' % (np.min(F_pos[:, 0]), np.max(F_pos[:, 0])) print '%f < Y_fof < %f' % (np.min(F_pos[:, 1]), np.max(F_pos[:, 1])) print '%f < Z_fof < %f' % (np.min(F_pos[:, 2]), np.max(F_pos[:, 2])) print '%e < M_fof < %e\n' % (np.min(F_mass), np.max(F_mass)) #Correct the masses of the FoF halos F_mass = F_Mpart * (F_part * (1.0 - F_part**(-0.6))) #compute the minimum and maximum mass if min_mass == None: min_mass = np.min(F_mass) if max_mass == None: max_mass = np.max(F_mass) print 'M_min = %e' % (min_mass) print 'M_max = %e\n' % (max_mass) #find the masses and mass intervals bins_mass = np.logspace(np.log10(min_mass), np.log10(max_mass), bins + 1) mass_mean = 10**(0.5 * (np.log10(bins_mass[1:]) + np.log10(bins_mass[:-1]))) dM = bins_mass[1:] - bins_mass[:-1] #compute the number of halos within each mass interval number = np.histogram(F_mass, bins=bins_mass)[0] print number print np.sum(number, dtype=np.float64) elif obj == 'halos_m200': #read CDM halos information halos = readsubf.subfind_catalog(groups_fname, groups_number, group_veldisp=True, masstab=True, long_ids=True, swap=False) H_pos = halos.group_pos / 1e3 #positions in Mpc/h H_mass = halos.group_m_mean200 * 1e10 #masses in Msun/h H_radius_m = halos.group_r_mean200 / 1e3 #radius in Mpc/h del halos #some verbose print '\nNumber of halos=', len(H_pos) print '%f < X < %f' % (np.min(H_pos[:, 0]), np.max(H_pos[:, 0])) print '%f < Y < %f' % (np.min(H_pos[:, 1]), np.max(H_pos[:, 1])) print '%f < Z < %f' % (np.min(H_pos[:, 2]), np.max(H_pos[:, 2])) print '%e < M < %e\n' % (np.min(H_mass), np.max(H_mass)) #compute the minimum and maximum mass if min_mass == None: min_mass = np.min(H_mass) if max_mass == None: max_mass = np.max(H_mass) #compute the number of halos within each mass interval bins_mass = np.logspace(np.log10(min_mass), np.log10(max_mass), bins + 1) mass_mean = 10**(0.5 * (np.log10(bins_mass[1:]) + np.log10(bins_mass[:-1]))) dM = bins_mass[1:] - bins_mass[:-1] number = np.histogram(H_mass, bins=bins_mass)[0] print number print np.sum(number, dtype=np.float64) elif obj == 'halos_c200': #read CDM halos information halos = readsubf.subfind_catalog(groups_fname, groups_number, group_veldisp=True, masstab=True, long_ids=True, swap=False) H_pos = halos.group_pos / 1e3 #positions in Mpc/h H_mass = halos.group_m_crit200 * 1e10 #masses in Msun/h H_radius_m = halos.group_r_crit200 / 1e3 #radius in Mpc/h del halos #some verbose print '\nNumber of halos=', len(H_pos) print '%f < X < %f' % (np.min(H_pos[:, 0]), np.max(H_pos[:, 0])) print '%f < Y < %f' % (np.min(H_pos[:, 1]), np.max(H_pos[:, 1])) print '%f < Z < %f' % (np.min(H_pos[:, 2]), np.max(H_pos[:, 2])) print '%e < M < %e\n' % (np.min(H_mass), np.max(H_mass)) #compute the minimum and maximum mass if min_mass == None: min_mass = np.min(H_mass) if max_mass == None: max_mass = np.max(H_mass) #compute the number of halos within each mass interval bins_mass = np.logspace(np.log10(min_mass), np.log10(max_mass), bins + 1) mass_mean = 10**(0.5 * (np.log10(bins_mass[1:]) + np.log10(bins_mass[:-1]))) dM = bins_mass[1:] - bins_mass[:-1] number = np.histogram(H_mass, bins=bins_mass)[0] print number print np.sum(number, dtype=np.float64) elif obj == 'subhalos': #read CDM halos information halos = readsubf.subfind_catalog(groups_fname, groups_number, group_veldisp=True, masstab=True, long_ids=True, swap=False) S_pos = halos.sub_pos / 1e3 #positions in Mpc/h S_mass = halos.sub_mass * 1e10 #masses in Msun/h del halos #some verbose print '\nNumber of subhalos=', len(S_pos) print '%f < X < %f' % (np.min(S_pos[:, 0]), np.max(S_pos[:, 0])) print '%f < Y < %f' % (np.min(S_pos[:, 1]), np.max(S_pos[:, 1])) print '%f < Z < %f' % (np.min(S_pos[:, 2]), np.max(S_pos[:, 2])) print '%e < M < %e\n' % (np.min(S_mass), np.max(S_mass)) #compute the minimum and maximum mass if min_mass == None: min_mass = np.min(S_mass) if max_mass == None: max_mass = np.max(S_mass) #compute the number of halos within each mass interval bins_mass = np.logspace(np.log10(min_mass), np.log10(max_mass), bins + 1) mass_mean = 10**(0.5 * (np.log10(bins_mass[1:]) + np.log10(bins_mass[:-1]))) dM = bins_mass[1:] - bins_mass[:-1] number = np.histogram(S_mass, bins=bins_mass)[0] print number print np.sum(number, dtype=np.float64) else: print 'bad object type selected' sys.exit() MF = number / (dM * BoxSize**3) delta_MF = np.sqrt(number) / (dM * BoxSize**3) f = open(f_out, 'w') for i in range(bins): f.write( str(mass_mean[i]) + ' ' + str(MF[i]) + ' ' + str(delta_MF[i]) + '\n') f.close()
f1 = '%s/%s/NCV_%d_%d/snapdir_%03d/snap_%03d' % (root, cosmo, pair, i, snapnum, snapnum) f2 = '%s/%s/NCV_%d_%d/' % (root, cosmo, pair, i) # compute delta_c delta_c = MASL.density_field_gadget(f1, ptypes, grid, MAS, do_RSD, axis) delta_c /= np.mean(delta_c, dtype=np.float64) delta_c -= 1.0 # compute delta_h delta_h = np.zeros((grid, grid, grid), dtype=np.float32) FoF = readfof.FoF_catalog(f2, snapnum, long_ids=False, swap=False, SFR=False, read_IDs=False) pos_h = FoF.GroupPos / 1e3 #Mpc/h mass = FoF.GroupMass * 1e10 #Msun/h indexes = np.where(mass > Mmin)[0] pos_h = pos_h[indexes] del indexes MASL.MA(pos_h, delta_h, BoxSize, MAS) delta_h /= np.mean(delta_h, dtype=np.float64) delta_h -= 1.0 # compute power spectra Pk = PKL.XPk([delta_c, delta_h], BoxSize, axis, [MAS, MAS], threads)
#compute the value of Omega_HI print 'Omega_HI = %.4e' % (np.sum(M_HI, dtype=np.float64) / BoxSize**3 / rho_crit) #we create the array Star_mass that only contain the masses of the stars Star_mass = np.zeros(Ntotal, dtype=np.float32) Star_IDs = readsnap.read_block(snapshot_fname, "ID ", parttype=4) - 1 #normalized Star_mass[Star_IDs]=\ readsnap.read_block(snapshot_fname,"MASS",parttype=4)*1e10 #Msun/h del Star_IDs # read FoF halos information halos = readfof.FoF_catalog(groups_fname, groups_number, long_ids=long_ids_flag, swap=False, SFR=SFR_flag) pos_FoF = halos.GroupPos / 1e3 #Mpc/h M_FoF = halos.GroupMass * 1e10 #Msun/h ID_FoF = halos.GroupIDs - 1 #normalize IDs Len = halos.GroupLen #number of particles in the halo Offset = halos.GroupOffset #offset of the halo in the ID array del halos # some verbose print 'Number of FoF halos:', len(pos_FoF), len(M_FoF) print '%f < X [Mpc/h] < %f' % (np.min(pos_FoF[:, 0]), np.max(pos_FoF[:, 0])) print '%f < Y [Mpc/h] < %f' % (np.min(pos_FoF[:, 1]), np.max(pos_FoF[:, 1])) print '%f < Z [Mpc/h] < %f' % (np.min(pos_FoF[:, 2]), np.max(pos_FoF[:, 2])) print '%e < M [Msun/h] < %e\n' % (np.min(M_FoF), np.max(M_FoF))
def find_Bk(folder, snapdir, snapnum, axis, Ngrid, step, Ncut, Nmax, do_RSD, fixed_Mmin, Mmin, Nhalos): # read header head = readgadget.header(snapdir) BoxSize = head.boxsize / 1e3 #Mpc/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 halo catalogue FoF = readfof.FoF_catalog(folder, snapnum, long_ids=False, swap=False, SFR=False, read_IDs=False) pos_h = FoF.GroupPos / 1e3 #Mpc/h mass = FoF.GroupMass * 1e10 #Msun/h vel_h = FoF.GroupVel * (1.0 + redshift) #km/s if fixed_Mmin: indexes = np.where(mass > Mmin)[0] pos_h = pos_h[indexes] vel_h = vel_h[indexes] del indexes else: indexes = np.argsort(mass)[ -Nhalos:] #take the Nhalos most massive halos pos_h = pos_h[indexes] vel_h = vel_h[indexes] del indexes # move halos to redshift-space if do_RSD: RSL.pos_redshift_space(pos_h, vel_h, BoxSize, Hubble, redshift, axis) # calculate bispectrum b123out = pySpec.Bk_periodic(pos_h.T, Lbox=BoxSize, Ngrid=Ngrid, step=step, Ncut=Ncut, Nmax=Nmax, fft='pyfftw', nthreads=1, silent=False) i_k = b123out['i_k1'] j_k = b123out['i_k2'] l_k = b123out['i_k3'] p0k1 = b123out['p0k1'] p0k2 = b123out['p0k2'] p0k3 = b123out['p0k3'] b123 = b123out['b123'] b_sn = b123out['b123_sn'] q123 = b123out['q123'] cnts = b123out['counts'] hdr = ('halo bispectrum; k_f = 2pi/%.1f, Nhalo=%i' % (BoxSize, pos_h.shape[0])) np.savetxt( fbk, np.array([i_k, j_k, l_k, p0k1, p0k2, p0k3, b123, q123, b_sn, cnts]).T, fmt='%i %i %i %.5e %.5e %.5e %.5e %.5e %.5e %.5e', delimiter='\t', header=hdr)
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 z = '%.3f' % redshift ######################################################################### ######################################################################### pos = readsnap.read_block(snapshot_fname, "POS ", parttype=1) / 1e3 #Mpc/h vel = readsnap.read_block(snapshot_fname, "VEL ", parttype=1) #km/s ######################################################################### ######################################################################### # read positions and velocities of halos FoF = readfof.FoF_catalog(snapdir, snapnum, long_ids=False, swap=False, SFR=False, read_IDs=True) pos_h = FoF.GroupPos / 1e3 #Mpc/h mass = FoF.GroupMass * 1e10 #Msun/h vel_h = FoF.GroupVel * (1.0 + redshift) #km/s indexes = np.where(mass > Mmin)[0] pos_h = pos_h[indexes] vel_h = vel_h[indexes] del indexes #########################################################################
def generate_data(realization,cluster): sim = realization #raise NotImplementedError("Please update the directory of the data to your system below.") #snapshot = '/mnt/ceph/users/fvillaescusa/Quijote/Snapshots/latin_hypercube_HR/%d/snapdir_004/snap_004' % (sim,) #snapdir = '/mnt/ceph/users/fvillaescusa/Quijote/Halos/latin_hypercube/%d' % (sim,) if cluster=='adroit': prefix = '/scratch/network/jdh4' snapshot = prefix +'/projects/QUIJOTE/Snapshots/fiducial_HR/%d/snapdir_004/snap_004' % (sim,) snapdir = prefix +'/projects/QUIJOTE/Halos/fiducial_HR/%d' % (sim,) elif cluster=='tiger': snapshot = '/projects/QUIJOTE/Snapshots/fiducial_HR/%d/snapdir_004/snap_004' % (sim,) snapdir = '/projects/QUIJOTE/Halos/fiducial_HR/%d' % (sim,) else: try: snapshot = '/mnt/ceph/users/fvillaescusa/Quijote/Snapshots/latin_hypercube_HR/%d/snapdir_004/snap_004' % (sim,) snapdir = '/mnt/ceph/users/fvillaescusa/Quijote/Halos/latin_hypercube/%d' % (sim,) except ValueError: print("Path not found. Wrong cluster or data DNE.") #snapshot = '/projects/QUIJOTE/Snapshots/fiducial_HR/%d/snapdir_004/snap_004' % (sim,) #snapdir = '/projects/QUIJOTE/Halos/fiducial_HR/%d' % (sim,) snapnum = 4 # parameters for density field grid = 1024 #density field will have grid^3 voxels ptypes = [1] #CDM MAS = 'CIC' #mass assignment scheme do_RSD = False #dont do redshift-space distortions axis = 0 #only needed if do_RSD=True # parameters for smoothing BoxSize = 1000.0 #Mpc/h R = 20.0 #Mpc.h Filter = 'Top-Hat' #'Top-Hat' or 'Gaussian' threads = 28 #number of openmp threads ####################################################################################### # # Computing density contrast field: # compute density field of the snapshot (density constrast d = rho/<rho>-1) delta = MASL.density_field_gadget(snapshot, ptypes, grid, MAS, do_RSD, axis) delta /= np.mean(delta, dtype=np.float64); delta -= 1.0 # # Smooth density field: # smooth the field on a given scale W_k = SL.FT_filter(BoxSize, R, grid, Filter, threads) delta_smoothed = SL.field_smoothing(delta, W_k, threads) # # Load halo properties: # read halo catalogue z_dict = {4:0.0, 3:0.5, 2:1.0, 1:2.0, 0:3.0} redshift = z_dict[snapnum] FoF = readfof.FoF_catalog(snapdir, snapnum, long_ids=False, swap=False, SFR=False, read_IDs=False) pos_h = FoF.GroupPos/1e3 #Halo positions in Mpc/h mass = FoF.GroupMass*1e10 #Halo masses in Msun/h vel_h = FoF.GroupVel*(1.0+redshift) #Halo peculiar velocities in km/s # # Find overdensity at each halo: # interpolate to find the value of the smoothed overdensity field at the position of each halo # delta_h will contain the value of the smoothed overdensity in the position of each halo delta_h = np.zeros(pos_h.shape[0], dtype=np.float32) MASL.CIC_interp(delta_smoothed, BoxSize, pos_h, delta_h) # # Save: cur_data = pd.DataFrame({ 'x': pos_h[:, 0], 'y': pos_h[:, 1], 'z': pos_h[:, 2], 'vx': vel_h[:, 0], 'vy': vel_h[:, 1], 'vz': vel_h[:, 2], 'M14': mass/1e14, 'delta': delta_h }) cur_data.to_hdf('halos_%d.h5' % (sim,), 'df')
#we set here the actions DD_action = 'compute' RR_action = 'read' #if needed, the RR pairs are computed above DR_action = 'compute' #Only the master will read the positions of the galaxies pos_g = None #### MASTER #### if myrank==0: #read FoF-halos/subfind-halos/subhalos information print '\nReading galaxy catalogue' if obj == 'FoF_halos': #read FoF file halos = readfof.FoF_catalog(groups_fname,groups_number, long_ids=False,swap=False) halos_pos = halos.GroupPos/1e3; #Mpc/h halos_mass = halos.GroupMass*1e10 #Msun/h halos_vel = halos.GroupVel*(1.0+redshift) #km/s halos_indexes = np.where((halos_mass>min_mass) & \ (halos_mass<max_mass))[0] pos_g = halos_pos[halos_indexes] if do_RSD: vel_g = halos_vel[halos_indexes] RSL.pos_redshift_space(pos_g,vel_g,BoxSize,Hubble,redshift,axis) elif obj == 'halos' or obj == 'subhalos': #read subfind file halos = readsubf.subfind_catalog(groups_fname,groups_number, group_veldisp=True,masstab=True,
def illustris_HI_assignment(snapshot_fname, groups_fname, groups_number, Np_halo=100, long_ids_flag=True): print '\n. . reading the snapshot header . .' #read snapshot header and obtain BoxSize, redshift and h head = readsnap.snapshot_header(snapshot_fname) BoxSize = head.boxsize / 1e3 #Mpc/h Nall = head.nall redshift = head.redshift mass_DMparticle = head.massarr[1] * 1e10 #Msun/h h = head.hubble del head #find the total number of particles in the simulation Ntotal = np.sum(Nall, dtype=np.int64) print 'Total number of particles in the simulation: %d' % Ntotal #read FoF halos information halos = readfof.FoF_catalog(groups_fname, groups_number, long_ids=long_ids_flag, swap=False) pos_FoF = halos.GroupPos / 1e3 #Mpc/h M_FoF = halos.GroupMass * 1e10 #Msun/h ID_FoF = halos.GroupIDs - 1 #normalize IDs Len = halos.GroupLen #number of particles in the halo Offset = halos.GroupOffset #offset of the halo in the ID array del halos #some verbose print 'Number of FoF halos:', len(pos_FoF), len(M_FoF) print '%f < X [Mpc/h] < %f' % (np.min(pos_FoF[:, 0]), np.max(pos_FoF[:, 0])) print '%f < Y [Mpc/h] < %f' % (np.min(pos_FoF[:, 1]), np.max(pos_FoF[:, 1])) print '%f < Z [Mpc/h] < %f' % (np.min(pos_FoF[:, 2]), np.max(pos_FoF[:, 2])) print '%e < M [Msun/h] < %e\n' % (np.min(M_FoF), np.max(M_FoF)) del pos_FoF #compute the total mass in halos from the halo catalogue print 'Total contributing mass from the catalogue = %e Msun/h'\ %(np.sum(M_FoF,dtype=np.float64)) print '. . considering halos with at least ' + str( Np_halo) + ' particles . . ' # cutting catalogue to halos with at least 100 particles mass_100p = mass_DMparticle * Np_halo indeces = np.where(M_FoF > mass_100p)[0] M_FoF = M_FoF[indeces] del indeces #compute the total mass in halos from the halo catalogue print 'Total contributing mass from the catalogue = %e Msun/h'\ %(np.sum(M_FoF,dtype=np.float64)) print 'Number of FoF halos:', len(M_FoF), '\n' print '%e < M [Msun/h] < %e' % (np.min(M_FoF), np.max(M_FoF)) print str(Np_halo) + '* the DM particle mass = %e [Msun/h]\n' % ( mass_DMparticle * Np_halo) # compute the values of M_HI(M_halo) function # see eq.13 of Villaescusa-Navarro et al. 2018 print '\nParameters for M_HI(M_halo) function:' print ' M_0 (z=%2.1f) = %2.2e Msun/h' % (redshift, M0_illustris(redshift)) print ' M_min (z=%2.1f) = %2.2e Msun/h' % (redshift, Mmin_illustris(redshift)) print ' alpha (z=%2.1f) = %1.2f\n' % (redshift, alpha_illustris(redshift)) #define the IDs array if long_ids_flag: IDs = np.empty(len(ID_FoF), dtype=np.uint64) else: IDs = np.empty(len(ID_FoF), dtype=np.uint32) #loop over the halos containing HI and assign the HI to the particles M_HI = np.zeros(Ntotal, dtype=np.float32) No_gas_halos = 0 IDs_offset = 0 for index in range(len(M_FoF)): #select the IDs of all particles belonging to the halo indexes = ID_FoF[Offset[index]:Offset[index] + Len[index]] #fill the IDs array IDs[IDs_offset:IDs_offset + len(indexes)] = indexes IDs_offset += len(indexes) #compute the total HI mass within the dark matter halo M_HI_halo = MHI_illustris(M_FoF[index], redshift) #if there are gas particles assign the HI to them Num_gas = len(indexes) if Num_gas > 0: M_HI[indexes] += (M_HI_halo * 1.0 / Num_gas) else: No_gas_halos += 1 print '\nNumber of halos with no gas particles=', No_gas_halos #just keep the IDs of the particles to which HI has been assigned IDs = IDs[0:IDs_offset] #compute the value of OmegaHI OmegaHI = np.sum(M_HI, dtype=np.float64) / BoxSize**3 / rho_crit print '\nOmega_HI (halos) = %e\n' % (OmegaHI) return OmegaHI, IDs, M_HI