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
58ca07aa
Commit
58ca07aa
authored
3 years ago
by
Raphael
Browse files
Options
Downloads
Patches
Plain Diff
added ignore for apply_func_on_time_window_function
parent
1ba9dceb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!12
version 0.2a
,
!10
Resolve "Image creation bugs with 0 size windows"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
skais/ais/ais_trajectory.py
+9
-2
9 additions, 2 deletions
skais/ais/ais_trajectory.py
skais/tests/ais/test_ais_trajectory.py
+14
-0
14 additions, 0 deletions
skais/tests/ais/test_ais_trajectory.py
with
23 additions
and
2 deletions
skais/ais/ais_trajectory.py
+
9
−
2
View file @
58ca07aa
...
...
@@ -39,6 +39,13 @@ def apply_func_on_window(dat, func, radius, on_edge='copy'):
data
=
dat
[
i
-
radius
:
i
+
radius
+
1
]
result
[
i
-
radius
]
=
func
(
data
)
return
result
elif
on_edge
==
'
ignore
'
:
for
i
in
range
(
0
,
dat
.
shape
[
0
]):
lower_bound
=
max
(
0
,
i
-
radius
)
upper_bound
=
min
(
dat
.
shape
[
0
],
i
+
radius
+
1
)
data
=
dat
[
lower_bound
:
upper_bound
]
result
[
i
]
=
func
(
data
)
return
result
else
:
raise
ValueError
...
...
@@ -96,9 +103,9 @@ class AISTrajectory(AISPoints):
return
result
def
apply_func_on_time_window
(
self
,
func
,
radius
,
column
,
new_column
=
None
):
def
apply_func_on_time_window
(
self
,
func
,
radius
,
column
,
new_column
=
None
,
on_edge
=
'
copy
'
):
dat
=
self
.
df
[
column
].
to_numpy
()
result
=
apply_func_on_window
(
dat
,
func
,
radius
,
on_edge
=
'
copy
'
)
result
=
apply_func_on_window
(
dat
,
func
,
radius
,
on_edge
)
if
new_column
is
None
:
self
.
df
[
column
]
=
result
...
...
This diff is collapsed.
Click to expand it.
skais/tests/ais/test_ais_trajectory.py
+
14
−
0
View file @
58ca07aa
...
...
@@ -320,3 +320,17 @@ class TestAISTrajectory(unittest.TestCase):
def
test_apply_func_on_window
(
self
):
self
.
assertRaises
(
ValueError
,
apply_func_on_window
,
np
.
arange
(
10
),
0
,
0
,
'
not valid string
'
)
def
test_apply_func_on_window_ignore
(
self
):
result
=
apply_func_on_window
(
np
.
arange
(
10
),
np
.
mean
,
2
,
'
ignore
'
)
expected
=
np
.
array
([
1
,
1.5
,
2
,
3
,
4
,
5
,
6
,
7
,
7.5
,
8
])
np
.
testing
.
assert_equal
(
result
,
expected
)
def
test_apply_func_on_window_ignore_short
(
self
):
result
=
apply_func_on_window
(
np
.
arange
(
5
),
np
.
mean
,
10
,
'
ignore
'
)
expected
=
np
.
array
([
2
,
2
,
2
,
2
,
2
])
np
.
testing
.
assert_equal
(
result
,
expected
)
\ No newline at end of file
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