def matterps2corr2esd(redshift,cosmology): z = redshift H_null,Ombh2,Omch2=cosmology pars = camb.CAMBparams() pars.set_cosmology(H0=H_null,ombh2=Ombh2,omch2=Omch2) pars.set_dark_energy() pars.InitPower.set_params(ns=nps) pars.set_matter_power(redshifts=[0.0,z],kmax=2.0) #Linear spectra-------- pars.NonLinear=model.NonLinear_none results =camb.get_results(pars) kh,znon,pk =results.get_matter_power_spectrum(minkh=1e-4,maxkh=1000.0,npoints=1024) xi =mcfit.P2xi(kh,l=0) #Calculate corr from PS------ nxx = 50 Rmin = -2.0 Rmax = 2.0 rr = np.logspace(Rmin,Rmax,nxx) rx,corrfunc =xi(pk,extrap=True) corr = np.interp(rr,rx,corrfunc[0,:]) #Calculate ESD from corr------ nxx = 10 Rp = np.linspace(0.03,20.,nxx) ESD = np.zeros(nxx) for i in range(nxx): tmp1 = integrate.quad(simR,Rp[i]+0.001,90.0,args=(rr,corr,Rp[i]),epsabs=1e-4) tmp2 = integrate.quad(simLR,0.001,Rp[i],args=(rr,corr,Rp[i]),epsabs=1e-4) ESD[i] = (4.0*tmp2[0]/Rp[i]/Rp[i]-2.0*tmp1[0])*omega_m*h #Luo et al 2017ApJ 836 38L EQ. 39-40 return {'Rp':Rp,'ESD':ESD}
def pk_to_xi(k, Pk, ell=0, extrap=True): r""" Return a callable function returning the correlation function multipole of degree :math:`\ell`, as computed from the Fourier transform of the input :math:`k` and :math:`P_\ell(k)` arrays. This uses the :mod:`mcfit` package perform the FFT. Parameters ---------- k : array_like wavenumbers where ``Pk`` is evaluated Pk : array_like the array holding the power spectrum multipole values ell : int multipole degree of the input power spectrum and the output correlation function; monopole by default extrap : bool, optional whether to extrapolate the power spectrum with a power law; can improve the smoothness of the FFT Returns ------- InterpolatedUnivariateSpline : a spline holding the interpolated correlation function values """ xi = mcfit.P2xi(k, l=ell, lowring=True) rr, CF = xi(Pk, extrap=extrap) return InterpolatedUnivariateSpline(rr, CF)
def pk_to_xi(k, Pk, extrap=True): r""" Return a callable function returning the correlation function, as computed from the Fourier transform of the input :math:`k` and :math:`P(k)` arrays. This uses the :mod:`mcfit` package perform the FFT. Parameters ---------- k : array_like wavenumbers where ``Pk`` is evaluated Pk : array_like the array holding the power spectrum values extrap : bool, optional whether to extrapolate the power spectrum with a power law; can improve the smoothness of the FFT Returns ------- InterpolatedUnivariateSpline : a spline holding the interpolated correlation function values """ xi = mcfit.P2xi(k) rr, CF = xi(Pk, extrap=extrap) return InterpolatedUnivariateSpline(rr, CF)
def camb_corr_func(zs, read=True): pks = power_spec_at_zs(zs, read=read) rs, cfs = mcfit.P2xi(k_grid, lowring=True)(pks, axis=1) return rs, cfs
def from_power_spectrum(cls, ks, zs, power_spectra): rs, xis = mcfit.P2xi(ks, lowring=True)(power_spectra, extrap=True) return cls(rs, zs, xis)