Exemplo n.º 1
0
	def get_xi_0_2_4_from_pk(self,path_to_pk,index=[0,1],comoving=True):

		f = cp.fgrowth(self._z,self._omega_matter_0)
		print '  The growth factor is : f = ', f
		print cp.fgrowth(0,self._omega_matter_0)
		a = cp.fgrowth(2.3,self._omega_matter_0)

		data = numpy.loadtxt(path_to_pk)
		k  = numpy.zeros( data[:,1].size+1 )
		pk = numpy.zeros( data[:,1].size+1 )

		if (comoving) :
			k = data[:,index[0]]
			pk = data[:,index[1]]*f*f
		else:
			k = data[:,index[0]]/self._h_0
			pk = data[:,index[1]]*numpy.power(self._h_0,3.)*f*f
		pk /= a*a

		#pk *= numpy.power(self.window_spherical(k,0.7),2.)

		r2,cric2 = self.xi_from_pk(k,pk)
		index_of_bin_greeter_than_half_max = numpy.arange(r2.size)[ r2>numpy.max(r2)/2. ][0]
		size = r2[1:index_of_bin_greeter_than_half_max].size
		print '  index of bin greeter than half max  =  ', index_of_bin_greeter_than_half_max
		print '  size = ', size
		xi0 = numpy.zeros( shape=(size,2) )
		xi0[:,0] = r2[1:index_of_bin_greeter_than_half_max]
		xi0[:,1] = cric2[1:index_of_bin_greeter_than_half_max]

		xi2, xi4 = self.get_xi2_and_xi4_from_xi0(xi0)

		return xi0, xi2, xi4
	def get_variance_function_vs_redshift(self,function_index,z_min, z_max, z_step=0.1):
		"""
			Get the mean of the given transforming functions versus the redshift

		"""
		
		z    = numpy.arange(z_min, z_max, z_step)
		mean = numpy.zeros(z.size)
		variance = numpy.zeros(z.size)
		
		for i in numpy.arange(mean.size):
			d_growth = cp.fgrowth(z[i],self._omega_matter_0)
			self._a     = self.get_parameter_a(z[i])
			self._gamma = 1.6*d_growth
			mean[i]     = self.get_mean_function(function_index)

			self._a     *= 2.
			variance[i] = self.get_mean_function(function_index)
			
		self._a     = self.get_parameter_a(self._z)
		self._gamma = self.get_parameter_gamma(self._z)
		
		var_delta = variance/(mean*mean) - 1.

		return numpy.array( zip(z,mean,variance,var_delta) )
