Beispiel #1
0
def dNdM(M,window='th',z=0):
    """
    The halo mass function as given equation 2 of
    Tinker 2008 ApJ 679, 1218
    Parameters
    ----------
    M: float
        Halo mass in units of M_sun/h
    window: string, optional
        Choice of window function. By default it
        is a top hat profile.
    z: float, optional
        Redshift at which the mass funciton is to
        be computed. Default value: 0
    Returns
    -------
    dNdM: float
        dN/dM. Implicitly dependent of redshift.
        This is in units of M^2/rho_m. To get the
        true dN/dM, multiply by rho_m/M^2
    """
    import numpy as np
    from compos import const

    const.initializecosmo(z=z)
    rho_crit0 = 2.776992e12*const.cosmo['h']**2 #M_sun/Mpc^3
    rho_m = const.cosmo['omega_0']*rho_crit0*(1+z)**3
    R = (3*M/const.cosmo['h']/(4*np.pi*rho_m))**(1/3)

    sigma = np.sqrt(psvariance(R,z=z)[0])

    dNdM = -f_of_sigma(sigma)*R*dlogsigma_dr(R)/3
    return dNdM
Beispiel #2
0
def psvariance(R, W='th',low = 1e-7,high=100,z=0):
    """
    Variance of the linear power spectrum. Use the
    power spectrum from COMPOS (Ziang Yen). Numerically
    and obtains the variance.
    Parameters
    ----------
    R: float
        Smoothing radius
    W: string, optional
        Form of the normalised window function.
        'th' for top-hat profile and 'ga' for
        gaussian.
    low: float, optional
        Lower integration limit to get the variance
    high: float, optional
        Upper integration limit
    z: float, optional
        Redshift. Defualt value is 0.
    Returns
    -------
    variance: float
        Variance of the smoothed ps.
    error: float
        Error incurred in variance from numerical integration
    """
    import numpy as np
    from scipy.integrate import quad
    from compos import const, matterps

    const.initializecosmo(z=z)
    integrand = lambda k: (k*window_th(k,R))**2*matterps.normalizedmp(k)
    integral = quad(integrand,low,high)
    variance = integral[0]/(2*np.pi)**2
    error = integral[1]/(2*np.pi)**2
    return variance, error
Beispiel #3
0
# This script calculates linear matter power spectrum at
# z = 0 with a given set of cosmologycal parameters#

import numpy as np
import matplotlib.pyplot as mp

from compos import const, matterps

const.initializecosmo()

k = np.linspace(-4, np.log10(6.71600e+02), 10000)
k = 10**k * const.cosmo['h']
p = matterps.normalizedmp(k)

# p_nw = matterps.normalizedmpnw(k)

mp.loglog(k / const.cosmo['h'], p * const.cosmo['h']**3)
plottextl = mp.xlim()[0] * 2
plottextd = mp.ylim()[0] * 2
mp.text(plottextl,
        plottextd,
        r'$h = $' + str(const.cosmo['h']) + ', $\Omega_mh^2$ = ' +
        str(const.cosmo['omega_0'] * const.cosmo['h']**2) +
        ', $\Omega_bh^2$ = ' +
        str(const.cosmo['omega_b'] * const.cosmo['h']**2),
        fontsize=15)
mp.ylabel('P(k)(h$^{-3}$Mpc$^{-3}$)')
mp.xlabel('k (h Mpc$^{-1}$)')
mp.savefig('../../results/matterps/mps.jpg')
mp.savefig('../../results/matterps/mps.pdf')
mp.show()
Beispiel #4
0
# This script uses pyhalofit.py to calculate nonlinear power spectra#

import numpy as np
import matplotlib.pyplot as mp

from compos import const, pyhalofit, growthfactor, matterps


# set parameters(as an example)#

const.initializecosmo()

x = np.linspace(-4, 1, 1000)
k = 10 ** x
d2 = growthfactor.growfunc_z(10)
d1 = growthfactor.growfunc_z(5)
pyhalofit.supparams(growthf=d2)
np2 = pyhalofit.nlpowerspec(k, 10)
pyhalofit.supparams(growthf=d1)
np1 = pyhalofit.nlpowerspec(k, 5)
pyhalofit.supparams()
np0 = pyhalofit.nlpowerspec(k, 0)
t = np.zeros((2, np.size(k)))

p2 = matterps.normalizedmp(k, 10)
p1 = matterps.normalizedmp(k, 5)
p0 = matterps.normalizedmp(k, 0)

mp.loglog(k/const.cosmo['h'], np0, label='nonlinear, z=0')
mp.loglog(k/const.cosmo['h'], p0, label='linear, z=0')
mp.loglog(k/const.cosmo['h'], np1, label='nonlinear,z=5')
Beispiel #5
0
# This code calls camb to generate a matter power spectrum
# at a given set of cosmological parameters and interpolate it at a given k#

