Skip to content
Snippets Groups Projects

Draft: Develop

Open Raphael Sturgis requested to merge develop into main
Files
2
+ 51
22
@@ -62,7 +62,7 @@ def apply_time_sequence(dat, time, func):
def __get_image_value__(features, bounds):
value = []
for f, b in zip(features, bounds):
value.append(1 - (b[1] - f) / b[1])
value.append(1 - (b[1] - f - b[0]) / (b[1] - b[0]))
return value
@@ -236,22 +236,42 @@ class AISTrajectory(AISPoints):
node_size=0):
nb_channels = 1
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]))
if min_lat == max_lat:
min_lat -= 1
max_lat += 1
if min_lon == max_lon:
min_lon -= 1
max_lon += 1
if bounding_box == 'fit':
lower_lon, upper_lon = (min(positions[:, 0]), max(positions[:, 0]))
lower_lat, upper_lat = (min(positions[:, 1]), max(positions[:, 1]))
elif bounding_box == 'centered':
center_lon, center_lat = positions[-1]
min_lon, max_lon = (min(positions[:, 0]), max(positions[:, 0]))
min_lat, max_lat = (min(positions[:, 1]), max(positions[:, 1]))
distance_to_center = max(center_lon - min_lon, max_lon - center_lon, center_lat - min_lat,
max_lat - center_lat)
upper_lat = center_lat + distance_to_center
lower_lat = center_lat - distance_to_center
upper_lon = center_lon + distance_to_center
lower_lon = center_lon - distance_to_center
elif type(bounding_box) is list:
upper_lon = bounding_box[1][0]
lower_lon = bounding_box[0][0]
upper_lat = bounding_box[1][1]
lower_lat = bounding_box[0][1]
else:
raise ValueError(f"Option not supported: {bounding_box}")
if lower_lat == upper_lat:
lower_lat -= 1
upper_lat += 1
if lower_lon == upper_lon:
lower_lon -= 1
upper_lon += 1
if features is None:
data = np.zeros((height, width, nb_channels), dtype=np.uint8)
for longitude, latitude in positions:
x_coord, y_coord = get_coord(latitude, longitude, height, width, min_lat, max_lat, min_lon, max_lon)
x_coord, y_coord = get_coord(latitude, longitude, height, width, lower_lat, upper_lat, lower_lon,
upper_lon)
x_lower_bound = max(0, x_coord - node_size)
x_upper_bound = min(height - 1, x_coord + node_size)
@@ -265,30 +285,38 @@ class AISTrajectory(AISPoints):
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)
x_prv, y_prev = get_coord(lat, lon, height, width, lower_lat, upper_lat, lower_lon, upper_lon)
x_nxt, y_nxt = get_coord(latitude, longitude, height, width, lower_lat, upper_lat, lower_lon,
upper_lon)
lon, lat = longitude, latitude
for x, y in bresenham(x_prv, y_prev, x_nxt, y_nxt):
data[x, y] = [1]
else:
bounds = []
if type(features) is list:
nb_channels = len(features)
features_vectors = self.df[features].to_numpy()
for c in features_vectors.T:
bounds.append((0, max(c)))
elif type(features) is str:
features = [features]
features_vectors = self.df[[features]].to_numpy()
for c in features_vectors.T:
bounds.append((0, max(c)))
elif type(features) is dict:
bounds = list(features.values())
features_vectors = self.df[features.keys()].to_numpy()
else:
raise TypeError("Type not supported")
data = np.zeros((height, width, nb_channels), dtype=np.float)
features_vectors = self.df[features].to_numpy()
bounds = []
for c in features_vectors.T:
bounds.append((min(c), max(c)))
for pos, f in zip(positions, features_vectors):
latitude = pos[1]
longitude = pos[0]
x_coord, y_coord = get_coord(latitude, longitude, height, width, min_lat, max_lat, min_lon, max_lon)
x_coord, y_coord = get_coord(latitude, longitude, height, width, lower_lat, upper_lat, lower_lon,
upper_lon)
value = __get_image_value__(f, bounds)
x_lower_bound = max(0, x_coord - node_size)
x_upper_bound = min(height - 1, x_coord + node_size)
@@ -307,8 +335,9 @@ class AISTrajectory(AISPoints):
for pos, f in zip(positions[1:], features_vectors[1:]):
latitude = pos[1]
longitude = pos[0]
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)
x_prv, y_prev = get_coord(lat, lon, height, width, lower_lat, upper_lat, lower_lon, upper_lon)
x_nxt, y_nxt = get_coord(latitude, longitude, height, width, lower_lat, upper_lat, lower_lon,
upper_lon)
lon, lat = longitude, latitude
for x, y in bresenham(x_prv, y_prev, x_nxt, y_nxt):
for i, v in enumerate(value):
Loading