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
abd34a4f
Commit
abd34a4f
authored
Apr 8, 2022
by
Raphael Sturgis
Browse files
Options
Downloads
Patches
Plain Diff
set boundaries for image and features
parent
51f21ad4
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
+18
-9
18 additions, 9 deletions
skais/ais/ais_trajectory.py
skais/tests/ais/test_ais_trajectory.py
+31
-21
31 additions, 21 deletions
skais/tests/ais/test_ais_trajectory.py
with
49 additions
and
30 deletions
skais/ais/ais_trajectory.py
+
18
−
9
View file @
abd34a4f
...
...
@@ -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,12 +236,11 @@ class AISTrajectory(AISPoints):
node_size
=
0
):
nb_channels
=
1
if
bounding_box
==
'
fit
'
:
positions
=
self
.
df
[[
'
longitude
'
,
'
latitude
'
]].
to_numpy
()
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
'
:
positions
=
self
.
df
[[
'
longitude
'
,
'
latitude
'
]].
to_numpy
()
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
]))
...
...
@@ -253,7 +252,11 @@ class AISTrajectory(AISPoints):
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
}
"
)
...
...
@@ -291,17 +294,23 @@ class AISTrajectory(AISPoints):
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
]
...
...
This diff is collapsed.
Click to expand it.
skais/tests/ais/test_ais_trajectory.py
+
31
−
21
View file @
abd34a4f
...
...
@@ -380,6 +380,7 @@ class TestAISTrajectory(unittest.TestCase):
self
.
assertListEqual
(
result
,
expected
)
class
TestAISTrajectoryImageGeneration
(
unittest
.
TestCase
):
def
setUp
(
self
)
->
None
:
self
.
trajectory
=
AISTrajectory
(
...
...
@@ -408,7 +409,6 @@ 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
'
,
features
=
None
,
node_size
=
1
).
reshape
((
9
,
9
))
expected
=
np
.
array
([[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
,
1
],
...
...
@@ -539,15 +539,24 @@ class TestAISTrajectoryImageGeneration(unittest.TestCase):
result
=
trajectory
.
generate_array_from_positions
(
height
=
9
,
width
=
18
,
link
=
True
,
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
]],
[[
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
]],
[[
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
]],
[[
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
]],
[[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.25
,
1
],
[
0.25
,
0.5
],
[
0.25
,
0.5
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.5
,
0.25
]],
[[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.25
,
1
],
[
0.25
,
1
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.25
,
0.5
],
[
0.25
,
0.5
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.5
,
0.25
]],
[[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.25
,
1
],
[
0.25
,
1
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.25
,
0.5
],
[
0.25
,
0.5
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.5
,
0.25
]],
[[
0
,
0
],
[
0.25
,
1
],
[
0.25
,
1
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.25
,
0.5
],
[
0.25
,
0.5
],
[
0
,
0
],
[
0.5
,
0.25
]],
[[
0.25
,
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.25
,
0.5
],
[
0.5
,
0.25
]]])
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
]],
[[
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
]],
[[
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
]],
[[
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
]],
[[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.25
,
1
],
[
0.25
,
0.5
],
[
0.25
,
0.5
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.5
,
0.25
]],
[[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.25
,
1
],
[
0.25
,
1
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.25
,
0.5
],
[
0.25
,
0.5
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.5
,
0.25
]],
[[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.25
,
1
],
[
0.25
,
1
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.25
,
0.5
],
[
0.25
,
0.5
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.5
,
0.25
]],
[[
0
,
0
],
[
0.25
,
1
],
[
0.25
,
1
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.25
,
0.5
],
[
0.25
,
0.5
],
[
0
,
0
],
[
0.5
,
0.25
]],
[[
0.25
,
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.25
,
0.5
],
[
0.5
,
0.25
]]])
np
.
testing
.
assert_array_equal
(
result
,
expected
)
...
...
@@ -567,7 +576,8 @@ 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
,
bounding_box
=
[(
0
,
0
),
(
10
,
10
)],
result
=
self
.
trajectory
.
generate_array_from_positions
(
height
=
9
,
width
=
9
,
link
=
False
,
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
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
],
...
...
@@ -577,11 +587,11 @@ class TestAISTrajectoryImageGeneration(unittest.TestCase):
[
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
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]])
[
1
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
]])
np
.
testing
.
assert_array_equal
(
result
,
expected
)
def
test_generate_array_f
rom_positions_with_line_grey_scale
(
self
):
def
test_generate_array_f
eature_bounds
(
self
):
trajectory
=
AISTrajectory
(
pd
.
DataFrame
(
{
...
...
@@ -594,7 +604,7 @@ 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
).
reshape
((
9
,
18
))
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
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0.5
],
...
...
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