Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ classifiers = [

]
dependencies = [
'pyfar>=0.5.0',
'pyfar>=0.6.0',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required for the PyfarDeprecationWarning

'numpy>=1.14.0',
'scipy>=1.5.0',
'matplotlib',
Expand Down
14 changes: 7 additions & 7 deletions pyrato/dsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pyfar as pf
import numpy as np

from pyfar.classes.warnings import PyfarDeprecationWarning

def find_impulse_response_start(
impulse_response,
Expand Down Expand Up @@ -97,7 +97,7 @@ def find_impulse_response_start(
warnings.warn(
"This function will be deprecated in version 0.5.0 "
"Use pyfar.dsp.find_impulse_response_start instead",
DeprecationWarning)
PyfarDeprecationWarning, stacklevel=2)

return pf.dsp.find_impulse_response_start(impulse_response, threshold)

Expand Down Expand Up @@ -275,7 +275,7 @@ def center_frequencies_octaves():
warnings.warn(
"This function will be deprecated in version 0.5.0 "
"Use pyfar.dsp.filter.fractional_octave_frequencies instead",
DeprecationWarning)
PyfarDeprecationWarning)

nominal, exact = pf.dsp.filter.fractional_octave_frequencies(
1, (20, 20e3), return_cutoff=False)
Expand All @@ -295,7 +295,7 @@ def center_frequencies_third_octaves():
warnings.warn(
"This function will be deprecated in version 0.5.0 "
"Use pyfar.dsp.filter.fractional_octave_frequencies instead",
DeprecationWarning)
PyfarDeprecationWarning)

nominal, exact = pf.dsp.filter.fractional_octave_frequencies(
3, (20, 20e3), return_cutoff=False)
Expand Down Expand Up @@ -327,10 +327,10 @@ def filter_fractional_octave_bands(
warnings.warn(
"This function will be deprecated in version 0.5.0 "
"Use pyfar.dsp.filter.fractional_octave_bands instead",
DeprecationWarning)
PyfarDeprecationWarning)

return pf.dsp.filter.fractional_octave_bands(
signal, num_fractions, freq_range=freq_range, order=order)
signal, num_fractions, frequency_range=freq_range, order=order)


def estimate_noise_energy(
Expand Down Expand Up @@ -487,7 +487,7 @@ def preprocess_rir(
n_channels = np.prod(data.cshape)

if shift:
rir_start_idx = find_impulse_response_start(data)
rir_start_idx = pf.dsp.find_impulse_response_start(data)

if channel_independent and not n_channels == 1:
shift_samples = -rir_start_idx
Expand Down
4 changes: 2 additions & 2 deletions pyrato/edc.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,12 +930,12 @@ def intersection_time_lundeby(
# (5) NEW LOCAL TIME INTERVAL LENGTH
n_blocks_in_decay = (np.diff(
10*np.log10(np.take(
time_window_data_current_channel, [start_idx, stop_idx])))
time_window_data_current_channel, [start_idx, stop_idx])))[0]
/ -10 * n_intervals_per_10dB)

n_samples_per_block = np.round(np.diff(np.take(
time_vector_window,
[start_idx, stop_idx])) / n_blocks_in_decay * sampling_rate)
[start_idx, stop_idx]))[0] / n_blocks_in_decay * sampling_rate)

window_time = n_samples_per_block/sampling_rate

Expand Down
3 changes: 2 additions & 1 deletion pyrato/roomacoustics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
from pyrato.rap import reverberation_time_linear_regression
import warnings
from pyfar.classes.warnings import PyfarDeprecationWarning


def reverberation_time_energy_decay_curve(
Expand Down Expand Up @@ -70,7 +71,7 @@ def reverberation_time_energy_decay_curve(
warnings.warn(
"This function will be deprecated in version 0.5.0 "
"Use pyrato.reverberation_time_linear_regression instead",
DeprecationWarning)
PyfarDeprecationWarning)

return reverberation_time_linear_regression(energy_decay_curve, T)

Expand Down
13 changes: 7 additions & 6 deletions tests/test_deprecation_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import pyfar as pf
import pyrato
import numpy as np
from pyfar.classes.warnings import PyfarDeprecationWarning


def test_warning_fractional_octave_bands():

with pytest.warns(DeprecationWarning, match='0.5.0'):
sig = pf.Signal([1, 2, 3], 44100)
with pytest.warns(PyfarDeprecationWarning, match='0.5.0'):
sig = pf.Signal([1, 2, 3], 48000)
pyrato.dsp.filter_fractional_octave_bands(sig, 1)


Expand All @@ -19,25 +20,25 @@ def test_warning_center_frequencies_thirds():
1250, 1600, 2000, 2500, 3150, 4000, 5000,
6300, 8000, 10000, 12500, 16000, 20000], dtype=float)

