Skip to content

Commit c58051f

Browse files
committed
Fix to prevent errors with numpy>=1.24.0 (replace all int and np.int with np.int_)
Signed-off-by: HaHeho <[email protected]>
1 parent 971cd1b commit c58051f

File tree

7 files changed

+45
-40
lines changed

7 files changed

+45
-40
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ Version history
127127
---------------
128128

129129
*unreleased*
130+
* Fix to prevent errors with `NumPy >= 1.24.0 <https://numpy.org/doc/stable//release/1.24.0-notes.html>`_ (replace all `int` and `np.int` with `np.int_`)
130131
* Improve `read_miro_struct()` to give warnings in case elevation data is found
131132
* Fix *Exp4* loading of MIRO files and improve documentation table formatting
132133
* Update README to reflect the name change of master branch to "main"

sound_field_analysis/gen.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def lebedev(max_order=None, degree=None):
145145
allowed_degrees = [6, 14, 26, 38, 50, 74, 86, 110, 146, 170, 194]
146146

147147
if max_order and 0 <= max_order <= 11:
148-
degree = allowed_degrees[int(max_order) - 1]
148+
degree = allowed_degrees[_np.int_(max_order) - 1]
149149
elif max_order:
150150
raise ValueError("Maximum order can only be between 0 and 11.")
151151

