def plot_halo_mass_func(self): """Plots the halo mass function from simulation as well as Sheth-Torman""" self.load_sigDLA() mass = np.logspace(8, 13, 51) halo_mass = halo_mass_function.HaloMassFunction(self.redshift, omega_m=self.omegam, omega_l=self.omegal, hubble=self.hubble, log_mass_lim=(7, 15)) shdndm = [halo_mass.dndm(mm) for mm in mass] adndm = np.array( [self.get_dndm(mass[ii], mass[ii + 1]) for ii in range(0, 50)]) plt.loglog(mass, shdndm, color="black", ls='--', label="Sheth-Tormen") plt.loglog(mass[0:-1], adndm, color=acol, ls=astyle, label="Arepo") #Make the ticks be less-dense ax = plt.gca() ax.yaxis.set_ticks( np.power( 10., np.arange(int(np.log10(shdndm[-1])), int(np.log10(shdndm[0])), 2))) plt.ylabel(r"dn/dM (h$^4$ $M^{-1}_\odot$ Mpc$^{-3}$)") plt.xlabel(r"Mass ($M_\odot$ h$^{-1}$)") plt.legend(loc=0) # plt.xlim(self.minplot,self.maxplot) tight_layout_wrapper() plt.show()
def halonumber(n): halo = hmf.HaloMassFunction(redshift=0) #set redshift = 0 h = 0.67 #hubble constant mass = np.array([12 + i * 8 / n for i in range(0, n + 1) ]) / h #upper limit of halo mass is 20 Msolar/h dn = halo.dndm(mass) number = (sum(2 * dn) - dn[0] - dn[-1]) * 8 / ( 2 * n * h) #use sum to calculate integral. print( "Hubble constant is %.2f.\nThe number of halos per (Mpc/h)^3 are %.0f" % (h, number))
def plot_rel_halo_mass_func(self): """Plots the halo mass function from simulation divided by fitting formula""" self.load_sigDLA() massedge=np.logspace(8,13,51) halo_mass=halo_mass_function.HaloMassFunction(self.redshift,omega_m=self.omegam, omega_l=self.omegal, hubble=self.hubble,log_mass_lim=(7,15)) adndm=np.array([self.get_dndm(massedge[ii],massedge[ii+1]) for ii in range(np.size(massedge)-1)]) mass=np.array([(massedge[ii]+massedge[ii+1])/2. for ii in range(np.size(massedge)-1)]) shdndm=[halo_mass.dndm(mm) for mm in mass] plt.semilogx(mass,adndm/shdndm,color="black",ls='-') #Make the ticks be less-dense plt.xlabel(r"Mass ($M_\odot$ h$^{-1}$)") # plt.xlim(self.minplot,self.maxplot) tight_layout_wrapper() plt.show()
def get_N_DLA_dz(self,params, mass=1e9,maxmass=12.5): """Get the DLA number density as a function of redshift, defined as: d N_DLA / dz ( > M, z) = dr/dz int^infinity_M n_h(M', z) sigma_DLA(M',z) dM' where n_h is the Sheth-Torman mass function, and sigma_DLA is a power-law fit to self.sigma_DLA. Parameters: lower_mass in M_sun/h. """ try: self.halo_mass.dndm(mass) except AttributeError: #Halo mass function object self.halo_mass=halo_mass_function.HaloMassFunction(self.redshift,omega_m=self.omegam, omega_l=self.omegal, hubble=self.hubble,log_mass_lim=(7,15)) result = integ.quad(self.NDLA_integrand,np.log10(mass),maxmass, epsrel=1e-2,args=(params,)) #drdz is in cm/h, while the rest is in kpc/h, so convert. return self.drdz(self.redshift)*result[0]/self.UnitLength_in_cm
import numpy as np import halo_mass_function as HMF import scipy as sp #M_sun = 2 * pow(10, 30) m = np.logspace(12, 20) halo = HMF.HaloMassFunction(redshift=0) h = halo.overden.hubble0 M = m / h dndm_0 = halo.dndm_z(M, zz=0) N = sp.integrate.trapz(dndm_0, M) print("N = ", N)