with pytest.warns(DeprecationWarning, match='0.5.0'):
with pytest.warns(PyfarDeprecationWarning, match='0.5.0'):
nom = pyrato.dsp.center_frequencies_third_octaves()[0]

np.testing.assert_allclose(nom, nominal)


def test_warning_center_frequencies_octaves():
with pytest.warns(DeprecationWarning, match='0.5.0'):
with pytest.warns(PyfarDeprecationWarning, match='0.5.0'):
nom, exact = pyrato.dsp.center_frequencies_octaves()


def test_warning_start_ir():
with pytest.warns(DeprecationWarning, match='0.5.0'):
with pytest.warns(PyfarDeprecationWarning, match='0.5.0'):

sig = pf.Signal([0, 0, 1, 0, 0], 44100)
pyrato.dsp.find_impulse_response_start(sig)


def test_warning_rt_edc():
with pytest.warns(DeprecationWarning, match='0.5.0'):
with pytest.warns(PyfarDeprecationWarning, match='0.5.0'):
edc = pf.TimeData([-5., -60.], [0.1, 1])
pyrato.reverberation_time_energy_decay_curve(edc)
119 changes: 0 additions & 119 deletions tests/test_dsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,125 +20,6 @@ def mock_shift_samples_2d(*args, **kwargs):
return np.array([76, 76])


def test_start_ir_insufficient_snr():
n_samples = 2**9
ir = np.zeros(n_samples, dtype=float)
ir[20] = 1
ir = pf.Signal(ir, 44100)

snr = 15

noise = np.random.randn(n_samples)
noise = noise / np.sqrt(np.mean(np.abs(noise**2))) * 10**(-snr/20)
noise = pf.Signal(noise, 44100)

ir_noise = ir + noise

with pytest.warns(match='SNR seems lower'):
dsp.find_impulse_response_start(ir_noise)


def test_start_ir():
n_samples = 2**10
ir = np.zeros(n_samples)
snr = 60

noise = pf.Signal(np.random.randn(n_samples) * 10**(-snr/20), 44100)

start_sample = 24
ir[start_sample] = 1

ir = pf.Signal(ir, 44100)

start_sample_est = dsp.find_impulse_response_start(ir)
assert start_sample_est == start_sample - 1

ir_awgn = ir + noise
start_sample_est = dsp.find_impulse_response_start(ir_awgn)
assert start_sample_est == start_sample - 1


def test_start_ir_thresh():
n_samples = 2**10
ir = np.zeros(n_samples)

start_sample = 24
ir[start_sample] = 1
ir[start_sample-4:start_sample] = 10**(-5/10)

ir = pf.Signal(ir, 44100)

start_sample_est = dsp.find_impulse_response_start(ir, threshold=20)
assert start_sample_est == start_sample - 4 - 1


def test_start_ir_multidim():
n_samples = 2**10
n_channels = 3
ir = np.zeros((n_channels, n_samples))

snr = 60

noise = pf.Signal(
np.random.randn(n_channels, n_samples) * 10**(-snr/20), 44100)

start_sample = [24, 5, 43]
ir[[0, 1, 2], start_sample] = 1

ir = pf.Signal(ir, 44100)

ir_awgn = ir + noise
start_sample_est = dsp.find_impulse_response_start(ir_awgn)

npt.assert_allclose(start_sample_est, np.array(start_sample) - 1)

ir = np.zeros((2, n_channels, n_samples))
noise = pf.Signal(
np.random.randn(2, n_channels, n_samples) * 10**(-snr/20), 44100)

start_sample_1 = [24, 5, 43]
ir[0, [0, 1, 2], start_sample_1] = 1
start_sample_2 = [14, 12, 16]
ir[1, [0, 1, 2], start_sample_2] = 1

ir = pf.Signal(ir, 44100)

start_samples = np.vstack((start_sample_1, start_sample_2))

ir_awgn = ir + noise
start_sample_est = dsp.find_impulse_response_start(ir_awgn)

npt.assert_allclose(start_sample_est, start_samples - 1)


def test_start_room_impulse_response():
rir = genfromtxt(
os.path.join(test_data_path, 'analytic_rir_psnr50_1D.csv'),
delimiter=',')

rir = pf.Signal(rir, 44100)

actual = dsp.find_impulse_response_start(rir, threshold=20)

expected = 0

npt.assert_allclose(actual, expected)


def test_start_room_impulse_response_shfted(monkeypatch):
rir = genfromtxt(
os.path.join(test_data_path, 'analytic_rir_psnr50_1D.csv'),
delimiter=',')

rir_shifted = np.roll(rir, 128, axis=-1)
rir_shifted = pf.Signal(rir_shifted, 44100)
actual = dsp.find_impulse_response_start(rir_shifted, threshold=20)

expected = 128

npt.assert_allclose(actual, expected)


def test_max_ir():
n_samples = 2**10
ir = np.zeros(n_samples)
Expand Down