@@ -276,7 +276,7 @@ def pressure_on_sphere(max_order, kr, taper_weights=None):
276276
p = _np.zeros_like(kr)
277277
for n in range(max_order + 1):
278278
# Calculate mode strength b_n(kr) for an incident plane wave on sphere according to [1, Eq.(9)]
279-
b_n = (4 * _np.pi * 1j ** n) * (
279+
b_n = (4 * _np.pi * 1j**n) * (
280280
spherical_jn(n, kr)
281281
- (
282282
spherical_jn(n, kr, derivative=True)
@@ -332,11 +332,11 @@ def spherical_head_filter_spec(
332332
Implement `arctan()` soft-clipping
333333
"""
334334
# frequency support vector & corresponding wave numbers k
335-
freqs = _np.linspace(0, fs / 2, int(NFFT / 2 + 1))
335+
freqs = _np.linspace(0, fs / 2, _np.int_(NFFT / 2 + 1))
336336
kr_SHF = kr(freqs, radius)
337337

338338
# calculate SH order necessary to expand sound field in entire modal range
339-
order_full = int(_np.ceil(kr_SHF[-1]))
339+
order_full = _np.int_(_np.ceil(kr_SHF[-1]))
340340

341341
# calculate filter
342342
G_SHF = spherical_head_filter(
@@ -532,7 +532,7 @@ def ideal_wave(
532532
"""
533533
array_configuration = ArrayConfiguration(*array_configuration)
534534

535-
order = _np.int(order)
535+
order = _np.int_(order)
536536
NFFT = NFFT // 2 + 1
537537
NMLocatorSize = (order + 1) ** 2
538538

@@ -609,7 +609,7 @@ def spherical_noise(
609609
order_max, gridData.azimuth, gridData.colatitude, kind=kind
610610
)
611611
else:
612-
order_max = _np.int(_np.sqrt(spherical_harmonic_bases.shape[1]) - 1)
612+
order_max = _np.int_(_np.sqrt(spherical_harmonic_bases.shape[1]) - 1)
613613
return _np.inner(
614614
spherical_harmonic_bases,
615615
_np.random.randn((order_max + 1) ** 2)

sound_field_analysis/io.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,12 @@ def _check_irs(irs):
466466
# store SOFA data as named tuple
467467
if isinstance(file, sofa.SOFAConventions.SOFASimpleFreeFieldHRIR):
468468
hrir_l = TimeSignal(
469-
signal=_check_irs(file.getDataIR()[:, 0]), fs=int(file.getSamplingRate()[0])
469+
signal=_check_irs(file.getDataIR()[:, 0]),
470+
fs=_np.int_(file.getSamplingRate()[0]),
470471
)
471472
hrir_r = TimeSignal(
472-
signal=_check_irs(file.getDataIR()[:, 1]), fs=int(file.getSamplingRate()[0])
473+
signal=_check_irs(file.getDataIR()[:, 1]),
474+
fs=_np.int_(file.getSamplingRate()[0]),
473475
)
474476

475477
# transform grid into azimuth, colatitude, radius in radians
@@ -486,7 +488,7 @@ def _check_irs(irs):
486488
else: # isinstance(file, sofa.SOFAConventions.SOFASingleRoomDRIR):
487489
drir_signal = TimeSignal(
488490
signal=_check_irs(_np.squeeze(file.getDataIR())),
489-
fs=int(file.getSamplingRate()[0]),
491+
fs=_np.int_(file.getSamplingRate()[0]),
490492
)
491493

492494
# transform grid into azimuth, colatitude, radius in radians
@@ -643,13 +645,13 @@ def write_SSR_IRs(filename, time_data_l, time_data_r, wavformat="float32"):
643645
if wavformat in ["float32", "float"]:
644646
sio.wavfile.write(
645647
filename=filename,
646-
rate=int(time_data_l.signal.fs),
648+
rate=_np.int_(time_data_l.signal.fs),
647649
data=data_to_write.T.astype(_np.float32),
648650
)
649651
elif wavformat in ["int32", "int16"]:
650652
sio.wavfile.write(
651653
filename=filename,
652-
rate=int(time_data_l.signal.fs),
654+
rate=_np.int_(time_data_l.signal.fs),
653655
data=(data_to_write.T * _np.iinfo(wavformat).max).astype(wavformat),
654656
)
655657
else:

sound_field_analysis/plot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def makeMTX(
115115
"""
116116

117117
if not viz_order:
118-
viz_order = _np.int(_np.ceil(_np.sqrt(spat_coeffs.shape[0]) - 1))
118+
viz_order = _np.int_(_np.ceil(_np.sqrt(spat_coeffs.shape[0]) - 1))
119119

120120
angles = (
121121
_np.mgrid[0:360:stepsize_deg, 0:181:stepsize_deg].reshape((2, -1))
@@ -152,7 +152,7 @@ def makeFullMTX(Pnm, dn, kr, viz_order=None):
152152
"""
153153
kr = _np.asarray(kr)
154154
if not viz_order:
155-
viz_order = _np.int(_np.ceil(_np.sqrt(Pnm.shape[0]) - 1))
155+
viz_order = _np.int_(_np.ceil(_np.sqrt(Pnm.shape[0]) - 1))
156156

157157
N = kr.size
158158
vizMtx = []
@@ -586,8 +586,8 @@ def plot3Dgrid(rows, cols, viz_data, style, normalize=True, title=None):
586586
for IDX in range(0, len(viz_data)):
587587
fig.add_trace(
588588
_genVisual(viz_data[IDX], style=style, normalize=normalize),
589-
row=int(rows[IDX]),
590-
col=int(cols[IDX]),
589+
row=_np.int_(rows[IDX]),
590+
col=_np.int_(cols[IDX]),
591591
)
592592
fig.layout[f"scene{IDX + 1:d}"].update(layout_3D)
593593

sound_field_analysis/process.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ def BEMA(Pnm, center_sig, dn, transition, avg_band_width=1, fade=True, max_order
7272
"""
7373

7474
if not max_order:
75-
max_order = int(_np.sqrt(Pnm.shape[0] - 1)) # SH order
75+
max_order = _np.int_(_np.sqrt(Pnm.shape[0] - 1)) # SH order
7676

77-
transition = int(_np.floor(transition))
77+
transition = _np.int_(_np.floor(transition))
7878

7979
# computing spatio-temporal Image Imn
80-
Imn = _np.zeros((Pnm.shape[0], 1), dtype=complex)
80+
Imn = _np.zeros((Pnm.shape[0], 1), dtype=_np.complex_)
8181
# first bin for averaging
82-
start_avg_bin = int(_np.floor(transition / (_np.power(2, avg_band_width))))
82+
start_avg_bin = _np.int_(_np.floor(transition / (_np.power(2, avg_band_width))))
8383

8484
modeCnt = 0
8585
avgPower = 0
@@ -104,7 +104,7 @@ def BEMA(Pnm, center_sig, dn, transition, avg_band_width=1, fade=True, max_order
104104
)
105105
center_sig = _np.multiply(center_sig, (1 / sq_avg))
106106

107-
Pnm_synth = _np.zeros(Pnm.shape, dtype=complex)
107+
Pnm_synth = _np.zeros(Pnm.shape, dtype=_np.complex_)
108108
modeCnt = 0
109109
for n in range(0, max_order + 1):
110110
for _ in range(0, 2 * n + 1):
@@ -216,7 +216,7 @@ def FFT(
216216
signals = signals[:, first_sample:last_sample]
217217

218218
if not NFFT:
219-
NFFT = int(2 ** _np.ceil(_np.log2(total_samples)))
219+
NFFT = _np.int_(2 ** _np.ceil(_np.log2(total_samples)))
220220

221221
fftData = _np.fft.rfft(signals, NFFT * oversampling, 1)
222222
if not calculate_freqs:
@@ -432,7 +432,7 @@ def iSpatFT(
432432
# TODO: Check `spherical_coefficients` and `spherical_harmonic_bases` length
433433
# correspond with `order_max`
434434
if order_max is None:
435-
order_max = int(_np.sqrt(number_of_coefficients) - 1)
435+
order_max = _np.int_(_np.sqrt(number_of_coefficients) - 1)
436436

437437
# Re-generate spherical harmonic bases if they were not provided or their
438438
# order is too small
@@ -494,7 +494,7 @@ def plane_wave_decomp(
494494
"radial filter (dn) are not consistent."
495495
)
496496

497-
max_order = int(_np.floor(_np.sqrt(NMDeliveredSize) - 1))
497+
max_order = _np.int_(_np.floor(_np.sqrt(NMDeliveredSize) - 1))
498498
if order > max_order:
499499
raise ValueError(
500500
f"The provided coefficients deliver a maximum order of {max_order} "
@@ -629,7 +629,7 @@ def rfi(dn, kernelSize=512, highPass=0.0):
629629
# downsize kernel
630630
latency = kernelSize / 2
631631
mid = dn_ir.shape[-1] / 2
632-
dn_ir = dn_ir[:, int(mid - latency) : int(mid + latency)]
632+
dn_ir = dn_ir[:, _np.int_(mid - latency) : _np.int_(mid + latency)]
633633

634634
# apply Hanning / cosine window
635635
# 0.5 + 0.5 * _np.cos(2 * _np.pi * (_np.arange(0, kernelSize)
@@ -714,7 +714,7 @@ def sfe(Pnm_kra, kra, krb, problem="interior"):
714714
raise ValueError("Invalid problem: Choose either interior or exterior.")
715715

716716
FCoeff = Pnm_kra.shape[0]
717-
N = int(_np.floor(_np.sqrt(FCoeff) - 1))
717+
N = _np.int_(_np.floor(_np.sqrt(FCoeff) - 1))
718718

719719
nvector = _np.zeros(FCoeff)
720720
IDX = 1

sound_field_analysis/sph.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def spbessel(n, kr):
149149
)
150150
J[_np.logical_and(kr == 0, n == 0)] = 1
151151
else:
152-
J = scy.spherical_jn(n.astype(_np.int), kr)
152+
J = scy.spherical_jn(n.astype(_np.int_), kr)
153153
return _np.squeeze(J)
154154

155155

@@ -179,7 +179,7 @@ def spneumann(n, kr):
179179
)
180180
Yv[kr < 0] = -Yv[kr < 0]
181181
else:
182-
Yv = scy.spherical_yn(n.astype(_np.int), kr)
182+
Yv = scy.spherical_yn(n.astype(_np.int_), kr)
183183
# return possible infs as nan to stay consistent
184184
Yv[_np.isinf(Yv)] = _np.nan
185185
return _np.squeeze(Yv)
@@ -277,7 +277,7 @@ def dspneumann(n, kr):
277277
return spneumann(n, kr) * n / kr - spneumann(n + 1, kr)
278278
else:
279279
return scy.spherical_yn(
280-
n.astype(_np.int), kr.astype(_np.complex), derivative=True
280+
n.astype(_np.int_), kr.astype(_np.complex_), derivative=True
281281
)
282282

283283

@@ -400,7 +400,7 @@ def array_extrapolation(order, freqs, array_configuration, normalize=True):
400400
k_dual = None
401401

402402
if normalize:
403-
scale_factor = _np.squeeze(4 * _np.pi * 1j ** order)
403+
scale_factor = _np.squeeze(4 * _np.pi * 1j**order)
404404
else:
405405
scale_factor = 1
406406

@@ -639,7 +639,7 @@ def mnArrays(nMax):
639639
# Order m = 0, -1, 0, 1, -2, -1, 0, 1, 2, ...
640640
# http://oeis.org/A196199
641641
elementNumber = _np.arange((nMax + 1) ** 2) + 1
642-
t = _np.floor(_np.sqrt(elementNumber - 1)).astype(int)
642+
t = _np.floor(_np.sqrt(elementNumber - 1)).astype(_np.int_)
643643
m = elementNumber - t * t - t - 1
644644

645645
return m, n
@@ -661,7 +661,7 @@ def reverseMnIds(nMax):
661661
"""
662662
m_ids = list(range(nMax * (nMax + 2) + 1))
663663
for o in range(nMax + 1):
664-
id_start = o ** 2
664+
id_start = o**2
665665
id_end = id_start + o * 2 + 1
666666
m_ids[id_start:id_end] = reversed(m_ids[id_start:id_end])
667667
return m_ids
@@ -728,7 +728,7 @@ def kr_full_spec(fs, radius, NFFT, temperature=20):
728728
kr : array_like
729729
kr vector of length NFFT/2 + 1 spanning the frequencies of 0:fs/2
730730
"""
731-
freqs = _np.linspace(0, fs / 2, int(NFFT / 2 + 1))
731+
freqs = _np.linspace(0, fs / 2, _np.int_(NFFT / 2 + 1))
732732
return kr(freqs, radius, temperature)
733733

734734

@@ -775,14 +775,14 @@ def _print_mic_scaling(N, freqs, array_radius, scatter_radius=None, dual_radius=
775775

776776

777777
def _print_bns(N, k_mic, k_scatter):
778-
print("bn_open_omni:", bn_open_omni(N, k_mic) * 4 * _np.pi * 1j ** N)
779-
print("bn_open_cardioid:", bn_open_cardioid(N, k_mic) * 4 * _np.pi * 1j ** N),
780-
print("bn_rigid_omni:", bn_rigid_omni(N, k_mic, k_scatter) * 4 * _np.pi * 1j ** N),
778+
print("bn_open_omni:", bn_open_omni(N, k_mic) * 4 * _np.pi * 1j**N)
779+
print("bn_open_cardioid:", bn_open_cardioid(N, k_mic) * 4 * _np.pi * 1j**N),
780+
print("bn_rigid_omni:", bn_rigid_omni(N, k_mic, k_scatter) * 4 * _np.pi * 1j**N),
781781
print(
782782
"bn_rigid_cardioid:",
783-
bn_rigid_cardioid(N, k_mic, k_scatter) * 4 * _np.pi * 1j ** N,
783+
bn_rigid_cardioid(N, k_mic, k_scatter) * 4 * _np.pi * 1j**N,
784784
)
785785
print(
786786
"bn_dual_open_omni:",
787-
bn_dual_open_omni(N, k_mic, k_scatter) * 4 * _np.pi * 1j ** N,
787+
bn_dual_open_omni(N, k_mic, k_scatter) * 4 * _np.pi * 1j**N,
788788
)

sound_field_analysis/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ def progress_bar(curIDX, maxIDX=None, description="Progress"):
8888
if maxIDX is None:
8989
print(f"\r{description}: {next(spinner)}", end="", flush=True)
9090
else:
91-
maxIDX = int(maxIDX) - 1
91+
maxIDX = np.int_(maxIDX) - 1
9292
if maxIDX == 0:
9393
amount_done = 1
9494
else:
9595
amount_done = curIDX / maxIDX
9696
print(
97-
f'\r{description}: [{"#" * int(amount_done * 50):50s}] {amount_done * 100:.1f}%',
97+
f'\r{description}: [{"#" * np.int_(amount_done * 50):50s}] {amount_done * 100:.1f}%',
9898
end="",
9999
flush=True,
100100
)
@@ -298,7 +298,9 @@ def interleave_channels(left_channel, right_channel, style=None):
298298

299299
def simple_resample(data, original_fs, target_fs):
300300
"""Wrap scipy.signal.resample with a simpler API."""
301-
return resample(data, num=int(data.shape[-1] * target_fs / original_fs), axis=-1)
301+
return resample(
302+
data, num=np.int_(data.shape[-1] * target_fs / original_fs), axis=-1
303+
)
302304

303305

304306
def scalar_broadcast_match(a, b):

0 commit comments

Comments
 (0)