Skip to content
Snippets Groups Projects
Commit 918ab5b4 authored by Raphael's avatar Raphael
Browse files

Continued angular basic process

parent ddf0b2bd
No related branches found
No related tags found
1 merge request!6Develop
...@@ -5,7 +5,7 @@ import numpy as np ...@@ -5,7 +5,7 @@ import numpy as np
from numba import jit from numba import jit
from scipy.interpolate import interp1d from scipy.interpolate import interp1d
from skais.stats.angluar import angular_dispersion from skais.process.basic_features_operations import angular_dispersion
from skais.utils.geography import great_circle from skais.utils.geography import great_circle
from skais.utils.stats import calc_std_dev from skais.utils.stats import calc_std_dev
......
File moved
import numpy as np
def angular_average_vector(angles):
n = len(angles)
x = np.sum(np.cos(angles)) / n
y = np.sum(np.sin(angles)) / n
return np.array([x, y])
def angular_dispersion(angles):
x, y = angular_average_vector(angles)
return np.sqrt(x ** 2 + y ** 2)
def angular_mean(angles):
x, y = angular_average_vector(angles)
theta = abs(np.arctan2(x, y))
if y > 0 and x > 0: # first Q
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
def angular_std(angles):
return 1 - angular_dispersion(angles)
import numpy as np
def angular_dispersion(x):
n = len(x)
X = np.sum(np.cos(x)) / n
Y = np.sum(np.sin(x)) / n
r = np.sqrt(X ** 2 + Y ** 2)
return r
def angular_mean(x):
n = len(x)
X = np.sum(np.cos(x)) / n
Y = np.sum(np.sin(x)) / n
theta = abs(np.arctan2(X, Y))
if Y > 0 and X > 0: # first Q
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
...@@ -2,7 +2,7 @@ import unittest ...@@ -2,7 +2,7 @@ import unittest
import numpy as np import numpy as np
from skais.stats.angluar import angular_mean from skais.process.basic_features_operations import angular_mean, angular_std
class TestAngular(unittest.TestCase): class TestAngular(unittest.TestCase):
...@@ -40,3 +40,13 @@ class TestAngular(unittest.TestCase): ...@@ -40,3 +40,13 @@ class TestAngular(unittest.TestCase):
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(-np.pi / 4, angular_mean(x))
def test_angular_std(self):
x = np.radians(np.array([0, 0, 0, 0]))
self.assertEqual(0, angular_std(x))
def test_angular_std(self):
x = np.radians(np.array([0, 90, 180, 270]))
self.assertAlmostEqual(1, angular_std(x))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment