Skip to content

Commit

Permalink
fixed scipy deprecations (#1187)
Browse files Browse the repository at this point in the history
  • Loading branch information
damonge authored Jun 18, 2024
1 parent dfa2b3b commit 68ee11e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion benchmarks/test_hod.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ def _nz_2mrs(z):
bias=(z_arr, np.ones(len(dndz))))
cl_hod = ccl.angular_cl(cosmo, tr, tr, ell=l_bm, p_of_k_a=pk_hod)

assert np.all(np.fabs(cl_hod/cl_bm-1) < 0.005)
assert np.all(np.fabs(cl_hod/cl_bm-1) < 0.006)
6 changes: 3 additions & 3 deletions benchmarks/test_isw.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import pyccl as ccl
from scipy.integrate import simps
from scipy.integrate import simpson


def test_iswcl():
Expand All @@ -27,7 +27,7 @@ def test_iswcl():
cl = ccl.angular_cl(COSMO, tr_n, tr_i, ls)

# Benchmark from Eq. 6 in 1710.03238
pz = nz / simps(nz, x=zs)
pz = nz / simpson(nz, x=zs)
H0 = h / ccl.physical_constants.CLIGHT_HMPC
# Prefactor
prefac = 3*COSMO['T_CMB']*(Oc+Ob)*H0**3/(ls+0.5)**2
Expand All @@ -43,7 +43,7 @@ def test_iswcl():
for c, z in zip(chi, zs)]).T
# Limber integral
cl_int = pks[:, :]*(pz*ez*gz)[None, :]
clbb = simps(cl_int, x=zs)
clbb = simpson(cl_int, x=zs)
clbb *= prefac

assert np.all(np.fabs(cl/clbb-1) < 1E-3)
7 changes: 5 additions & 2 deletions pyccl/halos/halo_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
__all__ = ("HMCalculator",)

import numpy as np
from scipy.integrate import simpson

from .. import CCLAutoRepr, unlock_instance
from .. import physical_constants as const
Expand Down Expand Up @@ -57,8 +58,7 @@ def __init__(self, *, mass_function, halo_bias, mass_def=None,
self._m0 = self._mass[0]

if integration_method_M == "simpson":
from scipy.integrate import simpson
self._integrator = simpson
self._integrator = self._integ_simpson
elif integration_method_M == "spline":
self._integrator = self._integ_spline
else:
Expand All @@ -68,6 +68,9 @@ def __init__(self, *, mass_function, halo_bias, mass_def=None,
self._cosmo_mf = self._cosmo_bf = None
self._a_mf = self._a_bf = -1

def _integ_simpson(self, fM, log10M):
return simpson(fM, x=log10M)

def _integ_spline(self, fM, log10M):
# Spline integrator
return _spline_integrate(log10M, fM, log10M[0], log10M[-1])
Expand Down

0 comments on commit 68ee11e

Please sign in to comment.