Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug in issue 1635 #1639

Merged
merged 1 commit into from Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 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)
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)
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),
x=layer_p) / pres_int
ret.append(arg_mean)

return ret

Expand Down
10 changes: 10 additions & 0 deletions tests/calc/test_indices.py
Expand Up @@ -73,6 +73,16 @@ 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')
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