Skip to content
Snippets Groups Projects

Resolve "Creation of images from AIS"

Merged Raphael Sturgis requested to merge 16-creation-of-images-from-ais into develop
5 files
+ 219
7
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -5,8 +5,9 @@ import numpy as np
from numba import jit
from scipy.interpolate import interp1d
from skais.utils.geography import great_circle, position_from_distance
from skais.utils.geography import great_circle, position_from_distance, get_coord
from skais.ais.ais_points import AISPoints
from skais.utils.geometry import bresenham
@jit(nopython=True)
@@ -41,7 +42,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 +223,39 @@ 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,
node_size=0):
nb_channels = 1
if features is not None:
nb_channels = len(features)
data = np.zeros((height, width, nb_channels), dtype=np.uint8)
if bounding_box != 'fit':
raise ValueError("feature not implemented")
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]))
for longitude, latitude in positions:
x_coord, y_coord = get_coord(latitude, longitude, height, width, min_lat, max_lat, min_lon, max_lon)
x_lower_bound = max(0, x_coord - node_size)
x_upper_bound = min(height - 1, x_coord + node_size)
y_lower_bound = max(0, y_coord - node_size)
y_upper_bound = min(width - 1, y_coord + node_size)
for x in range(x_lower_bound, x_upper_bound + 1):
for y in range(y_lower_bound, y_upper_bound + 1):
data[x, y] = [1]
if link:
lon, lat = positions[0, 0], positions[0, 1]
for longitude, latitude in positions[1:]:
x_prv, y_prev = get_coord(lat, lon, height, width, min_lat, max_lat, min_lon, max_lon)
x_nxt, y_nxt = get_coord(latitude, longitude, height, width, min_lat, max_lat, min_lon, max_lon)
lon, lat = longitude, latitude
for x, y in bresenham(x_prv, y_prev, x_nxt, y_nxt):
data[x, y] = [1]
return data
Loading