From fe57f69e95eb91df0e3d79ff8c915ef0eeffaa84 Mon Sep 17 00:00:00 2001
From: Raphael Sturgis <raphael.sturgis@lis-lab.fr>
Date: Mon, 21 Mar 2022 07:15:47 +0100
Subject: [PATCH] implementation of generate_array_from_positions

---
 skais/ais/ais_trajectory.py | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/skais/ais/ais_trajectory.py b/skais/ais/ais_trajectory.py
index f836472..18ad39c 100644
--- a/skais/ais/ais_trajectory.py
+++ b/skais/ais/ais_trajectory.py
@@ -41,7 +41,7 @@ def apply_func_on_window(dat, func, radius, on_edge='copy'):
         return result
     elif on_edge == 'ignore':
         for i in range(0, dat.shape[0]):
-            lower_bound = max(0, i-radius)
+            lower_bound = max(0, i - radius)
             upper_bound = min(dat.shape[0], i + radius + 1)
             data = dat[lower_bound:upper_bound]
             result[i] = func(data)
@@ -222,4 +222,22 @@ class AISTrajectory(AISPoints):
             if current_label != row[label_column]:
                 current_label = row[label_column]
                 result.append((row['ts_sec'], current_label))
-        return result
\ No newline at end of file
+        return result
+
+    def generate_array_from_positions(self, height=256, width=256, link=True, bounding_box='fit', features=None):
+        nb_channels = 1
+        if features is not None:
+            nb_channels = len(features)
+        data = np.zeros((height, width, nb_channels), dtype=np.uint8)
+        if link:
+            raise ValueError("feature not implemented")
+        if bounding_box != 'fit':
+            raise ValueError("feature not implemented")
+        positions = self.df[['longitude', 'latitude']].to_numpy()
+        range_longitude = (min(positions[0, :]), max(positions[0, :]))
+        range_latitude = (min(positions[1, :]), max(positions[1, :]))
+        for longitude, latitude in positions:
+            x_coord = width * (longitude - range_longitude[0]) / (range_longitude[1] - range_longitude[0])
+            y_coord = height * (longitude - range_latitude[0]) / (range_latitude[1] - range_latitude[0])
+            data[x_coord, y_coord, :] = 1
+        return data
-- 
GitLab