From 20188debb25eb7715dcfc22159ce4463f11d2f93 Mon Sep 17 00:00:00 2001 From: Anne Heimes <64446926+ahms5@users.noreply.github.com> Date: Tue, 11 Feb 2025 15:29:57 +0100 Subject: [PATCH 1/5] fix deprecation warnings --- pyproject.toml | 2 +- pyrato/dsp.py | 13 +++++++------ pyrato/edc.py | 4 ++-- pyrato/roomacoustics.py | 3 ++- tests/test_deprecation_warnings.py | 11 ++++++----- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bc59a49..3176dd0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,7 @@ classifiers = [ ] dependencies = [ - 'pyfar>=0.5.0', + 'pyfar>=0.6.0', 'numpy>=1.14.0', 'scipy>=1.5.0', 'matplotlib', diff --git a/pyrato/dsp.py b/pyrato/dsp.py index 0db0347..3a6e2de 100644 --- a/pyrato/dsp.py +++ b/pyrato/dsp.py @@ -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, @@ -93,7 +93,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) @@ -270,7 +270,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) @@ -290,7 +290,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) @@ -322,7 +322,7 @@ 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) @@ -421,7 +421,8 @@ def _smooth_rir( data = np.atleast_2d(data) n_samples = data.shape[-1] n_samples_nan = np.count_nonzero(np.isnan(data), axis=-1) - + # if isinstance(smooth_block_length, np.ndarray): + # assert False n_samples_per_block = int(np.round(smooth_block_length * sampling_rate, 0)) n_blocks = np.asarray( np.floor((n_samples-n_samples_nan)/n_samples_per_block), diff --git a/pyrato/edc.py b/pyrato/edc.py index aa0230b..fe7c03d 100644 --- a/pyrato/edc.py +++ b/pyrato/edc.py @@ -929,12 +929,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 diff --git a/pyrato/roomacoustics.py b/pyrato/roomacoustics.py index 6716d28..bfa6800 100644 --- a/pyrato/roomacoustics.py +++ b/pyrato/roomacoustics.py @@ -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( @@ -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) diff --git a/tests/test_deprecation_warnings.py b/tests/test_deprecation_warnings.py index c8c60b0..a3e5c63 100644 --- a/tests/test_deprecation_warnings.py +++ b/tests/test_deprecation_warnings.py @@ -3,11 +3,12 @@ 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'): + with pytest.warns(PyfarDeprecationWarning, match='0.5.0'): sig = pf.Signal([1, 2, 3], 44100) pyrato.dsp.filter_fractional_octave_bands(sig, 1) @@ -20,25 +21,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) From 62dee9c4c176d76cee8de2fd1b64643bfa2ec04e Mon Sep 17 00:00:00 2001 From: Anne Heimes <64446926+ahms5@users.noreply.github.com> Date: Tue, 11 Feb 2025 15:38:13 +0100 Subject: [PATCH 2/5] remove internal use of find_impulse_response_start and fix dep --- pyrato/dsp.py | 4 +- tests/test_deprecation_warnings.py | 2 +- tests/test_dsp.py | 119 ----------------------------- 3 files changed, 3 insertions(+), 122 deletions(-) diff --git a/pyrato/dsp.py b/pyrato/dsp.py index 3a6e2de..3812ab7 100644 --- a/pyrato/dsp.py +++ b/pyrato/dsp.py @@ -325,7 +325,7 @@ def filter_fractional_octave_bands( 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( @@ -481,7 +481,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 diff --git a/tests/test_deprecation_warnings.py b/tests/test_deprecation_warnings.py index a3e5c63..b56198f 100644 --- a/tests/test_deprecation_warnings.py +++ b/tests/test_deprecation_warnings.py @@ -9,7 +9,7 @@ def test_warning_fractional_octave_bands(): with pytest.warns(PyfarDeprecationWarning, match='0.5.0'): - sig = pf.Signal([1, 2, 3], 44100) + sig = pf.Signal([1, 2, 3], 48000) pyrato.dsp.filter_fractional_octave_bands(sig, 1) diff --git a/tests/test_dsp.py b/tests/test_dsp.py index 6d2b82a..cdd3642 100644 --- a/tests/test_dsp.py +++ b/tests/test_dsp.py @@ -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) From 3bc130bbde6bfe7661c4ff7369843e10992e8645 Mon Sep 17 00:00:00 2001 From: Anne Heimes <64446926+ahms5@users.noreply.github.com> Date: Tue, 11 Feb 2025 15:52:57 +0100 Subject: [PATCH 3/5] Update pyrato/dsp.py --- pyrato/dsp.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pyrato/dsp.py b/pyrato/dsp.py index 3812ab7..b8b57c6 100644 --- a/pyrato/dsp.py +++ b/pyrato/dsp.py @@ -421,8 +421,6 @@ def _smooth_rir( data = np.atleast_2d(data) n_samples = data.shape[-1] n_samples_nan = np.count_nonzero(np.isnan(data), axis=-1) - # if isinstance(smooth_block_length, np.ndarray): - # assert False n_samples_per_block = int(np.round(smooth_block_length * sampling_rate, 0)) n_blocks = np.asarray( np.floor((n_samples-n_samples_nan)/n_samples_per_block), From 6cd285c6aaf32c74008bc9bf79137588803eb0f5 Mon Sep 17 00:00:00 2001 From: Anne Heimes <64446926+ahms5@users.noreply.github.com> Date: Tue, 11 Feb 2025 15:53:38 +0100 Subject: [PATCH 4/5] Update pyrato/dsp.py --- pyrato/dsp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrato/dsp.py b/pyrato/dsp.py index b8b57c6..aa056a1 100644 --- a/pyrato/dsp.py +++ b/pyrato/dsp.py @@ -421,6 +421,7 @@ def _smooth_rir( data = np.atleast_2d(data) n_samples = data.shape[-1] n_samples_nan = np.count_nonzero(np.isnan(data), axis=-1) + n_samples_per_block = int(np.round(smooth_block_length * sampling_rate, 0)) n_blocks = np.asarray( np.floor((n_samples-n_samples_nan)/n_samples_per_block), From 83324a0139df1e4a9bec9991f32bde4b9a5a6be7 Mon Sep 17 00:00:00 2001 From: Anne Heimes <64446926+ahms5@users.noreply.github.com> Date: Mon, 31 Mar 2025 08:36:24 +0200 Subject: [PATCH 5/5] Update tests/test_deprecation_warnings.py --- tests/test_deprecation_warnings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_deprecation_warnings.py b/tests/test_deprecation_warnings.py index 33661d3..d8c7037 100644 --- a/tests/test_deprecation_warnings.py +++ b/tests/test_deprecation_warnings.py @@ -8,7 +8,7 @@ def test_warning_fractional_octave_bands(): with pytest.warns(PyfarDeprecationWarning, match='0.5.0'): - sig = pf.Signal([1, 2, 3], 48000) + sig = pf.Signal([1, 2, 3], 44100) pyrato.dsp.filter_fractional_octave_bands(sig, 1)