Exemplo n.º 3
0
def test_growth(cosmo=None):
    if cosmo is None:
        cosmo = cosmo_wmap_5()
    print "Comparing growth factor with calculations from http://icosmo.org/"

    # load external distance calculations
    # z D
    growth_file = os.path.dirname(os.path.abspath(__file__))
    growth_file = os.path.join(growth_file, 'icosmo_testdata', 'growth.txt')
    ic_growth = numpy.loadtxt(growth_file)

    z = ic_growth[:,0]

    cp_growth = cp.fgrowth(z, cosmo['omega_M_0'])

    label = r"$D(z)$"
    pylab.figure()
    pylab.plot(z, ic_growth[:,1], 
               label=label + ' IC', ls=':')
    pylab.plot(z, cp_growth, label=label + ' perturbation.py', ls='-')
    pylab.legend(loc='best')

    pylab.figure()
    diff = (ic_growth[:,1] - cp_growth) / ic_growth[:,1]

    maxdiff = numpy.max(numpy.abs(diff))
    print "Maximum fraction difference in %s is %e." % (label,
                                                        maxdiff)
    pylab.plot(z,
               diff, 
               label=label, ls='-')
    pylab.legend(loc='best')

    ntest.assert_array_less(numpy.abs(diff), 5e-3)
	def get_xi0_transformed(self, xi_r, xi_z):
		"""
			Get the transformed correlation function:
			xi_r: coordinate of the points where to calculate
				the correlation function.

		"""
		
		verbose = True

		d_growth    = cp.fgrowth(xi_z,self._omega_matter_0)
		xi0         = numpy.interp(xi_r,self._CAMB._xi0[:,0],self._CAMB._xi0[:,1])*d_growth*d_growth
		self._a     = self.get_parameter_a(xi_z)
		self._gamma = self.get_parameter_gamma(xi_z)
		mean_F1     = self.get_mean_function(0)
		mean_F2     = self.get_mean_function(1)

		if (verbose):
			print '\n'
			print '  Producing the transformation at z = ', xi_z
			print '  D_growth_factor = ', d_growth
			if ( self._correlation=='q_f' or self._correlation=='f_f' ):
				print '  a               = ', self._a
				print '  gamma           = ', self._gamma
			if (self._correlation=='q_f' or self._correlation=='q_q'):
				print '  cut_QSO         = ', self._cut_QSO
			print '  < F1 >          = ', mean_F1
			print '  < F2 >          = ', mean_F2
			print '\n'

		reduced_xi = xi0*xi0/numpy.power(self._sigma_gauss,4.)
		if ( reduced_xi[ reduced_xi>1. ].size  ):
			print '  ERROR:: reduced_xi>1.'
			return None

		def get_transformation(xi):

			sqrt_xi = numpy.sqrt(1.-xi*xi/numpy.power(self._sigma_gauss,4.) )
	
			### Function to integrate
			def F1_times_F2(y,x):
				t  = xi*x/numpy.power(self._sigma_gauss,2.)+sqrt_xi*y
				f1 = self._F1(x)*numpy.exp(-0.5*numpy.power(x/self._sigma_gauss,2.))
				f2 = self._F2(t)*numpy.exp(-0.5*numpy.power(y/self._sigma_gauss,2.))
				return f1*f2
	
			### Integral range
			if (self._correlation=='i_i' or self._correlation=='f_f'):
				def lim_min_y(x):
					return -numpy.inf+x*0.
			elif (self._correlation=='q_f' or self._correlation=='q_q'):
				def lim_min_y(x):
					return (self._cut_QSO-xi*x/numpy.power(self._sigma_gauss,2.))/sqrt_xi
	
			def lim_max_y(x):
				return numpy.inf+x*0.
					
			return scipy.integrate.dblquad(F1_times_F2, self.lim_min_mean_F1,numpy.inf, lim_min_y, lim_max_y)[0]
	
		return numpy.array([ get_transformation(el) for el in xi0 ])/(mean_F1*mean_F2*2.*numpy.pi*self._sigma_gauss*self._sigma_gauss) - 1.
Exemplo n.º 5
0
def interp_z_dependent_velocity_factors(z, deltaz=1e-3):
    from cosmolopy.perturbation import fgrowth
    zgrid = np.arange(np.min(z)-deltaz, np.max(z)+deltaz, deltaz)
    hz_grid = distance.hubble_z(zgrid, **cosmo)
    fgrowth_grid = fgrowth(zgrid, cosmo['omega_M_0'])
    a_grid = 1./(1.+zgrid)
    tmp_grid = fgrowth_grid*a_grid*hz_grid
    from scipy import interpolate
    f = interpolate.interp1d(zgrid, tmp_grid)
    return f(z)
Exemplo n.º 6
0
def corr_delta_vel(r, z=0.4, kmin=1e-3, kmax=0.2):
    # r is in Mpc
    a = 1./(1.+z)
    hz = distance.hubble_z(z, **cosmo)
    fgrowth = perturbation.fgrowth(z, cosmo['omega_M_0'])
    k = np.arange(kmin,kmax,kmin)
    dk = k[1]-k[0]
    corr = []
    pk = perturbation.power_spectrum(k, z, **cosmo)
    for this_r in r:
        this_corr = a*hz*fgrowth/2./np.pi**2. * np.sum(dk*k*pk*spherical_bessel_j1(k*this_r))
        corr.append(this_corr)
    return np.array(corr)
