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

tests

parent 944ad87c
No related branches found
No related tags found
2 merge requests!17Resolve "Functionality for experiments using CNNs",!13Draft: Develop
...@@ -380,8 +380,9 @@ class TestAISTrajectory(unittest.TestCase): ...@@ -380,8 +380,9 @@ class TestAISTrajectory(unittest.TestCase):
self.assertListEqual(result, expected) self.assertListEqual(result, expected)
def test_generate_array_from_positions(self): class TestAISTrajectoryImageGeneration(unittest.TestCase):
trajectory = AISTrajectory( def setUp(self) -> None:
self.trajectory = AISTrajectory(
pd.DataFrame( pd.DataFrame(
{ {
"latitude": [0, 10, 0, -10], "latitude": [0, 10, 0, -10],
...@@ -391,7 +392,8 @@ class TestAISTrajectory(unittest.TestCase): ...@@ -391,7 +392,8 @@ class TestAISTrajectory(unittest.TestCase):
) )
) )
result = trajectory.generate_array_from_positions(height=9, width=9, link=False, bounding_box='fit', def test_generate_array_from_positions(self):
result = self.trajectory.generate_array_from_positions(height=9, width=9, link=False, bounding_box='fit',
features=None, node_size=0).reshape((9, 9)) features=None, node_size=0).reshape((9, 9))
expected = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 1], expected = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0],
...@@ -406,17 +408,8 @@ class TestAISTrajectory(unittest.TestCase): ...@@ -406,17 +408,8 @@ class TestAISTrajectory(unittest.TestCase):
np.testing.assert_array_equal(result, expected) np.testing.assert_array_equal(result, expected)
def test_generate_array_from_positions_node_size(self): def test_generate_array_from_positions_node_size(self):
trajectory = AISTrajectory(
pd.DataFrame(
{
"latitude": [0, 10, 0, -10],
"longitude": [0, 10, 10, -10],
"ts_sec": [i for i in range(4)]
}
)
)
result = trajectory.generate_array_from_positions(height=9, width=9, link=False, bounding_box='fit', result = self.trajectory.generate_array_from_positions(height=9, width=9, link=False, bounding_box='fit',
features=None, node_size=1).reshape((9, 9)) features=None, node_size=1).reshape((9, 9))
expected = np.array([[0, 0, 0, 0, 0, 0, 0, 1, 1], expected = np.array([[0, 0, 0, 0, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0, 0, 1, 1],
...@@ -557,3 +550,59 @@ class TestAISTrajectory(unittest.TestCase): ...@@ -557,3 +550,59 @@ class TestAISTrajectory(unittest.TestCase):
[[0.25,1], [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.25,0.5], [0.5,0.25]]]) [[0.25,1], [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.25,0.5], [0.5,0.25]]])
np.testing.assert_array_equal(result, expected) np.testing.assert_array_equal(result, expected)
def test_generate_array_centered(self):
result = self.trajectory.generate_array_from_positions(height=9, width=9, link=False, bounding_box='centered',
features=None, node_size=0).reshape((9, 9))
expected = np.array([[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, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 0, 0]])
np.testing.assert_array_equal(result, expected)
def test_generate_array_bounding_box(self):
result = self.trajectory.generate_array_from_positions(height=9, width=9, link=False, bounding_box=[(0, 0), (10,10)],
features=None, node_size=0).reshape((9, 9))
expected = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 1],
[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, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 0, 0]])
np.testing.assert_array_equal(result, expected)
def test_generate_array_from_positions_with_line_grey_scale(self):
trajectory = AISTrajectory(
pd.DataFrame(
{
"latitude": [0, 10, 0, 20],
"longitude": [0, 10, 20, 20],
"ts_sec": [i for i in range(4)],
"sog": [10,10,20,40]
}
)
)
result = trajectory.generate_array_from_positions(height=9, width=18, link=True, bounding_box='fit',
features=("sog", (0,80)), node_size=0).reshape((9, 18))
expected = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5],
[0, 0, 0, 0, 0, 0, 0, 0.25, 0.25, 0.25, 0, 0, 0, 0, 0, 0, 0, 0.5],
[0, 0, 0, 0, 0, 0.25, 0.25, 0, 0, 0, 0.25, 0.25, 0, 0, 0, 0, 0, 0.5],
[0, 0, 0, 0.25, 0.25, 0, 0, 0, 0, 0, 0, 0, 0.25, 0.25, 0, 0, 0, 0.5],
[0, 0.25, 0.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.25, 0.25, 0, 0.5],
[0.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.25, 0.5]])/2
np.testing.assert_array_equal(result, expected)
\ 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