Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Raphael Sturgis
skais
Commits
2ddf04a8
Commit
2ddf04a8
authored
May 16, 2022
by
Raphael Sturgis
Browse files
update
parent
9487015c
Changes
1
Hide whitespace changes
Inline
Side-by-side
skais/ais/ais_trajectory.py
View file @
2ddf04a8
...
...
@@ -53,6 +53,19 @@ def apply_func_on_window(dat, func, radius, on_edge='copy'):
raise
ValueError
def
apply_func_on_window_2
(
dat
,
func
,
radius
):
result
=
np
.
zeros
(
dat
.
shape
[
0
])
for
i
in
range
(
0
,
dat
.
shape
[
0
]):
ts
=
dat
[
i
][
0
]
lower_bound
=
max
(
0
,
np
.
argmin
(
dat
>
(
ts
-
radius
)))
upper_bound
=
np
.
argmax
(
dat
<
ts
+
radius
)
if
upper_bound
==
0
:
upper_bound
=
dat
.
shape
[
0
]
data
=
dat
[
lower_bound
:
upper_bound
]
result
[
i
]
=
func
(
data
)
return
result
def
apply_time_sequence
(
dat
,
time
,
func
):
result
=
np
.
empty
(
dat
.
shape
[
0
])
result
[
0
]
=
func
(
dat
[
0
],
dat
[
1
],
time
[
0
],
time
[
1
])
...
...
@@ -252,6 +265,19 @@ class AISTrajectory(AISPoints):
else
:
self
.
df
[
new_column
]
=
result
def
apply_func_on_time_window_2
(
self
,
func
,
radius
,
column
,
new_column
=
None
):
if
type
(
column
)
is
not
list
:
df_column
=
[
'ts_sec'
,
column
]
else
:
df_column
=
column
+
[
'ts_sec'
]
dat
=
self
.
df
[
df_column
].
to_numpy
()
result
=
apply_func_on_window_2
(
dat
,
func
,
radius
)
if
new_column
is
None
:
self
.
df
[
column
]
=
result
else
:
self
.
df
[
new_column
]
=
result
# TODO rename function/simplify
def
apply_func_on_time_sequence
(
self
,
func
,
column
,
new_column
=
None
):
dat
=
self
.
df
[
column
].
to_numpy
()
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment