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

Auto-format code by autopep8 #297

Merged
merged 1 commit into from
Dec 20, 2024
Merged
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
4 changes: 3 additions & 1 deletion src/acom_music_box/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

# The possible units we can convert to and from
# functions that do conversions update this dictionary for their units in
# functions that do conversions update this dictionary for their units in
# the appropriate way
unit_conversions = {
'mol m-3': 0,
Expand All @@ -19,6 +19,7 @@
'mol mol-1': 0
}


def extract_unit(data, key):
"""Extract the value and unit from the key in data."""
pattern = re.compile(rf'{key} \[(.+)\]')
Expand Down Expand Up @@ -203,6 +204,7 @@ def convert_from_number_density(data, output_unit, temperature, pressure):
else:
return data * conversion_factor


def calculate_air_density(temperature, pressure):
"""
Calculate the air density in moles m-3
Expand Down
29 changes: 15 additions & 14 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,20 @@ def test_invalid_concentration():
with pytest.raises(ValueError):
convert_concentration(data, 'invalid_concentration', 298.15, 101325)


@pytest.mark.parametrize("data, output_unit, temperature, pressure, expected",
[
(1, 'mol m-3', 298.15, 101325, 1),
(1, 'mol cm-3', 298.15, 101325, 1e-6),
(1, 'molec m-3', 298.15, 101325, 1 * 6.02214076e+23),
(1, 'molec cm-3', 298.15, 101325, 1e-6 * 6.02214076e+23),
(1, 'molecule m-3', 298.15, 101325, 1 * 6.02214076e+23),
(1, 'molecule cm-3', 298.15, 101325, 1e-6 * 6.02214076e+23),
(1, 'ppth', 298.15, 101325, 1e3 / calculate_air_density(298.15, 101325)),
(1, 'ppm', 298.15, 101325, 1e6 / calculate_air_density(298.15, 101325)),
(1, 'ppb', 298.15, 101325, 1e9 / calculate_air_density(298.15, 101325)),
(1, 'ppt', 298.15, 101325, 1e12 / calculate_air_density(298.15, 101325)),
(1, 'mol mol-1', 298.15, 101325, 1 / calculate_air_density(298.15, 101325)),
])
[
(1, 'mol m-3', 298.15, 101325, 1),
(1, 'mol cm-3', 298.15, 101325, 1e-6),
(1, 'molec m-3', 298.15, 101325, 1 * 6.02214076e+23),
(1, 'molec cm-3', 298.15, 101325, 1e-6 * 6.02214076e+23),
(1, 'molecule m-3', 298.15, 101325, 1 * 6.02214076e+23),
(1, 'molecule cm-3', 298.15, 101325, 1e-6 * 6.02214076e+23),
(1, 'ppth', 298.15, 101325, 1e3 / calculate_air_density(298.15, 101325)),
(1, 'ppm', 298.15, 101325, 1e6 / calculate_air_density(298.15, 101325)),
(1, 'ppb', 298.15, 101325, 1e9 / calculate_air_density(298.15, 101325)),
(1, 'ppt', 298.15, 101325, 1e12 / calculate_air_density(298.15, 101325)),
(1, 'mol mol-1', 298.15, 101325, 1 / calculate_air_density(298.15, 101325)),
])
def test_convert_from_number_density(data, output_unit, temperature, pressure, expected):
assert math.isclose(convert_from_number_density(data, output_unit, temperature, pressure), expected)
assert math.isclose(convert_from_number_density(data, output_unit, temperature, pressure), expected)