From 1144582be41fa03ae411032003677f1a863e9926 Mon Sep 17 00:00:00 2001 From: JaneLiu Date: Sat, 26 Oct 2019 16:03:19 -0400 Subject: [PATCH 1/2] feat(at): Added apparent temperature(AT). --- ladybug_comfort/apparent.py | 96 +++++++++++++++++++++++++++++++++++++ tests/apparent_test.py | 26 ++++++++++ 2 files changed, 122 insertions(+) create mode 100644 ladybug_comfort/apparent.py create mode 100644 tests/apparent_test.py diff --git a/ladybug_comfort/apparent.py b/ladybug_comfort/apparent.py new file mode 100644 index 00000000..94c191b9 --- /dev/null +++ b/ladybug_comfort/apparent.py @@ -0,0 +1,96 @@ +# coding=utf-8 +"""Utility functions for calculating the Apparent Temperature (AT).""" +from __future__ import division + +import math + + +def apparent_temperature(ta, rh, ws): + """Calculate apparent temperature (AT) from air temperature, relative humidity, and wind speed. + + The Australian Apparent Temperature (AT) is a type of heat index that was used by the + Australian Bureau of Meteorology(ABM). It is based on a mathematical model published + by Robert G. Steadman in 1994 [1]. Two forms of the model are available, one including + radiation and one without. This algorithm uses the non-radiation version. [2] + + Note: + [1] Steadman, R. G. (1994). Norms of apparent temperature in Australia. Aust. Met. Mag, 43, 1-16. + [2] Thermal Comfort observations. (n.d.). Retrieved May 20, 2016, + from http://www.bom.gov.au/info/thermal_stress/ + + Args: + ta: Air temperature [C] + rh: Relative humidity [%] + ws: Wind speed (km /h) + + Returns: + at: Apparent Temperature[C] + """ + + # e = Water vapour pressure (hPa) [humidity] + e = (rh / 100) * 6.105 * math.exp((17.27 * ta) / (237.7 + ta)) + at = ta + (0.33 * e) - (0.70 * ws) - 4.00 + + return at + + +def apparent_temperature_warning_category(at): + + """Get the category of apparent suggestion associated with a given apparent temperature (AT). + + Categories to indicate apparent suggestion: + 4 = (>40 C) Minimal; sun protection required. + 3 = (35-40 C) Minimal; sun protection as needed. + 2 = (30-35 C) Short sleeve, shirt and shorts. + 1 = (25-30 C) Light undershirt. + 0 = (20-25 C) Cotton-type slacks (pants). + -1 = (15-20 C) Normal office wear. + -2 = (10-15 C) Thin or sleeveless sweater. + -3 = (5-10 C) Sweater. Thicker underwear. + -4 = (0-5 C) Coat and sweater. + -5 = (-5-0 C) Overcoat. Wind protection as needed. + -6 = (<-5 C) Overcoat. Head insulation. Heavier footwear. + + Args: + at: Apparent temperature [C] + + Returns: + category: An integer indicating the level of warning associated with the + heat index. Values are one of the following: + 4 = Minimal. + 3 = Minimal. + 2 = Short sleeve, shirt and shorts. + 1 = Light undershirt. + 0 = Cotton-type slacks (pants). + -1 = Normal office wear. + -2 = Thin or sleeveless sweater. + -3 = Sweater. Thicker underwear. + -4 = Coat and sweater. + -5 = Overcoat. + -6 = Overcoat. + """ + + if at > 40: + category = 4 + elif at > 35 and at <= 40: + category = 3 + elif at > 30 and at <= 35: + category = 2 + elif at > 25 and at <= 30: + category = 1 + elif at > 20 and at <= 25: + category = 0 + elif at > 15 and at <= 20: + category = -1 + elif at > 10 and at <= 15: + category = -2 + elif at > 5 and at <= 10: + category = -3 + elif at > 0 and at <= 5: + category = -4 + elif at > -5 and at <= 0: + category = -5 + else: + category = -6 + + return category diff --git a/tests/apparent_test.py b/tests/apparent_test.py new file mode 100644 index 00000000..6f64bcee --- /dev/null +++ b/tests/apparent_test.py @@ -0,0 +1,26 @@ +# coding utf-8 +import pytest + +from ladybug_comfort.apparent import apparent_temperature, apparent_temperature_warning_category + + +def test_apparent_temperature(): + """Test the apparent_temperature function.""" + assert apparent_temperature(32, 85, 10) == pytest.approx(34.290083, rel=1e-3) + assert apparent_temperature(20, 50, 15) == pytest.approx(9.3482423, rel=1e-3) + + assert apparent_temperature_warning_category(60) == 4 + assert apparent_temperature_warning_category(40) == 3 + assert apparent_temperature_warning_category(35) == 2 + assert apparent_temperature_warning_category(26) == 1 + assert apparent_temperature_warning_category(25) == 0 + assert apparent_temperature_warning_category(16) == -1 + assert apparent_temperature_warning_category(11) == -2 + assert apparent_temperature_warning_category(6) == -3 + assert apparent_temperature_warning_category(5) == -4 + assert apparent_temperature_warning_category(0) == -5 + assert apparent_temperature_warning_category(-5) == -6 + + + + From b7c320dcfced60822be309b4a98c000930877845 Mon Sep 17 00:00:00 2001 From: JaneLiu Date: Tue, 29 Oct 2019 23:09:36 -0400 Subject: [PATCH 2/2] style(at): Updated to follow the style guide. A minor update to improve code efficiency. --- ladybug_comfort/apparent.py | 45 ++++++++++++++++++++----------------- tests/apparent_test.py | 4 ---- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/ladybug_comfort/apparent.py b/ladybug_comfort/apparent.py index 94c191b9..ba9d5fab 100644 --- a/ladybug_comfort/apparent.py +++ b/ladybug_comfort/apparent.py @@ -6,15 +6,18 @@ def apparent_temperature(ta, rh, ws): - """Calculate apparent temperature (AT) from air temperature, relative humidity, and wind speed. + """Calculate apparent temperature (AT) from air temperature, relative humidity, + and wind speed. - The Australian Apparent Temperature (AT) is a type of heat index that was used by the - Australian Bureau of Meteorology(ABM). It is based on a mathematical model published - by Robert G. Steadman in 1994 [1]. Two forms of the model are available, one including - radiation and one without. This algorithm uses the non-radiation version. [2] + The Australian Apparent Temperature (AT) is a type of heat index that was used by + the Australian Bureau of Meteorology (ABM). It is based on a mathematical model + published by Robert G. Steadman in 1994 [1]. Two forms of the model are available, + one including radiation and one without. This algorithm uses the non-radiation + version. [2] Note: - [1] Steadman, R. G. (1994). Norms of apparent temperature in Australia. Aust. Met. Mag, 43, 1-16. + [1] Steadman, R. G. (1994). Norms of apparent temperature in Australia. Aust. + Met. Mag, 43, 1-16. [2] Thermal Comfort observations. (n.d.). Retrieved May 20, 2016, from http://www.bom.gov.au/info/thermal_stress/ @@ -35,12 +38,12 @@ def apparent_temperature(ta, rh, ws): def apparent_temperature_warning_category(at): - - """Get the category of apparent suggestion associated with a given apparent temperature (AT). + """Get the category of apparent suggestion associated with a given apparent + temperature (AT). Categories to indicate apparent suggestion: - 4 = (>40 C) Minimal; sun protection required. - 3 = (35-40 C) Minimal; sun protection as needed. + 4 = (>40 C) Minimal clothing; sun protection required. + 3 = (35-40 C) Minimal clothing; sun protection as needed. 2 = (30-35 C) Short sleeve, shirt and shorts. 1 = (25-30 C) Light undershirt. 0 = (20-25 C) Cotton-type slacks (pants). @@ -57,8 +60,8 @@ def apparent_temperature_warning_category(at): Returns: category: An integer indicating the level of warning associated with the heat index. Values are one of the following: - 4 = Minimal. - 3 = Minimal. + 4 = Minimal clothing. + 3 = Minimal clothing. 2 = Short sleeve, shirt and shorts. 1 = Light undershirt. 0 = Cotton-type slacks (pants). @@ -72,23 +75,23 @@ def apparent_temperature_warning_category(at): if at > 40: category = 4 - elif at > 35 and at <= 40: + elif at > 35: category = 3 - elif at > 30 and at <= 35: + elif at > 30: category = 2 - elif at > 25 and at <= 30: + elif at > 25: category = 1 - elif at > 20 and at <= 25: + elif at > 20: category = 0 - elif at > 15 and at <= 20: + elif at > 15: category = -1 - elif at > 10 and at <= 15: + elif at > 10: category = -2 - elif at > 5 and at <= 10: + elif at > 5: category = -3 - elif at > 0 and at <= 5: + elif at > 0: category = -4 - elif at > -5 and at <= 0: + elif at > -5: category = -5 else: category = -6 diff --git a/tests/apparent_test.py b/tests/apparent_test.py index 6f64bcee..39702deb 100644 --- a/tests/apparent_test.py +++ b/tests/apparent_test.py @@ -20,7 +20,3 @@ def test_apparent_temperature(): assert apparent_temperature_warning_category(5) == -4 assert apparent_temperature_warning_category(0) == -5 assert apparent_temperature_warning_category(-5) == -6 - - - -