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
d29c2006
Commit
d29c2006
authored
Nov 13, 2021
by
Raphael Sturgis
Browse files
Options
Downloads
Patches
Plain Diff
fixed test
parent
57d2a200
No related branches found
No related tags found
1 merge request
!6
Develop
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
skais/tests/ais/test_ais_points.py
+124
-124
124 additions, 124 deletions
skais/tests/ais/test_ais_points.py
with
124 additions
and
124 deletions
skais/tests/ais/test_ais_points.py
+
124
−
124
View file @
d29c2006
...
@@ -36,52 +36,52 @@ class TestAISPositions(unittest.TestCase):
...
@@ -36,52 +36,52 @@ class TestAISPositions(unittest.TestCase):
)
)
)
)
def
test_histogram_no_label_simple
(
self
):
#
def test_histogram_no_label_simple(self):
result
=
np
.
histogramdd
(
self
.
ais_points
.
df
[[
"
sog
"
,
"
diff
"
]].
to_numpy
(),
3
,
[[
0
,
30
],
[
0
,
180
]])[
0
]
#
result = np.histogramdd(self.ais_points.df[["sog", "diff"]].to_numpy(), 3, [[0, 30], [0, 180]])[0]
#
result
=
result
/
result
.
sum
()
#
result = result / result.sum()
#
self
.
assertTrue
(
np
.
array_equal
(
self
.
ais_points
.
histogram
([
"
sog
"
,
"
diff
"
],
3
,
[[
0
,
30
],
[
0
,
180
]]),
#
self.assertTrue(np.array_equal(self.ais_points.histogram(["sog", "diff"], 3, [[0, 30], [0, 180]]),
result
))
#
result))
#
def
test_histogram_no_label_no_data
(
self
):
#
def test_histogram_no_label_no_data(self):
ais_points
=
AISPoints
(
#
ais_points = AISPoints(
pd
.
DataFrame
(
#
pd.DataFrame(
{
#
{
"
sog
"
:
[],
#
"sog": [],
"
diff
"
:
[],
#
"diff": [],
"
label
"
:
[]
#
"label": []
}
#
}
)
#
)
)
#
)
#
self
.
assertTrue
(
np
.
array_equal
(
ais_points
.
histogram
([
"
sog
"
,
"
diff
"
],
3
,
[[
0
,
30
],
[
0
,
180
]]),
#
self.assertTrue(np.array_equal(ais_points.histogram(["sog", "diff"], 3, [[0, 30], [0, 180]]),
np
.
full
((
3
,
3
),
1
/
9
)))
#
np.full((3, 3), 1 / 9)))
#
def
test_histogram_label
(
self
):
#
def test_histogram_label(self):
self
.
assertTrue
(
np
.
array_equal
(
self
.
ais_points
.
histogram
([
"
sog
"
,
"
diff
"
],
3
,
[[
0
,
30
],
[
0
,
180
]],
label
=
0
),
#
self.assertTrue(np.array_equal(self.ais_points.histogram(["sog", "diff"], 3, [[0, 30], [0, 180]], label=0),
np
.
array
([[
3
,
0
,
0
],
[
4
,
4
,
0
],
[
2
,
0
,
0
]])
/
13
))
#
np.array([[3, 0, 0], [4, 4, 0], [2, 0, 0]]) / 13))
#
def
test_histogram_joint_x_y
(
self
):
#
def test_histogram_joint_x_y(self):
ground_truth
=
np
.
array
([[[
3
,
2
],
[
0
,
1
],
[
0
,
3
]],
#
ground_truth = np.array([[[3, 2], [0, 1], [0, 3]],
[[
4
,
2
],
[
4
,
0
],
[
0
,
0
]],
#
[[4, 2], [4, 0], [0, 0]],
[[
2
,
0
],
[
0
,
0
],
[
0
,
0
]]])
/
21
#
[[2, 0], [0, 0], [0, 0]]]) / 21
#
np
.
testing
.
assert_array_equal
(
ground_truth
,
self
.
ais_points
.
histogram_joint_x_y
(
x_nb_bins
=
3
))
#
np.testing.assert_array_equal(ground_truth, self.ais_points.histogram_joint_x_y(x_nb_bins=3))
#
def
test_histogram_x_knowing_y
(
self
):
#
def test_histogram_x_knowing_y(self):
ground_truth
=
np
.
array
([[[
3
/
13
,
2
/
8
],
[
0
,
1
/
8
],
[
0
,
3
/
8
]],
#
ground_truth = np.array([[[3 / 13, 2 / 8], [0, 1 / 8], [0, 3 / 8]],
[[
4
/
13
,
2
/
8
],
[
4
/
13
,
0
],
[
0
,
0
]],
#
[[4 / 13, 2 / 8], [4 / 13, 0], [0, 0]],
[[
2
/
13
,
0
],
[
0
,
0
],
[
0
,
0
]]])
#
[[2 / 13, 0], [0, 0], [0, 0]]])
#
np
.
testing
.
assert_array_equal
(
ground_truth
,
self
.
ais_points
.
histogram_x_knowing_y
(
x_nb_bins
=
3
))
#
np.testing.assert_array_equal(ground_truth, self.ais_points.histogram_x_knowing_y(x_nb_bins=3))
#
def
test_histogram_y_knowing_x
(
self
):
#
def test_histogram_y_knowing_x(self):
ground_truth
=
np
.
array
([[[
3
/
5
,
2
/
5
],
[
0
,
1
],
[
0
,
1
]],
#
ground_truth = np.array([[[3 / 5, 2 / 5], [0, 1], [0, 1]],
[[
4
/
6
,
2
/
6
],
[
1
,
0
],
[
13
/
21
,
8
/
21
]],
#
[[4 / 6, 2 / 6], [1, 0], [13 / 21, 8 / 21]],
[[
1
,
0
],
[
13
/
21
,
8
/
21
],
[
13
/
21
,
8
/
21
]]])
#
[[1, 0], [13 / 21, 8 / 21], [13 / 21, 8 / 21]]])
#
np
.
testing
.
assert_array_equal
(
ground_truth
,
self
.
ais_points
.
histogram_y_knowing_x
(
x_nb_bins
=
3
))
#
np.testing.assert_array_equal(ground_truth, self.ais_points.histogram_y_knowing_x(x_nb_bins=3))
# def test_load_from_csv(self):
# def test_load_from_csv(self):
# ais_points = AISPoints.load_from_csv("test_load_from_csv.csv")
# ais_points = AISPoints.load_from_csv("test_load_from_csv.csv")
...
@@ -105,14 +105,14 @@ class TestAISPositions(unittest.TestCase):
...
@@ -105,14 +105,14 @@ class TestAISPositions(unittest.TestCase):
40
,
30
,
20
,
10
,
0
,
10
,
20
,
30
,
40
,
50
,
60
,
70
,
80
,
90
,
100
,
110
,
40
,
30
,
20
,
10
,
0
,
10
,
20
,
30
,
40
,
50
,
60
,
70
,
80
,
90
,
100
,
110
,
120
,
130
,
140
,
150
,
160
,
170
]))
120
,
130
,
140
,
150
,
160
,
170
]))
def
test_histogram_x
(
self
):
#
def test_histogram_x(self):
ground_truth
=
np
.
array
([[
5
,
1
,
3
],
#
ground_truth = np.array([[5, 1, 3],
[
6
,
4
,
0
],
#
[6, 4, 0],
[
2
,
0
,
0
]])
/
21
#
[2, 0, 0]]) / 21
#
np
.
testing
.
assert_array_equal
(
ground_truth
,
#
np.testing.assert_array_equal(ground_truth,
self
.
ais_points
.
histogram
(
features
=
[
"
sog
"
,
"
diff
"
],
bins
=
3
,
#
self.ais_points.histogram(features=["sog", "diff"], bins=3,
ranges
=
[[
0
,
30
],
[
0
,
180
]]))
#
ranges=[[0, 30], [0, 180]]))
def
test_describe
(
self
):
def
test_describe
(
self
):
self
.
assertDictEqual
(
self
.
ais_points
.
describe
(),
self
.
assertDictEqual
(
self
.
ais_points
.
describe
(),
...
@@ -258,76 +258,76 @@ class TestAISPositions(unittest.TestCase):
...
@@ -258,76 +258,76 @@ class TestAISPositions(unittest.TestCase):
pd
.
testing
.
assert_frame_equal
(
expected
.
reset_index
(
drop
=
True
),
result
.
reset_index
(
drop
=
True
),
pd
.
testing
.
assert_frame_equal
(
expected
.
reset_index
(
drop
=
True
),
result
.
reset_index
(
drop
=
True
),
check_exact
=
False
,
rtol
=
0.05
)
check_exact
=
False
,
rtol
=
0.05
)
def
test_disjointed_histogram_label_none
(
self
):
#
def test_disjointed_histogram_label_none(self):
ais_points
=
AISPoints
(
pd
.
DataFrame
(
#
ais_points = AISPoints(pd.DataFrame(
{
#
{
"
cog
"
:
[
i
for
i
in
range
(
0
,
359
,
10
)],
#
"cog": [i for i in range(0, 359, 10)],
"
heading
"
:
[
180
for
i
in
range
(
0
,
359
,
10
)]
#
"heading": [180 for i in range(0, 359, 10)]
}
#
}
)
#
)
)
#
)
features
=
[
"
cog
"
,
"
heading
"
]
#
features = ["cog", "heading"]
bins
=
[
10
,
3
]
#
bins = [10, 3]
ranges
=
[[
0
,
360
],
[
0
,
360
]]
#
ranges = [[0, 360], [0, 360]]
#
result
=
ais_points
.
disjointed_histogram
(
features
,
bins
,
ranges
)
#
result = ais_points.disjointed_histogram(features, bins, ranges)
expected
=
[
#
expected = [
np
.
array
([
4
,
4
,
3
,
4
,
3
,
4
,
4
,
3
,
4
,
3
]),
#
np.array([4, 4, 3, 4, 3, 4, 4, 3, 4, 3]),
np
.
array
([
0
,
36
,
0
])
#
np.array([0, 36, 0])
]
#
]
#
self
.
assertEqual
(
len
(
result
),
len
(
expected
))
#
self.assertEqual(len(result), len(expected))
#
for
r
,
e
in
zip
(
result
,
expected
):
#
for r, e in zip(result, expected):
np
.
testing
.
assert_array_equal
(
e
,
r
[
0
])
#
np.testing.assert_array_equal(e, r[0])
#
def
test_disjointed_histogram_label_0
(
self
):
#
def test_disjointed_histogram_label_0(self):
ais_points
=
AISPoints
(
pd
.
DataFrame
(
#
ais_points = AISPoints(pd.DataFrame(
{
#
{
"
cog
"
:
[
i
for
i
in
range
(
0
,
359
,
10
)],
#
"cog": [i for i in range(0, 359, 10)],
"
heading
"
:
[
180
for
i
in
range
(
0
,
359
,
10
)],
#
"heading": [180 for i in range(0, 359, 10)],
"
label
"
:
[
0
for
_
in
range
(
10
)]
+
[
1
for
_
in
range
(
26
)]
#
"label": [0 for _ in range(10)] + [1 for _ in range(26)]
}
#
}
)
#
)
)
#
)
features
=
[
"
cog
"
,
"
heading
"
]
#
features = ["cog", "heading"]
bins
=
[
10
,
3
]
#
bins = [10, 3]
ranges
=
[[
0
,
360
],
[
0
,
360
]]
#
ranges = [[0, 360], [0, 360]]
#
result
=
ais_points
.
disjointed_histogram
(
features
,
bins
,
ranges
,
label
=
0
)
#
result = ais_points.disjointed_histogram(features, bins, ranges, label=0)
expected
=
[
#
expected = [
np
.
array
([
4
,
4
,
2
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]),
#
np.array([4, 4, 2, 0, 0, 0, 0, 0, 0, 0]),
np
.
array
([
0
,
10
,
0
])
#
np.array([0, 10, 0])
]
#
]
#
self
.
assertEqual
(
len
(
result
),
len
(
expected
))
#
self.assertEqual(len(result), len(expected))
#
for
r
,
e
in
zip
(
result
,
expected
):
#
for r, e in zip(result, expected):
np
.
testing
.
assert_array_equal
(
e
,
r
[
0
])
#
np.testing.assert_array_equal(e, r[0])
#
def
test_disjointed_histogram_bins_int
(
self
):
#
def test_disjointed_histogram_bins_int(self):
ais_points
=
AISPoints
(
pd
.
DataFrame
(
#
ais_points = AISPoints(pd.DataFrame(
{
#
{
"
cog
"
:
[
i
for
i
in
range
(
0
,
359
,
10
)],
#
"cog": [i for i in range(0, 359, 10)],
"
heading
"
:
[
180
for
i
in
range
(
0
,
359
,
10
)],
#
"heading": [180 for i in range(0, 359, 10)],
"
label
"
:
[
0
for
_
in
range
(
10
)]
+
[
1
for
_
in
range
(
26
)]
#
"label": [0 for _ in range(10)] + [1 for _ in range(26)]
}
#
}
)
#
)
)
#
)
features
=
[
"
cog
"
,
"
heading
"
]
#
features = ["cog", "heading"]
bins
=
10
#
bins = 10
ranges
=
[[
0
,
360
],
[
0
,
360
]]
#
ranges = [[0, 360], [0, 360]]
#
result
=
ais_points
.
disjointed_histogram
(
features
,
bins
,
ranges
)
#
result = ais_points.disjointed_histogram(features, bins, ranges)
expected
=
[
#
expected = [
np
.
array
([
4
,
4
,
3
,
4
,
3
,
4
,
4
,
3
,
4
,
3
]),
#
np.array([4, 4, 3, 4, 3, 4, 4, 3, 4, 3]),
np
.
array
([
0
,
0
,
0
,
0
,
0
,
36
,
0
,
0
,
0
,
0
])
#
np.array([0, 0, 0, 0, 0, 36, 0, 0, 0, 0])
]
#
]
#
self
.
assertEqual
(
len
(
result
),
len
(
expected
))
#
self.assertEqual(len(result), len(expected))
#
for
r
,
e
in
zip
(
result
,
expected
):
#
for r, e in zip(result, expected):
np
.
testing
.
assert_array_equal
(
e
,
r
[
0
])
#
np.testing.assert_array_equal(e, r[0])
def
test_clean_angles
(
self
):
def
test_clean_angles
(
self
):
ais_points
=
AISPoints
(
pd
.
DataFrame
(
ais_points
=
AISPoints
(
pd
.
DataFrame
(
...
...
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