1212# Parameters
1313xmin_Tk = 1e-5 # Scale at which to switch to Taylor expansion approximation in tophat Fourier functions
1414eps_sigmaR = 1e-4 # Accuracy of the sigmaR integration
15- eps_sigmaV = 1e-4 # Accuracy of the sigmaV integration NOTE: Seems to fail with higher accuracy
15+ eps_sigmaV = 1e-4 # Accuracy of the sigmaV integration NOTE: Seems to fail with higher accuracy (1e-4; when zs=[0] only?!?)
1616eps_neff = 1e-4 # Accuracy of the neff integration (d ln sigma^2/d ln k)
1717
1818### Backgroud ###
@@ -110,14 +110,14 @@ def _transformed_integrand(t:np.ndarray, R:float, Pk:callable, integrand:callabl
110110def _sigmaR_integrand (k :np .ndarray , R :float , Pk :callable ) -> np .ndarray :
111111 '''
112112 Integrand for calculating sigma(R)
113- Note that k can be a float or an array here
114113 '''
115114 return Pk (k )* (k ** 2 )* _Tophat_k (k * R )** 2
116115
117116
118- def sigmaR (R :np .ndarray , Pk :callable , eps = eps_sigmaR , transform_integrand = False ) -> np .ndarray :
117+ def sigmaR (R :np .ndarray , Pk :callable , kmin = 0. , kmax = np . inf , eps = eps_sigmaR , transform_integrand = False ) -> np .ndarray :
119118 '''
120- Quad integration TODO: This is slow, there must be something better to do
119+ Quad integration to get sigma(R)
120+ TODO: This is slow, there must be something better to do
121121 args:
122122 R: Comoving Lagrangian radius [Mpc/h]
123123 Pk: Function of k to evaluate the linear power spectrum
@@ -127,7 +127,6 @@ def sigmaR_vec(R:float, Pk:callable):
127127 sigmaR_squared , _ = integrate .quad (lambda t : _transformed_integrand (t , R , Pk , _sigmaR_integrand ),
128128 0. , 1. , epsabs = eps , epsrel = eps )
129129 else :
130- kmin , kmax = 0. , np .inf
131130 sigmaR_squared , _ = integrate .quad (lambda k : _sigmaR_integrand (k , R , Pk ),
132131 kmin , kmax , epsabs = eps , epsrel = eps )
133132 sigmaR = np .sqrt (sigmaR_squared / (2. * np .pi ** 2 ))
@@ -144,12 +143,12 @@ def _sigmaV_integrand(k:np.ndarray, R:float, Pk:callable) -> np.ndarray:
144143 return integrand
145144
146145
147- def sigmaV (R :float , Pk :callable , eps = eps_sigmaV , transform_integrand = False ) -> float :
146+ def sigmaV (R :float , Pk :callable , kmin = 0. , kmax = np . inf , eps = eps_sigmaV , transform_integrand = False ) -> float :
148147 '''
149148 Integration to get the 1D RMS in the linear displacement field
150- TODO: This generates a warning sometimes, there must be a cleverer way to integrate here.
149+ TODO: This generates a warning sometimes, and is slow, there must be a cleverer way to integrate here.
151150 Unless eps_sigmaV > 1e-3 the integration fails for z=0 sometimes, but not after being called for
152- z > 0. I really don't understand this, but it's annoying and should be fixed.
151+ z > 0. I really don't understand this, but it's annoying and should be fixed (kmin /= 0. helps) .
153152 I should look at how CAMB deals with these type of integrals (e.g., sigmaR).
154153 args:
155154 Pk: Function of k to evaluate the linear power spectrum
@@ -159,7 +158,6 @@ def sigmaV(R:float, Pk:callable, eps=eps_sigmaV, transform_integrand=False) -> f
159158 sigmaV_squared , _ = integrate .quad (lambda t : _transformed_integrand (t , R , Pk , _sigmaV_integrand ),
160159 0. , 1. , epsabs = eps , epsrel = eps )
161160 else :
162- kmin , kmax = 0. , np .inf
163161 sigmaV_squared , _ = integrate .quad (lambda k : _sigmaV_integrand (k , R , Pk ),
164162 kmin , kmax , epsabs = eps , epsrel = eps )
165163 sigmaV = np .sqrt (sigmaV_squared / (2. * np .pi ** 2 ))
@@ -171,17 +169,16 @@ def _dsigmaR_integrand(k:float, R:float, Pk:callable) -> float:
171169 return Pk (k )* (k ** 3 )* _Tophat_k (k * R )* _dTophat_k (k * R )
172170
173171
174- def _dlnsigma2_dlnR (R :float , Pk :callable , eps = eps_neff , transform_integrand = False ) -> float :
172+ def _dlnsigma2_dlnR (R :float , Pk :callable , kmin = 0. , kmax = np . inf , eps = eps_neff , transform_integrand = False ) -> float :
175173 '''
176174 Calculates d(ln sigma^2)/d(ln R) by integration
177175 3+neff = -d(ln sigma^2) / dR
178- TODO: Vectorize
176+ TODO: This is slow, regardless of whether transform_integrand is set or not
179177 '''
180178 if transform_integrand :
181179 dsigma , _ = integrate .quad (lambda t : _transformed_integrand (t , R , Pk , _dsigmaR_integrand ),
182180 0. , 1. , epsabs = eps , epsrel = eps )
183181 else :
184- kmin , kmax = 0. , np .inf # Evaluate the integral and convert to a nicer form
185182 dsigma , _ = integrate .quad (lambda k : _dsigmaR_integrand (k , R , Pk ),
186183 kmin , kmax , epsabs = eps , epsrel = eps )
187184 dsigma = R * dsigma / (np .pi * sigmaR (R , Pk ))** 2
0 commit comments