Skip to content

Commit b274aab

Browse files
committed
MNT: fix numpy and scipy deprecations
For scipy 1.14 and numpy 2.0
1 parent 9b5f039 commit b274aab

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

bin/matdyn2fqha.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434

3535
import sys
3636
import numpy as np
37-
from scipy.integrate import simps
37+
from scipy.integrate import simpson as simps
3838

3939
filename = sys.argv[1]
4040
arr = np.loadtxt(filename)
4141
freq = arr[:,0]
4242
dos = arr[:,1]
4343

44-
integral = simps(dos, freq)
44+
integral = simps(dos, x=freq)
4545

4646
natom = integral / 3.
4747
nstep = len(freq)

src/pwtools/num.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from math import sqrt, sin, cos, radians, pi
44
import scipy.optimize as optimize
55
from scipy.interpolate import bisplrep, bisplev, splev, splrep
6-
from scipy.integrate import simps
6+
from scipy.integrate import simpson as simps
77
from pwtools import _flib
88
import warnings
99

@@ -87,7 +87,7 @@ def norm_int(y, x, area=1.0, scale=True, func=simps):
8787
different scales.
8888
func : callable
8989
Function to do integration (like scipy.integrate.{simps,trapz,...}
90-
Called as ``func(y,x)``. Default: simps
90+
Called as ``func(y,x=x)``. Default: simps
9191
9292
Returns
9393
-------
@@ -107,7 +107,7 @@ def norm_int(y, x, area=1.0, scale=True, func=simps):
107107
fx = fy = 1.0
108108
sx, sy = x, y
109109
# Area under unscaled y(x).
110-
_area = func(sy, sx) * fx * fy
110+
_area = func(sy, x=sx) * fx * fy
111111
return y * area / _area
112112

113113

@@ -1097,7 +1097,7 @@ def a2_to_an(self):
10971097
a = np.unique(self.a2[:, colidx])
10981098
axes.append(a)
10991099
dims.append(len(a))
1100-
assert np.product(dims) == self.a2.shape[0]
1100+
assert np.prod(dims) == self.a2.shape[0]
11011101
idx = itertools.product(*tuple(map(range, dims)))
11021102
an = np.empty(dims, dtype=self.a2.dtype)
11031103
# an[1,2,3] == an[(1,2,3)], need way to eliminate loop over index array

src/pwtools/thermo.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import warnings
44

55
import numpy as np
6-
from scipy.integrate import simps, trapz
6+
from scipy.integrate import trapezoid as trapz
77
from pwtools.constants import kb, hplanck, R, pi, c0, Ry_to_J, eV,\
88
eV_by_Ang3_to_GPa
99
from pwtools.verbose import verbose
@@ -48,7 +48,7 @@ def __init__(self, freq, dos, T=None, temp=None, skipfreq=False,
4848
If not None, then re-normalize the area int(freq) dos to `dosarea`,
4949
after `skipfreq` was applied if used.
5050
integrator : callable
51-
Function which integrates x-y data. Called as ``integrator(y,x)``,
51+
Function which integrates x-y data. Called as ``integrator(y,x=x)``,
5252
like ``scipy.integrate.{trapz,simps}``. Usually, `trapz` is
5353
numerically more stable for weird DOS data and accurate enough if
5454
the frequency axis resolution is good.
@@ -158,7 +158,7 @@ def _norm_int(self, y, x, area):
158158
fy = np.abs(y).max()
159159
sx = x / fx
160160
sy = y / fy
161-
_area = self.integrator(sy, sx) * fx * fy
161+
_area = self.integrator(sy, x=sx) * fx * fy
162162
return y*area/_area
163163

164164
def _printwarn(self, msg):

test/test_norm_int.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import numpy as np
2-
from scipy.integrate import simps
2+
from scipy.integrate import simpson as simps
33
from pwtools.num import norm_int
44

55
def test_norm_int():
@@ -9,4 +9,4 @@ def test_norm_int():
99

1010
for scale in [True, False]:
1111
yy = norm_int(y, x, area=10.0, scale=scale)
12-
assert np.allclose(simps(yy,x), 10.0)
12+
assert np.allclose(simps(yy,x=x), 10.0)

test/test_qha.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy as np
88
from numpy.testing import assert_array_almost_equal as aaae
99

10-
from scipy.integrate import simps, trapz
10+
from scipy.integrate import simpson as simps
1111
from pwtools.thermo import HarmonicThermo
1212
from pwtools import common
1313
from pwtools.constants import Ry_to_J, eV, Ry, kb
@@ -91,4 +91,4 @@ def test_qha():
9191
area = np.random.rand()*10
9292
ha = HarmonicThermo(pdos[:,0], pdos[:,1], skipfreq=True, dosarea=area,
9393
integrator=simps)
94-
assert np.allclose(simps(ha.dos, ha.f), area)
94+
assert np.allclose(simps(ha.dos, x=ha.f), area)

test/test_trajectory.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import copy
55

66
import numpy as np
7-
from scipy.signal import hann
7+
from scipy.signal.windows import hann
88

99
from pwtools.crys import Trajectory, Structure
1010
from pwtools import crys, constants

0 commit comments

Comments
 (0)