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
69ba597d
Commit
69ba597d
authored
3 years ago
by
Raphael
Browse files
Options
Downloads
Patches
Plain Diff
Added construction of image using images
parent
55ed8761
No related branches found
No related tags found
2 merge requests
!16
Resolve "Creation of images with colored points using features"
,
!13
Draft: Develop
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
skais/ais/ais_trajectory.py
+69
-20
69 additions, 20 deletions
skais/ais/ais_trajectory.py
skais/tests/ais/test_ais_trajectory.py
+1
-1
1 addition, 1 deletion
skais/tests/ais/test_ais_trajectory.py
with
70 additions
and
21 deletions
skais/ais/ais_trajectory.py
+
69
−
20
View file @
69ba597d
...
@@ -59,6 +59,13 @@ def apply_time_sequence(dat, time, func):
...
@@ -59,6 +59,13 @@ def apply_time_sequence(dat, time, func):
return
result
return
result
def
__get_image_value__
(
features
,
bounds
):
value
=
[]
for
f
,
b
in
zip
(
features
,
bounds
):
value
.
append
(
1
-
(
b
[
1
]
-
f
)
/
b
[
1
])
return
value
class
AISTrajectory
(
AISPoints
):
class
AISTrajectory
(
AISPoints
):
def
__init__
(
self
,
df
,
mmsi
=
0
,
interpolation_time
=
None
):
def
__init__
(
self
,
df
,
mmsi
=
0
,
interpolation_time
=
None
):
df
=
df
.
drop_duplicates
(
subset
=
[
'
ts_sec
'
])
df
=
df
.
drop_duplicates
(
subset
=
[
'
ts_sec
'
])
...
@@ -228,9 +235,7 @@ class AISTrajectory(AISPoints):
...
@@ -228,9 +235,7 @@ class AISTrajectory(AISPoints):
def
generate_array_from_positions
(
self
,
height
=
256
,
width
=
256
,
link
=
True
,
bounding_box
=
'
fit
'
,
features
=
None
,
def
generate_array_from_positions
(
self
,
height
=
256
,
width
=
256
,
link
=
True
,
bounding_box
=
'
fit
'
,
features
=
None
,
node_size
=
0
):
node_size
=
0
):
nb_channels
=
1
nb_channels
=
1
if
features
is
not
None
:
nb_channels
=
len
(
features
)
data
=
np
.
zeros
((
height
,
width
,
nb_channels
),
dtype
=
np
.
uint8
)
if
bounding_box
!=
'
fit
'
:
if
bounding_box
!=
'
fit
'
:
raise
ValueError
(
"
feature not implemented
"
)
raise
ValueError
(
"
feature not implemented
"
)
positions
=
self
.
df
[[
'
longitude
'
,
'
latitude
'
]].
to_numpy
()
positions
=
self
.
df
[[
'
longitude
'
,
'
latitude
'
]].
to_numpy
()
...
@@ -243,6 +248,8 @@ class AISTrajectory(AISPoints):
...
@@ -243,6 +248,8 @@ class AISTrajectory(AISPoints):
min_lon
-=
1
min_lon
-=
1
max_lon
+=
1
max_lon
+=
1
if
features
is
None
:
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
,
min_lat
,
max_lat
,
min_lon
,
max_lon
)
...
@@ -255,7 +262,6 @@ class AISTrajectory(AISPoints):
...
@@ -255,7 +262,6 @@ class AISTrajectory(AISPoints):
for
x
in
range
(
x_lower_bound
,
x_upper_bound
+
1
):
for
x
in
range
(
x_lower_bound
,
x_upper_bound
+
1
):
for
y
in
range
(
y_lower_bound
,
y_upper_bound
+
1
):
for
y
in
range
(
y_lower_bound
,
y_upper_bound
+
1
):
data
[
x
,
y
]
=
[
1
]
data
[
x
,
y
]
=
[
1
]
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
:]:
...
@@ -265,4 +271,47 @@ class AISTrajectory(AISPoints):
...
@@ -265,4 +271,47 @@ class AISTrajectory(AISPoints):
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
):
data
[
x
,
y
]
=
[
1
]
data
[
x
,
y
]
=
[
1
]
else
:
if
type
(
features
)
is
list
:
nb_channels
=
len
(
features
)
elif
type
(
features
)
is
str
:
features
=
[
features
]
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
)
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
)
y_lower_bound
=
max
(
0
,
y_coord
-
node_size
)
y_upper_bound
=
min
(
width
-
1
,
y_coord
+
node_size
)
for
x
in
range
(
x_lower_bound
,
x_upper_bound
+
1
):
for
y
in
range
(
y_lower_bound
,
y_upper_bound
+
1
):
for
i
,
v
in
enumerate
(
value
):
data
[
x
,
y
,
i
]
=
v
if
link
:
lon
,
lat
=
positions
[
0
,
0
],
positions
[
0
,
1
]
value
=
__get_image_value__
(
features_vectors
[
0
],
bounds
)
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
)
lon
,
lat
=
longitude
,
latitude
for
x
,
y
in
bresenham
(
x_prv
,
y_prev
,
x_nxt
,
y_nxt
):
for
i
,
v
in
enumerate
(
value
):
data
[
x
,
y
,
i
]
=
v
value
=
__get_image_value__
(
f
,
bounds
)
return
data
return
data
This diff is collapsed.
Click to expand it.
skais/tests/ais/test_ais_trajectory.py
+
1
−
1
View file @
69ba597d
...
@@ -545,7 +545,7 @@ class TestAISTrajectory(unittest.TestCase):
...
@@ -545,7 +545,7 @@ class TestAISTrajectory(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
=
True
,
bounding_box
=
'
fit
'
,
features
=
[
'
sog
'
,
'
cog
'
],
node_size
=
0
)
.
reshape
((
9
,
18
))
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
]],
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
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0
,
0
],
[
0.5
,
0.25
]],
...
...
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