From 5dc60119989f49ee42dca49baf21e09f537e8e1e Mon Sep 17 00:00:00 2001 From: Sam Gardner Date: Thu, 10 Aug 2023 23:05:32 +0000 Subject: [PATCH 1/3] fix mlcape if parcel_start_pressure != bottom --- src/metpy/calc/thermo.py | 7 ++++--- tests/calc/test_thermo.py | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/metpy/calc/thermo.py b/src/metpy/calc/thermo.py index 75fadfe55f5..c00e957db06 100644 --- a/src/metpy/calc/thermo.py +++ b/src/metpy/calc/thermo.py @@ -3011,13 +3011,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]) diff --git a/tests/calc/test_thermo.py b/tests/calc/test_thermo.py index 73f14f9a007..3a83a5e31a7 100644 --- a/tests/calc/test_thermo.py +++ b/tests/calc/test_thermo.py @@ -1549,6 +1549,10 @@ def test_mixed_layer_cape_cin(multiple_intersections): mlcape, mlcin = mixed_layer_cape_cin(pressure, temperature, dewpoint) assert_almost_equal(mlcape, 1132.706800436 * units('joule / kilogram'), 2) assert_almost_equal(mlcin, -13.4809966289 * units('joule / kilogram'), 2) + 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_mixed_layer(): From 429caf249c46de00d036eea097a5e79a146e0da1 Mon Sep 17 00:00:00 2001 From: Sam Gardner Date: Thu, 10 Aug 2023 23:41:38 +0000 Subject: [PATCH 2/3] fix spacing --- tests/calc/test_thermo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/calc/test_thermo.py b/tests/calc/test_thermo.py index 3a83a5e31a7..60be72145e2 100644 --- a/tests/calc/test_thermo.py +++ b/tests/calc/test_thermo.py @@ -1550,7 +1550,7 @@ def test_mixed_layer_cape_cin(multiple_intersections): assert_almost_equal(mlcape, 1132.706800436 * units('joule / kilogram'), 2) assert_almost_equal(mlcin, -13.4809966289 * units('joule / kilogram'), 2) mlcape_middle, mlcin_middle = mixed_layer_cape_cin(pressure, temperature, dewpoint, - parcel_start_pressure=800 * units.hPa) + 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) From e90cdf62d9397e686f1e1df3fe9d6e593e0a8c18 Mon Sep 17 00:00:00 2001 From: Sam Gardner Date: Tue, 14 Nov 2023 18:05:11 -0600 Subject: [PATCH 3/3] split that test --- tests/calc/test_thermo.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/calc/test_thermo.py b/tests/calc/test_thermo.py index 8b7e2fa4517..462a53786e8 100644 --- a/tests/calc/test_thermo.py +++ b/tests/calc/test_thermo.py @@ -1554,6 +1554,11 @@ def test_mixed_layer_cape_cin(multiple_intersections): mlcape, mlcin = mixed_layer_cape_cin(pressure, temperature, dewpoint) assert_almost_equal(mlcape, 1132.706800436 * units('joule / kilogram'), 2) 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)