Skip to content

Commit

Permalink
Update to most_unstable_cape_cin to include the LCL in the profile
Browse files Browse the repository at this point in the history
if the start of the most unstable parcel is below the LCL.
Closes #1108.
  • Loading branch information
zbruick committed Jul 23, 2019
1 parent 8324543 commit 4934b52
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion metpy/calc/tests/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ def test_most_unstable_cape_cin_surface():
dewpoint = np.array([19., -11.2, -10.8, -10.4, -10., -53.2]) * units.celsius
mucape, mucin = most_unstable_cape_cin(pressure, temperature, dewpoint)
assert_almost_equal(mucape, 75.7340825 * units('joule / kilogram'), 6)
assert_almost_equal(mucin, -89.8179205 * units('joule / kilogram'), 6)
assert_almost_equal(mucin, -136.607809 * units('joule / kilogram'), 6)


def test_most_unstable_cape_cin():
Expand Down
20 changes: 13 additions & 7 deletions metpy/calc/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1774,13 +1774,19 @@ def most_unstable_cape_cin(pressure, temperature, dewpoint, **kwargs):
cape_cin, most_unstable_parcel, parcel_profile
"""
_, parcel_temperature, parcel_dewpoint, parcel_idx = most_unstable_parcel(pressure,
temperature,
dewpoint,
**kwargs)
mu_profile = parcel_profile(pressure[parcel_idx:], parcel_temperature, parcel_dewpoint)
return cape_cin(pressure[parcel_idx:], temperature[parcel_idx:],
dewpoint[parcel_idx:], mu_profile)
parcel_pressure, parcel_temperature, parcel_dewpoint, parcel_idx = \
most_unstable_parcel(pressure, temperature, dewpoint, **kwargs)
lcl_pressure, _ = lcl(pressure[0], temperature[0], dewpoint[0])
if parcel_pressure > lcl_pressure:
p, t, td, mu_profile = parcel_profile_with_lcl(pressure[parcel_idx:],
temperature[parcel_idx:],
dewpoint[parcel_idx:])
return cape_cin(p, t, td, mu_profile)
else:
mu_profile = parcel_profile(pressure[parcel_idx:], parcel_temperature,
parcel_dewpoint)
return cape_cin(pressure[parcel_idx:], temperature[parcel_idx:],
dewpoint[parcel_idx:], mu_profile)


@exporter.export
Expand Down

0 comments on commit 4934b52

Please sign in to comment.