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
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
Olivier Bertrand
navipy
Commits
6a895ea7
Commit
6a895ea7
authored
7 years ago
by
Luise Odenthal
Browse files
Options
Downloads
Patches
Plain Diff
changed test
parent
b2c15fe2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
navipy/comparing/test.py
+191
-0
191 additions, 0 deletions
navipy/comparing/test.py
with
191 additions
and
0 deletions
navipy/comparing/test.py
0 → 100644
+
191
−
0
View file @
6a895ea7
import
unittest
import
numpy
as
np
from
navipy.database
import
database
import
navipy.comparing
as
comparing
import
navipy.processing
as
processing
import
pkg_resources
def
is_numeric_array
(
array
):
"""
Checks if the dtype of the array is numeric.
Booleans, unsigned integer, signed integer, floats and complex are
considered numeric.
Parameters
----------
array : `numpy.ndarray`-like
The array to check.
Returns
-------
is_numeric : `bool`
True if it is a recognized numerical and False if object or
string.
"""
numerical_dtype_kinds
=
{
'
b
'
,
# boolean
'
u
'
,
# unsigned integer
'
i
'
,
# signed integer
'
f
'
,
# floats
'
c
'
}
# complex
try
:
return
array
.
dtype
.
kind
in
numerical_dtype_kinds
except
AttributeError
:
# in case it's not a numpy array it will probably have no dtype.
return
np
.
asarray
(
array
).
dtype
.
kind
in
numerical_dtype_kinds
class
TestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
mydb_filename
=
pkg_resources
.
resource_filename
(
'
navipy
'
,
'
resources/database.db
'
)
self
.
mydb
=
database
.
DataBaseLoad
(
self
.
mydb_filename
)
def
test_imagediff_curr
(
self
):
curr
=
processing
.
scene
(
self
.
mydb
,
rowid
=
1
)
mem
=
processing
.
scene
(
self
.
mydb
,
rowid
=
2
)
curr2
=
curr
.
copy
()
curr2
[
3
,
5
,
2
,
0
]
=
np
.
nan
curr3
=
[[
1
,
2
,
3
],
[
1
,
2
,
3
],
[
1
,
2
,
3
]]
curr3
=
[
curr3
,
curr3
,
curr3
]
curr3
=
np
.
array
(
curr3
)
curr4
=
np
.
zeros
((
3
,
4
,
5
,
0
))
for
s
in
[
curr2
,
curr3
,
curr4
]:
# put useless stuff here
with
self
.
assertRaises
(
Exception
)
as
cm
:
comparing
.
imagediff
(
s
,
mem
)
print
(
"
wanted exception occured
"
,
cm
.
exception
)
# should be working -> check if result is correct
for
s
in
[
curr
]:
diff
=
comparing
.
imagediff
(
s
,
mem
)
self
.
assertFalse
(
diff
.
shape
[
1
]
<=
0
)
self
.
assertTrue
(
diff
.
shape
[
2
]
==
4
)
self
.
assertFalse
(
np
.
any
(
np
.
isnan
(
diff
)))
self
.
assertTrue
(
is_numeric_array
(
diff
))
self
.
assertTrue
(
diff
.
shape
[
3
]
==
1
)
self
.
assertTrue
(
diff
.
shape
[
0
]
>
0
)
self
.
assertTrue
(
diff
.
shape
[
1
]
>
0
)
def
test_imagediff_memory
(
self
):
curr
=
processing
.
scene
(
self
.
mydb
,
rowid
=
1
)
mem
=
processing
.
scene
(
self
.
mydb
,
rowid
=
2
)
mem2
=
curr
.
copy
()
mem2
[
3
,
5
,
2
,
0
]
=
np
.
nan
mem3
=
[[
1
,
2
,
3
],
[
1
,
2
,
3
],
[
1
,
2
,
3
]]
mem3
=
[
mem3
,
mem3
,
mem3
]
mem3
=
np
.
array
(
mem3
)
mem4
=
np
.
zeros
((
3
,
4
,
5
,
0
))
for
s
in
[
mem2
,
mem3
,
mem4
]:
# put useless stuff here
with
self
.
assertRaises
(
Exception
)
as
cm
:
comparing
.
imagediff
(
curr
,
s
)
print
(
"
wanted exception occured
"
,
cm
.
exception
)
# should be working -> check if result is correct
for
s
in
[
mem
]:
diff
=
comparing
.
imagediff
(
curr
,
s
)
self
.
assertFalse
(
diff
.
shape
[
1
]
<=
0
)
self
.
assertTrue
(
diff
.
shape
[
2
]
==
4
)
self
.
assertFalse
(
np
.
any
(
np
.
isnan
(
diff
)))
self
.
assertTrue
(
is_numeric_array
(
diff
))
def
test_rot_imagediff_curr
(
self
):
curr
=
processing
.
scene
(
self
.
mydb
,
rowid
=
1
)
mem
=
processing
.
scene
(
self
.
mydb
,
rowid
=
2
)
curr2
=
curr
.
copy
()
curr2
[
3
,
5
,
2
,
0
]
=
np
.
nan
curr3
=
[[
1
,
2
,
3
],
[
1
,
2
,
3
],
[
1
,
2
,
3
]]
curr3
=
[
curr3
,
curr3
,
curr3
]
curr3
=
np
.
array
(
curr3
)
curr4
=
np
.
zeros
((
3
,
4
,
5
,
0
))
for
s
in
[
curr2
,
curr3
,
curr4
]:
# put useless stuff here
with
self
.
assertRaises
(
Exception
)
as
cm
:
comparing
.
rot_imagediff
(
s
,
mem
)
print
(
"
wanted exception occured
"
,
cm
.
exception
)
# should be working -> check if result is correct
for
s
in
[
curr
]:
diff
=
comparing
.
rot_imagediff
(
s
,
mem
)
self
.
assertFalse
(
diff
.
shape
[
1
]
<=
0
)
self
.
assertTrue
(
diff
.
shape
[
2
]
==
4
)
self
.
assertFalse
(
np
.
any
(
np
.
isnan
(
diff
)))
self
.
assertTrue
(
is_numeric_array
(
diff
))
self
.
assertTrue
(
diff
.
shape
[
3
]
==
1
)
self
.
assertTrue
(
diff
.
shape
[
0
]
>
0
)
self
.
assertTrue
(
diff
.
shape
[
1
]
>
0
)
def
test_rotimagediff_memory
(
self
):
curr
=
processing
.
scene
(
self
.
mydb
,
rowid
=
1
)
mem
=
processing
.
scene
(
self
.
mydb
,
rowid
=
2
)
mem2
=
curr
.
copy
()
mem2
[
3
,
5
,
2
,
0
]
=
np
.
nan
mem3
=
[[
1
,
2
,
3
],
[
1
,
2
,
3
],
[
1
,
2
,
3
]]
mem3
=
[
mem3
,
mem3
,
mem3
]
mem3
=
np
.
array
(
mem3
)
mem4
=
np
.
zeros
((
3
,
4
,
5
,
0
))
for
s
in
[
mem2
,
mem3
,
mem4
]:
# put useless stuff here
with
self
.
assertRaises
(
Exception
)
as
cm
:
comparing
.
rot_imagediff
(
curr
,
s
)
print
(
"
wanted exception occured
"
,
cm
.
exception
)
# should be working -> check if result is correct
for
s
in
[
mem
]:
diff
=
comparing
.
rot_imagediff
(
curr
,
s
)
self
.
assertFalse
(
diff
.
shape
[
1
]
<=
0
)
self
.
assertTrue
(
diff
.
shape
[
2
]
==
4
)
self
.
assertFalse
(
np
.
any
(
np
.
isnan
(
diff
)))
self
.
assertTrue
(
is_numeric_array
(
diff
))
self
.
assertTrue
(
diff
.
shape
[
3
]
==
1
)
self
.
assertTrue
(
diff
.
shape
[
0
]
>
0
)
self
.
assertTrue
(
diff
.
shape
[
1
]
>
0
)
def
test_simple_imagediff_curr
(
self
):
curr
=
processing
.
scene
(
self
.
mydb
,
rowid
=
1
)
mem
=
processing
.
scene
(
self
.
mydb
,
rowid
=
2
)
curr2
=
curr
.
copy
()
curr2
[
3
,
5
,
2
,
0
]
=
np
.
nan
curr3
=
[[
1
,
2
,
3
],
[
1
,
2
,
3
],
[
1
,
2
,
3
]]
curr3
=
[
curr3
,
curr3
,
curr3
]
curr3
=
np
.
array
(
curr3
)
curr4
=
np
.
zeros
((
3
,
4
,
5
,
0
))
for
s
in
[
curr2
,
curr3
,
curr4
]:
# put useless stuff here
with
self
.
assertRaises
(
Exception
)
as
cm
:
comparing
.
simple_imagediff
(
s
,
mem
)
print
(
"
wanted exception occured
"
,
cm
.
exception
)
# should be working -> check if result is correct
for
s
in
[
curr
]:
diff
=
comparing
.
rot_imagediff
(
s
,
mem
)
self
.
assertFalse
(
diff
.
shape
[
1
]
<=
0
)
self
.
assertTrue
(
diff
.
shape
[
2
]
==
4
)
self
.
assertFalse
(
np
.
any
(
np
.
isnan
(
diff
)))
self
.
assertTrue
(
is_numeric_array
(
diff
))
self
.
assertTrue
(
diff
.
shape
[
3
]
==
1
)
self
.
assertTrue
(
diff
.
shape
[
0
]
>
0
)
self
.
assertTrue
(
diff
.
shape
[
1
]
>
0
)
def
test_diff_optic_flow_memory
(
self
):
curr
=
processing
.
scene
(
self
.
mydb
,
rowid
=
1
)
mem
=
processing
.
scene
(
self
.
mydb
,
rowid
=
2
)
mem2
=
curr
.
copy
()
mem2
[
3
,
5
,
2
,
0
]
=
np
.
nan
mem3
=
[[
1
,
2
,
3
],
[
1
,
2
,
3
],
[
1
,
2
,
3
]]
mem3
=
[
mem3
,
mem3
,
mem3
]
mem3
=
np
.
array
(
mem3
)
mem4
=
np
.
zeros
((
3
,
4
,
5
,
0
))
for
s
in
[
mem2
,
mem3
,
mem4
]:
# put useless stuff here
with
self
.
assertRaises
(
Exception
)
as
cm
:
comparing
.
diff_optic_flow
(
curr
,
s
)
print
(
"
wanted exception occured
"
,
cm
.
exception
)
# should be working -> check if result is correct
for
s
in
[
mem
]:
vec
=
comparing
.
diff_optic_flow
(
curr
,
s
)
self
.
assertFalse
(
vec
.
shape
[
1
]
==
(
1
,
2
))
self
.
assertFalse
(
np
.
any
(
np
.
isnan
(
vec
)))
self
.
assertTrue
(
is_numeric_array
(
vec
))
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