Skip to content

Commit

Permalink
return heat_index with temperature units (#3307)
Browse files Browse the repository at this point in the history
* return heat_index with temperature units

* move conversion

---------

Co-authored-by: renee.walton <renee.walton@corteva.com>
  • Loading branch information
rwalton91 and renee.walton authored Dec 11, 2023
1 parent 77e8768 commit 0f71eea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/metpy/calc/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def heat_index(temperature, relative_humidity, mask_undefined=True):
>>> from metpy.calc import heat_index
>>> from metpy.units import units
>>> heat_index(30 * units.degC, 90 * units.percent)
<Quantity([105.3943646], 'degree_Fahrenheit')>
<Quantity([40.774647], 'degree_Celsius')>
>>> heat_index(90 * units.degF, 90 * units.percent)
<Quantity([121.901204], 'degree_Fahrenheit')>
>>> heat_index(60 * units.degF, 90 * units.percent)
Expand Down Expand Up @@ -338,7 +338,7 @@ def heat_index(temperature, relative_humidity, mask_undefined=True):
if mask.any():
hi = masked_array(hi, mask=mask)

return hi
return hi.to(temperature.units)


@exporter.export
Expand Down
9 changes: 5 additions & 4 deletions tests/calc/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,20 @@ def test_heat_index_undefined_flag():


def test_heat_index_units():
"""Test units coming out of heat index."""
"""Test units coming out of heat index are unchanged."""
temp = units.Quantity([35., 20.], units.degC)
rh = 70 * units.percent
hi = heat_index(temp, rh)
assert_almost_equal(hi.to('degC'), units.Quantity([50.3405, np.nan], units.degC), 4)
assert hi.units == temp.units
assert_almost_equal(hi, units.Quantity([50.3405, np.nan], units.degC), 4)


def test_heat_index_ratio():
"""Test giving humidity as number [0, 1] to heat index."""
temp = units.Quantity([35., 20.], units.degC)
rh = 0.7
hi = heat_index(temp, rh)
assert_almost_equal(hi.to('degC'), units.Quantity([50.3405, np.nan], units.degC), 4)
assert_almost_equal(hi, units.Quantity([50.3405, np.nan], units.degC), 4)


def test_heat_index_vs_nws():
Expand All @@ -278,7 +279,7 @@ def test_heat_index_kelvin():
rh = 0.7
hi = heat_index(temp, rh)
# NB rounded up test value here vs the above two tests
assert_almost_equal(hi.to('degC'), 50.3406 * units.degC, 4)
assert_almost_equal(hi, 50.3406 * units.degC, 4)


def test_height_to_geopotential(array_type):
Expand Down

0 comments on commit 0f71eea

Please sign in to comment.