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

complete coverage of ais_points

parent 2bf2710c
No related branches found
No related tags found
No related merge requests found
......@@ -36,9 +36,12 @@ from scipy.stats import stats
class AISPoints:
# Todo: Should be more elegant
def __init__(self, df=None):
if 'ts' in df:
df['ts'] = pd.to_datetime(df.ts)
if 'mmsi' in df:
df = df.sort_values(['mmsi', 'ts'])
self.df = df
......
......@@ -9,12 +9,29 @@ from skais.ais.ais_trajectory import AISTrajectory
class TestAISPositions(unittest.TestCase):
# Lazy test
def test_init(self):
ais_points = AISPoints(
pd.DataFrame(
{
"sog": [2, 3, 7, 15, 14, 12, 18, 25, 21, 12, 11, 16, 19, 2, 5, 15, 12, 7, 8, 9, 1],
"diff": [35, 45, 59, 12, 1, 2, 54, 5, 47, 86, 119, 68, 75, 54, 55, 12, 32, 62, 159, 157, 132],
"label": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
"ts": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
"mmsi": [0 for i in range(21)]
}
)
)
self.assertIsNotNone(ais_points)
def test_describe(self):
ais_points = AISPoints(pd.DataFrame(
{
"sog": [2, 3, 7, 15, 14, 12, 18, 25, 21, 12, 11, 16, 19, 2, 5, 15, 12, 7, 8, 9, 1],
"diff": [35, 45, 59, 12, 1, 2, 54, 5, 47, 86, 119, 68, 75, 54, 55, 12, 32, 62, 159, 157, 132],
"label": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
"ts": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
"mmsi": [0 for i in range(21)]
}
))
......@@ -29,7 +46,6 @@ class TestAISPositions(unittest.TestCase):
'average diff': 1271 / 21
})
def test_remove_outliers_simple(self):
ais_points = AISPoints(pd.DataFrame(
{
......@@ -46,7 +62,6 @@ class TestAISPositions(unittest.TestCase):
ais_points.remove_outliers(["cog", "heading"])
pd.testing.assert_frame_equal(expected.reset_index(drop=True), ais_points.df.reset_index(drop=True))
def test_remove_outliers_rank(self):
ais_points = AISPoints(pd.DataFrame(
{
......@@ -91,7 +106,6 @@ class TestAISPositions(unittest.TestCase):
with self.assertRaises(ValueError):
ais_points.remove_outliers(["cog"], rank=0)
def test_clean_angles(self):
ais_points = AISPoints(pd.DataFrame(
{
......@@ -161,6 +175,22 @@ class TestAISPositions(unittest.TestCase):
pd.testing.assert_frame_equal(expected.reset_index(drop=True), result.reset_index(drop=True),
check_exact=False, rtol=0.05)
def test_normalize_raise(self):
ais_points = AISPoints(pd.DataFrame(
{
"cog": [i for i in range(0, 359, 10)],
"heading": [180 for i in range(0, 359, 10)]
}
)
)
self.assertRaises(
ValueError,
ais_points.normalize,
['cog', 'heading'],
normalization_type="non-existing-normalization"
)
def test_compute_drift(self):
ais_points = AISPoints(pd.DataFrame(
......@@ -226,11 +256,20 @@ class TestAISPositions(unittest.TestCase):
#
# np.testing.assert_array_equal(ground_truth, self.ais_points.histogram_y_knowing_x(x_nb_bins=3))
# def test_load_from_csv(self):
# ais_points = AISPoints.load_from_csv("test_load_from_csv.csv")
#
# pd.testing.assert_frame_equal(ais_points.df, self.ais_points.df)
def test_load_from_csv(self):
result = AISPoints.load_from_csv("skais/tests/ais/test_load_from_csv.csv")
ais_points = AISPoints(pd.DataFrame(
{
"sog": [2, 3, 7, 15, 14, 12, 18, 25, 21, 12, 11, 16, 19, 2, 5, 15, 12, 7, 8, 9, 1],
"diff": [35, 45, 59, 12, 1, 2, 54, 5, 47, 86, 119, 68, 75, 54, 55, 12, 32, 62, 159, 157, 132],
"label": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
"ts": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
"mmsi": [0 for i in range(21)]
}
))
pd.testing.assert_frame_equal(result.df.reset_index(drop=True), ais_points.df.reset_index(drop=True))
# def test_histogram_x(self):
# ground_truth = np.array([[5, 1, 3],
......@@ -241,13 +280,13 @@ class TestAISPositions(unittest.TestCase):
# self.ais_points.histogram(features=["sog", "diff"], bins=3,
# ranges=[[0, 30], [0, 180]]))
def test_fuse_single(self):
ais_points = AISPoints(pd.DataFrame(
{
"sog": [2, 3, 7, 15, 14, 12, 18, 25, 21, 12, 11, 16, 19, 2, 5, 15, 12, 7, 8, 9, 1],
"diff": [35, 45, 59, 12, 1, 2, 54, 5, 47, 86, 119, 68, 75, 54, 55, 12, 32, 62, 159, 157, 132],
"label": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
"ts": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
"mmsi": [0 for i in range(21)]
}
))
......@@ -260,6 +299,7 @@ class TestAISPositions(unittest.TestCase):
"sog": [2, 3, 7, 15, 14, 12, 18, 25, 21, 12, 11, 16, 19, 2, 5, 15, 12, 7, 8, 9, 1],
"diff": [35, 45, 59, 12, 1, 2, 54, 5, 47, 86, 119, 68, 75, 54, 55, 12, 32, 62, 159, 157, 132],
"label": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
"ts": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
"mmsi": [0 for i in range(21)]
}
))
......@@ -272,6 +312,7 @@ class TestAISPositions(unittest.TestCase):
"sog": [2, 3, 7, 15, 14, 12, 18, 25, 21, 12, 11, 16, 19, 2, 5, 15, 12, 7, 8, 9, 1],
"diff": [35, 45, 59, 12, 1, 2, 54, 5, 47, 86, 119, 68, 75, 54, 55, 12, 32, 62, 159, 157, 132],
"label": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
"ts": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"mmsi": [0 for i in range(21)]
}
))
......@@ -284,9 +325,13 @@ class TestAISPositions(unittest.TestCase):
59, 12, 1, 2, 54, 5, 47, 86, 119, 68, 75, 54, 55, 12, 32, 62, 159, 157, 132],
"label": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
"ts": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"mmsi": [0 for i in range(42)]
}
)
value['ts'] = pd.to_datetime(value.ts)
pd.testing.assert_frame_equal(AISPoints.fuse(ais_points, ais_points).df.reset_index(drop=True),
value.reset_index(drop=True))
#
......@@ -354,7 +399,6 @@ class TestAISPositions(unittest.TestCase):
# for r, e in zip(result, expected):
# pd.testing.assert_frame_equal(e.reset_index(drop=True), r.df.reset_index(drop=True))
# def test_disjointed_histogram_label_none(self):
# ais_points = AISPoints(pd.DataFrame(
# {
......@@ -425,5 +469,3 @@ class TestAISPositions(unittest.TestCase):
#
# for r, e in zip(result, expected):
# np.testing.assert_array_equal(e, r[0])
sog,diff,label,mmsi
2,35,0,0
3,45,0,0
7,59,0,0
15,12,0,0
14,1,0,0
12,2,0,0
18,54,0,0
25,5,0,0
21,47,0,0
12,86,0,0
11,119,0,0
16,68,0,0
19,75,0,0
2,54,1,0
5,55,1,0
15,12,1,0
12,32,1,0
7,62,1,0
8,159,1,0
9,157,1,0
1,132,1,0
\ No newline at end of file
sog,diff,label,ts,mmsi
2,35,0,0,0
3,45,0,0,0
7,59,0,0,0
15,12,0,0,0
14,1,0,0,0
12,2,0,0,0
18,54,0,0,0
25,5,0,0,0
21,47,0,0,0
12,86,0,0,0
11,119,0,0,0
16,68,0,0,0
19,75,0,0,0
2,54,1,1,0
5,55,1,1,0
15,12,1,1,0
12,32,1,1,0
7,62,1,1,0
8,159,1,1,0
9,157,1,1,0
1,132,1,1,0
\ 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