Skip to content
Snippets Groups Projects
Commit ce2d40e6 authored by Mads M. Pedersen's avatar Mads M. Pedersen
Browse files

nan support in std_deg

parent 9f8ae4ad
No related branches found
No related tags found
No related merge requests found
...@@ -50,7 +50,7 @@ def std_deg(dir): ...@@ -50,7 +50,7 @@ def std_deg(dir):
std_deg : float std_deg : float
standard deviation standard deviation
""" """
return deg(np.sqrt(1 - (np.mean(sind(dir)) ** 2 + np.mean(cosd(dir)) ** 2))) return deg(np.sqrt(1 - (np.nanmean(sind(dir)) ** 2 + np.nanmean(cosd(dir)) ** 2)))
def wsp_dir2uv(wsp, dir, dir_ref=None): def wsp_dir2uv(wsp, dir, dir_ref=None):
......
...@@ -65,6 +65,9 @@ class TestGeometry(unittest.TestCase): ...@@ -65,6 +65,9 @@ class TestGeometry(unittest.TestCase):
self.assertEqual(std_deg(np.array([0, 0, 0])), 0) self.assertEqual(std_deg(np.array([0, 0, 0])), 0)
self.assertAlmostEqual(std_deg(np.array([0, 90, 180, 270])), 57.296, 2) self.assertAlmostEqual(std_deg(np.array([0, 90, 180, 270])), 57.296, 2)
def test_std_deg_nan(self):
self.assertAlmostEqual(std_deg(np.array([0, 90, 180, 270, np.nan])), 57.296, 2)
def test_wspdir2uv(self): def test_wspdir2uv(self):
u, v = wsp_dir2uv(np.array([1, 1, 1]), np.array([30, 0, 330])) u, v = wsp_dir2uv(np.array([1, 1, 1]), np.array([30, 0, 330]))
np.testing.assert_array_almost_equal(u, [0.8660, 1, 0.8660], 3) np.testing.assert_array_almost_equal(u, [0.8660, 1, 0.8660], 3)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment