Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

69 deprecation warnings need dealing with #71

Merged
merged 5 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion clarity/data/HOA_tools_cec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import numpy as np
from numba import njit
from numba.typed import List as TypedList
from scipy.signal import convolve
from scipy.spatial.transform import Rotation as R
from scipy.special import comb
Expand Down Expand Up @@ -45,9 +46,14 @@ def compute_rotation_matrix(n: int, foa_rotmat: np.ndarray) -> np.ndarray:
sub_matrices = [np.eye(i * 2 + 1) for i in np.arange(n + 1)]
sub_matrices[1] = foa_rotmat

typed_sub_matrices = TypedList()
[typed_sub_matrices.append(x) for x in sub_matrices]

if n > 1:
for i in np.arange(2, n + 1):
rot_mat, sub_matrices = compute_band_rotation(i, sub_matrices, rot_mat)
rot_mat, typed_sub_matrices = compute_band_rotation(
i, typed_sub_matrices, rot_mat
)

return rot_mat

Expand Down
12 changes: 8 additions & 4 deletions clarity/data/scene_renderer_cec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import logging
import math
import warnings
from pathlib import Path

import librosa
Expand Down Expand Up @@ -169,10 +170,13 @@ def load_interferer_signals(self, scene):
"""
interferer_audio_paths = self.prepare_interferer_paths(scene)
# NOTE: all interferer signals are assumed to by at the Clarity fs = 44100 Hz
signals = [
librosa.load(signal_path, sr=None)[0]
for signal_path in interferer_audio_paths
]
with warnings.catch_warnings():
# Suppress annoying warning generated by librosa when reading mp3 files
warnings.simplefilter("ignore")
signals = [
librosa.load(signal_path, sr=None)[0]
for signal_path in interferer_audio_paths
]
signal_starts = [interferer["offset"] for interferer in scene["interferers"]]
signal_lengths = [
interferer["time_end"] - interferer["time_start"]
Expand Down
2 changes: 1 addition & 1 deletion clarity/enhancer/gha/gainrule_camfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def freq_interp_sh(f_in, y_in, f):
y_in = y_in[0]

vals = np.pad(
f_in.astype(np.float), 1, constant_values=((0.5 * f_in[0], 2 * f_in[-1]))
f_in.astype(float), 1, constant_values=((0.5 * f_in[0], 2 * f_in[-1]))
)
yvals = np.pad(y_in, 1, constant_values=((y_in[0], y_in[-1])))

Expand Down
24 changes: 12 additions & 12 deletions clarity/predictor/torch_msbg.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@

def generate_key_percent(signal, thr_dB, winlen):
if winlen != np.floor(winlen):
winlen = np.int(np.floor(winlen))
winlen = int(np.floor(winlen))
print("\nGenerate_key_percent: \t Window length must be integer")

siglen = len(signal)
expected = thr_dB.copy() # expected threshold
non_zero = 10.0 ** ((expected - 30) / 10) # put floor into histogram distribution

nframes = 0
totframes = np.int(np.floor(siglen / winlen))
totframes = int(np.floor(siglen / winlen))
every_dB = np.zeros(totframes)

for ix in range(totframes):
Expand All @@ -56,12 +56,12 @@ def generate_key_percent(signal, thr_dB, winlen):
# between the two peaks, and set a bit above that, as it heads for main peak
frame_idx = np.where(every_dB >= expected)[0]
valid_frames = len(frame_idx)
key = np.zeros(valid_frames * winlen, dtype=np.int)
key = np.zeros(valid_frames * winlen, dtype=int)

# convert frame numbers into indices for signal
for ix in range(valid_frames):
key[ix * winlen : ix * winlen + winlen] = np.arange(
frame_idx[ix] * winlen, frame_idx[ix] * winlen + winlen, dtype=np.int
frame_idx[ix] * winlen, frame_idx[ix] * winlen + winlen, dtype=int
)
return key, used_thr_dB

Expand All @@ -84,7 +84,7 @@ def measure_rms(signal, sr, dB_rel_rms):
# use this RMS to generate key threshold to more accurate RMS
key_thr_dB = np.max([20 * np.log10(first_stage_rms) + dB_rel_rms, -80])
key, used_thr_dB = generate_key_percent(
signal, key_thr_dB, np.int(np.round(win_secs * sr))
signal, key_thr_dB, int(np.round(win_secs * sr))
)
# active = 100.0 * len(key) / len(signal)
rms = np.sqrt(np.mean(signal[key] ** 2))
Expand All @@ -94,18 +94,18 @@ def measure_rms(signal, sr, dB_rel_rms):

def makesmearmat3(rl, ru, sr):
fftsize = 512
nyquist = np.int(fftsize // 2)
nyquist = int(fftsize // 2)
fnor = audfilt(1, 1, nyquist, sr)
fwid = audfilt(rl, ru, nyquist, sr)
fnext = np.hstack([fnor, np.zeros([nyquist, nyquist // 2])])

for i in np.arange(nyquist // 2 + 1, nyquist + 1, dtype=np.int):
for i in np.arange(nyquist // 2 + 1, nyquist + 1, dtype=int):
fnext[i - 1, nyquist : np.min([2 * i - 1, 3 * nyquist // 2])] = np.flip(
fnor[
i - 1, np.max([1, 2 * i - 3 * nyquist // 2]) - 1 : (2 * i - nyquist - 1)
]
)
fsmear = np.linalg.lstsq(fnext, fwid)[
fsmear = np.linalg.lstsq(fnext, fwid, rcond=-1)[
0
] # https://stackoverflow.com/questions/33559946/numpy-vs-mldivide-matlab-operator
fsmear = fsmear[:nyquist, :]
Expand All @@ -130,15 +130,15 @@ def audfilt(rl, ru, size, sr):
aud_filter[0, 0] = aud_filter[0, 0] / ((rl + ru) / 2)

g = np.zeros(size)
for i in np.arange(2, size + 1, 1, dtype=np.int):
for i in np.arange(2, size + 1, 1, dtype=int):
fhz = (i - 1) * sr / (2 * size)
erbhz = 24.7 * ((fhz * 0.00437) + 1)
pl = 4 * fhz / (erbhz * rl)
pu = 4 * fhz / (erbhz * ru)
j = np.arange(1, i, dtype=np.int)
j = np.arange(1, i, dtype=int)
g[j - 1] = np.abs((i - j) / (i - 1))
aud_filter[i - 1, j - 1] = (1 + (pl * g[j - 1])) * np.exp(-pl * g[j - 1])
j = np.arange(i, size + 1, dtype=np.int)
j = np.arange(i, size + 1, dtype=int)
g[j - 1] = np.abs((i - j) / (i - 1))
aud_filter[i - 1, j - 1] = (1 + (pu * g[j - 1])) * np.exp(-pu * g[j - 1])
aud_filter[i - 1, :] = aud_filter[i - 1, :] / (erbhz * (rl + ru) / (2 * 24.7))
Expand Down Expand Up @@ -427,7 +427,7 @@ def __init__(
corrn_used = np.append(corrn[ixf_useful], last_corrn)
corrn_forward = 10 ** (0.05 * corrn_used)
corrn_backward = 10 ** (0.05 * -1 * corrn_used)
n_wdw = np.int(2 * np.floor((sr / 16e3) * 368 / 2))
n_wdw = int(2 * np.floor((sr / 16e3) * 368 / 2))
coch_filter_forward = firwin2(
n_wdw + 1, hz_used / nyquist, corrn_forward, window=("kaiser", 4)
)
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ testpaths = [
"tests",
]
filterwarnings = [
"ignore::DeprecationWarning",
"ignore::UserWarning"
]

Expand Down
13 changes: 8 additions & 5 deletions tests/regression/test_data_HOA_tools_cec2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
from numba.typed import List
from scipy.spatial.transform import Rotation as R

from clarity.data import HOA_tools_cec2 as hoa
Expand Down Expand Up @@ -34,7 +35,7 @@ def test_U(regtest):
theta = 45
order = 2
foa = R.from_euler("y", theta, degrees=True).as_matrix()
rotmats = [foa, hoa.compute_rotation_matrix(order, foa)]
rotmats = List([foa, hoa.compute_rotation_matrix(order, foa)])
u = hoa.U.py_func(m, n, order, rotmats)
regtest.write(f"U value {u:0.3f}\n")

Expand All @@ -44,7 +45,7 @@ def test_V(regtest):
theta = 45
order = 2
foa = R.from_euler("y", theta, degrees=True).as_matrix()
rotmats = [foa, hoa.compute_rotation_matrix(order, foa)]
rotmats = List([foa, hoa.compute_rotation_matrix(order, foa)])
for i in range(3):
v = hoa.V.py_func(i - 1, n, order, rotmats)
regtest.write(f"V[{i}] value {v:0.3f}\n")
Expand All @@ -55,7 +56,7 @@ def test_W(regtest):
theta = 45
order = 2
foa = R.from_euler("y", theta, degrees=True).as_matrix()
rotmats = [foa, hoa.compute_rotation_matrix(order, foa)]
rotmats = List([foa, hoa.compute_rotation_matrix(order, foa)])
for i in range(3):
w = hoa.W.py_func(i - 1, n, order, rotmats)
regtest.write(f"W[{i}] value {w:0.3f}\n")
Expand Down Expand Up @@ -84,10 +85,12 @@ def test_compute_band_rotation(regtest):

sub_matrices = [np.eye(i * 2 + 1) for i in np.arange(n + 1)]
sub_matrices[1] = foa_rotmat
typed_sub_matrices = List()
[typed_sub_matrices.append(x) for x in sub_matrices]

if n > 1:
for i in np.arange(2, n + 1):
rot_mat, sub_matrices = hoa.compute_band_rotation.py_func(
i, sub_matrices, rot_mat
rot_mat, typed_sub_matrices = hoa.compute_band_rotation.py_func(
i, typed_sub_matrices, rot_mat
)
regtest.write(f"Band rotations {rot_mat}, {sub_matrices}\n")