From 8895e544f14abe814710acaa84aaf3968bf90411 Mon Sep 17 00:00:00 2001 From: kgoebber Date: Mon, 28 Dec 2020 15:30:00 -0600 Subject: [PATCH] fix bug in issue 1635 --- src/metpy/calc/indices.py | 8 ++++---- tests/calc/test_indices.py | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/metpy/calc/indices.py b/src/metpy/calc/indices.py index 20fd0f16de..c43f3a0848 100644 --- a/src/metpy/calc/indices.py +++ b/src/metpy/calc/indices.py @@ -134,11 +134,11 @@ def mean_pressure_weighted(pressure, *args, height=None, bottom=None, depth=None layer_arg = layer_arg[1:] # Taking the integral of the weights (pressure) to feed into the weighting # function. Said integral works out to this function: - pres_int = 0.5 * (layer_p[-1].magnitude**2 - layer_p[0].magnitude**2) + pres_int = 0.5 * (layer_p[-1]**2 - layer_p[0]**2) for i, datavar in enumerate(args): - arg_mean = np.trapz((layer_arg[i] * layer_p).magnitude, - x=layer_p.magnitude) / pres_int - ret.append(arg_mean * datavar.units) + arg_mean = np.trapz((layer_arg[i] * layer_p), + x=layer_p) / pres_int + ret.append(arg_mean) return ret diff --git a/tests/calc/test_indices.py b/tests/calc/test_indices.py index 68b68127cd..b0541004fb 100644 --- a/tests/calc/test_indices.py +++ b/tests/calc/test_indices.py @@ -73,6 +73,17 @@ def test_mean_pressure_weighted(): assert_almost_equal(v, 7.966031839967931 * units('m/s'), 7) +def test_mean_pressure_weighted_temperature(): + """Test pressure-weighted mean temperature function with vertical interpolation.""" + data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC') + print(data['temperature']) + T = mean_pressure_weighted(data['pressure'], + data['temperature'], + height=data['height'], + depth=6000 * units('meter')) + assert_almost_equal(T, 281.535035296836 * units('kelvin'), 7) + + def test_mean_pressure_weighted_elevated(): """Test pressure-weighted mean wind function with a base above the surface.""" data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')