Skip to content

Commit

Permalink
Merge pull request #1055 from zbruick/el_lcl_1020
Browse files Browse the repository at this point in the history
Prevent an EL below a LCL
  • Loading branch information
dopplershift authored Jun 12, 2019
2 parents c01ef17 + b0e9483 commit c8aaacf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
25 changes: 25 additions & 0 deletions metpy/calc/tests/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,31 @@ def test_no_el_parcel_colder():
assert assert_nan(el_temperature, temperatures.units)


def test_el_below_lcl():
"""Test LFC when there is positive area below the LCL (#1003)."""
p = [902.1554, 897.9034, 893.6506, 889.4047, 883.063, 874.6284, 866.2387, 857.887,
849.5506, 841.2686, 833.0042, 824.7891, 812.5049, 796.2104, 776.0027, 751.9025,
727.9612, 704.1409, 680.4028, 656.7156, 629.077, 597.4286, 565.6315, 533.5961,
501.2452, 468.493, 435.2486, 401.4239, 366.9387, 331.7026, 295.6319, 258.6428,
220.9178, 182.9384, 144.959, 106.9778, 69.00213] * units.hPa
t = [-3.039381, -3.703779, -4.15996, -4.562574, -5.131827, -5.856229, -6.568434,
-7.276881, -7.985013, -8.670911, -8.958063, -7.631381, -6.05927, -5.083627,
-5.11576, -5.687552, -5.453021, -4.981445, -5.236665, -6.324916, -8.434324,
-11.58795, -14.99297, -18.45947, -21.92021, -25.40522, -28.914, -32.78637,
-37.7179, -43.56836, -49.61077, -54.24449, -56.16666, -57.03775, -58.28041,
-60.86264, -64.21677] * units.degC
td = [-22.08774, -22.18181, -22.2508, -22.31323, -22.4024, -22.51582, -22.62526,
-22.72919, -22.82095, -22.86173, -22.49489, -21.66936, -21.67332, -21.94054,
-23.63561, -27.17466, -31.87395, -38.31725, -44.54717, -46.99218, -43.17544,
-37.40019, -34.3351, -36.42896, -42.1396, -46.95909, -49.36232, -48.94634,
-47.90178, -49.97902, -55.02753, -63.06276, -72.53742, -88.81377, -93.54573,
-92.92464, -91.57479] * units.degC
prof = parcel_profile(p, t[0], td[0]).to('degC')
el_p, el_t = el(p, t, td, prof)
assert assert_nan(el_p, p.units)
assert assert_nan(el_t, t.units)


def test_wet_psychrometric_vapor_pressure():
"""Test calculation of vapor pressure from wet and dry bulb temperatures."""
p = 1013.25 * units.mbar
Expand Down
6 changes: 4 additions & 2 deletions metpy/calc/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,11 @@ def el(pressure, temperature, dewpt, parcel_temperature_profile=None):
if parcel_temperature_profile[-1] > temperature[-1]:
return np.nan * pressure.units, np.nan * temperature.units

# Otherwise the last intersection (as long as there is one) is the EL
# Otherwise the last intersection (as long as there is one, and it's not
# below the LCL) is the EL
x, y = find_intersections(pressure[1:], parcel_temperature_profile[1:], temperature[1:])
if len(x) > 0:
lcl_p, _ = lcl(pressure[0], temperature[0], dewpt[0])
if len(x) > 0 and x[-1] < lcl_p:
return x[-1], y[-1]
else:
return np.nan * pressure.units, np.nan * temperature.units
Expand Down

0 comments on commit c8aaacf

Please sign in to comment.