diff --git a/skais/ais/ais_trajectory.py b/skais/ais/ais_trajectory.py index 3cbc82a842c873b036035ea569a253cc87f73d04..71fb3776053bd70d08e16cf446d89d11ce81d4a5 100644 --- a/skais/ais/ais_trajectory.py +++ b/skais/ais/ais_trajectory.py @@ -5,7 +5,7 @@ import numpy as np from numba import jit 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.stats import calc_std_dev diff --git a/skais/stats/__init__.py b/skais/process/__init__.py similarity index 100% rename from skais/stats/__init__.py rename to skais/process/__init__.py diff --git a/skais/process/basic_features_operations.py b/skais/process/basic_features_operations.py new file mode 100644 index 0000000000000000000000000000000000000000..127102e61f5ac2183277e4714188d1b5b3547650 --- /dev/null +++ b/skais/process/basic_features_operations.py @@ -0,0 +1,33 @@ +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) + diff --git a/skais/stats/angluar.py b/skais/stats/angluar.py deleted file mode 100644 index b2181db23a26afff28985c2953489e6284d13a70..0000000000000000000000000000000000000000 --- a/skais/stats/angluar.py +++ /dev/null @@ -1,30 +0,0 @@ -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 diff --git a/skais/tests/stats/test_angular.py b/skais/tests/process/test_basic_features_operations.py similarity index 69% rename from skais/tests/stats/test_angular.py rename to skais/tests/process/test_basic_features_operations.py index 0accd40b70e382ad3f35b569c9f1099f3761db53..c8f5a5cece00242e781037d11e8d85d0ca0fe01c 100644 --- a/skais/tests/stats/test_angular.py +++ b/skais/tests/process/test_basic_features_operations.py @@ -2,7 +2,7 @@ import unittest 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): @@ -29,14 +29,24 @@ class TestAngular(unittest.TestCase): def test_angular_mean_second_quadrant(self): x = np.radians(np.array([133, 134, 135, 136, 137])) - self.assertEqual(3*np.pi / 4, angular_mean(x)) + self.assertEqual(3 * np.pi / 4, angular_mean(x)) 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(-3 * 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)) + + 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