Exemplo n.º 7
0
def Z_params(z, cosmo):
    """ Quantities which depend on only the redshift and cosmology.

    These *do not* depend on the halo mass.
    """
    Z = {}
    Z['rho_bar_m'] = cosmo.Om(z) * cosmo.critical_density(z)
    Z['delta_vir'] = deltavir(z, cosmo=cosmo)

    # A14, overdensity threshold for spherical collapse
    Z['delta_c'] = 3 / 20. * (12 * pi)**(2/3.) * \
                   (1 + 0.013 * log10(cosmo.Om(z)))
    Z['growth_factor'] = fgrowth(z, cosmo.Om0)
    return Z
Exemplo n.º 8
0
def D(z, Om=0.3):
    """
    Linear growth rate D(z).
    
    Syntax:
    
        D(z,Om=0.3)
    
    where
        
        z: redshift (float or array)
        Om: matter density in units of the critical density, at z=0
            (default=0.3) 
    """
    return cper.fgrowth(z, Om)
Exemplo n.º 9
0
	def test_cosmolopy(self):


		import cosmolopy.perturbation as cp
		cosmo = {
			'omega_M_0' : 0.27,
			'omega_lambda_0' : 1.-0.27,
			'omega_b_0' : 0.0463265,
			'omega_n_0' : 0.0,
			'N_nu' : 0,
			'h' : 0.7,
			'n' : 1.0,
			'sigma_8' : 0.794961,
			'baryonic_effects' : True
		}

		z = 2.4
		za = numpy.arange(0.,10.,0.01)
		k = numpy.arange(0.,100.,0.0001)

		f = cp.fgrowth(za, cosmo['omega_M_0'])
		plt.plot(za,f)
		plt.show()

		pk = cp.power_spectrum(k, z, **cosmo)

		plt.plot(k,k*k*pk)
		plt.show()

		print cp.transfer_function_EH(k, **cosmo)
		plt.plot(k,cp.transfer_function_EH(k, **cosmo)[0] )
		plt.show()

		r2,cric2 = self.xi_from_pk(k,pk)
		r2 *= 0.7

		plt.plot(r2,r2*r2*cric2)
		plt.show()

		return
Exemplo n.º 10
0
dxl_2 = np.zeros(50)
dxh_2 = np.zeros(50)
dyl_2 = np.zeros(50)
dyh_2 = np.zeros(50)
x_2, y_2, dxl_2, dxh_2, dyl_2, dyh_2 = np.loadtxt("../../Data_files/pourtsidou_xyscan_curve_z_2.txt", unpack=True)

xplot_2 = np.arange(10, x_2[int(np.size(x_2))-1], x_2[int(np.size(x_2))-1]/2000)
tck_2 = interpolate.splrep(x_2,y_2, s=0)
tckerr_2 = interpolate.splrep(x_2,dyh_2,s=0)
yploterr_2 = interpolate.splev(xplot_2, tckerr_2, der=0)
yplot_2 = interpolate.splev(xplot_2, tck_2, der=0)
plt.errorbar(xplot_2,yplot_2, yerr=yploterr_2,color='black', ecolor='yellow', label='Pourtsidou et al. 2014 (z=2)')


for redshift in range(2,3):
    constantfactor[redshift] = (9/4)* np.power(H0/c,4) * np.power(omegam0,2)*(fgrowth(redshift, 0.308, unnormed=False) * (1 + redshift))**2
    xs[redshift] = cd.comoving_distance(redshift, **cosmo) # upper limit of integration
    
    for i in range (l_plot_ll, l_plot_ul):
        print("--------------------------------result[]"+str(i))
        result[i] = integration(i, redshift)
        for k in range(k_ll, k_ul):
            resultk[i,k] = integrationk(i,k,redshift)

    for i in range(20,700,50):
        integ = 0
        integ_sum = 0
        print("-------------------------------i "+str(i))
        for k in range(k_ll, k_ul):
            integ = dblintegration(i,k)
            integ_sum = integ_sum + integ
def constantfactor(redshift):
    return (9 / 4) * (H0 / c)**4 * omegam0**2 * (
        fgrowth(redshift, 0.308, unnormed=False) * (1 + redshift))**2
Exemplo n.º 12
0
def growthf(z, omega_M_0):
	'''f growth calculate the 
	'''
	return cp.fgrowth(z, omega_M_0, unnormed=True)
