diff --git a/skais/ais/ais_trajectory.py b/skais/ais/ais_trajectory.py index e123aff7898a03ad1eff6d03c94f70b3734d1e71..db1cd8f7311fbdd1e17cb2e6afc863d1bdc997c6 100644 --- a/skais/ais/ais_trajectory.py +++ b/skais/ais/ais_trajectory.py @@ -236,6 +236,13 @@ class AISTrajectory(AISPoints): positions = self.df[['longitude', 'latitude']].to_numpy() min_lon, max_lon = (min(positions[:, 0]), max(positions[:, 0])) min_lat, max_lat = (min(positions[:, 1]), max(positions[:, 1])) + if min_lat == max_lat: + min_lat -= 1 + max_lat += 1 + if min_lon == max_lon: + min_lon -= 1 + max_lon += 1 + for longitude, latitude in positions: x_coord, y_coord = get_coord(latitude, longitude, height, width, min_lat, max_lat, min_lon, max_lon) diff --git a/skais/tests/ais/test_ais_trajectory.py b/skais/tests/ais/test_ais_trajectory.py index fe8efc4c087776701515b8036ae9ecf4939e3b27..6f2b6fa628eb4f52844fb2e07a869f223222e6ea 100644 --- a/skais/tests/ais/test_ais_trajectory.py +++ b/skais/tests/ais/test_ais_trajectory.py @@ -453,4 +453,54 @@ class TestAISTrajectory(unittest.TestCase): [0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1]]) + np.testing.assert_array_equal(result, expected) + + def test_generate_array_from_positions_single_point(self): + trajectory = AISTrajectory( + pd.DataFrame( + { + "latitude": [5], + "longitude": [20], + "ts_sec": [0] + } + ) + ) + + result = trajectory.generate_array_from_positions(height=9, width=9, link=False, bounding_box='fit', + features=None).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, 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]]) + + np.testing.assert_array_equal(result, expected) + + def test_generate_array_from_positions_overlapping_points(self): + trajectory = AISTrajectory( + pd.DataFrame( + { + "latitude": [5, 5, 5, 5], + "longitude": [20, 20, 20, 20], + "ts_sec": [0, 1, 2, 3] + } + ) + ) + + result = trajectory.generate_array_from_positions(height=9, width=9, link=False, bounding_box='fit', + features=None).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, 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]]) + np.testing.assert_array_equal(result, expected) \ No newline at end of file