Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
skais
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Raphael Sturgis
skais
Commits
51f21ad4
Commit
51f21ad4
authored
3 years ago
by
Raphael Sturgis
Browse files
Options
Downloads
Patches
Plain Diff
centered
parent
382329d1
No related branches found
No related tags found
2 merge requests
!17
Resolve "Functionality for experiments using CNNs"
,
!13
Draft: Develop
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
skais/ais/ais_trajectory.py
+37
-17
37 additions, 17 deletions
skais/ais/ais_trajectory.py
skais/tests/ais/test_ais_trajectory.py
+4
-4
4 additions, 4 deletions
skais/tests/ais/test_ais_trajectory.py
with
41 additions
and
21 deletions
skais/ais/ais_trajectory.py
+
37
−
17
View file @
51f21ad4
...
@@ -236,22 +236,39 @@ class AISTrajectory(AISPoints):
...
@@ -236,22 +236,39 @@ class AISTrajectory(AISPoints):
node_size
=
0
):
node_size
=
0
):
nb_channels
=
1
nb_channels
=
1
if
bounding_box
!=
'
fit
'
:
if
bounding_box
==
'
fit
'
:
raise
ValueError
(
"
feature not implemented
"
)
positions
=
self
.
df
[[
'
longitude
'
,
'
latitude
'
]].
to_numpy
()
positions
=
self
.
df
[[
'
longitude
'
,
'
latitude
'
]].
to_numpy
()
lower_lon
,
upper_lon
=
(
min
(
positions
[:,
0
]),
max
(
positions
[:,
0
]))
lower_lat
,
upper_lat
=
(
min
(
positions
[:,
1
]),
max
(
positions
[:,
1
]))
elif
bounding_box
==
'
centered
'
:
positions
=
self
.
df
[[
'
longitude
'
,
'
latitude
'
]].
to_numpy
()
center_lon
,
center_lat
=
positions
[
-
1
]
min_lon
,
max_lon
=
(
min
(
positions
[:,
0
]),
max
(
positions
[:,
0
]))
min_lon
,
max_lon
=
(
min
(
positions
[:,
0
]),
max
(
positions
[:,
0
]))
min_lat
,
max_lat
=
(
min
(
positions
[:,
1
]),
max
(
positions
[:,
1
]))
min_lat
,
max_lat
=
(
min
(
positions
[:,
1
]),
max
(
positions
[:,
1
]))
if
min_lat
==
max_lat
:
min_lat
-=
1
distance_to_center
=
max
(
center_lon
-
min_lon
,
max_lon
-
center_lon
,
center_lat
-
min_lat
,
max_lat
+=
1
max_lat
-
center_lat
)
if
min_lon
==
max_lon
:
min_lon
-=
1
upper_lat
=
center_lat
+
distance_to_center
max_lon
+=
1
lower_lat
=
center_lat
-
distance_to_center
upper_lon
=
center_lon
+
distance_to_center
lower_lon
=
center_lon
-
distance_to_center
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
:
if
features
is
None
:
data
=
np
.
zeros
((
height
,
width
,
nb_channels
),
dtype
=
np
.
uint8
)
data
=
np
.
zeros
((
height
,
width
,
nb_channels
),
dtype
=
np
.
uint8
)
for
longitude
,
latitude
in
positions
:
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_lower_bound
=
max
(
0
,
x_coord
-
node_size
)
x_upper_bound
=
min
(
height
-
1
,
x_coord
+
node_size
)
x_upper_bound
=
min
(
height
-
1
,
x_coord
+
node_size
)
...
@@ -265,8 +282,9 @@ class AISTrajectory(AISPoints):
...
@@ -265,8 +282,9 @@ class AISTrajectory(AISPoints):
if
link
:
if
link
:
lon
,
lat
=
positions
[
0
,
0
],
positions
[
0
,
1
]
lon
,
lat
=
positions
[
0
,
0
],
positions
[
0
,
1
]
for
longitude
,
latitude
in
positions
[
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_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
,
min_lat
,
max_lat
,
min_lon
,
max_lon
)
x_nxt
,
y_nxt
=
get_coord
(
latitude
,
longitude
,
height
,
width
,
lower_lat
,
upper_lat
,
lower_lon
,
upper_lon
)
lon
,
lat
=
longitude
,
latitude
lon
,
lat
=
longitude
,
latitude
for
x
,
y
in
bresenham
(
x_prv
,
y_prev
,
x_nxt
,
y_nxt
):
for
x
,
y
in
bresenham
(
x_prv
,
y_prev
,
x_nxt
,
y_nxt
):
...
@@ -288,7 +306,8 @@ class AISTrajectory(AISPoints):
...
@@ -288,7 +306,8 @@ class AISTrajectory(AISPoints):
for
pos
,
f
in
zip
(
positions
,
features_vectors
):
for
pos
,
f
in
zip
(
positions
,
features_vectors
):
latitude
=
pos
[
1
]
latitude
=
pos
[
1
]
longitude
=
pos
[
0
]
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
)
value
=
__get_image_value__
(
f
,
bounds
)
x_lower_bound
=
max
(
0
,
x_coord
-
node_size
)
x_lower_bound
=
max
(
0
,
x_coord
-
node_size
)
x_upper_bound
=
min
(
height
-
1
,
x_coord
+
node_size
)
x_upper_bound
=
min
(
height
-
1
,
x_coord
+
node_size
)
...
@@ -307,8 +326,9 @@ class AISTrajectory(AISPoints):
...
@@ -307,8 +326,9 @@ class AISTrajectory(AISPoints):
for
pos
,
f
in
zip
(
positions
[
1
:],
features_vectors
[
1
:]):
for
pos
,
f
in
zip
(
positions
[
1
:],
features_vectors
[
1
:]):
latitude
=
pos
[
1
]
latitude
=
pos
[
1
]
longitude
=
pos
[
0
]
longitude
=
pos
[
0
]
x_prv
,
y_prev
=
get_coord
(
lat
,
lon
,
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
,
min_lat
,
max_lat
,
min_lon
,
max_lon
)
x_nxt
,
y_nxt
=
get_coord
(
latitude
,
longitude
,
height
,
width
,
lower_lat
,
upper_lat
,
lower_lon
,
upper_lon
)
lon
,
lat
=
longitude
,
latitude
lon
,
lat
=
longitude
,
latitude
for
x
,
y
in
bresenham
(
x_prv
,
y_prev
,
x_nxt
,
y_nxt
):
for
x
,
y
in
bresenham
(
x_prv
,
y_prev
,
x_nxt
,
y_nxt
):
for
i
,
v
in
enumerate
(
value
):
for
i
,
v
in
enumerate
(
value
):
...
...
This diff is collapsed.
Click to expand it.
skais/tests/ais/test_ais_trajectory.py
+
4
−
4
View file @
51f21ad4
...
@@ -554,15 +554,15 @@ class TestAISTrajectoryImageGeneration(unittest.TestCase):
...
@@ -554,15 +554,15 @@ class TestAISTrajectoryImageGeneration(unittest.TestCase):
def
test_generate_array_centered
(
self
):
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
=
False
,
bounding_box
=
'
centered
'
,
features
=
None
,
node_size
=
0
).
reshape
((
9
,
9
))
features
=
None
,
node_size
=
0
).
reshape
((
9
,
9
))
expected
=
np
.
array
([[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
],
expected
=
np
.
array
([[
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
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
,
1
,
0
,
1
],
[
0
,
0
,
0
,
0
,
0
,
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
,
1
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
1
,
0
,
1
,
0
,
0
,
0
,
0
],
[
0
,
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
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]])
np
.
testing
.
assert_array_equal
(
result
,
expected
)
np
.
testing
.
assert_array_equal
(
result
,
expected
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment