Exemple #1
0
def get_masses(nu, z, box=0):
    Ombh2, Omch2, w, ns, ln10As, H0, Neff, sig8 = np.genfromtxt(
        AD.path_to_building_box_cosmologies())[int(box)]
    h = H0 / 100.
    Ob = Ombh2 / h**2
    Oc = Omch2 / h**2
    Om = Ob + Oc
    cosmo = {
        "om": Om,
        "ob": Ob,
        "ol": 1 - Om,
        "h": h,
        "s8": sig8,
        "ns": ns,
        "w0": w,
        "Neff": Neff,
        "wa": 0
    }
    cc.set_cosmology(cosmo)
    Ms = np.logspace(8, 17, num=100)  #Msun/h
    a = 1.0 / (1 + z)
    nus = np.array([DELTAC / cc.sigmaMtophat(Mi, a) for Mi in Ms])
    from scipy.interpolate import interp1d
    spl = interp1d(nus, np.log(Ms))
    return np.exp(spl(nu))  #np.log10(spl(nu))
def bias_denominator_integrand(logm, a, delta, cd) :
	import cosmocalc
	import numpy as np
	## Set the cosmocalc cosmology
	cosmocalc.set_cosmology(cd)
	## Need the mass in the integral, not the log10(mass)
	m = np.power(10., logm)
	## Return the integrand
	return cosmocalc.tinker2010_mass_function(m, a, delta)*m
def get_cosmocalc_beta(M, z):
    a = 1. / (1 + z)
    import cosmocalc as cc
    MF = cc.tinker2008_mass_function
    cc.set_cosmology(cos)
    d = 1.00001
    dndM1 = MF(M, a, 200)
    dndM2 = MF(M * d, a, 200)
    return np.log(dndM2 / dndM1) / np.log(d)
Exemple #4
0
 def set_new_cosmology(self, cosmo_dict, scale_factor):
     # Constants
     G = 4.52e-48  # Newton's gravitional constant in Mpc^3/s^2/Solar Mass
     Mpcperkm = 3.241e-20  # Mpc/km; used to convert H0 to s^-1
     self.cosmo_dict = cosmo_dict
     cc.set_cosmology(cosmo_dict)
     self.build_splines(scale_factor)
     Om, H0 = cosmo_dict["om"], cosmo_dict["h"] * 100.0
     self.rhom = Om * 3.0 * (H0 * Mpcperkm) ** 2 / (8 * np.pi * G * (H0 / 100.0) ** 2)  # Msun h^2/Mpc^3
Exemple #5
0
 def set_new_cosmology(self, cosmo_dict):
     """Specify a new set of cosmological parameters and then build splines that depend on these.
     
     Args:
         cosmo_dict (dictionary): Keys are cosmological parameters, specifically om for Omega_matter and h for Hubble constant/100.
     """
     cc.set_cosmology(cosmo_dict)
     Om = cosmo_dict["om"]
     self.rhom = Om * rhocrit  #Msunh^2/Mpc^3
     self.cosmo_dict = cosmo_dict
     return
 def set_new_cosmology(self, cosmo_dict):
     """Specify a new set of cosmological parameters and then build splines that depend on these.
     
     Args:
         cosmo_dict (dictionary): Keys are cosmological parameters, specifically om for Omega_matter and h for Hubble constant/100.
     """
     print "setting cc cos:",cosmo_dict
     cc.set_cosmology(cosmo_dict)
     print "sigma inside = ",cc.sigmaMtophat(1e14, 0.25)
     Om = cosmo_dict["om"]
     self.rhom=Om*rhocrit#Msunh^2/Mpc^3
     self.cosmo_dict = cosmo_dict
     return
Exemple #7
0
def set_cosmology(cos):
    ombh2, omch2, w0, ns, ln10As, H0, Neff, sigma8 = cos
    h = H0 / 100.
    Ob = ombh2 / h**2
    Om = Ob + omch2 / h**2
    cosmo_dict = {
        "om": Om,
        "ob": Ob,
        "ol": 1 - Om,
        "ok": 0.0,
        "h": h,
        "s8": sigma8,
        "ns": ns,
        "w0": w0,
        "wa": 0.0
    }
    cc.set_cosmology(cosmo_dict)
    return
