diff --git a/tests/calc/test_thermo.py b/tests/calc/test_thermo.py index a0deabedf64..cc8e5827bfc 100644 --- a/tests/calc/test_thermo.py +++ b/tests/calc/test_thermo.py @@ -2112,3 +2112,48 @@ def test_parcel_profile_drop_duplicates(): with pytest.warns(UserWarning, match='Duplicate pressure'): profile = parcel_profile(pressure, temperature, dewpoint) assert_almost_equal(profile, truth, 5) + + +def test_parcel_profile_with_lcl_as_dataset_duplicates(): + """Test that parcel profile dataset creation works with duplicate pressures in profile.""" + pressure = np.array( + [951., 951., 937.9, 925., 908., 30., 27.7, 27.7, 26.4, 25.1] + ) * units.hPa + + temperature = np.array( + [20., 20., 19.5, 19., 18.6, -58.5, -58.1, -58.1, -57.2, -56.2] + ) * units.degC + + dewpoint = np.array( + [19.4, 19.4, 19., 18.6, 18.3, -73.5, -75.1, -75.1, -77., -78.8] + ) * units.degC + + truth = xr.Dataset( + { + 'ambient_temperature': ( + ('isobaric',), + np.insert(temperature.m, 2, 19.679237747615478) * units.degC + ), + 'ambient_dew_point': ( + ('isobaric',), + np.insert(dewpoint.m, 2, 19.143390198092384) * units.degC + ), + 'parcel_temperature': ( + ('isobaric',), + [ + 293.15, 293.15, 292.40749167, 292.22841462, 291.73069653, 291.06139433, + 125.22698955, 122.40534065, 122.40534065, 120.73573642, 119.0063293 + ] * units.kelvin + ) + }, + coords={ + 'isobaric': ( + 'isobaric', + np.insert(pressure.m, 2, 942.6) + ) + } + ) + + profile = parcel_profile_with_lcl_as_dataset(pressure, temperature, dewpoint) + + xr.testing.assert_allclose(profile, truth, atol=1e-5)