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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Raphael Sturgis
skais
Merge requests
!20
Resolve "Improve performances of image generation"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Improve performances of image generation"
24-improve-performances-of-image-generation
into
develop
Overview
0
Commits
3
Pipelines
0
Changes
3
Merged
Raphael Sturgis
requested to merge
24-improve-performances-of-image-generation
into
develop
3 years ago
Overview
0
Commits
3
Pipelines
0
Changes
3
Expand
Closes
#24 (closed)
0
0
Merge request reports
Compare
develop
develop (base)
and
latest version
latest version
55e29634
3 commits,
3 years ago
3 files
+
147
−
111
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
skais/ais/ais_trajectory.py
+
142
−
111
Options
@@ -60,13 +60,125 @@ def apply_time_sequence(dat, time, func):
return
result
@jit
(
nopython
=
True
)
def
__get_image_value__
(
features
,
bounds
):
value
=
[]
value
=
np
.
zeros
((
len
(
features
)))
i
=
0
for
f
,
b
in
zip
(
features
,
bounds
):
value
.
append
(
1
-
(
b
[
1
]
-
f
-
b
[
0
])
/
(
b
[
1
]
-
b
[
0
]))
value
[
i
]
=
(
1
-
(
b
[
1
]
-
f
-
b
[
0
])
/
(
b
[
1
]
-
b
[
0
]))
i
=
i
+
1
return
value
def
__get_bounding_box__
(
bounding_box
,
positions
,
ref_index
):
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
[
ref_index
]
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
:
if
type
(
bounding_box
[
0
])
is
not
numbers
.
Number
:
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
:
center_lon
,
center_lat
=
positions
[
ref_index
]
distance_to_center_lon
=
bounding_box
[
0
]
distance_to_center_lat
=
bounding_box
[
1
]
upper_lat
=
center_lat
+
distance_to_center_lat
lower_lat
=
center_lat
-
distance_to_center_lat
upper_lon
=
center_lon
+
distance_to_center_lon
lower_lon
=
center_lon
-
distance_to_center_lon
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
return
lower_lon
,
upper_lon
,
lower_lat
,
upper_lat
@jit
(
nopython
=
True
)
def
generate_points
(
data
,
positions
,
height
,
width
,
node_size
,
lower_lat
,
upper_lat
,
lower_lon
,
upper_lon
):
for
longitude
,
latitude
in
positions
:
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
)
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
):
data
[
x
,
y
]
=
[
1
]
@jit
(
nopython
=
True
)
def
generate_links
(
data
,
positions
,
height
,
width
,
lower_lat
,
upper_lat
,
lower_lon
,
upper_lon
):
lon
,
lat
=
positions
[
0
,
0
],
positions
[
0
,
1
]
for
longitude
,
latitude
in
positions
[
1
:]:
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
]
@jit
(
nopython
=
True
)
def
generate_points_with_features
(
data
,
positions
,
features_vectors
,
bounds
,
node_size
,
height
,
width
,
lower_lat
,
upper_lat
,
lower_lon
,
upper_lon
,
link
):
for
pos
,
f
in
zip
(
positions
,
features_vectors
):
latitude
=
pos
[
1
]
longitude
=
pos
[
0
]
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
)
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
,
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
):
data
[
x
,
y
,
i
]
=
v
value
=
__get_image_value__
(
f
,
bounds
)
class
AISTrajectory
(
AISPoints
):
def
__init__
(
self
,
df
,
mmsi
=
0
,
interpolation_time
=
None
):
df
=
df
.
drop_duplicates
(
subset
=
[
'
ts_sec
'
])
@@ -233,125 +345,44 @@ 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
):
nb_channels
=
1
def
generate_array_from_positions
(
self
,
height
=
256
,
width
=
256
,
link
=
True
,
bounding_box
=
'
fit
'
,
ref_index
=-
1
,
features
=
None
,
node_size
=
0
):
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
'
:
center_lon
,
center_lat
=
positions
[
ref_index
]
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
:
if
type
(
bounding_box
[
0
])
is
not
numbers
.
Number
:
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
:
center_lon
,
center_lat
=
positions
[
ref_index
]
distance_to_center_lon
=
bounding_box
[
0
]
distance_to_center_lat
=
bounding_box
[
1
]
upper_lat
=
center_lat
+
distance_to_center_lat
lower_lat
=
center_lat
-
distance_to_center_lat
upper_lon
=
center_lon
+
distance_to_center_lon
lower_lon
=
center_lon
-
distance_to_center_lon
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
lower_lon
,
upper_lon
,
lower_lat
,
upper_lat
=
__get_bounding_box__
(
bounding_box
,
positions
,
ref_index
)
bounds
=
[]
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
,
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
)
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
):
data
[
x
,
y
]
=
[
1
]
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
,
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
]
features_vectors
=
None
elif
type
(
features
)
is
list
:
features_vectors
=
self
.
df
[
features
].
to_numpy
()
for
c
in
features_vectors
.
T
:
bounds
.
append
((
0
,
max
(
c
)))
elif
type
(
features
)
is
str
:
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
:
bounds
=
[]
if
type
(
features
)
is
list
:
features_vectors
=
self
.
df
[
features
].
to_numpy
()
for
c
in
features_vectors
.
T
:
bounds
.
append
((
0
,
max
(
c
)))
elif
type
(
features
)
is
str
:
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
"
)
raise
TypeError
(
"
Type not supported
"
)
if
features_vectors
is
not
None
:
nb_channels
=
len
(
features_vectors
.
T
)
data
=
np
.
zeros
((
height
,
width
,
nb_channels
),
dtype
=
np
.
float
)
else
:
nb_channels
=
1
data
=
np
.
zeros
((
height
,
width
,
nb_channels
),
dtype
=
np
.
float
)
for
pos
,
f
in
zip
(
positions
,
features_vectors
):
latitude
=
pos
[
1
]
longitude
=
pos
[
0
]
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
)
if
features_vectors
is
None
:
y_lower_bound
=
max
(
0
,
y_coord
-
node_size
)
y_upper_bound
=
min
(
width
-
1
,
y_coord
+
node_size
)
generate_points
(
data
,
positions
,
height
,
width
,
node_size
,
lower_lat
,
upper_lat
,
lower_lon
,
upper_lon
)
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
,
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
):
data
[
x
,
y
,
i
]
=
v
value
=
__get_image_value__
(
f
,
bounds
)
generate_links
(
data
,
positions
,
height
,
width
,
lower_lat
,
upper_lat
,
lower_lon
,
upper_lon
)
else
:
generate_points_with_features
(
data
,
positions
,
features_vectors
,
bounds
,
node_size
,
height
,
width
,
lower_lat
,
upper_lat
,
lower_lon
,
upper_lon
,
link
)
return
data
Loading