Exemple #8
0
    def calcMassFunction(self, z=0, delta=200):

	# mass bins, definitions, z bins

	if hasattr(delta, '__iter__'):
            self.ndefs = len(delta)
        else:
            self.ndefs = 1
	    delta = [delta]

	if hasattr(z , '__iter__'):
            self.nzbins = len(z)
	else:
	    z=[z]
            self.nzbins = 1

	self.nbands = self.ndefs

	cd = {
               	"OmegaM":0.286,
               "OmegaB":0.05,
               "OmegaDE":0.714,
               "OmegaK":0.0,
               "h":0.7,
               "Sigma8":0.82,
               "SpectralIndex":0.96,
               "w0":-1.0,
               "wa":0.0
	}
	cosmocalc.set_cosmology(cd)

	mass_fn_n     = np.zeros((len(self.massbins)-1, self.ndefs, self.nzbins))
	mass_fn_error = np.zeros((len(self.massbins)-1, self.ndefs, self.nzbins))

        for k in range(self.nzbins):
		for j in range(self.ndefs):
	            for i in range(len(self.massbins)-1):
        	        integral = quad(lambda mass: cosmocalc.tinker2008_mass_function(mass, 1/(1+z[k]), delta[j]), self.massbins[i], self.massbins[i+1])
                	mass_fn_n[i][j][k] = integral[0]
                	mass_fn_error[i][j][k] = integral[1]

	self.y  = mass_fn_n
	self.ye = mass_fn_error
def plot_tinker_bias(cosmo_dict, i):
    cc.set_cosmology(cosmo_dict)
    
    for j in range(N_z):
        a = scale_factors[j]
        #First plot the data.
        data = np.loadtxt(datapath%(i, i, j))
        lM_bins = data[:,:2]
        lM = np.mean(data[:, :2], 1)
        M = 10**lM
        N = data[:,2]
        cov = np.loadtxt(covpath%(i, i, j))
        err = np.sqrt(np.diagonal(cov))
        bG = get_bG(cosmo_dict, a, M)
        plt.plot(M, bG, c=cmap(c[j]))
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.xscale('log')
    plt.subplots_adjust(bottom=0.15)
    plt.show()
Exemple #10
0
 def set_cosmology(self, cosmo_dict):
     self.cosmo_dict = cosmo_dict
     self.rhom = cosmo_dict['om'] * rhocrit  #Msun h^2/Mpc^3
     cc.set_cosmology(cosmo_dict)
     cos = self.cos_from_dict(cosmo_dict)
     self.t08_slopes_intercepts = self.t_08.predict_slopes_intercepts(cos)
                                      redshift=redshifts[z_index],
                                      lM_bins=lM_bins)
N_emu = n * volume

#Make the analytic covariance matrix
cov_an = np.diag(N_emu)

#Set up cosmocalc
ombh2, omch2, w0, ns, ln10As, H0, Neff, sigma8 = test_cosmo
h = H0 / 100.
Ob = ombh2 / h**2
Om = Ob + omch2 / h**2
cosmo_dict = {"om":Om,"ob":Ob,"ol":1-Om,\
                  "ok":0.0,"h":h,"s8":sigma8,\
                  "ns":ns,"w0":w0,"wa":0.0}
cc.set_cosmology(cosmo_dict)  #Used to create the splines in cosmocalc

#Get the biases
bias = np.zeros_like(lM)
a = 1. / (1 + redshifts[z_index])
for i in xrange(0, len(lM)):
    M = 10**lM[i]
    bias[i] = cc.tinker2010_bias(M, a, 200)

#Get sigmaR
R = (3. / 4. / np.pi * volume)**(1. / 3.)
sigmaR = cc.sigmaRtophat_exact(R, a)
print sigmaR**2

for i in xrange(0, len(bias)):
    for j in xrange(0, len(bias)):
def get_cc_prediction(bin_center_mass, a, cosmo):
    import cosmocalc as cc
    cc.set_cosmology(cosmo)
    return np.array(
        [cc.tinker2008_mass_function(M, a, 200) * M for M in bin_center_mass])
    test_cosmo = all_cosmologies[box]
    test_data = data[box]
    training_cosmologies = np.delete(all_cosmologies,box,0)
    training_data = np.delete(data,box,0)

    #Train
    mf_emulator = mfe.mf_emulator("test")
    mf_emulator.train(training_cosmologies,training_data)

    #Set up cosmocalc
    ombh2,omch2,w0,ns,ln10As,H0,Neff,sigma8 = test_cosmo
    h = H0/100.
    Ob = ombh2/h**2
    Om = Ob + omch2/h**2
    cosmo_dict = {"om":Om,"ob":Ob,"ol":1-Om,"ok":0.0,"h":h,"s8":sigma8,"ns":ns,"w0":w0,"wa":0.0}
    cc.set_cosmology(cosmo_dict)

    #Now loop over each redshift bin
    for zind in xrange(0,N_z):
        z = redshifts[zind]
        a = scale_factors[zind]
        sigmaR = cc.sigmaRtophat_exact(R,a)
        
        #Read in the data
        MF_data = np.genfromtxt("../../all_MF_data/building_MF_data/full_mf_data/Box%03d_full/Box%03d_full_Z%d.txt"%(box,box,zind))
        lM_bins = MF_data[:,:2]
        lM = np.mean(lM_bins,1)
        N_data = MF_data[:,2]
        N_data_array.append(N_data)
        logN_data_array.append(np.log(N_data))