Skip to content

Commit

Permalink
fix mlcape if parcel_start_pressure != bottom (#3147)
Browse files Browse the repository at this point in the history
* fix mlcape if parcel_start_pressure != bottom

* fix spacing

* split that test
  • Loading branch information
wx4stg authored Nov 15, 2023
1 parent eaa93e7 commit 64faccb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
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)


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

0 comments on commit 64faccb

Please sign in to comment.