# This script calculates linear matter power spectrum at
# z = 0 with a given set of cosmologycal parameters#

import numpy as np
import os
import matplotlib.pyplot as mp

from compos import const, camb_interp

f = os.getcwd()
const.initializecosmo(kmax=20, callcamb=1)
os.chdir(f)

k = np.linspace(-3, 1, 10000)
k = 10**k * const.cosmo['h']

p = camb_interp.normCAMB_Pk(k)

mp.loglog(k / const.cosmo['h'], p * const.cosmo['h']**3)
plottextl = mp.xlim()[0] * 2
plottextd = mp.ylim()[0] * 2
mp.text(plottextl,
        plottextd,
        r'$h = $' + str(const.cosmo['h']) + ', $\Omega_mh^2$ = ' +
        str(const.cosmo['omega_0'] * const.cosmo['h']**2) +
        ', $\Omega_bh^2$ = ' +
        str(const.cosmo['omega_b'] * const.cosmo['h']**2),
        fontsize=15)
Beispiel #6
0
import numpy as np
import matplotlib.pyplot as mp

import os
from compos import const, camb_interp, pyhalofit_camb

f = os.getcwd()
const.initializecosmo(callcamb=1)

pyhalofit_camb.supparams()
x = np.linspace(-4, np.log(2), 1000)
k = 10 ** x
p = pyhalofit_camb.nlpowerspec(k)
t = np.zeros((2, np.size(k)))
t[0] = k
t[1] = p
t = np.transpose(t)
p2 = camb_interp.CAMB_Pk(k)

os.chdir(f)
np.savetxt('../../results/pyhalofit/halofit_camb.txt', t)
mp.loglog(k, p, label='nonlinear')
mp.loglog(k, p2, label='linear')
mp.text(0.001, 0.1, '$h = 0.7, \Omega_mh^2$ = ' +
        str(const.cosmo['omega_0']*const.cosmo['h']**2) +
        ',$ \Omega_qh^2 = $'+str(const.cosmo['omega_q'] *
                                 const.cosmo['h']**2)+',', fontsize=15)
mp.legend()
mp.xlabel('k (h Mpc$^{-1}$)')
mp.ylabel('P(k) (h$^{-3}$ Mpc$^{-3}$)')
mp.savefig('../../results/pyhalofit/pyhalofit_camb.pdf')
Beispiel #7
0
# This code calls camb to generate a matter power spectrum
# at a given set of cosmological parameters and interpolate it at a given k#

# This script calculates linear matter power spectrum at
# z = 0 with a given set of cosmologycal parameters#

import numpy as np
import os
import matplotlib.pyplot as mp

from compos import const, camb_interp

f = os.getcwd()
const.initializecosmo(kmax=20, callcamb=1)
os.chdir(f)

k = np.linspace(-3, 1, 10000)
k = 10 ** k * const.cosmo['h']

p = camb_interp.normCAMB_Pk(k)

mp.loglog(k / const.cosmo['h'], p * const.cosmo['h'] ** 3)
plottextl = mp.xlim()[0] * 2
plottextd = mp.ylim()[0] * 2
mp.text(plottextl, plottextd, r'$h = $' + str(const.cosmo['h']) +
        ', $\Omega_mh^2$ = ' + str(const.cosmo['omega_0'] *
                                   const.cosmo['h'] ** 2) +
        ', $\Omega_bh^2$ = ' + str(const.cosmo['omega_b'] *
                                   const.cosmo['h'] ** 2), fontsize=15)
mp.ylabel('P(k)(h$^{-3}$Mpc$^{-3}$)')
mp.xlabel('k (h Mpc$^{-1}$)')
Beispiel #8
0
# This script gives examples of growth factor with respect to
# a with different set of (w_0, w_1)

import numpy as np
import matplotlib.pyplot as mp
import time

from compos import const, growthfactor

t0 = time.time()

const.initializecosmo(.3, 0, 0.67, 2.7255/2.7, omq=0.7, sigma8=0.8288)

a = np.linspace(0.0001, 1, 500)

# growthfactor.generateDE(-1, 0)
g1 = np.zeros(np.size(a))
for i in range(0, np.size(g1)):
    g1[i] = growthfactor.growfunc_a(a[i])

const.initializecosmo(0.3, 0, 0.67, 2.7255/2.7, omq=0.7, sigma8=0.8288,
                      w_0=-0.8, w_1=0, n_s=0.96)

# growthfactor.generateDE(-0.8, 0)
g2 = np.zeros(np.size(a))
for i in range(0, np.size(g1)):
    g2[i] = growthfactor.growfunc_a(a[i])

const.initializecosmo(0.3, 0, 0.67, 2.7255/2.7, omq=0.7, sigma8=0.8288,
                      w_0=-0.8, w_1=-0.6, n_s=0.96)