-
Notifications
You must be signed in to change notification settings - Fork 14
Refactor: Eyring reverberation time calculation #131
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6aa6766
refactor Eyring reverberation time calculation
mberz 4905048
- Add type hints
mberz 10a3ff4
improve grouping of input checks
mberz a75b430
Add return in example
mberz 1a78858
formatting example
mberz 5869911
update typing
mberz f2d1a32
fix obsolete use of np.any
mberz 10babb2
update tests & explicitly include edge cases for absorption
mberz e1517d1
Add check speed of sound negative
mberz ca62a03
more compact format
mberz 9d6b8a3
docstring format
mberz 7784fc6
formatting
mberz d242042
formatting
mberz e472cac
suppress warnings for divide by zero which are explicitly handled below
mberz d4d603c
docstring and type hinting update
mberz 31b4b00
Update type hinting to be compatible with earlier numpy versions
mberz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,42 @@ | ||
| """Tests for Eyring's equation""" | ||
| """Tests for Eyring's equation.""" | ||
| import numpy.testing as npt | ||
| import pytest | ||
| from pyrato.parametric import reverberation_time_eyring | ||
| import numpy as np | ||
|
|
||
| def test_analytic_Eyring(): | ||
| @pytest.mark.parametrize( | ||
| ("mean_absorption", "expected"), | ||
| [ | ||
| ([0.2, 0.2], [0.481, 0.481]), | ||
| (1, 0), | ||
| (0, np.inf), | ||
| ([0, 1, 0], [np.inf, 0, np.inf]), | ||
| ]) | ||
| def test_analytic_Eyring(mean_absorption, expected): | ||
| volume = 64 | ||
| surface = 96 | ||
| mean_alpha = 0.2 | ||
| reverb_test = reverberation_time_eyring(volume,surface,mean_alpha) | ||
| npt.assert_allclose(reverb_test, 0.481, rtol=1e-3) | ||
| surface_area = 96 | ||
| reverb_test = reverberation_time_eyring( | ||
| volume, surface_area, mean_absorption) | ||
| npt.assert_allclose(reverb_test, expected, rtol=1e-3) | ||
|
|
||
| @pytest.mark.parametrize("volume, surface", [(0, -2), (-1, 0)]) | ||
| def test_input_geometry_Eyring(volume, surface): | ||
| mean_alpha = 0.2 | ||
| @pytest.mark.parametrize(("volume", "surface_area"), [(0, -2), (-1, 0)]) | ||
mberz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def test_input_geometry_Eyring(volume, surface_area): | ||
| mean_absorption = 0.2 | ||
| with pytest.raises(ValueError, match="should be larger than 0"): | ||
| reverberation_time_eyring(volume,surface,mean_alpha) | ||
| reverberation_time_eyring(volume, surface_area, mean_absorption) | ||
|
|
||
| @pytest.mark.parametrize("mean_alpha", [-1, 2]) | ||
| def test_input_alpha_Eyring(mean_alpha): | ||
| @pytest.mark.parametrize("mean_absorption", [-1, 2]) | ||
| def test_input_absorption_Eyring(mean_absorption): | ||
| volume = 64 | ||
| surface = 96 | ||
| with pytest.raises( | ||
| ValueError, match="mean_alpha should be between 0 and 1" | ||
| ): | ||
| reverberation_time_eyring(volume,surface,mean_alpha) | ||
| surface_area = 96 | ||
| with pytest.raises(ValueError, match="should be between 0 and 1"): | ||
| reverberation_time_eyring(volume, surface_area, mean_absorption) | ||
|
|
||
| def test_error_speed_of_sound_Eyring(): | ||
| volume = 64 | ||
| surface_area = 96 | ||
| mean_absorption = 0.2 | ||
| with pytest.raises(ValueError, match="should be larger than 0"): | ||
| reverberation_time_eyring( | ||
| volume, surface_area, mean_absorption, | ||
| speed_of_sound=-1) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.