Skip to content

Commit

Permalink
Merge pull request #94 from briis/dev
Browse files Browse the repository at this point in the history
Fix vapor pressure
  • Loading branch information
natekspencer committed Oct 10, 2023
2 parents 20699c5 + 5412411 commit 83769c5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
5 changes: 3 additions & 2 deletions pyweatherflowudp/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
UNIT_KILOGRAMS_PER_CUBIC_METER,
UNIT_METERS,
UNIT_MILLIBARS,
UNIT_PASCAL,
UNIT_PERCENT,
units,
)
Expand Down Expand Up @@ -162,8 +163,8 @@ def vapor_pressure(
else 1
),
)
* UNIT_MILLIBARS
)
* UNIT_PASCAL
).to(UNIT_MILLIBARS)


def wet_bulb_temperature(
Expand Down
1 change: 1 addition & 0 deletions pyweatherflowudp/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
UNIT_MILLIMETERS_PER_MINUTE = units.mm / units.min
UNIT_MILLIMETERS_PER_HOUR = units.mm / units.h
UNIT_MINUTES = units.min
UNIT_PASCAL = units.Pa
UNIT_PERCENT = units.percent
UNIT_SECONDS = units.sec
UNIT_VOLTS = units.V
26 changes: 24 additions & 2 deletions tests/test_calc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"""Test calculations."""
from pyweatherflowudp.calc import heat_index
from pyweatherflowudp.const import UNIT_DEGREES_CELSIUS, UNIT_PERCENT
from pyweatherflowudp.calc import heat_index, vapor_pressure
from pyweatherflowudp.const import (
UNIT_DEGREES_CELSIUS,
UNIT_MILLIBARS,
UNIT_PERCENT,
units,
)


def test_heat_index() -> None:
Expand All @@ -16,3 +21,20 @@ def test_heat_index() -> None:

temp_degrees = 10 * UNIT_DEGREES_CELSIUS
assert heat_index(temp_degrees, relative_humidity) is None


def test_vapor_pressure() -> None:
"""Test the vapor_pressure calculations."""
temp_degrees = 71.7 * units.degF
relative_humidity = 55.17 * UNIT_PERCENT

vap_pressure = vapor_pressure(temp_degrees, relative_humidity)
assert round(vap_pressure, 3) == 14.641 * UNIT_MILLIBARS
assert round(vap_pressure.to(units.kPa), 3) == 1.464 * units.kPa

temp_degrees = 60.0 * units.degF
relative_humidity = 41.93 * UNIT_PERCENT

vap_pressure = vapor_pressure(temp_degrees, relative_humidity)
assert round(vap_pressure, 3) == 7.411 * UNIT_MILLIBARS
assert round(vap_pressure.to(units.kPa), 3) == 0.741 * units.kPa
2 changes: 1 addition & 1 deletion tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def load_complete(event):
assert round(device.dew_point_temperature, 5) == 11.52825 * UNIT_DEGREES_CELSIUS
assert device.feels_like_temperature == 22.37 * UNIT_DEGREES_CELSIUS
assert device.heat_index is None
assert round(device.vapor_pressure, 5) == 1359.55045 * UNIT_MILLIBARS
assert round(device.vapor_pressure, 5) == 13.59550 * UNIT_MILLIBARS
assert round(device.wet_bulb_temperature, 5) == 15.77886 * UNIT_DEGREES_CELSIUS
assert device.wind_chill_temperature is None

Expand Down

0 comments on commit 83769c5

Please sign in to comment.