-
Notifications
You must be signed in to change notification settings - Fork 14
Feature/speed_of_sound #100
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
Changes from all commits
58d876e
ad95f02
6bdb0a7
4f05d1f
429ac5c
12282bf
d84eae8
59ded35
f8cf348
253fa03
e714941
3a292fc
1047b9a
4c74ca8
c7acec6
d3c5ef5
1fd2345
5ba1081
6b1d526
1e89eca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,41 @@ | |
| """ | ||
| import numpy as np | ||
|
|
||
| def calculate_speed_of_sound(temperature): | ||
| r"""Calculate the speed of sound in air depending on the temperature. | ||
|
|
||
| Speed of sound is calculated as [#]_. | ||
|
|
||
| .. math:: | ||
| c = c_0 \sqrt{\frac{T - T_0}{20 - T_0}} | ||
| .. math:: | ||
| T_0=-273.15 | ||
| .. math:: | ||
| c_0 = 343.2 | ||
|
|
||
| Parameters | ||
| ---------- | ||
| temperature : double | ||
| Temperature in degrees Celsius. | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add explicit formula and cite properly the source, according to pyfar convention |
||
| Returns | ||
| ------- | ||
| speed_of_sound : double | ||
| Speed of sound in m/s. | ||
|
|
||
| References | ||
| ---------- | ||
| .. [#] ISO 9613-1 (Formula A.5) | ||
| """ | ||
| if temperature < -273.15: | ||
| raise ValueError( | ||
| "Temperature must be greater than absolute zero (-273.15 °C).") | ||
| T_0 = -273.15 | ||
| c_0 = 343.2 | ||
| speed_of_sound = c_0 * np.sqrt((temperature - T_0)/(20 - T_0)) | ||
| return speed_of_sound | ||
|
|
||
|
|
||
| def energy_decay_curve_analytic( | ||
| surfaces, alphas, volume, times, source=None, | ||
| receiver=None, method='eyring', c=343.4, frequency=None, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #!/usr/bin/env python | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| """Tests for reverberation time related things.""" | ||
| import numpy as np | ||
| import numpy.testing as npt | ||
|
|
||
| import pyrato as ra | ||
| import pytest | ||
|
|
||
| @pytest.mark.parametrize('T',[0,20,1000]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing 2 situations in this statement: those who work (20, 1000) and those who fail (0). Extract?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No the zero should also work. |
||
| def test_speed_of_sound(T): | ||
| speed=ra.parametric.calculate_speed_of_sound(T) | ||
| assert isinstance(T, (int, float)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. redundant? Implicit in specification of param
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you specify? |
||
| npt.assert_allclose(speed, 343.2 * np.sqrt((T + 273.15) / 293.15)) | ||
| with pytest.raises(ValueError,match= | ||
| "Temperature must be greater than absolute zero"): | ||
| ra.parametric.calculate_speed_of_sound(-300) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.