From 5412411ff1a1c28a340852db50282c38966bb3d4 Mon Sep 17 00:00:00 2001 From: Nathan Spencer Date: Tue, 10 Oct 2023 10:29:44 -0600 Subject: [PATCH] Fix vapor pressure --- pyweatherflowudp/calc.py | 5 +++-- pyweatherflowudp/const.py | 1 + tests/test_calc.py | 26 ++++++++++++++++++++++++-- tests/test_device.py | 2 +- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/pyweatherflowudp/calc.py b/pyweatherflowudp/calc.py index 21b1ae7..6aefcdc 100644 --- a/pyweatherflowudp/calc.py +++ b/pyweatherflowudp/calc.py @@ -9,6 +9,7 @@ UNIT_KILOGRAMS_PER_CUBIC_METER, UNIT_METERS, UNIT_MILLIBARS, + UNIT_PASCAL, UNIT_PERCENT, units, ) @@ -162,8 +163,8 @@ def vapor_pressure( else 1 ), ) - * UNIT_MILLIBARS - ) + * UNIT_PASCAL + ).to(UNIT_MILLIBARS) def wet_bulb_temperature( diff --git a/pyweatherflowudp/const.py b/pyweatherflowudp/const.py index 69ae490..de59adf 100644 --- a/pyweatherflowudp/const.py +++ b/pyweatherflowudp/const.py @@ -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 diff --git a/tests/test_calc.py b/tests/test_calc.py index 46fb309..c65961a 100644 --- a/tests/test_calc.py +++ b/tests/test_calc.py @@ -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: @@ -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 diff --git a/tests/test_device.py b/tests/test_device.py index eaf71a7..bb39268 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -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