diff --git a/wetb/utils/geometry.py b/wetb/utils/geometry.py index e82594ab3f77f7c8e43963006ec834553e223c84..e7dd0638b303313a1735961d3d93b5b529a91e5e 100644 --- a/wetb/utils/geometry.py +++ b/wetb/utils/geometry.py @@ -35,7 +35,7 @@ def mean_deg(dir, axis=0): mean_deg : float Mean angle """ - return deg(np.arctan2(np.mean(sind(dir[:]), axis), np.mean(cosd(dir[:]), axis))) + return deg(np.arctan2(np.nanmean(sind(dir[:]), axis), np.nanmean(cosd(dir[:]), axis))) def std_deg(dir): """Standard deviation of angles in degrees diff --git a/wetb/utils/tests/test_geometry.py b/wetb/utils/tests/test_geometry.py index e2fbf1f1faa5d951d611b4386cf0a95ca800ab42..7a1d4a7ae04639b4a089b4c135b5a6005db3b180 100644 --- a/wetb/utils/tests/test_geometry.py +++ b/wetb/utils/tests/test_geometry.py @@ -57,6 +57,9 @@ class TestGeometry(unittest.TestCase): np.testing.assert_array_almost_equal(mean_deg(a, 1), [45, 0, -45]) np.testing.assert_array_almost_equal(mean_deg(a.T, 0), [45, 0, -45]) + def test_mean_deg_nan(self): + self.assertEqual(mean_deg(np.array([0., 90, np.nan])), 45) + def test_std_deg(self): self.assertEqual(std_deg(np.array([0, 0, 0])), 0)