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
Commits
2ddf04a8
Commit
2ddf04a8
authored
3 years ago
by
Raphael Sturgis
Browse files
Options
Downloads
Patches
Plain Diff
update
parent
9487015c
Branches
29-add-apply_func_on_time_window-time-version
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
skais/ais/ais_trajectory.py
+26
-0
26 additions, 0 deletions
skais/ais/ais_trajectory.py
with
26 additions
and
0 deletions
skais/ais/ais_trajectory.py
+
26
−
0
View file @
2ddf04a8
...
@@ -53,6 +53,19 @@ def apply_func_on_window(dat, func, radius, on_edge='copy'):
...
@@ -53,6 +53,19 @@ def apply_func_on_window(dat, func, radius, on_edge='copy'):
raise
ValueError
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
):
def
apply_time_sequence
(
dat
,
time
,
func
):
result
=
np
.
empty
(
dat
.
shape
[
0
])
result
=
np
.
empty
(
dat
.
shape
[
0
])
result
[
0
]
=
func
(
dat
[
0
],
dat
[
1
],
time
[
0
],
time
[
1
])
result
[
0
]
=
func
(
dat
[
0
],
dat
[
1
],
time
[
0
],
time
[
1
])
...
@@ -252,6 +265,19 @@ class AISTrajectory(AISPoints):
...
@@ -252,6 +265,19 @@ class AISTrajectory(AISPoints):
else
:
else
:
self
.
df
[
new_column
]
=
result
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
# TODO rename function/simplify
def
apply_func_on_time_sequence
(
self
,
func
,
column
,
new_column
=
None
):
def
apply_func_on_time_sequence
(
self
,
func
,
column
,
new_column
=
None
):
dat
=
self
.
df
[
column
].
to_numpy
()
dat
=
self
.
df
[
column
].
to_numpy
()
...
...
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