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

fix mlcape if parcel_start_pressure != bottom #3147

Merged
merged 4 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/metpy/calc/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3027,13 +3027,14 @@ def mixed_layer_cape_cin(pressure, temperature, dewpoint, **kwargs):

"""
depth = kwargs.get('depth', units.Quantity(100, 'hPa'))
start_p = kwargs.get('parcel_start_pressure', pressure[0])
parcel_pressure, parcel_temp, parcel_dewpoint = mixed_parcel(pressure, temperature,
dewpoint, **kwargs)

# Remove values below top of mixed layer and add in the mixed layer values
pressure_prof = pressure[pressure < (pressure[0] - depth)]
temp_prof = temperature[pressure < (pressure[0] - depth)]
dew_prof = dewpoint[pressure < (pressure[0] - depth)]
pressure_prof = pressure[pressure < (start_p - depth)]
temp_prof = temperature[pressure < (start_p - depth)]
dew_prof = dewpoint[pressure < (start_p - depth)]
pressure_prof = concatenate([parcel_pressure, pressure_prof])
temp_prof = concatenate([parcel_temp, temp_prof])
dew_prof = concatenate([parcel_dewpoint, dew_prof])
Expand Down
9 changes: 9 additions & 0 deletions tests/calc/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,15 @@ def test_mixed_layer_cape_cin(multiple_intersections):
assert_almost_equal(mlcin, -13.4809966289 * units('joule / kilogram'), 2)


def test_mixed_layer_cape_cin_bottom_pressure(multiple_intersections):
"""Test the calculation of mixed layer cape/cin with a specified bottom pressure."""
pressure, temperature, dewpoint = multiple_intersections
mlcape_middle, mlcin_middle = mixed_layer_cape_cin(pressure, temperature, dewpoint,
parcel_start_pressure=800 * units.hPa)
assert_almost_equal(mlcape_middle, 0 * units('joule / kilogram'), 2)
assert_almost_equal(mlcin_middle, 0 * units('joule / kilogram'), 2)
wx4stg marked this conversation as resolved.
Show resolved Hide resolved


def test_dcape():
"""Test the calculation of DCAPE."""
pressure = [1008., 1000., 950., 900., 850., 800., 750., 700., 650., 600.,
Expand Down