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 all ruff stuff #45

Open
wants to merge 12 commits into
base: new_cookiecutter_fix_dep
Choose a base branch
from
Open
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
26 changes: 14 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ tests = [
"pytest",
"pytest-cov",
"watchdog",
"ruff==0.4.1",
"ruff==0.11.2",
"coverage",
]
docs = [
Expand Down Expand Up @@ -79,6 +79,8 @@ find = {} # Scan the project directory with the default parameters
exclude = [
".git",
"docs",
"examples",
"tests/test_data/*",
]
line-length = 79
lint.ignore = [
Expand All @@ -94,21 +96,21 @@ lint.ignore = [
]
lint.select = [
"A", # Avoid builtin function and type shadowing
# "ARG", # Remove unused function/method arguments
# "B", # bugbear extension
# "C4", # Check for common security issues
# "COM", # trailing comma rules
# "D", # Docstring guidelines
"ARG", # Remove unused function/method arguments
"B", # bugbear extension
"C4", # Check for common security issues
"COM", # trailing comma rules
"D", # Docstring guidelines
# "D417", # Missing argument descriptions in the docstring
# "E", # PEP8 errors
# "ERA", # No commented out code
# "F", # Pyflakes
"E", # PEP8 errors
"ERA", # No commented out code
"F", # Pyflakes
"FIX", # Code should not contain FIXME, TODO, etc
"I002", # missing required import
# "NPY", # Check all numpy related deprecations
# "PT", # Pytest style
"NPY", # Check all numpy related deprecations
"PT", # Pytest style
"TID252", # Use absolute over relative imports
# "W", # PEP8 warnings
"W", # PEP8 warnings
]

# 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 @@ -23,5 +23,5 @@
'dsp',
'analytic',
'parametric',
'air_attenuation_coefficient'
'air_attenuation_coefficient',
]
4 changes: 3 additions & 1 deletion pyrato/analytic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Analytic functions for room acoustics."""

from .analytic import (
rectangular_room_rigid_walls,
eigenfrequencies_rectangular_room_rigid
eigenfrequencies_rectangular_room_rigid,
)

from .impedance import (
Expand Down
6 changes: 3 additions & 3 deletions pyrato/analytic/analytic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Analytic functions for room acoustics."""
# -*- coding: utf-8 -*-
import pyfar as pf
import numpy as np
Expand Down Expand Up @@ -35,7 +36,6 @@ def eigenfrequencies_rectangular_room_rigid(

Examples
--------

Calculate the eigenfrequencies under 75 Hz of a small room and plot.

.. plot::
Expand Down 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
15 changes: 8 additions & 7 deletions pyrato/analytic/impedance.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Analytic functions for impedance calculations."""
from itertools import count

import numpy as np
Expand Down Expand Up @@ -121,7 +122,7 @@ def gradient_trancendental_equation_eigenfrequencies_impedance(


def initial_solution_transcendental_equation(k, L, zeta):
""" Initial solution to the transcendental equation for the complex
"""Initial solution to the transcendental equation for the complex
eigenfrequencies of the rectangular room with uniform impedance at
the boundaries. This will approximate the zeroth order mode.

Expand Down Expand Up @@ -231,7 +232,7 @@ def normal_eigenfrequencies_rectangular_room_impedance(
each room dimension.
"""
k_ns = []
for dim, L_l, zeta_l in zip(count(), L, zeta):
for _, L_l, zeta_l in zip(count(), L, zeta):
k_ns_l = eigenfrequencies_rectangular_room_1d(
L_l, ks, k_max, zeta_l)
k_ns.append(k_ns_l)
Expand Down Expand Up @@ -284,7 +285,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 @@ -322,7 +323,7 @@ def eigenfrequencies_rectangular_room_impedance(
def mode_function_impedance(position, eigenvalue, phase):
r"""The modal function for a room with boundary impedances.

See [#]_ .
See [#]_.

.. math::

Expand Down Expand Up @@ -396,7 +397,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 @@ -435,7 +436,7 @@ def rectangular_room_impedance(
c=343.9,
n_samples=2**12,
remove_cavity_mode=False):
r""" Calculate the room impulse response and room transfer function for a
r"""Calculate the room impulse response and room transfer function for a
rectangular room with arbitrary boundary impedances.

Parameters
Expand Down Expand Up @@ -493,7 +494,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
13 changes: 7 additions & 6 deletions pyrato/dsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def find_impulse_response_maximum(
np.any(max_sample > mask_start):
warnings.warn(
"The SNR seems lower than the specified threshold value. Check "
"if this is a valid impulse response with sufficient SNR.")
"if this is a valid impulse response with sufficient SNR.",
stacklevel=2)

return max_sample

Expand Down Expand Up @@ -275,7 +276,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",
PyfarDeprecationWarning)
PyfarDeprecationWarning, stacklevel=2)

nominal, exact = pf.dsp.filter.fractional_octave_frequencies(
1, (20, 20e3), return_cutoff=False)
Expand All @@ -295,7 +296,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",
PyfarDeprecationWarning)
PyfarDeprecationWarning, stacklevel=2)

nominal, exact = pf.dsp.filter.fractional_octave_frequencies(
3, (20, 20e3), return_cutoff=False)
Expand Down Expand Up @@ -327,7 +328,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",
PyfarDeprecationWarning)
PyfarDeprecationWarning, stacklevel=2)

return pf.dsp.filter.fractional_octave_bands(
signal, num_fractions, frequency_range=freq_range, order=order)
Expand Down Expand Up @@ -404,7 +405,7 @@ def _smooth_rir(
data,
sampling_rate,
smooth_block_length=0.075):
""" Smoothens the RIR by averaging the data in an specified interval.
"""Smoothens the RIR by averaging the data in an specified interval.

Parameters
----------
Expand Down Expand Up @@ -457,7 +458,7 @@ def preprocess_rir(
is_energy=False,
shift=False,
channel_independent=False):
""" Preprocess the room impulse response for further processing:
"""Preprocess the room impulse response for further processing:
- Square data
- Shift the RIR to the first sample of the array, compensating for the
delay of the time of arrival of the direct sound. The time shift is
Expand Down
16 changes: 6 additions & 10 deletions pyrato/edc.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def energy_decay_curve_truncation(
normalize=True,
threshold=15,
plot=False):
""" This function truncates a given room impulse response by the
"""This function truncates a given room impulse response by the
intersection time after Lundeby and calculates the energy decay curve.

Parameters
Expand Down Expand Up @@ -224,7 +224,6 @@ def energy_decay_curve_truncation(

Examples
--------

Plot the RIR and the EDC calculated truncating the integration at the
intersection time.

Expand Down Expand Up @@ -364,7 +363,6 @@ def energy_decay_curve_lundeby(

Examples
--------

Plot the RIR and the EDC calculated after Lundeby.

.. plot::
Expand Down Expand Up @@ -651,7 +649,6 @@ def energy_decay_curve_chu_lundeby(

Examples
--------

Calculate and plot the EDC using a combination of Chu's and Lundeby's
methods.

Expand Down Expand Up @@ -805,7 +802,6 @@ def intersection_time_lundeby(

Examples
--------

Estimate the intersection time :math:`T_i` and plot the RIR and the
estimated noise power.

Expand Down Expand Up @@ -890,9 +886,8 @@ def intersection_time_lundeby(
(10*np.log10(noise_estimation[ch]) +
dB_above_noise))[-1, 0] + start_idx)
except IndexError as e:
raise ValueError(
'Regression failed: Low SNR. Estimation terminated.'
) from e
raise Exception(
'Regression failed: Low SNR. Estimation terminated.') from e

dyn_range = np.diff(10*np.log10(np.take(
time_window_data_current_channel, [start_idx, stop_idx])))
Expand Down Expand Up @@ -984,7 +979,7 @@ def intersection_time_lundeby(
+ dB_above_noise))[0, 0] + start_idx_loop
except IndexError as e:
raise ValueError(
'Regression failed: Low SNR. Estimation terminated.'
'Regression failed: Low SNR. Estimation terminated.',
) from e

# regression_matrix*slope = edc
Expand Down Expand Up @@ -1017,7 +1012,8 @@ def intersection_time_lundeby(
if loop_counter > 30:
# TO-DO: Paper says 5 iterations are sufficient in all cases!
warnings.warn(
"Lundeby algorithm was terminated after 30 iterations.")
"Lundeby algorithm was terminated after 30 iterations.",
stacklevel=2)
break

reverberation_time[ch] = -60/slope[1]
Expand Down
11 changes: 3 additions & 8 deletions pyrato/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def reverberation_time_linear_regression(

Examples
--------

Estimate the reverberation time from an energy decay curve.

>>> import numpy as np
Expand All @@ -62,12 +61,11 @@ def reverberation_time_linear_regression(
>>> rir = rir + awgn
...
>>> edc = ra.energy_decay_curve_chu_lundeby(rir)
>>> t_20 = ra.reverberation_time_linear_regression(edc, 'T20')
>>> t_20 = ra.parameters.reverberation_time_linear_regression(edc, 'T20')
>>> t_20
... array([0.99526253])

"""
intervals = [20, 30, 40, 50, 60]

if T == 'EDT':
upper = -0.1
Expand All @@ -76,12 +74,9 @@ def reverberation_time_linear_regression(
upper = -25.
lower = -35.
else:
try:
(int(re.findall(r'\d+', T)[0]) in intervals)
except IndexError:
if T not in ['T20', 'T30', 'T40', 'T50', 'T60']:
raise ValueError(
"{} is not a valid interval for the regression.".format(T))

f"{T} is not a valid interval for the regression.")
upper = -5
lower = -np.double(re.findall(r'\d+', T)) + upper

Expand Down
2 changes: 1 addition & 1 deletion pyrato/parametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def air_attenuation_coefficient(

warnings.warn(
'Will be replaced by respective function in pyfar before v1.0.0',
PyfarDeprecationWarning)
PyfarDeprecationWarning, stacklevel=2)

# room temperature in Kelvin
t_K = temperature + 273.16
Expand Down
Loading