Exemplo n.º 13
0
def Deltac(z):
    fgrowth = pb.fgrowth(z, cosmo['omega_M_0'])  # = D(z)/D(0)
    #return 1.686/fgrowth
    return 1.686 * fgrowth  #?????
def constantfactor(redshift):
    return 9 * (H0 / c)**3 * omegam0**2 * (
        fgrowth(redshift, omegam0, unnormed=False) * (1 + redshift))**2
def angpowspec_integrand_without_j(z, ell):
    dist = distance(z)
    return (1 - dist / chi_s[redshift])**2 * np.interp(ell / dist, PS, dPS) * (
        fgrowth(z, omegam0, unnormed=False))**2 / hubble_ratio(z)
Exemplo n.º 16
0
def Deltac(z):
	fgrowth = pb.fgrowth(z, cosmo['omega_M_0'])    # = D(z)/D(0)
	return 1.686/fgrowth
Exemplo n.º 17
0
def dDdz(z):
    dz = 1e-10
    return (pb.fgrowth(z + dz, COSMO['omega_M_0']) -
            pb.fgrowth(z, COSMO['omega_M_0'])) / dz
Exemplo n.º 18
0
def dDdtoverD(z):
    return dDdt(z) / pb.fgrowth(z, COSMO['omega_M_0'])
Exemplo n.º 19
0
def v_from_m(m200,a):
    z=1./a -1.
    return (1.12*(m200/5e13)**0.3+0.53)/prtrb.fgrowth(z,Omega_M)
Exemplo n.º 20
0
def conc(m200, a):
    z = (1./a)-1.
    v = v_from_m(m200,a)
    return prtrb.fgrowth(z,Omega_M)**0.54*5.9*v**-0.35
Exemplo n.º 21
0
def conc_from_v(v,z):
    return prtrb.fgrowth(z,Omega_M)**0.54*5.9*v**-0.35
Exemplo n.º 22
0
}

#array definitions
xs = np.zeros(11)
fgrow = np.zeros(11)
l = np.arange(0, 1001)
constantfactor = np.zeros(11)
result = np.arange(0, 1001)

#reading the data file
kn, dkn = np.loadtxt("../Data_files/CAMB_linear.txt", unpack=True)

plt.subplots()
for redshift in range(1, 11):
    constantfactor[redshift] = (9 / 4) * np.power(H0 / c, 4) * np.power(
        omegam0, 2) * (fgrowth(redshift, 0.308, unnormed=False) *
                       (1 + redshift))**2
    xs[redshift] = cd.comoving_distance(redshift,
                                        **cosmo)  # upper limit of integration

    for i in range(10, 1000):
        result[i] = integration(i, redshift)
    plt.plot(l[10:1000],
             constantfactor[redshift] * result[10:1000],
             label='z = {}'.format(redshift))

plt.xlabel('l')
plt.ylabel(r'$C_{l}$')
plt.suptitle("Angular Power Spectrum")
plt.legend()
plt.xscale("log")
def angpowspec_integrand_without_j_unnormed_false(z, ell):
    distance_at_redshift = np.interp(z, redshift_from_file, distance_from_file)
    return ((chi_s[redshift] - distance_at_redshift) / chi_s[redshift]
            )**2 * np.interp(ell / distance_at_redshift, PS,
                             dPS) * (fgrowth(z, omegam0, unnormed=False) *
                                     (1 + z))**2 / hubble_ratio(z)
Exemplo n.º 24
0
import numpy as np
import math
import cosmolopy.distance as cd
import cosmolopy.perturbation as cp
import scipy.integrate as integrate
import matplotlib.pyplot as plt
from cosmolopy.perturbation import fgrowth

#finding fgrowth
fgrow = np.zeros(11)
for i in range(11):
    fgrow[i] = fgrowth(i, 0.308, unnormed=False)

#constants
zcounter = 2
omegam0 = 0.308
c = 3 * 10**8
H0 = 73.8 * 1000
cosmo = {
    'omega_M_0': 0.308,
    'omega_lambda_0': 0.692,
    'omega_k_0': 0.0,
    'h': 0.678
}
constantfactor = (9 / 4) * np.power(H0 / c, 4) * np.power(omegam0,
                                                          2) * fgrow[zcounter]

