Skip to content

Commit

Permalink
remove nans from bunkers input (#3131)
Browse files Browse the repository at this point in the history
* remove nans from bunkers input

* test for nan in bunkers

* codestyle
  • Loading branch information
wx4stg authored Aug 15, 2023
1 parent a5748b8 commit 2809552
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/metpy/calc/indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ def bunkers_storm_motion(pressure, u, v, height):
Renamed ``heights`` parameter to ``height``
"""
# remove nans from input data
pressure, u, v, height = _remove_nans(pressure, u, v, height)

# mean wind from sfc-6km
wind_mean = weighted_continuous_average(pressure, u, v, height=height,
depth=units.Quantity(6000, 'meter'))
Expand Down
15 changes: 15 additions & 0 deletions tests/calc/test_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@ def test_bunkers_motion():
assert_almost_equal(motion.flatten(), truth, 8)


def test_bunkers_motion_with_nans():
"""Test Bunkers storm motion with observed sounding."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
u_with_nan = data['u_wind']
u_with_nan[24:26] = np.nan
v_with_nan = data['v_wind']
v_with_nan[24:26] = np.nan
motion = concatenate(bunkers_storm_motion(data['pressure'],
u_with_nan, v_with_nan,
data['height']))
truth = [2.09232447, 0.97612357, 11.25513401, 12.85227283, 6.67372924,
6.9141982] * units('m/s')
assert_almost_equal(motion.flatten(), truth, 8)


def test_bulk_shear():
"""Test bulk shear with observed sounding."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand Down

0 comments on commit 2809552

Please sign in to comment.