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
2137c807
Commit
2137c807
authored
3 years ago
by
Raphael Sturgis
Browse files
Options
Downloads
Patches
Plain Diff
restructure AISPoints
parent
9a94e525
No related branches found
No related tags found
1 merge request
!6
Develop
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
skais/ais/ais_points.py
+55
-68
55 additions, 68 deletions
skais/ais/ais_points.py
skais/ais/ais_trajectory.py
+3
-0
3 additions, 0 deletions
skais/ais/ais_trajectory.py
skais/tests/ais/test_ais_points.py
+285
-235
285 additions, 235 deletions
skais/tests/ais/test_ais_points.py
with
343 additions
and
303 deletions
skais/ais/ais_points.py
+
55
−
68
View file @
2137c807
import
pickle
from
datetime
import
datetime
import
pandas
as
pd
import
numpy
as
np
from
numba
import
jit
import
pandas
as
pd
from
scipy.stats
import
stats
from
skais.ais.ais_trajectory
import
AISTrajectory
# TODO: remove
def
compute_trajectories
(
df
,
time_gap
,
min_size
=
50
,
size_limit
=
500
,
interpolation_time
=
None
):
n_sample
=
len
(
df
.
index
)
result
=
[]
work_df
=
df
.
copy
()
index
=
0
while
index
<
n_sample
:
i
=
compute_trajectory
(
df
[
'
ts_sec
'
][
index
:].
to_numpy
(),
time_gap
,
size_limit
)
trajectory
=
AISTrajectory
(
work_df
[:
i
],
interpolation_time
=
interpolation_time
)
if
len
(
trajectory
.
df
.
index
)
>
min_size
:
result
.
append
(
trajectory
)
work_df
=
work_df
[
i
:]
index
+=
i
return
result
# TODO: remove
@jit
(
nopython
=
True
)
def
compute_trajectory
(
times
,
time_gap
,
size_limit
):
n_samples
=
len
(
times
)
previous_date
=
times
[
0
]
i
=
0
for
i
in
range
(
size_limit
):
if
i
>=
n_samples
or
((
times
[
i
]
-
previous_date
)
/
60
>
time_gap
):
return
i
previous_date
=
times
[
i
]
return
i
+
1
# def compute_trajectories(df, time_gap, min_size=50, size_limit=500, interpolation_time=None):
# n_sample = len(df.index)
# result = []
# work_df = df.copy()
#
# index = 0
# while index < n_sample:
# i = compute_trajectory(df['ts_sec'][index:].to_numpy(), time_gap, size_limit)
# trajectory = AISTrajectory(work_df[:i], interpolation_time=interpolation_time)
# if len(trajectory.df.index) > min_size:
# result.append(trajectory)
# work_df = work_df[i:]
# index += i
#
# return result
#
#
# @jit(nopython=True)
# def compute_trajectory(times, time_gap, size_limit):
# n_samples = len(times)
#
# previous_date = times[0]
#
# i = 0
# for i in range(size_limit):
# if i >= n_samples or ((times[i] - previous_date) / 60 > time_gap):
# return i
# previous_date = times[i]
#
# return i + 1
class
AISPoints
:
...
...
@@ -50,6 +45,19 @@ class AISPoints:
self
.
df
=
df
def
describe
(
self
):
description
=
{
"
nb vessels
"
:
len
(
self
.
df
.
mmsi
.
unique
()),
"
nb points
"
:
len
(
self
.
df
.
index
),
"
average speed
"
:
self
.
df
[
'
sog
'
].
mean
(),
"
average diff
"
:
self
.
df
[
'
diff
'
].
mean
()
}
for
n
in
np
.
sort
(
self
.
df
[
'
label
'
].
unique
()):
description
[
f
"
labeled
{
n
}
"
]
=
len
(
self
.
df
[
self
.
df
[
'
label
'
]
==
n
].
index
)
return
description
# cleaning functions
def
remove_outliers
(
self
,
features
,
rank
=
4
):
if
rank
<=
0
:
...
...
@@ -96,43 +104,22 @@ class AISPoints:
return
normalization_type
,
normalization_dict
# New features
# TODO: rename
def
compute_diff_heading_cog
(
self
):
self
.
df
[
"
diff
"
]
=
self
.
df
.
apply
(
lambda
x
:
180
-
abs
(
abs
(
x
[
'
heading
'
]
-
x
[
'
cog
'
])
-
180
),
def
compute_drift
(
self
):
self
.
df
[
"
drift
"
]
=
self
.
df
.
apply
(
lambda
x
:
180
-
abs
(
abs
(
x
[
'
heading
'
]
-
x
[
'
cog
'
])
-
180
),
axis
=
1
)
# Trajectories
"""
Separates AISPoints into individual trajectories
"""
# TODO: redo
def
get_trajectories
(
self
,
time_gap
=
30
,
min_size
=
50
,
interpolation_time
=
None
):
if
'
ts
'
in
self
.
df
:
self
.
df
[
'
ts
'
]
=
pd
.
to_datetime
(
self
.
df
[
'
ts
'
],
infer_datetime_format
=
True
)
self
.
df
[
'
ts_sec
'
]
=
self
.
df
[
'
ts
'
].
apply
(
lambda
x
:
datetime
.
timestamp
(
x
))
dat
=
self
.
df
else
:
raise
ValueError
def
get_trajectories
(
self
):
trajectories
=
[]
for
mmsi
in
dat
.
mmsi
.
unique
():
trajectories
+=
compute_trajectories
(
dat
[
dat
[
'
mmsi
'
]
==
mmsi
],
time_gap
,
min_size
=
min_size
,
interpolation_time
=
interpolation_time
)
for
mmsi
in
self
.
df
.
mmsi
.
unique
():
trajectories
.
append
(
AISTrajectory
(
self
.
df
[
self
.
df
[
'
mmsi
'
]
==
mmsi
].
reset_index
(
drop
=
True
)))
return
trajectories
def
describe
(
self
):
stats
=
{
"
nb vessels
"
:
len
(
self
.
df
.
mmsi
.
unique
()),
"
nb points
"
:
len
(
self
.
df
.
index
),
"
average speed
"
:
self
.
df
[
'
sog
'
].
mean
(),
"
average diff
"
:
self
.
df
[
'
diff
'
].
mean
()
}
for
n
in
np
.
sort
(
self
.
df
[
'
label
'
].
unique
()):
stats
[
f
"
labeled
{
n
}
"
]
=
len
(
self
.
df
[
self
.
df
[
'
label
'
]
==
n
].
index
)
return
stats
# Static methods
@staticmethod
def
fuse
(
*
args
):
...
...
This diff is collapsed.
Click to expand it.
skais/ais/ais_trajectory.py
+
3
−
0
View file @
2137c807
...
...
@@ -245,6 +245,9 @@ class AISTrajectory:
# self.df = df.dropna()
self
.
df
=
df
def
__eq__
(
self
,
other
):
return
self
.
df
.
equals
(
other
.
df
)
def
compute_angle_l1
(
self
,
radius
):
dat
=
self
.
df
[
'
angles_diff
'
].
to_numpy
()
l1
=
l1_angle
(
dat
,
radius
)
...
...
This diff is collapsed.
Click to expand it.
skais/tests/ais/test_ais_points.py
+
285
−
235
View file @
2137c807
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