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

Merge branch...

Merge branch '25-fix-fix-bug-indexerror-index-1-is-out-of-bounds-when-generating-multi-channel-images' into 'develop'

Resolve "[fix] fix bug "IndexError: index 1 is out of bounds" when generating multi channel images"

See merge request !19
parents 1a00f8f6 6d4024b7
No related branches found
No related tags found
2 merge requests!19Resolve "[fix] fix bug "IndexError: index 1 is out of bounds" when generating multi channel images",!13Draft: Develop
This commit is part of merge request !13. Comments created here will be created in the context of that merge request.
__version__ = "0.1a" __version__ = "0.2a"
...@@ -306,7 +306,6 @@ class AISTrajectory(AISPoints): ...@@ -306,7 +306,6 @@ class AISTrajectory(AISPoints):
else: else:
bounds = [] bounds = []
if type(features) is list: if type(features) is list:
nb_channels = len(features)
features_vectors = self.df[features].to_numpy() features_vectors = self.df[features].to_numpy()
for c in features_vectors.T: for c in features_vectors.T:
bounds.append((0, max(c))) bounds.append((0, max(c)))
...@@ -319,6 +318,8 @@ class AISTrajectory(AISPoints): ...@@ -319,6 +318,8 @@ class AISTrajectory(AISPoints):
features_vectors = self.df[features.keys()].to_numpy() features_vectors = self.df[features.keys()].to_numpy()
else: else:
raise TypeError("Type not supported") raise TypeError("Type not supported")
nb_channels = len(features_vectors.T)
data = np.zeros((height, width, nb_channels), dtype=np.float) data = np.zeros((height, width, nb_channels), dtype=np.float)
......
...@@ -616,3 +616,39 @@ class TestAISTrajectoryImageGeneration(unittest.TestCase): ...@@ -616,3 +616,39 @@ class TestAISTrajectoryImageGeneration(unittest.TestCase):
[0.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.25, 0.5]]) / 2 [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) np.testing.assert_array_equal(result, expected)
def test_generate_array_from_positions_with_line_multi_channel_dict(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],
"cog": [40, 20, 10, 10]
}
)
)
result = trajectory.generate_array_from_positions(height=9, width=18, link=True, bounding_box='fit',
features={'sog': (0, 40), 'cog': (0, 40)}, node_size=0)
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.5, 0.25]],
[[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.5, 0.25]],
[[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.5, 0.25]],
[[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.5, 0.25]],
[[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0.25, 1], [0.25, 0.5],
[0.25, 0.5], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0.5, 0.25]],
[[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0.25, 1], [0.25, 1], [0, 0], [0, 0], [0, 0],
[0.25, 0.5], [0.25, 0.5], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0.5, 0.25]],
[[0, 0], [0, 0], [0, 0], [0.25, 1], [0.25, 1], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
[0, 0], [0, 0], [0.25, 0.5], [0.25, 0.5], [0, 0], [0, 0], [0, 0], [0.5, 0.25]],
[[0, 0], [0.25, 1], [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.25, 0.5], [0.25, 0.5], [0, 0], [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)
\ 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