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

Cookiecutter fix ruff #38

Closed
wants to merge 3 commits into from
Closed
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
16 changes: 8 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ lint.select = [
# "D", # Docstring guidelines
# "NPY", # Check all numpy related deprecations
# "D417", # Missing argument descriptions in the docstring
# "PT", # Pytest style
# "A", # Avoid builtin function and type shadowing
# "ERA", # No commented out code
# "NPY", # Check all numpy related deprecations
# "COM", # trailing comma rules
# "I002", # missing required import
# "TID252", # Use absolute over relative imports
# "FIX", # Code should not contain FIXME, TODO, etc
"PT", # Pytest style
"A", # Avoid builtin function and type shadowing
"ERA", # No commented out code
"NPY", # Check all numpy related deprecations
"COM", # trailing comma rules
"I002", # missing required import
"TID252", # Use absolute over relative imports
"FIX", # Code should not contain FIXME, TODO, etc
]

# Ignore missing docstrings in tests
Expand Down
2 changes: 1 addition & 1 deletion pyrato/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


from .rap import (
reverberation_time_linear_regression
reverberation_time_linear_regression,
)
from .roomacoustics import (
reverberation_time_energy_decay_curve,
Expand Down
4 changes: 2 additions & 2 deletions pyrato/analytic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .analytic import (
rectangular_room_rigid_walls,
eigenfrequencies_rectangular_room_rigid
eigenfrequencies_rectangular_room_rigid,
)

__all__ = (
'rectangular_room_rigid_walls',
'eigenfrequencies_rectangular_room_rigid'
'eigenfrequencies_rectangular_room_rigid',
)
4 changes: 2 additions & 2 deletions pyrato/analytic/analytic.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def eigenfrequencies_rectangular_room_rigid(
for n_y in range(0, n_y_max):
n_modes += int(np.floor(np.real(
np.sqrt(
(2*f_max/c)**2 - (n_x/L_x)**2 - (n_y/L_y)**2
(2*f_max/c)**2 - (n_x/L_x)**2 - (n_y/L_y)**2,
) * L_z))) + 1

n = np.zeros((3, n_modes), dtype=int)
Expand All @@ -89,7 +89,7 @@ def eigenfrequencies_rectangular_room_rigid(
for n_y in range(0, n_y_max):
n_z_max = int(np.floor(np.real(
np.sqrt(
(2*f_max/c)**2 - (n_x/L_x)**2 - (n_y/L_y)**2
(2*f_max/c)**2 - (n_x/L_x)**2 - (n_y/L_y)**2,
) * L_z))) + 1

idx_end = idx + n_z_max
Expand Down
6 changes: 3 additions & 3 deletions pyrato/analytic/impedance.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def eigenfrequencies_rectangular_room_impedance(
mask = ks >= 0.02
ks_search = ks[mask]
k_ns = normal_eigenfrequencies_rectangular_room_impedance(
L, ks_search, k_max, zeta
L, ks_search, k_max, zeta,
)
for idx in range(0, len(L)):
k_ns[idx] = np.hstack((
Expand Down Expand Up @@ -394,7 +394,7 @@ def pressure_modal_superposition(
k_ns_xyz = np.array([
k_ns[0][mode_indices[:, 0]],
k_ns[1][mode_indices[:, 1]],
k_ns[2][mode_indices[:, 2]]
k_ns[2][mode_indices[:, 2]],
])

phi = np.arctanh(ks/(zeta_0 * k_ns_xyz.T).T)
Expand Down Expand Up @@ -491,7 +491,7 @@ def rectangular_room_impedance(
k_ns_xyz = np.array([
k_ns[0][mode_indices[:, 0]],
k_ns[1][mode_indices[:, 1]],
k_ns[2][mode_indices[:, 2]]
k_ns[2][mode_indices[:, 2]],
])

return rir, spectrum, k_ns_xyz
12 changes: 6 additions & 6 deletions tests/test_analytic_impedance.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_eigenfreq_impedance_1d_real():
k_max = 1e3*2*np.pi/c

k_ns = analytic.eigenfrequencies_rectangular_room_1d(
L, k, k_max, zeta
L, k, k_max, zeta,
)

truth = np.array([
Expand All @@ -35,7 +35,7 @@ def test_eigenfreq_impedance_1d_real_jac():
k_max = 1e3*2*np.pi/c

k_ns = analytic.eigenfrequencies_rectangular_room_1d(
L, k, k_max, zeta, gradient=True
L, k, k_max, zeta, gradient=True,
)

truth = np.array([
Expand All @@ -59,7 +59,7 @@ def test_analytic_shoebox_eigenfreqs_impedance_multi_k():
k = np.linspace(0, k_max*1.1, 2**10)

k_ns, _ = analytic.eigenfrequencies_rectangular_room_impedance(
L, k, k_max, zetas
L, k, k_max, zetas,
)

truth = np.array([
Expand Down Expand Up @@ -103,7 +103,7 @@ def test_analytic_shoebox_eigenfreqs_impedance():
k_max = 1e3*2*np.pi/c

k_ns, _ = analytic.eigenfrequencies_rectangular_room_impedance(
L, k, k_max, zetas
L, k, k_max, zetas,
)

truth = np.array([
Expand Down Expand Up @@ -148,7 +148,7 @@ def test_analytic_eigenfrequencies_impedance_cplx():
k = np.linspace(k_min, k_max*1.1, 2**10)

k_ns, _ = analytic.eigenfrequencies_rectangular_room_impedance(
L, k, k_max, zetas, only_normal=True
L, k, k_max, zetas, only_normal=True,
)

k_ns_x = np.loadtxt(
Expand Down Expand Up @@ -180,7 +180,7 @@ def test_analytic_eigenfrequencies_impedance_zeta15():
k = np.linspace(k_min, k_max*1.1, 2**10)

k_ns, _ = analytic.eigenfrequencies_rectangular_room_impedance(
L, k, k_max, zetas, only_normal=True
L, k, k_max, zetas, only_normal=True,
)

k_ns_x = np.loadtxt(
Expand Down
36 changes: 0 additions & 36 deletions tests/test_data/generate_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,6 @@
max_freq = 1000
n_samples = 2**13

# rir_1 = analytic.rectangular_room_rigid_walls(
# dimensions=room_dimensions, source=src_pos, receiver=rec_pos, reverberation_time=t_60, max_freq=max_freq,
# samplingrate=sampling_rate, speed_of_sound=343.9, n_samples=n_samples*2)[0]

# rir_2 = analytic.rectangular_room_rigid_walls(
# dimensions=room_dimensions, source=src_pos, receiver=rec_pos, reverberation_time=t_60*2, max_freq=max_freq,
# samplingrate=sampling_rate, speed_of_sound=343.9, n_samples=n_samples*2)[0]

# # %%

# rir_array = np.zeros(([2, rir_2.time.size]))

# psnr = 50

# # rir_1 /= np.amax(np.abs(rir_1))
# # rir_2 /= np.amax(np.abs(rir_2))

# rir_array[0] = rir_1.time
# rir_array[1] = rir_2.time

# rir_array = pf.dsp.normalize(pf.Signal(rir_array, sampling_rate))

# rms = 10**(-(psnr-10) / 20)
# noise = pf.signals.noise(
# n_samples*2, rms=rms, sampling_rate=sampling_rate, seed=1)

# rir_array += noise

# %%
# Use existing RIR to avoid re-generating data for all tests

Expand Down Expand Up @@ -130,11 +102,6 @@
rir_array, freq='broadband', is_energy=False, time_shift=True,
channel_independent=False, plot=False)

# noise_energy_from_edc_1D = pyrato.edc.estimate_noise_energy_from_edc(
# edc_lundeby_chu_1D, intersection_time_1D[0], sampling_rate)
# noise_energy_from_edc_2D = pyrato.edc.estimate_noise_energy_from_edc(
# edc_lundeby_chu_2D, intersection_time_2D[0], sampling_rate)

# %%
pf.plot.time(edc_lundeby_2D, dB=True, log_prefix=10)
# %%
Expand Down Expand Up @@ -205,7 +172,4 @@
np.savetxt("intersection_time_1D.csv", intersection_time_1D, delimiter=",")
np.savetxt("intersection_time_2D.csv", intersection_time_2D, delimiter=",")

# np.savetxt("noise_energy_from_edc_1D.csv", noise_energy_from_edc_1D, delimiter=",")
# np.savetxt("noise_energy_from_edc_2D.csv", noise_energy_from_edc_2D, delimiter=",")

# %%
16 changes: 9 additions & 7 deletions tests/test_dsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def test_start_ir_insufficient_snr():

snr = 15

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

Expand All @@ -42,8 +43,8 @@ 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)
rng = np.random.default_rng()
noise = pf.Signal(rng.standard_normal(n_samples) * 10**(-snr/20), 44100)

start_sample = 24
ir[start_sample] = 1
Expand Down Expand Up @@ -77,10 +78,11 @@ def test_start_ir_multidim():
n_channels = 3
ir = np.zeros((n_channels, n_samples))

rng = np.random.default_rng()
snr = 60

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

start_sample = [24, 5, 43]
ir[[0, 1, 2], start_sample] = 1
Expand All @@ -94,7 +96,7 @@ def test_start_ir_multidim():

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

start_sample_1 = [24, 5, 43]
ir[0, [0, 1, 2], start_sample_1] = 1
Expand Down Expand Up @@ -144,9 +146,9 @@ def test_max_ir():
ir = np.zeros(n_samples)

snr = 60

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

start_sample = 24
ir[start_sample] = 1
Expand Down
4 changes: 1 addition & 3 deletions tests/test_rt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# -*- coding: utf-8 -*-

""" Tests for reverberation time related things. """
from pytest import raises

import numpy as np
import numpy.testing as npt

Expand Down Expand Up @@ -62,5 +60,5 @@ def test_rt_from_edc_error():
edc_exp = pf.TimeData(10**(edc/10), times)
T = 'Bla'

with raises(ValueError, match='is not a valid interval.'):
with pytest.raises(ValueError, match='is not a valid interval.'):
ra.reverberation_time_linear_regression(edc_exp, T=T)
Loading