Skip to content

Commit

Permalink
Add test for duplicates in profile _as_dataset
Browse files Browse the repository at this point in the history
Make sure duplicate handling doesn't interrupt dataset construction
and proper alignment of results.
  • Loading branch information
dcamron committed Apr 6, 2022
1 parent 57e6c3c commit 83e541f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/calc/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 83e541f

Please sign in to comment.