From 2ae9f700319a0eaf31dc166dc74b8584da7f52ff Mon Sep 17 00:00:00 2001 From: "J.R. Leeman" Date: Mon, 13 Mar 2017 13:29:34 -0600 Subject: [PATCH 1/2] Add psychrometric calculations per @tariik's input --- docs/api/thermo.rst | 2 + metpy/calc/thermo.py | 100 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/docs/api/thermo.rst b/docs/api/thermo.rst index 07c6ac9ab51..536f796201d 100644 --- a/docs/api/thermo.rst +++ b/docs/api/thermo.rst @@ -24,3 +24,5 @@ Thermodynamic Calculations virtual_temperature virtual_potential_temperature density + relative_humidity_wet_psychrometric + psychrometric_vapor_pressure_wet diff --git a/metpy/calc/thermo.py b/metpy/calc/thermo.py index 9d64c34e6d2..6acce6558ed 100644 --- a/metpy/calc/thermo.py +++ b/metpy/calc/thermo.py @@ -665,3 +665,103 @@ def density(pressure, temperature, mixing, molecular_weight_ratio=epsilon): """ virttemp = virtual_temperature(temperature, mixing, molecular_weight_ratio) return (pressure / (Rd * virttemp)).to(units.kilogram / units.meter ** 3) + + +@exporter.export +def relative_humidity_wet_psychrometric(dry_bulb_temperature, web_bulb_temperature, + pressure, **kwargs): + r"""Calculate the relative humidity with wet bulb and dry bulb temperatures. + + Parameters + ---------- + dry_bulb_temperature: `pint.Quantity` + Dry bulb temperature + web_bulb_temperature: `pint.Quantity` + Wet bulb temperature + pressure: `pint.Quantity` + Total atmospheric pressure + + Returns + ------- + `pint.Quantity` + Relative humidity + + Notes + ----- + .. math:: RH = 100 \frac{e}{e_s} + + * :math:`RH` is relative humidity + * :math:`e` is vapor pressure from the wet psychrometric calculation + * :math:`e_s` is the saturation vapor pressure + + References + ---------- + .. [10] WMO GUIDE TO METEOROLOGICAL INSTRUMENTS AND METHODS OF OBSERVATION WMO-No.8 + (2008 edition, Updated in 2010) : PART 4 + https://www.wmo.int/pages/prog/www/IMOP/CIMO-Guide.html + + .. [11] Fan, Jinpeng. "Determination of the psychrometer coefficient A of the WMO + reference psychrometer by comparison with a standard gravimetric hygrometer." + Journal of Atmospheric and Oceanic Technology 4.1 (1987): 239-244. + + See Also + -------- + psychrometric_vapor_pressure_wet, saturation_vapor_pressure + """ + return (100 * units.percent * psychrometric_vapor_pressure_wet(dry_bulb_temperature, + web_bulb_temperature, pressure, **kwargs) / + saturation_vapor_pressure(dry_bulb_temperature)) + + +@exporter.export +def psychrometric_vapor_pressure_wet(dry_bulb_temperature, web_bulb_temperature, pressure, + psychrometer_coefficient=6.21e-4 / units.kelvin): + r"""Calculate the vapor pressure with wet bulb and dry bulb temperatures. + + Parameters + ---------- + dry_bulb_temperature: `pint.Quantity` + Dry bulb temperature + web_bulb_temperature: `pint.Quantity` + Wet bulb temperature + pressure: `pint.Quantity` + Total atmospheric pressure + psychrometer coefficient: `pint.Quantity` + Psychrometer coefficient + + Returns + ------- + `pint.Quantity` + Vapor pressure + + Notes + ----- + .. math:: e' = e'_w(T_w) - A p (T - T_w) + + * :math:`e'` is vapor pressure + * :math:`e'_w(T_w)` is the saturation vapor pressure with respect to water at temperature + :math:`T_w` + * :math:`p` is the pressure of the wet bulb + * :math:`T` is the temperature of the dry bulb + * :math:`T_w` is the temperature of the wet bulb + * :math:`A` is the psychrometer coefficient + + Psychrometer coefficient depends on the specific instrument being used and the ventilation + of the instrument. + + References + ---------- + .. [12] WMO GUIDE TO METEOROLOGICAL INSTRUMENTS AND METHODS OF OBSERVATION WMO-No.8 + (2008 edition, Updated in 2010) : PART 4 + https://www.wmo.int/pages/prog/www/IMOP/CIMO-Guide.html + + .. [13] Fan, Jinpeng. "Determination of the psychrometer coefficient A of the WMO reference + psychrometer by comparison with a standard gravimetric hygrometer." + Journal of Atmospheric and Oceanic Technology 4.1 (1987): 239-244. + + See Also + -------- + saturation_vapor_pressure + """ + return (saturation_vapor_pressure(web_bulb_temperature) - psychrometer_coefficient * + pressure * (dry_bulb_temperature - web_bulb_temperature).to('kelvin')) From 1103b180aa800563d721d20365d4c4600667e986 Mon Sep 17 00:00:00 2001 From: "J.R. Leeman" Date: Mon, 13 Mar 2017 13:37:42 -0600 Subject: [PATCH 2/2] Add tests for psychrometric calculations --- metpy/calc/tests/test_thermo.py | 37 +++++++++++++++++++++++++++++++-- metpy/calc/thermo.py | 6 +++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/metpy/calc/tests/test_thermo.py b/metpy/calc/tests/test_thermo.py index 73c8004e8d1..fe44e97c3ae 100644 --- a/metpy/calc/tests/test_thermo.py +++ b/metpy/calc/tests/test_thermo.py @@ -8,8 +8,9 @@ from metpy.calc import (density, dewpoint, dewpoint_rh, dry_lapse, el, equivalent_potential_temperature, lcl, lfc, mixing_ratio, moist_lapse, - parcel_profile, potential_temperature, saturation_mixing_ratio, - saturation_vapor_pressure, vapor_pressure, + parcel_profile, potential_temperature, + psychrometric_vapor_pressure_wet, relative_humidity_wet_psychrometric, + saturation_mixing_ratio, saturation_vapor_pressure, vapor_pressure, virtual_potential_temperature, virtual_temperature) from metpy.testing import assert_almost_equal, assert_array_almost_equal @@ -248,3 +249,35 @@ def test_no_el(): el_pressure, el_temperature = el(levels, temperatures, dewpoints) assert el_pressure is None assert el_temperature is None + + +def test_wet_psychrometric_vapor_pressure(): + """Test calculation of vapor pressure from wet and dry bulb temperatures.""" + p = 1013.25 * units.mbar + dry_bulb_temperature = 20. * units.degC + wet_bulb_temperature = 18. * units.degC + psychrometric_vapor_pressure = psychrometric_vapor_pressure_wet(dry_bulb_temperature, + wet_bulb_temperature, p) + assert_almost_equal(psychrometric_vapor_pressure, 19.3673 * units.mbar, 3) + + +def test_wet_psychrometric_rh(): + """Test calculation of relative humidity from wet and dry bulb temperatures.""" + p = 1013.25 * units.mbar + dry_bulb_temperature = 20. * units.degC + wet_bulb_temperature = 18. * units.degC + psychrometric_rh = relative_humidity_wet_psychrometric(dry_bulb_temperature, + wet_bulb_temperature, p) + assert_almost_equal(psychrometric_rh, 82.8747 * units.percent, 3) + + +def test_wet_psychrometric_rh_kwargs(): + """Test calculation of relative humidity from wet and dry bulb temperatures.""" + p = 1013.25 * units.mbar + dry_bulb_temperature = 20. * units.degC + wet_bulb_temperature = 18. * units.degC + coeff = 6.1e-4 / units.kelvin + psychrometric_rh = relative_humidity_wet_psychrometric(dry_bulb_temperature, + wet_bulb_temperature, p, + psychrometer_coefficient=coeff) + assert_almost_equal(psychrometric_rh, 82.9701 * units.percent, 3) diff --git a/metpy/calc/thermo.py b/metpy/calc/thermo.py index 6acce6558ed..af841ee8119 100644 --- a/metpy/calc/thermo.py +++ b/metpy/calc/thermo.py @@ -714,7 +714,7 @@ def relative_humidity_wet_psychrometric(dry_bulb_temperature, web_bulb_temperatu @exporter.export -def psychrometric_vapor_pressure_wet(dry_bulb_temperature, web_bulb_temperature, pressure, +def psychrometric_vapor_pressure_wet(dry_bulb_temperature, wet_bulb_temperature, pressure, psychrometer_coefficient=6.21e-4 / units.kelvin): r"""Calculate the vapor pressure with wet bulb and dry bulb temperatures. @@ -763,5 +763,5 @@ def psychrometric_vapor_pressure_wet(dry_bulb_temperature, web_bulb_temperature, -------- saturation_vapor_pressure """ - return (saturation_vapor_pressure(web_bulb_temperature) - psychrometer_coefficient * - pressure * (dry_bulb_temperature - web_bulb_temperature).to('kelvin')) + return (saturation_vapor_pressure(wet_bulb_temperature) - psychrometer_coefficient * + pressure * (dry_bulb_temperature - wet_bulb_temperature).to('kelvin'))