Skip to content
Snippets Groups Projects
Commit 71ab7a04 authored by Raphael's avatar Raphael
Browse files

refactoring for getting coordinate in array

parent 9c4e8021
Branches
Tags
3 merge requests!12version 0.2a,!10Resolve "Image creation bugs with 0 size windows",!9Resolve "Creation of images from AIS"
This commit is part of merge request !9. Comments created here will be created in the context of that merge request.
......@@ -5,7 +5,7 @@ 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
......@@ -229,16 +229,13 @@ class AISTrajectory(AISPoints):
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]))
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 = max(min(height - int(height * (latitude - range_latitude[0]) / (range_latitude[1] - range_latitude[0])) - 1, height - 1), 0)
y_coord = max(min(int((width - 1) * (longitude - range_longitude[0]) / (range_longitude[1] - range_longitude[0])), width - 1), 0)
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)
......@@ -249,4 +246,7 @@ class AISTrajectory(AISPoints):
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:
raise ValueError("feature not implemented")
return data
......@@ -23,6 +23,13 @@ def great_circle(lat1, lat2, long1, long2):
return d
def get_coord(lat, lon, height, width, min_lat, max_lat, min_lon, max_lon):
x_coord = max(min(height - int(height * (lat - min_lat) / (max_lat - min_lat)) - 1, height - 1), 0)
y_coord = max(min(int((width - 1) * (lon - min_lon) / (max_lon - min_lon)), width - 1), 0)
return x_coord, y_coord
def position_from_distance(position, distances):
lat = np.arcsin(
np.sin(np.radians(position[0])) * np.cos(distances[0] / R) + np.cos(np.radians(position[0])) * np.sin(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment