Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
navipy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Olivier Bertrand
navipy
Commits
798c1e73
Commit
798c1e73
authored
5 years ago
by
Olivier Bertrand
Browse files
Options
Downloads
Patches
Plain Diff
Add test for sinuosity and travelled dist
parent
02f10e3a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.coverage
+0
-0
0 additions, 0 deletions
.coverage
navipy/trajectories/__init__.py
+4
-4
4 additions, 4 deletions
navipy/trajectories/__init__.py
navipy/trajectories/test_trajectory.py
+18
-17
18 additions, 17 deletions
navipy/trajectories/test_trajectory.py
with
22 additions
and
21 deletions
.coverage
+
0
−
0
View file @
798c1e73
No preview for this file type
This diff is collapsed.
Click to expand it.
navipy/trajectories/__init__.py
+
4
−
4
View file @
798c1e73
...
@@ -102,7 +102,7 @@ def _invmarkerstransform(index_i, trajectory,
...
@@ -102,7 +102,7 @@ def _invmarkerstransform(index_i, trajectory,
class
Trajectory
(
pd
.
DataFrame
):
class
Trajectory
(
pd
.
DataFrame
):
def
__init__
(
self
,
rotconv
=
'
zyx
'
,
indeces
=
np
.
arange
(
1
)):
def
__init__
(
self
,
rotconv
=
'
zyx
'
,
indeces
=
np
.
arange
(
1
)):
columns
=
self
.
__build_columns
(
rotconv
)
columns
=
self
.
__build_columns
(
rotconv
)
super
().
__init__
(
index
=
indeces
,
columns
=
columns
)
super
().
__init__
(
index
=
indeces
,
columns
=
columns
,
dtype
=
np
.
float
)
self
.
__rotconv
=
rotconv
self
.
__rotconv
=
rotconv
self
.
sampling_rate
=
0
self
.
sampling_rate
=
0
...
@@ -678,12 +678,12 @@ class Trajectory(pd.DataFrame):
...
@@ -678,12 +678,12 @@ class Trajectory(pd.DataFrame):
# We remove nans between section
# We remove nans between section
# and then calculate the velocity
# and then calculate the velocity
# it is equivalent to interpolate between non-nan blocks
# it is equivalent to interpolate between non-nan blocks
subtraj
=
self
.
location
.
dropna
().
reset_index
().
drop
(
'
index
'
,
subtraj
=
self
.
location
.
dropna
().
reset_index
().
drop
(
'
index
'
,
axis
=
1
)
axis
=
1
,
level
=
0
)
if
subtraj
.
dropna
().
shape
[
0
]
<
2
:
if
subtraj
.
dropna
().
shape
[
0
]
<
2
:
print
(
'
Trajectory has less than 2 non nans points
'
)
print
(
'
Trajectory has less than 2 non nans points
'
)
return
np
.
nan
return
np
.
nan
velocity
=
subtraj
.
diff
()
# only location is of relevance
# only location is of relevance
velocity
=
subtraj
.
astype
(
float
).
diff
()
speed
=
np
.
sqrt
(
velocity
.
x
**
2
+
velocity
.
y
**
2
+
velocity
.
z
**
2
)
speed
=
np
.
sqrt
(
velocity
.
x
**
2
+
velocity
.
y
**
2
+
velocity
.
z
**
2
)
travel_dist
=
np
.
sum
(
speed
)
travel_dist
=
np
.
sum
(
speed
)
return
travel_dist
return
travel_dist
...
...
This diff is collapsed.
Click to expand it.
navipy/trajectories/test_trajectory.py
+
18
−
17
View file @
798c1e73
...
@@ -54,38 +54,39 @@ class TestTrajectoryTransform(unittest.TestCase):
...
@@ -54,38 +54,39 @@ class TestTrajectoryTransform(unittest.TestCase):
pass
pass
def
test_traveldist
(
self
):
def
test_traveldist
(
self
):
indeces
=
np
.
linspace
(
0
,
2
*
np
.
pi
,
1
000
)
indeces
=
np
.
linspace
(
0
,
2
*
np
.
pi
,
2
000
)
radius
=
5
radius
=
5
mytraj
=
Trajectory
(
indeces
=
indeces
,
rotconv
=
'
zyx
'
)
mytraj
=
Trajectory
(
indeces
=
indeces
,
rotconv
=
'
zyx
'
)
mytraj
.
x
=
indeces
mytraj
.
x
=
radius
*
np
.
cos
(
indeces
)
mytraj
.
y
=
radius
*
np
.
cos
(
indeces
)
mytraj
.
y
=
radius
*
np
.
sin
(
indeces
)
mytraj
.
z
=
0
mytraj
.
z
=
0
# The length of
a cos from 0 to 2pi
# The length of
function above
# is equal to perimeter of the circle
# is equal to perimeter of the circle
# 2*pi*r
# 2*pi*r
travel_dist_theo
=
2
*
np
.
pi
*
radius
travel_dist_theo
=
2
*
np
.
pi
*
radius
travel_dist
=
mytraj
.
traveled_distance
()
travel_dist
=
mytraj
.
traveled_distance
()
np
.
testing
.
assert_almost_equal
(
travel_dist
,
travel_dist_theo
)
np
.
testing
.
assert_almost_equal
(
travel_dist
,
travel_dist_theo
,
decimal
=
4
)
# Test with nans
# Test with nans
mytraj
.
loc
[[
15
,
50
,
90
],
:]
=
np
.
nan
mytraj
.
i
loc
[[
15
,
50
,
90
],
:]
=
np
.
nan
travel_dist
=
mytraj
.
traveled_distance
()
travel_dist
=
mytraj
.
traveled_distance
()
np
.
testing
.
assert_almost_equal
(
travel_dist
,
travel_dist_theo
)
np
.
testing
.
assert_almost_equal
(
travel_dist
,
travel_dist_theo
,
decimal
=
4
)
def
test_sinuosity
(
self
):
def
test_sinuosity
(
self
):
indeces
=
np
.
linspace
(
0
,
2
*
np
.
pi
,
1000
)
indeces
=
np
.
linspace
(
0
,
np
.
pi
,
1000
)
radius
=
5
radius
=
5
mytraj
=
Trajectory
(
indeces
=
indeces
,
rotconv
=
'
zyx
'
)
mytraj
=
Trajectory
(
indeces
=
indeces
,
rotconv
=
'
zyx
'
)
mytraj
.
x
=
indeces
mytraj
.
x
=
radius
*
np
.
cos
(
indeces
)
mytraj
.
y
=
radius
*
np
.
cos
(
indeces
)
mytraj
.
y
=
radius
*
np
.
sin
(
indeces
)
mytraj
.
z
=
0
mytraj
.
z
=
0
# The length of a cos from 0 to 2pi
# The length of function above
# is equal to perimeter of the circle
# is equal to half the perimeter of the circle
# 2*pi*r
# pi*r
# the sinuosity will be equal to the radius
# the sinuosity will be equal to:
# because dist from start to end is 2*pi
sinuosity_theo
=
np
.
pi
*
radius
/
(
2
*
radius
)
sinuosity_theo
=
radius
sinuosity
=
mytraj
.
sinuosity
()
sinuosity
=
mytraj
.
sinuosity
()
np
.
testing
.
assert_almost_equal
(
sinuosity
,
sinuosity_theo
)
np
.
testing
.
assert_almost_equal
(
sinuosity
,
sinuosity_theo
,
decimal
=
4
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
...
...
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