Skip to content

Commit 4a2d86b

Browse files
changes
1 parent c40bd59 commit 4a2d86b

File tree

5 files changed

+34
-384
lines changed

5 files changed

+34
-384
lines changed

pyhmcode/cosmology.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ def sigmaR_vec(R:float, Pk:callable):
102102
return sigma_func(R, Pk)
103103

104104

105+
def _sigmaV_integrand(k:float, Pk:callable):
106+
return Pk(k)
105107
# def _sigmaV_integrand(t, Pk, alpha=3.):
106108
# k = (-1.+1./t)**alpha
107109
# return Pk(k)*k*alpha/(t*(1.-t))
@@ -119,28 +121,41 @@ def sigmaV(Pk:callable, eps=eps_sigmaV) -> float:
119121
eps: Integration accuracy
120122
'''
121123
kmin, kmax = 0., np.inf
122-
sigmaV_squared, _ = integrate.quad(Pk, kmin, kmax, epsrel=eps, epsabs=eps)
124+
#sigmaV_squared, _ = integrate.quad(Pk, kmin, kmax, epsrel=eps, epsabs=eps)
125+
sigmaV_squared, _ = integrate.quad(lambda k: _sigmaV_integrand(k, Pk), kmin, kmax, epsrel=eps, epsabs=eps)
123126
#sigmaV_squared, _ = integrate.quad(_sigmaV_integrand, 0., 1., args=(Pk,), epsabs=eps, epsrel=eps)
124127
sigmaV = np.sqrt(sigmaV_squared/(2.*np.pi**2))
125128
sigmaV /= np.sqrt(3.) # Convert from 3D displacement to 1D displacement
126129
return sigmaV
127130

128131

129-
def _dsigmaR_integrand(k:float, R:float, Pk) -> float:
132+
def _dsigmaR_integrand(k:float, R:float, Pk:callable) -> float:
130133
return Pk(k)*(k**3)*_Tophat_k(k*R)*_dTophat_k(k*R)
131134

132135

133-
def dlnsigma2_dlnR(R:float, Pk) -> float:
136+
def dlnsigma2_dlnR(R:float, Pk:callable) -> float:
134137
'''
135138
Calculates d(ln sigma^2)/d(ln R) by integration
139+
3+neff = -d(ln sigma^2) / dR
136140
'''
137-
def dsigmaR_vec(R, Pk):
138-
kmin, kmax = 0., np.inf # Evaluate the integral and convert to a nicer form
139-
dsigma, _ = integrate.quad(lambda k: _dsigmaR_integrand(k, R, Pk), kmin, kmax)
140-
dsigma = R*dsigma/(np.pi*_sigmaR_quad(R, Pk))**2
141-
return dsigma
142-
dsigma_func = np.vectorize(dsigmaR_vec, excluded=['Pk'])
143-
return dsigma_func(R, Pk)
141+
# def dsigmaR_vec(R, Pk):
142+
# kmin, kmax = 0., np.inf # Evaluate the integral and convert to a nicer form
143+
# dsigma, _ = integrate.quad(lambda k: _dsigmaR_integrand(k, R, Pk), kmin, kmax)
144+
# dsigma = R*dsigma/(np.pi*_sigmaR_quad(R, Pk))**2
145+
# return dsigma
146+
# dsigma_func = np.vectorize(dsigmaR_vec, excluded=['Pk'])
147+
# return dsigma_func(R, Pk)
148+
kmin, kmax = 0., np.inf # Evaluate the integral and convert to a nicer form
149+
dsigma, _ = integrate.quad(lambda k: _dsigmaR_integrand(k, R, Pk), kmin, kmax)
150+
dsigma = R*dsigma/(np.pi*_sigmaR_quad(R, Pk))**2
151+
return dsigma
152+
153+
154+
def neff(R:float, Pk:callable) -> float:
155+
'''
156+
Effective index of the power spectrum at scale 'R'
157+
'''
158+
return -3.-dlnsigma2_dlnR(R, Pk)
144159

145160
### ###
146161

pyhmcode/pyhmcode.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Standard imports
22
import numpy as np
3+
from time import time
34

45
# Third-party imports
56
import camb
@@ -26,7 +27,8 @@ def hmcode(k:np.array, zs:np.array, CAMB_results:camb.CAMBdata,
2627
'''
2728

2829
# Checks
29-
if not util.is_array_monotonic(-zs):
30+
if verbose: t_start = time()
31+
if not util.is_array_monotonic(-np.array(zs)):
3032
raise ValueError('Redshift must be monotonically decreasing')
3133

3234
# Halo mass range
@@ -107,8 +109,9 @@ def hmcode(k:np.array, zs:np.array, CAMB_results:camb.CAMBdata,
107109
# Parameters of the linear spectrum pertaining to non-linear growth
108110
Rnl = _get_nonlinear_radius(R[0], R[-1], dc, iz, CAMB_results, cold=True) # Non-linear Lagrangian radius
109111
sigma8 = _get_sigmaR(8., iz, CAMB_results, cold=True) # RMS in the linear cold matter field at 8 Mpc/h
110-
sigmaV = cosmology.sigmaV(Pk=lambda k: Pk_lin_interp(z, k)) # RMS in the linear displacement field
112+
sigmaV = cosmology.sigmaV(lambda k: Pk_lin_interp(z, k)) # RMS in the linear displacement field
111113
neff = _get_effective_index(Rnl, R, sigmaM) # Effective index of spectrum at collapse scale
114+
112115
if verbose:
113116
print('Non-linear Lagrangian radius: {:.4} Mpc/h'.format(Rnl))
114117
print('RMS in matter field at 8 Mpc/h: {:.4}'.format(sigma8))
@@ -159,6 +162,10 @@ def hmcode(k:np.array, zs:np.array, CAMB_results:camb.CAMBdata,
159162
Pk_HMcode[iz, :] = Pk_hm
160163

161164
# Finish
165+
if verbose:
166+
t_finish = time()
167+
print('HMcode predictions complete for {:} redshifts'.format(len(zs)))
168+
print('Total HMcode run time: {:.3f}s'.format(t_finish-t_start))
162169
return Pk_HMcode
163170

164171

tests/notebooks/HMcode.ipynb

Lines changed: 0 additions & 178 deletions
This file was deleted.

tests/notebooks/HMx.ipynb

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)