Skip to content

Commit

Permalink
Auto-format code using pep8 (#297)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Actions <[email protected]>
  • Loading branch information
github-actions[bot] and actions-user authored Dec 20, 2024
1 parent ca54b94 commit 6b7536c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
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)

0 comments on commit 6b7536c

Please sign in to comment.