# notation
# 'n' -> Linear
# 'o' -> Non-Linear
def constantfactor_constant_growth_factor_unnormed_true(redshift):
    return 9 * (H0 / c)**3 * omegam0**2 * (
        fgrowth(redshift, omegam0, unnormed=True) * (1 + redshift))**2
Exemplo n.º 26
0
# To compare power spectrum obtained from CAMB data at different redshifts
# P(k) x Growth factor Vs. k

import numpy as np
import math
import cosmolopy.distance as cd
import cosmolopy.perturbation as cp
import scipy.integrate as integrate
import matplotlib.pyplot as plt
from cosmolopy.perturbation import fgrowth  

kn,dkn = np.loadtxt("../../../Pow_spec_test_code/power_spectrum/CAMB_linear.txt", unpack=True)

plt.subplots()
for redshift in range(1,11):
    fgrow = fgrowth(redshift, 0.308, unnormed=True)
    plt.plot(kn,fgrow*dkn, label='z = {}, fg = {}'.format(redshift, round(fgrow,5)))

plt.xlabel(r'k $(h \; Mpc^{-1})$')
plt.ylabel(r'P(k) ($Mpc \; h^{-1})^3$')
plt.suptitle(r"Power Spectrum $\times$ Growth factor")
plt.legend()
plt.xscale("log")
plt.yscale("log")
plt.savefig("compare_powspec_at_diff_z_True.pdf")
plt.show()
Exemplo n.º 27
0
import numpy as np
import math
import cosmolopy.distance as cd
import cosmolopy.perturbation as cp
import scipy.integrate as integrate
import matplotlib.pyplot as plt
from cosmolopy.perturbation import fgrowth

#finding fgrowth
fgrow = np.zeros(11)
for i in range(11):
    fgrow[i] = fgrowth(
        i, 0.308, unnormed=False
    )  # unnormed = True for redshift higher than 2 and False for redshift lower than 2; Read the manual
    print(fgrow[i])

#constants
zcounter = 2  # redshift for this code
omegam0 = 0.308
c = 3 * 10**8
H0 = 73.8 * 1000
cosmo = {
    'omega_M_0': 0.308,
    'omega_lambda_0': 0.692,
    'omega_k_0': 0.0,
    'h': 0.678
}
constantfactor = (9 / 4) * np.power(H0 / c, 4) * np.power(omegam0,
                                                          2) * fgrow[zcounter]

# notation
def D(z):
     return cp.fgrowth(z,omega_M_0, unnormed=False)
Exemplo n.º 29
0
# CAMB de juillet 2013
# /home/gpfs/manip/mnt0607/bao/hdumasde/Program/baofit/models/DR9LyaMocks_params.ini

# Pour Christophe Magneville :
# change :
# 	transfer_redshift(1) = 0.
# 
#
#
# Run :
#	/home/gpfs/manip/mnt0607/bao/hdumasde/Program/camb/camb DR9LyaMocks_params.ini

h = 0.70
omega_m_0 = 0.27

f = cp.fgrowth(2.25,omega_m_0)
print f

'''
camb_CMV = numpy.loadtxt('/home/gpfs/manip/mnt0607/bao/cmv/Helion/cmvtstpk_Helion.data')
k_CMV  = camb_CMV[:,1]/h
pk_CMV = camb_CMV[:,4]*numpy.power(h,3.)*f*f

camb_baofit = numpy.loadtxt('/home/gpfs/manip/mnt0607/bao/hdumasde/Program/baofit/models/DR9LyaMocks_matterpower.dat')
k_baofit  = camb_baofit[:,0]
pk_baofit = camb_baofit[:,1]
print '  nb of points baofit : ', k_baofit.size


camb_init = numpy.loadtxt('/home/gpfs/manip/mnt0607/bao/hdumasde/Code/CrossCorrelation/Mock_JMLG/Produce_CAMB/DR9LyaMocks_matterpower.dat_init')
k_init  = camb_init[:,0]