Skip to content

Commit

Permalink
fix bug in issue 1635
Browse files Browse the repository at this point in the history
  • Loading branch information
kgoebber committed Dec 28, 2020
1 parent ab940e3 commit 8895e54
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/metpy/calc/indices.py
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions tests/calc/test_indices.py
Expand Up @@ -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')
Expand Down

0 comments on commit 8895e54

Please sign in to comment.