Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calc.moist_lapse returns incorrect values for Fahrenheit #2005

Closed
joejoezz opened this issue Aug 2, 2021 · 1 comment · Fixed by #2008
Closed

calc.moist_lapse returns incorrect values for Fahrenheit #2005

joejoezz opened this issue Aug 2, 2021 · 1 comment · Fixed by #2008
Labels
Area: Calc Pertains to calculations Type: Bug Something is not working like it should
Milestone

Comments

@joejoezz
Copy link

joejoezz commented Aug 2, 2021

Hello...first time issue reporter here, hopefully I'm doing this right but if not please let me know. It appears that metpy.calc.moist_lapse doesn't work for degrees F, which in turn also causes metpy.calc.wet_bulb_temperature to return wrong values. Here is a test with a temp of 70 F, a dew point of 30 F, and a pressure of 1013 hPa. The wet bulb temperature should be 50.27 degrees F. Thanks!

import metpy.calc as mpcalc
from metpy.units import units

temp_f = 70 * units('degF')
dewpt_f = 30 * units('degF')
pressure = 1013 * units('hPa')
temp_c = temp_f.to('degC')
dewpt_c = dewpt_f.to('degC')

# wet bulb C vs F comparison
wet_bulb_c = mpcalc.wet_bulb_temperature(pressure, temp_c, dewpt_c)
wet_bulb_f = mpcalc.wet_bulb_temperature(pressure, temp_f, dewpt_f)
print('Wet bulb test')
print(wet_bulb_c.to('degF'))
print(wet_bulb_f)

# LCL C vs F comparison
lcl_press_c, lcl_temp_c = mpcalc.lcl(pressure, temp_c, dewpt_c)
lcl_press_f, lcl_temp_f = mpcalc.lcl(pressure, temp_f, dewpt_f)
print('LCL test')
print(lcl_temp_c.to('degF'))
print(lcl_temp_f)

# moist lapse C vs F comparison
t_sfc_f = mpcalc.moist_lapse(pressure, lcl_temp_f, lcl_press_f)
t_sfc_c = mpcalc.moist_lapse(pressure, lcl_temp_c, lcl_press_c)
print('Moist lapse test')
print(t_sfc_c.to('degF'))
print(t_sfc_f)

And the output...
Wet bulb test
50.27419018728051 degree_Fahrenheit
38.64463846517734 degree_Fahrenheit
LCL test
21.973671886917185 degree_Fahrenheit
21.973671886917185 degree_Fahrenheit
Moist lapse test
50.27419018728051 degree_Fahrenheit
38.64463846517734 degree_Fahrenheit

Python 3.6.13, Metpy 1.0.1

@joejoezz joejoezz added the Type: Bug Something is not working like it should label Aug 2, 2021
@dopplershift dopplershift added the Area: Calc Pertains to calculations label Aug 2, 2021
@dopplershift dopplershift added this to the 1.1.0 milestone Aug 2, 2021
@dopplershift
Copy link
Member

Thanks for the report, and all of the detailed information above. You definitely found a corner case in our unit-handling. Testing and fixing this also revealed a direct problem in the unit-handling in wet_bulb_temperature itself too. The fix will be included in the forthcoming 1.1 release.

dopplershift added a commit to dopplershift/MetPy that referenced this issue Aug 3, 2021
moist_lapse and wet_bulb_temperature were handling units manually for
various reasons--and weren't getting it quite right. Expand testing to
parameterize across the various temperature units to catch this going
forward.

Also update a test image that barely changed due to minute changes in
the moist_lapse calculation.
dopplershift added a commit to dopplershift/MetPy that referenced this issue Aug 3, 2021
moist_lapse and wet_bulb_temperature were handling units manually for
various reasons--and weren't getting it quite right. Expand testing to
parameterize across the various temperature units to catch this going
forward.

Also update a test image and a threshold due to visually imperceptible changes
due to the moist_lapse calculation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Calc Pertains to calculations Type: Bug Something is not working like it should
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants