Esempio n. 1
0
def study_sdss_density(hemi='south'):
    grid = grid3d(hemi=hemi)
    n_data = num_sdss_data_both_catalogs(hemi, grid)
    n_rand, weight = num_sdss_rand_both_catalogs(hemi, grid)
    n_rand *= ((n_data*weight).sum() / (n_rand*weight).sum())
    delta = (n_data - n_rand) / n_rand
    delta[weight==0]=0.
    fdelta = np.fft.fftn(delta*weight)
    power = np.abs(fdelta)**2.
    ks = get_wavenumbers(delta.shape, grid.reso_mpc)
    kmag = ks[3]
    kbin = np.arange(0,0.06,0.002)
    ind = np.digitize(kmag.ravel(), kbin)
    power_ravel = power.ravel()
    power_bin = np.zeros_like(kbin)
    for i in range(len(kbin)):
        print i
        wh = np.where(ind==i)[0]
        power_bin[i] = power_ravel[wh].mean()
    #pl.clf()
    #pl.plot(kbin, power_bin)
    from cosmolopy import perturbation
    pk = perturbation.power_spectrum(kbin, 0.4, **cosmo)
    pl.clf(); pl.plot(kbin, power_bin/pk, 'b')
    pl.plot(kbin, power_bin/pk, 'bo')    
    pl.xlabel('k (1/Mpc)',fontsize=16)
    pl.ylabel('P(k) ratio, DATA/THEORY [arb. norm.]',fontsize=16)
    ipdb.set_trace()
Esempio n. 2
0
def sigma_integrand_ufunc(k, MASS, Z, COSMO1):
    # Same function as sigma_integrand, but works on arrays of k, not just scalars.
    # Useful for plotting purposes.
    # k must be in inverse Mpc
    tophat_radius_Mpc = ((3 * MASS / (4 * pi * Z['rho_bar_m']))**(1/3.)).to(u.Mpc).value
    return k**2 * power_spectrum(k, 0, **COSMO1) / (2*pi**2) \
           * w_tophat(k, tophat_radius_Mpc)**2
Esempio n. 3
0
    def sigma_integrand(k):
        # k must be in inverse Mpc

        # should we use the REDSHIFT here? It's currently set to
        # zero. Setting z=0.6 simply changes the normalisation by a
        # factor of ~2. The description in Zhu et al., just before
        # A15, says that it is the present-day value (i.e. z=0), so
        # that's what we're using.
         
        return k**2 * power_spectrum(float(k), 0, **COSMO1) / (2*pi**2) \
               * w_tophat(float(k), float(tophat_radius_Mpc))**2
Esempio n. 4
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)
Esempio n. 5
0
def plot_optimal_delta_filter():
    # see Ho&Spergel 0903.2845
    #nbar = 3e-4 / (0.7**3.)
    nbar = 3e-4 / (0.7**3.) / 10.    
    k = np.arange(1e-3,1,1e-3)
    zmean = 0.3
    from cosmolopy import perturbation
    pk = perturbation.power_spectrum(k, zmean, **cosmo)
    bias = 2.0
    w = pk*bias**2. / (pk*bias**2. + 1./nbar)
    pl.clf(); pl.plot(k, w)
    reso_mpc = 16.
    fwhm = 1.2*reso_mpc
    ipdb.set_trace()
Esempio n. 6
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
Esempio n. 7
0
def Del2k(k):
	Pk = pb.power_spectrum(k,0.,**cosmo)
	Del2k = k**3*Pk/2/n.pi**2
	#fgrowth = pb.fgrowth(z, cosmo['omega_M_0']) 
	#Del2k0 = Del2k/fgrowth**2#*pb.norm_power(**cosmo)
	return Del2k
Esempio n. 8
0
def Del2k(k):
    Pk = pb.power_spectrum(k, 0., **cosmo)
    Del2k = k**3 * Pk / 2 / n.pi**2
    #fgrowth = pb.fgrowth(z, cosmo['omega_M_0'])
    #Del2k0 = Del2k/fgrowth**2#*pb.norm_power(**cosmo)
    return Del2k
Esempio n. 9
0
print("Comoving distance to z=6 is %.lf Mpc"%(d_co))

from cosmolopy import*
d_a=cd.angular_diameter_distance(6,**fidcosmo)
print("Angular-diameter distance to z=6 is %.lf Mpc"%(d_a))
d_light=cd.light_travel_distance(6,**fidcosmo)
print"Light-travel distance to z=6 is %.lf Mpc"%(d_light)"""

import cosmolopy.perturbation as cp
import numpy as np
import math
log_k=np.arange(np.log10(2*math.pi/10000) ,np.log10(2*math.pi/40),0.05) #k Mpc^-1
print(log_k.shape)
k=10**log_k
print("k=",k)
cosmology={'omega_M_0' : 0.308,'omega_b_0' : 0.022,'omega_n_0' : 0.0,'N_nu' : 3,'omega_lambda_0' : 0.692,
'h' : 0.72,'n' : 0.95,'sigma_8' : 0.8}
spectrum=cp.power_spectrum(10**log_k,1.,**cosmology)
print("spectrum" ,spectrum)
import matplotlib.pyplot as mpl
mpl.plot(log_k,spectrum,color="r",lw=2, alpha=0.8)
mpl.ylabel('Power spectrum')
mpl.xlabel('wave number log10_k (Mpc^-1)')
mpl.show()

cosmology=cd.set_omega_k_0(cosmology)
print(cosmology['omega_k_0'])

from ed_functions_memo2 import sigma_v_function
from ed_functions_memo2 import sigma_v_nonlinear
Esempio n. 10
0
def _Del2k(k):
    print 'computing non-cached Del2k'
    Pk = pb.power_spectrum(k, 0.0, **cosmo)
    Del2 = k**3 * Pk / 2. / np.pi**2.
    np.savez('Del2k', k=k, Del2=Del2)
    return Del2
Esempio n. 11
0
                #print(res)
                out[i,j] = res
    
            # save as we go
            #with open('temp.npz', 'w') as fh:
            #    print('Updating temp.npz')
            #    np.savez(fh, out=out, logk=logkvals, logM=logMvals)

        t2 = time.time()
        print('Total time elapsed {} min'.format((t2 - t1) / 60))

    saveobj('SIGMA_CACHE.sav', SIGMA_CACHE, overwrite=1)
    
    Phm_term = np.trapz(out, x=10**logMvals, axis=-1)

    Phm = Phm_term * M['bias'] * power_spectrum(10**logkvals, 0, **COSMO1)

    kvals = 10**logkvals

    # now take the fourier transform of Phm to get the correlation function.

    # xi(r) = ind dk^3 / (2 * pi)^3 * P(k) * exp(i * k dot r)

    # xi(r) = ind dk / (2 * pi) * P(k) * exp(i * k * r)

    # Note that exp(i * k * r) = cos(kr) + i * sin(kr). We only want
    # the real part.

    # where k and r are vectors

    # note rvals should not be outside limits corresponsing to