Skip to content

Commit

Permalink
Use np.asanyarray instead of explicitly checking for a mask
Browse files Browse the repository at this point in the history
  • Loading branch information
rpmanser committed Aug 19, 2021
1 parent ee1c96b commit b476eb5
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/metpy/calc/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,10 @@ def wind_direction(u, v, convention='from'):
if np.any(mask):
wdir[mask] += units.Quantity(360., 'deg')
# avoid unintended modification of `pint.Quantity` by direct use of magnitude
calm_mask = (np.asarray(u.magnitude) == 0.) & (np.asarray(v.magnitude) == 0.)

if hasattr(wdir, 'mask'):
array_mask = wdir.mask
else:
array_mask = False
calm_mask = (np.asanyarray(u.magnitude) == 0.) & (np.asanyarray(v.magnitude) == 0.)

# np.any check required for legacy numpy which treats 0-d False boolean index as zero
if np.any(calm_mask & np.logical_not(array_mask)):
if np.any(calm_mask):
wdir[calm_mask] = units.Quantity(0., 'deg')
return wdir.reshape(origshape).to('degrees')

Expand Down

0 comments on commit b476eb5

Please sign in to comment.