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"
This commit is part of merge request !10. Comments created here will be created in the context of that merge request.
......@@ -18,16 +18,14 @@ def angular_dispersion(angles):
def angular_mean(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
if y > 0 >= x: # Second Q
return np.pi / 2 + theta
if y <= 0 < x: # Fourth Q
return np.pi / 2 - theta
else: # Third Q
return - theta
elif x <= 0:
return np.pi + theta
else:
return 2*np.pi + theta
def angular_std(angles):
......
......@@ -9,7 +9,7 @@ class TestAngular(unittest.TestCase):
def test_angular_mean_simple(self):
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):
x = np.radians(np.array([180, 180, 180, 180, 179, 181]))
......@@ -19,7 +19,7 @@ class TestAngular(unittest.TestCase):
def test_angular_mean_simple_3(self):
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):
x = np.radians(np.array([43, 44, 45, 46, 47]))
......@@ -34,12 +34,12 @@ class TestAngular(unittest.TestCase):
def test_angular_mean_third_quadrant(self):
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):
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):
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