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

links can be black

parent af54ffde
No related branches found
No related tags found
2 merge requests!23Resolve "Links can be black",!13Draft: Develop
This commit is part of merge request !13. Comments created here will be created in the context of that merge request.
......@@ -153,7 +153,8 @@ def generate_points_with_features(data, positions, features_vectors, bounds, nod
@jit(nopython=True)
def generate_links(data, positions, height, width, lower_lat, upper_lat, lower_lon, upper_lon, values, interpolate=False):
def generate_links(data, positions, height, width, lower_lat, upper_lat, lower_lon, upper_lon, values,
link_type=None):
lon, lat = positions[0, 0], positions[0, 1]
current_value = values[0]
......@@ -164,19 +165,24 @@ def generate_links(data, positions, height, width, lower_lat, upper_lat, lower_l
x_nxt, y_nxt = get_coord(latitude, longitude, height, width, lower_lat, upper_lat, lower_lon,
upper_lon)
lon, lat = longitude, latitude
if interpolate and (nxt_value != current_value).all() and (x_prv != x_nxt) and (y_prev!= y_nxt):
dist = dist_on_grid(x_prv, y_prev, x_nxt, y_nxt)
for x, y in bresenham(x_prv, y_prev, x_nxt, y_nxt):
dist_prev = dist_on_grid(x_prv, y_prev, x, y)
dist_next = dist_on_grid(x, y, x_nxt, y_nxt)
pixel_color = current_value * (1-dist_prev/dist) + nxt_value * (1-dist_next/dist)
for i in range(len(pixel_color)):
dist = dist_on_grid(x_prv, y_prev, x_nxt, y_nxt)
for x, y in bresenham(x_prv, y_prev, x_nxt, y_nxt):
dist_prev = dist_on_grid(x_prv, y_prev, x, y)
dist_next = dist_on_grid(x, y, x_nxt, y_nxt)
pixel_color = current_value * (1 - dist_prev / dist) + nxt_value * (1 - dist_next / dist)
for i in range(len(pixel_color)):
if nxt_value[i] == current_value[i]:
data[x, y, i] = current_value[i]
elif link_type == 'interpolate':
data[x, y, i] = pixel_color[i]
else:
for x, y in bresenham(x_prv, y_prev, x_nxt, y_nxt):
for i in range(len(current_value)):
elif link_type == 'previous':
data[x, y, i] = current_value[i]
elif link_type == 'next':
data[x, y, i] = nxt_value[i]
elif link_type == 'solid':
data[x, y, i] = 1
current_value = nxt_value
......@@ -358,8 +364,8 @@ class AISTrajectory(AISPoints):
result.append((row['ts_sec'], current_label))
return result
def generate_array_from_positions(self, height=256, width=256, link=True, bounding_box='fit', ref_index=-1,
features=None, node_size=0, interpolation=False):
def generate_array_from_positions(self, height=256, width=256, link=None, bounding_box='fit', ref_index=-1,
features=None, node_size=0):
positions = self.df[['longitude', 'latitude']].to_numpy()
......@@ -393,14 +399,15 @@ class AISTrajectory(AISPoints):
generate_points(data, positions, height, width, node_size, lower_lat, upper_lat, lower_lon, upper_lon)
if link:
if link is not None:
generate_links(data, positions, height, width, lower_lat, upper_lat, lower_lon, upper_lon,
np.ones((len(positions), 1)))
np.ones((len(positions), 1)), link)
else:
generate_points_with_features(data, positions, features_vectors, np.array(bounds), node_size, height, width,
lower_lat, upper_lat, lower_lon, upper_lon)
if link:
if link is not None:
generate_links(data, positions, height, width, lower_lat, upper_lat, lower_lon, upper_lon,
generate_values(features_vectors, bounds), interpolate=interpolation)
generate_values(features_vectors, bounds), link)
return data
DISABLE_JIT: 1
\ No newline at end of file
import numba
import unittest
from skais.ais.ais_trajectory import *
......@@ -311,12 +312,12 @@ class TestAISTrajectory(unittest.TestCase):
def test_compute_trajectory(self):
times = np.array([i for i in range(0, 3001, 600)] + [i for i in range(4001, 7001, 600)])
self.assertEqual(6, compute_trajectory.py_func(times, 800))
self.assertEqual(6, compute_trajectory(times, 800))
def test_compute_trajectory_empty(self):
times = np.array([])
self.assertEqual(0, compute_trajectory.py_func(times, 800))
self.assertEqual(0, compute_trajectory(times, 800))
def test_apply_func_on_window(self):
self.assertRaises(ValueError, apply_func_on_window, np.arange(10), 0, 0, 'not valid string')
......@@ -394,7 +395,7 @@ class TestAISTrajectoryImageGeneration(unittest.TestCase):
)
def test_generate_array_from_positions(self):
result = self.trajectory.generate_array_from_positions(height=9, width=9, link=False, bounding_box='fit',
result = self.trajectory.generate_array_from_positions(height=9, width=9, link=None, bounding_box='fit',
features=None, node_size=0).reshape((9, 9))
expected = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
......@@ -409,7 +410,7 @@ class TestAISTrajectoryImageGeneration(unittest.TestCase):
np.testing.assert_array_equal(result, expected)
def test_generate_array_from_positions_node_size(self):
result = self.trajectory.generate_array_from_positions(height=9, width=9, link=False, bounding_box='fit',
result = self.trajectory.generate_array_from_positions(height=9, width=9, link=None, bounding_box='fit',
features=None, node_size=1).reshape((9, 9))
expected = np.array([[0, 0, 0, 0, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 1, 1],
......@@ -434,7 +435,7 @@ class TestAISTrajectoryImageGeneration(unittest.TestCase):
)
)
result = trajectory.generate_array_from_positions(height=9, width=18, link=True, bounding_box='fit',
result = trajectory.generate_array_from_positions(height=9, width=18, link='solid', bounding_box='fit',
features=None, node_size=0).reshape((9, 18))
expected = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
......@@ -510,7 +511,7 @@ class TestAISTrajectoryImageGeneration(unittest.TestCase):
)
)
result = trajectory.generate_array_from_positions(height=9, width=18, link=True, bounding_box='fit',
result = trajectory.generate_array_from_positions(height=9, width=18, link='previous', bounding_box='fit',
features="sog", node_size=0).reshape((9, 18))
expected = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5],
......@@ -537,7 +538,7 @@ class TestAISTrajectoryImageGeneration(unittest.TestCase):
)
)
result = trajectory.generate_array_from_positions(height=9, width=18, link=True, bounding_box='fit',
result = trajectory.generate_array_from_positions(height=9, width=18, link='previous', bounding_box='fit',
features=['sog', 'cog'], 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]],
......@@ -561,7 +562,7 @@ class TestAISTrajectoryImageGeneration(unittest.TestCase):
np.testing.assert_array_equal(result, expected)
def test_generate_array_centered(self):
result = self.trajectory.generate_array_from_positions(height=9, width=9, link=False, bounding_box='centered',
result = self.trajectory.generate_array_from_positions(height=9, width=9, link=None, bounding_box='centered',
features=None, node_size=0).reshape((9, 9))
expected = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
......@@ -576,7 +577,7 @@ class TestAISTrajectoryImageGeneration(unittest.TestCase):
np.testing.assert_array_equal(result, expected)
def test_generate_array_bounding_box(self):
result = self.trajectory.generate_array_from_positions(height=9, width=9, link=False,
result = self.trajectory.generate_array_from_positions(height=9, width=9, link=None,
bounding_box=[(0, 0), (10, 10)],
features=None, node_size=0).reshape((9, 9))
expected = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 1],
......@@ -603,7 +604,7 @@ class TestAISTrajectoryImageGeneration(unittest.TestCase):
)
)
result = trajectory.generate_array_from_positions(height=9, width=18, link=True, bounding_box='fit',
result = trajectory.generate_array_from_positions(height=9, width=18, link='previous', bounding_box='fit',
features={"sog": (0, 80)}, node_size=0).reshape((9, 18))
expected = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5],
......@@ -614,7 +615,8 @@ class TestAISTrajectoryImageGeneration(unittest.TestCase):
[0, 0, 0, 0.25, 0.25, 0, 0, 0, 0, 0, 0, 0, 0.25, 0.25, 0, 0, 0, 0.5],
[0, 0.25, 0.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.25, 0.25, 0, 0.5],
[0.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.25, 0.5]]) / 2
with np.printoptions(threshold=320):
print(result)
np.testing.assert_array_equal(result, expected)
def test_generate_array_from_positions_with_line_multi_channel_dict(self):
......@@ -630,7 +632,7 @@ class TestAISTrajectoryImageGeneration(unittest.TestCase):
)
)
result = trajectory.generate_array_from_positions(height=9, width=18, link=True, bounding_box='fit',
result = trajectory.generate_array_from_positions(height=9, width=18, link='previous', 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]],
......@@ -665,10 +667,9 @@ class TestAISTrajectoryImageGeneration(unittest.TestCase):
)
)
result = trajectory.generate_array_from_positions(height=9, width=18, link=True, bounding_box='fit',
features={"sog": (0, 80)}, node_size=0,
interpolation='linear').reshape((9, 18))
print(result)
result = trajectory.generate_array_from_positions(height=9, width=18, link='interpolate', bounding_box='fit',
features={"sog": (0, 80)}, node_size=0).reshape((9, 18))
expected = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.46875],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.4375],
......
......@@ -4,97 +4,97 @@ from skais.process.geography import *
class MyTestCase(unittest.TestCase):
def test_to_rad_0(self):
result = to_rad.py_func(0)
result = to_rad(0)
expected = 0
self.assertAlmostEqual(result, expected)
def test_to_rad_90(self):
result = to_rad.py_func(90)
result = to_rad(90)
expected = np.pi / 2
self.assertAlmostEqual(result, expected)
def test_to_rad_180(self):
result = to_rad.py_func(180)
result = to_rad(180)
expected = np.pi
self.assertAlmostEqual(result, expected)
def test_to_rad_360(self):
result = to_rad.py_func(360)
result = to_rad(360)
expected = 2 * np.pi
self.assertAlmostEqual(result, expected)
def test_to_rad_m180(self):
result = to_rad.py_func(-180)
result = to_rad(-180)
expected = -np.pi
self.assertAlmostEqual(result, expected)
def test_to_rad_m90(self):
result = to_rad.py_func(-90)
result = to_rad(-90)
expected = -np.pi / 2
self.assertAlmostEqual(result, expected)
def test_to_rad_270(self):
result = to_rad.py_func(270)
result = to_rad(270)
expected = 3 * np.pi / 2
self.assertAlmostEqual(result, expected)
def test_to_rad_810(self):
result = to_rad.py_func(810)
result = to_rad(810)
expected = 9 * np.pi / 2
self.assertAlmostEqual(result, expected)
def test_to_deg_0(self):
result = to_deg.py_func(0)
result = to_deg(0)
expected = 0
self.assertAlmostEqual(result, expected)
def test_to_deg_90(self):
result = to_deg.py_func(np.pi / 2)
result = to_deg(np.pi / 2)
expected = 90
self.assertAlmostEqual(result, expected)
def test_to_deg_180(self):
result = to_deg.py_func(np.pi)
result = to_deg(np.pi)
expected = 180
self.assertAlmostEqual(result, expected)
def test_to_deg_360(self):
result = to_deg.py_func(2 * np.pi)
result = to_deg(2 * np.pi)
expected = 360
self.assertAlmostEqual(result, expected)
def test_to_deg_m180(self):
result = to_deg.py_func(-np.pi)
result = to_deg(-np.pi)
expected = -180
self.assertAlmostEqual(result, expected)
def test_to_deg_m90(self):
result = to_deg.py_func(-np.pi / 2)
result = to_deg(-np.pi / 2)
expected = -90
self.assertAlmostEqual(result, expected)
def test_to_deg_270(self):
result = to_deg.py_func(3 * np.pi / 2)
result = to_deg(3 * np.pi / 2)
expected = 270
self.assertAlmostEqual(result, expected)
def test_to_deg_810(self):
result = to_deg.py_func(9 * np.pi / 2)
result = to_deg(9 * np.pi / 2)
expected = 810
self.assertAlmostEqual(result, expected)
......@@ -103,7 +103,7 @@ class MyTestCase(unittest.TestCase):
paris = (2.3522, 48.8566)
marseille = (5.3698, 43.2965)
result = bearing.py_func(paris, marseille)
result = bearing(paris, marseille)
expected = 158.2694
self.assertAlmostEqual(result, expected, places=4)
......@@ -112,7 +112,7 @@ class MyTestCase(unittest.TestCase):
p1 = (0, 0)
p2 = (90, 0)
result = bearing.py_func(p1, p2)
result = bearing(p1, p2)
expected = 90
self.assertAlmostEqual(result, expected)
......@@ -121,7 +121,7 @@ class MyTestCase(unittest.TestCase):
p1 = (0, 0)
p2 = (0, 90)
result = bearing.py_func(p1, p2)
result = bearing(p1, p2)
expected = 0
self.assertAlmostEqual(result, expected)
......@@ -131,28 +131,28 @@ class MyTestCase(unittest.TestCase):
p2 = (0, 0)
p3 = (10, 0)
self.assertAlmostEqual(90, angle_between_three_points.py_func(p1, p2, p3), places=3)
self.assertAlmostEqual(90, angle_between_three_points(p1, p2, p3), places=3)
def test_angle_between_three_points_2(self):
p1 = (0, -10)
p2 = (0, 0)
p3 = (-10, 0)
self.assertAlmostEqual(-90, angle_between_three_points.py_func(p1, p2, p3), places=3)
self.assertAlmostEqual(-90, angle_between_three_points(p1, p2, p3), places=3)
def test_angle_between_three_points_3(self):
p1 = (0, -10)
p2 = (0, 0)
p3 = (10, 10)
self.assertAlmostEqual(180 - 44.56139, angle_between_three_points.py_func(p1, p2, p3), places=3)
self.assertAlmostEqual(180 - 44.56139, angle_between_three_points(p1, p2, p3), places=3)
def test_angle_between_three_points_4(self):
p1 = (0, 0)
p2 = (0, 10)
p3 = (0, 0)
self.assertAlmostEqual(0, abs(angle_between_three_points.py_func(p1, p2, p3)), places=3)
self.assertAlmostEqual(0, abs(angle_between_three_points(p1, p2, p3)), places=3)
def test_compute_point_angles(self):
dat = np.array([(0, 0), (0, 10), (10, 10), (0, 10)])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment