def test_fcolls(self): pert = Perturbations(M=np.linspace(10, 15, 1301)) fits = ['PS', 'Peacock'] for fit in fits: pert.update(mf_fit=fit) yield self.check_fcoll, pert, fit
def test_sigmas(self): pert = Perturbations(M=np.linspace(7, 15, 801), omegab=0.05, omegac=0.25, omegav=0.7, sigma_8=0.8, n=1, H0=70.0, k_bounds=[np.exp(-21), np.exp(21)], transfer__kmax=10, transfer__k_per_logint=50, mf_fit='ST', z=0.0) for redshift in [0.0, 2.0]: pert.update(z=redshift) for origin in ['camb', 'hmf']: for col in ['sigma', 'lnsigma', 'n_eff']: yield self.check_col, pert, "ST", redshift, origin, col
def test_fits(self): pert = Perturbations(M=np.linspace(7, 15, 801), omegab=0.05, omegac=0.25, omegav=0.7, sigma_8=0.8, n=1, H0=70.0, k_bounds=[np.exp(-21), np.exp(21)], transfer__kmax=10, transfer__k_per_logint=50, mf_fit='ST', z=0.0) for redshift in [0.0, 2.0]: pert.update(z=redshift) for fit in ["ST", "PS", "Reed03", "Warren", "Jenkins", "Reed07"]: pert.update(mf_fit=fit) for origin in ['camb', 'hmf']: for col in ['dndlog10m', 'ngtm', 'fsigma']: yield self.check_col, pert, fit, redshift, origin, col
def test_kbounds(): M = np.linspace(8, 15, 70) pert = Perturbations(M, k_bounds=kbounds[0]) assert check_k(pert.k) assert check_mf(pert.MassFunction()) assert check_vfv(pert.vfv) for bounds in kbounds[1:]: pert.update(k_bounds=bounds) assert check_k(pert.k) assert check_mf(pert.MassFunction()) assert check_vfv(pert.vfv)
def test_wdm(): M = np.linspace(8, 15, 70) pert = Perturbations(M, wdm=wdms[0]) assert check_k(pert.k) assert check_mf(pert.MassFunction()) assert check_vfv(pert.vfv) for wdm in wdms[1:]: pert.update(wdm=wdm) assert check_k(pert.k) assert check_mf(pert.MassFunction()) assert check_vfv(pert.vfv)
def test_z(): M = np.linspace(8, 15, 70) pert = Perturbations(M, z=redshifts[0]) assert check_k(pert.k) assert check_mf(pert.MassFunction()) assert check_vfv(pert.vfv) for z in redshifts[1:]: pert.update(z=z) assert check_k(pert.k) assert check_mf(pert.MassFunction()) assert check_vfv(pert.vfv)
def test_on(): M = np.linspace(8, 15, 70) pert = Perturbations(M, omegan=omegans[0]) assert check_k(pert.k) assert check_mf(pert.MassFunction()) assert check_vfv(pert.vfv) for on in omegans[1:]: pert.update(omegan=on) assert check_k(pert.k) assert check_mf(pert.MassFunction()) assert check_vfv(pert.vfv)
def test_H0(): M = np.linspace(8, 15, 70) pert = Perturbations(M, H0=H0s[0]) assert check_k(pert.k) assert check_mf(pert.MassFunction()) assert check_vfv(pert.vfv) for h in H0s[1:]: pert.update(H0=h) assert check_k(pert.k) assert check_mf(pert.MassFunction()) assert check_vfv(pert.vfv)
def test_sigma_8(): M = np.linspace(8, 15, 70) pert = Perturbations(M, sigma_8=sigma_8s[0]) assert check_k(pert.k) assert check_mf(pert.MassFunction()) assert check_vfv(pert.vfv) for s8 in sigma_8s[1:]: pert.update(sigma_8=s8) assert check_k(pert.k) assert check_mf(pert.MassFunction()) assert check_vfv(pert.vfv)
def test_n(): M = np.linspace(8, 15, 70) pert = Perturbations(M, n=ns[0]) assert check_k(pert.k) assert check_mf(pert.MassFunction()) assert check_vfv(pert.vfv) for n in ns[1:]: pert.update(n=n) assert check_k(pert.k) assert check_mf(pert.MassFunction()) assert check_vfv(pert.vfv)
def __init__(self): # Make a pert class self.pert = Perturbations(omegab=0.05, omegac=0.25, omegav=0.7, sigma_8=0.8, n=1, H0=70.0, k_bounds=[np.exp(-21), np.exp(21)], transfer__kmax=10, transfer__k_per_logint=50) #Get the camb transfer self.camb_transfer = np.genfromtxt("data/camb_transfer") #Get the camb power spec self.camb_power = np.genfromtxt('data/camb_power') #Get the genmf power (ie. camb power normalised by genmf) self.genmf_power = np.genfromtxt('data/genmf_power')
class TestPower(object): def __init__(self): # Make a pert class self.pert = Perturbations(omegab=0.05, omegac=0.25, omegav=0.7, sigma_8=0.8, n=1, H0=70.0, k_bounds=[np.exp(-21), np.exp(21)], transfer__kmax=10, transfer__k_per_logint=50) #Get the camb transfer self.camb_transfer = np.genfromtxt("data/camb_transfer") #Get the camb power spec self.camb_power = np.genfromtxt('data/camb_power') #Get the genmf power (ie. camb power normalised by genmf) self.genmf_power = np.genfromtxt('data/genmf_power') def test_transfer(self): """ Testing whether the transfer function calculated by pycamb is the same as that of camb (via CLI)""" my_T_vec = self.pert._transfer_function_callable(np.log(self.camb_transfer[:, 0])) assert rms_diff(my_T_vec, np.log(self.camb_transfer[:, 1]), 1E-3)
#plt.savefig(directory + 'sigma.eps') #=============================================================================== # fsigma and fsigma (Compare) one on the other #=============================================================================== plt.clf() M = np.linspace(10, 15, 501) fig = plt.figure(figsize=(12 * 1.2, 7.0 * 1.2)) gs = gridspec.GridSpec(2, 1, height_ratios=[2, 1]) ax = [plt.subplot(gs[1])] ax.insert(0, plt.subplot(gs[0], sharex=ax[0])) ax[0].grid(True) ax[1].grid(True) pert = Perturbations(M) vfv_ST = pert.fsigma approaches = [ 'PS', 'ST', 'Jenkins', 'Reed03', 'Warren', 'Reed07', 'Tinker', 'Crocce', 'Courtin', 'Bhattacharya', 'Angulo', 'Angulo_Bound', 'Watson_FoF', 'Watson', "Peacock", "Behroozi" ] lines = ["-", "--", "-.", ":"] ax[1].set_xlabel(xlab) ax[0].set_ylabel(r'Fraction of Mass Collapsed, $f(\sigma)$') ax[1].set_ylabel(r'$f(\sigma)/f_{\rm ST}(\sigma)$') for i, approach in enumerate(approaches): pert.update(mf_fit=approach) ax[0].plot(10**M,
import time redshifts = [0.0, 1.0] fits = ["ST", "PS"] s8s = [0.8, 0.9] omegavs = [0.7, 0.6] #=============================================================================== # Do hmf first #=============================================================================== # First do a "fair" comparison of a single calculation start = time.time() pert = Perturbations(M=np.linspace(3, 17, 1401), k_bounds=np.exp([-21, 21]), omegav=0.7, omegab=0.05, omegac=0.25, H0=70.0, n=1.0, sigma_8=0.8) #pert.dndlnm pert.ngtm time_hmf_1 = time.time() - start #Now do a comparison of 2 redshifts, 2 fitting functions, 2 sigma_8s and 2 cosmos start = time.time() pert = Perturbations(M=np.linspace(3, 17, 1401), k_bounds=np.exp([-21, 21]), omegav=0.7, omegab=0.05,
# -*- coding: utf-8 -*- # <nbformat>3.0</nbformat> # <codecell> from hmf import Perturbations import numpy as np M = np.arange(10,15,0.01) pert_object = Perturbations(M,z=6.0) mass_func = pert_object.dndlnm # <codecell> %pylab inline plot (M, log10(mass_func)) # <codecell>
# -*- coding: utf-8 -*- # <nbformat>3.0</nbformat> # <codecell> from hmf import Perturbations import numpy as np M = np.arange(10,15,0.01) pert_object = Perturbations(M,z=0.0) """ PLANCK PARAMETERS (mar-2013) Angular size of sound horizon at recombination theta_* = (1.0414)*10^-2 Baryons density: Omega_b h^2 = 0.0220 Omega_b = 0.0486 Dark cold matter density: Omega_c h^2 = 0.1199 Omega_c = 0.2647 Spectral index n_s = 0.9693 Hubble constant: H_0 = 67.3 km s^-1 Mpc ^-1 h = 0.67.3 Matter density: Omega_m = 0.315 Optical depth tau = 0.089 """ # <codecell>
import sys from hmf import Perturbations import time redshifts = [0.0, 1.0] fits = ["ST", "PS"] s8s = [0.8, 0.9] omegavs = [0.7, 0.6] #=============================================================================== # Do hmf first #=============================================================================== # First do a "fair" comparison of a single calculation start = time.time() pert = Perturbations(M=np.linspace(3, 17, 1401), k_bounds=np.exp([-21, 21]), omegav=0.7, omegab=0.05, omegac=0.25, H0=70.0, n=1.0, sigma_8=0.8) #pert.dndlnm pert.ngtm time_hmf_1 = time.time() - start #Now do a comparison of 2 redshifts, 2 fitting functions, 2 sigma_8s and 2 cosmos start = time.time() pert = Perturbations(M=np.linspace(3, 17, 1401), k_bounds=np.exp([-21, 21]), omegav=0.7, omegab=0.05, omegac=0.25, H0=70.0, n=1.0, sigma_8=0.8) for z in redshifts: pert.update(z=z) pert.ngtm
''' This script explores the projected differences between using an EH and CAMB transfer function. ''' from hmf import Perturbations import time import numpy as np omegab = [0.02, 0.05, 0.1] omegac = [0.2, 0.25, 0.5] H0 = [50, 70, 90] n = [0.8, 0.9, 1.0] pert_camb = Perturbations(transfer_fit="CAMB") pert_EH = Perturbations(transfer_fit="EH") camb_time = 0.0 eh_time = 0.0 for ob in omegab: for oc in omegac: for h in H0: for nn in n: pert_camb.update(omegab=ob, omegac=oc, H0=h, n=nn) pert_EH.update(omegab=ob, omegac=oc, H0=h, n=nn) start = time.time() camb = pert_camb.dndm camb_time += time.time() - start start = time.time() eh = pert_EH.dndm
''' This script explores the projected differences between using an EH and CAMB transfer function. ''' from hmf import Perturbations import time import numpy as np omegab = [0.02, 0.05, 0.1] omegac = [0.2, 0.25, 0.5] H0 = [50, 70, 90] n = [0.8, 0.9, 1.0] pert_camb = Perturbations(transfer_fit="CAMB") pert_EH = Perturbations(transfer_fit="EH") camb_time = 0.0 eh_time = 0.0 for ob in omegab: for oc in omegac: for h in H0: for nn in n: pert_camb.update(omegab=ob, omegac=oc, H0=h, n=nn) pert_EH.update(omegab=ob, omegac=oc, H0=h, n=nn) start = time.time() camb = pert_camb.dndm camb_time += time.time() - start start = time.time()
#=============================================================================== # fsigma and fsigma (Compare) one on the other #=============================================================================== plt.clf() M = np.linspace(10, 15, 501) fig = plt.figure(figsize=(12 * 1.2, 7.0 * 1.2)) gs = gridspec.GridSpec(2, 1, height_ratios=[2, 1]) ax = [plt.subplot(gs[1])] ax.insert(0, plt.subplot(gs[0], sharex=ax[0])) ax[0].grid(True) ax[1].grid(True) pert = Perturbations(M) vfv_ST = pert.fsigma approaches = ['PS', 'ST', 'Jenkins', 'Reed03', 'Warren', 'Reed07', 'Tinker', 'Crocce', 'Courtin', 'Bhattacharya', 'Angulo', 'Angulo_Bound', 'Watson_FoF', 'Watson', "Peacock", "Behroozi"] lines = ["-", "--", "-.", ":"] ax[1].set_xlabel(xlab) ax[0].set_ylabel(r'Fraction of Mass Collapsed, $f(\sigma)$') ax[1].set_ylabel(r'$f(\sigma)/f_{\rm ST}(\sigma)$') for i, approach in enumerate(approaches): pert.update(mf_fit=approach) ax[0].plot(10 ** M, pert.fsigma, label=approach.replace("_", " "), linestyle=lines[(i / 7) % 4]) ax[1].plot(10 ** M, pert.fsigma / vfv_ST, linestyle=lines[(i / 7) % 4])
Omega_b h^2 = 0.0220 Dark cold matter density: Omega_c h^2 = 0.1199 Spectral index n_s = 0.9693 Hubble constant: H_0 = 67.3 km s^-1 Mpc ^-1 Matter density: Omega_m = 0.315 Optical depth tau = 0.089 """ # <codecell> pert_object = Perturbations(M,z=1.0) pert_object.update(omegab = 0.05) print "Transfer Cosmo" print pert_object._transfer_cosmo print "Extra Cosmo" print pert_object._extra_cosmo print "Cosmo Params" print pert_object.cosmo_params # <codecell> #kwargs = {'sigma_8':0.9} #kwargs = {'z':6.0, 'sigma_8'} #pert_object.update(**kwargs)
# -*- coding: utf-8 -*- # <nbformat>3.0</nbformat> # <codecell> from hmf import Perturbations import numpy as np M = np.arange(10,15,0.01) pert_object = Perturbations(M,z=6.0) object_mass_func = pert_object.dndlnm #Output: #WARNING: Unrecognized parameters: #transfer__kmax #transfer__k_per_logint # <codecell> #""" #PLANCK PARAMETERS (mar-2013) #Angular size of sound horizon at recombination # theta_* = (1.0414)*10^-2 #Baryons density: # Omega_b h^2 = 0.0220 # Omega_b = 0.0486 #Dark cold matter density: # Omega_c h^2 = 0.1199 # Omega_c = 0.2647 #Spectral index # n_s = 0.9693 #Hubble constant: