Skip to content
Snippets Groups Projects
Commit aac48af1 authored by Raphael Sturgis's avatar Raphael Sturgis
Browse files

rewrote average angle to correspond to article

parent 16c2a9b2
No related branches found
No related tags found
2 merge requests!12version 0.2a,!10Resolve "Image creation bugs with 0 size windows"
...@@ -18,16 +18,14 @@ def angular_dispersion(angles): ...@@ -18,16 +18,14 @@ def angular_dispersion(angles):
def angular_mean(angles): def angular_mean(angles):
x, y = angular_average_vector(angles) x, y = angular_average_vector(angles)
theta = abs(np.arctan2(x, y)) theta = np.arctan(y/x)
if y > 0 and x > 0: # first Q if y > 0 and x > 0:
return theta return theta
if y > 0 >= x: # Second Q elif x <= 0:
return np.pi / 2 + theta return np.pi + theta
if y <= 0 < x: # Fourth Q else:
return np.pi / 2 - theta return 2*np.pi + theta
else: # Third Q
return - theta
def angular_std(angles): def angular_std(angles):
......
...@@ -9,7 +9,7 @@ class TestAngular(unittest.TestCase): ...@@ -9,7 +9,7 @@ class TestAngular(unittest.TestCase):
def test_angular_mean_simple(self): def test_angular_mean_simple(self):
x = np.radians(np.array([1, 359])) x = np.radians(np.array([1, 359]))
self.assertEqual(0.0, angular_mean(x)) self.assertEqual(2*np.pi, angular_mean(x))
def test_angular_mean_simple_2(self): def test_angular_mean_simple_2(self):
x = np.radians(np.array([180, 180, 180, 180, 179, 181])) x = np.radians(np.array([180, 180, 180, 180, 179, 181]))
...@@ -19,7 +19,7 @@ class TestAngular(unittest.TestCase): ...@@ -19,7 +19,7 @@ class TestAngular(unittest.TestCase):
def test_angular_mean_simple_3(self): def test_angular_mean_simple_3(self):
x = np.radians(np.array([0, 0, 0, 0, 359, 1])) x = np.radians(np.array([0, 0, 0, 0, 359, 1]))
self.assertEqual(0.0, angular_mean(x)) self.assertEqual(2*np.pi, angular_mean(x))
def test_angular_mean_first_quadrant(self): def test_angular_mean_first_quadrant(self):
x = np.radians(np.array([43, 44, 45, 46, 47])) x = np.radians(np.array([43, 44, 45, 46, 47]))
...@@ -34,12 +34,12 @@ class TestAngular(unittest.TestCase): ...@@ -34,12 +34,12 @@ class TestAngular(unittest.TestCase):
def test_angular_mean_third_quadrant(self): def test_angular_mean_third_quadrant(self):
x = np.radians(np.array([223, 224, 225, 226, 227])) x = np.radians(np.array([223, 224, 225, 226, 227]))
self.assertEqual(-3 * np.pi / 4, angular_mean(x)) self.assertEqual(5 * np.pi / 4, angular_mean(x))
def test_angular_mean_fourth_quadrant(self): def test_angular_mean_fourth_quadrant(self):
x = np.radians(np.array([313, 314, 315, 316, 317])) x = np.radians(np.array([313, 314, 315, 316, 317]))
self.assertEqual(-np.pi / 4, angular_mean(x)) self.assertEqual(7*np.pi / 4, angular_mean(x))
def test_angular_std(self): def test_angular_std(self):
x = np.radians(np.array([0, 0, 0, 0])) x = np.radians(np.array([0, 0, 0, 0]))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment