Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
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
Michiel Cottaar
fslpy
Commits
8721da08
Commit
8721da08
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
tests for naninfrange module
parent
8467fdf5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_imagewrapper.py
+2
-44
2 additions, 44 deletions
tests/test_imagewrapper.py
tests/test_naninfrange.py
+52
-0
52 additions, 0 deletions
tests/test_naninfrange.py
with
54 additions
and
44 deletions
tests/test_imagewrapper.py
+
2
−
44
View file @
8721da08
...
...
@@ -9,14 +9,12 @@ from __future__ import print_function
import
collections
import
random
import
time
import
itertools
as
it
import
numpy
as
np
import
nibabel
as
nib
import
pytest
import
fsl.data.image
as
image
import
fsl.utils.naninfrange
as
nir
import
fsl.data.imagewrapper
as
imagewrap
from
.
import
random_voxels
...
...
@@ -291,46 +289,6 @@ def test_sliceTupleToSliceObj():
assert
func
(
slices
)
==
sliceobj
def
test_naninfrange
():
# numinf, numnan, expectedResult
tests
=
[(
0
,
0
,
(
0
,
100
)),
(
0
,
1
,
(
0
,
100
)),
(
1
,
0
,
(
0
,
100
)),
(
1
,
1
,
(
0
,
100
)),
(
5
,
5
,
(
0
,
100
)),
(
0
,
'
all
'
,
(
np
.
nan
,
np
.
nan
)),
(
'
all
'
,
0
,
(
np
.
nan
,
np
.
nan
))]
# Test non floating point data as wll
data
=
np
.
linspace
(
0
,
100
,
100
,
dtype
=
np
.
uint32
)
assert
imagewrap
.
naninfrange
(
data
)
==
(
0
,
100
)
for
numinf
,
numnan
,
expected
in
tests
:
data
=
np
.
linspace
(
0
,
100
,
100
)
if
numinf
==
'
all
'
:
data
[:]
=
np
.
inf
elif
numnan
==
'
all
'
:
data
[:]
=
np
.
nan
nanoff
=
1
if
numinf
!=
'
all
'
:
for
i
in
range
(
1
,
numinf
+
1
):
data
[
i
]
=
np
.
inf
nanoff
+=
numinf
if
numnan
!=
'
all
'
:
for
i
in
range
(
nanoff
,
numnan
+
nanoff
):
data
[
i
]
=
np
.
nan
result
=
imagewrap
.
naninfrange
(
data
)
if
np
.
isfinite
(
expected
[
0
]):
assert
result
[
0
]
==
expected
[
0
]
elif
np
.
isnan
(
expected
[
0
]):
assert
np
.
isnan
(
result
[
0
])
elif
np
.
isinf
(
expected
[
0
]):
assert
np
.
isinf
(
result
[
0
])
if
np
.
isfinite
(
expected
[
1
]):
assert
result
[
1
]
==
expected
[
1
]
elif
np
.
isnan
(
expected
[
1
]):
assert
np
.
isnan
(
result
[
1
])
elif
np
.
isinf
(
expected
[
1
]):
assert
np
.
isinf
(
result
[
1
])
def
test_adjustCoverage
():
...
...
@@ -617,7 +575,7 @@ def _test_ImageWrapper_read(niters, seed, threaded, addnans=False):
data
[
coords
]
=
np
.
nan
volRanges
=
[
imagewrap
.
naninfrange
(
data
[...,
v
])
for
v
in
range
(
nvols
)]
volRanges
=
[
nir
.
naninfrange
(
data
[...,
v
])
for
v
in
range
(
nvols
)]
rrs
=
[]
for
vol
in
range
(
nvols
):
...
...
This diff is collapsed.
Click to expand it.
tests/test_naninfrange.py
0 → 100644
+
52
−
0
View file @
8721da08
#!/usr/bin/env python
#
# test_naninfrange.py -
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
import
numpy
as
np
import
fsl.utils.naninfrange
as
naninfrange
def
test_naninfrange
():
# numinf, numnan, expectedResult
tests
=
[(
0
,
0
,
(
0
,
100
)),
(
0
,
1
,
(
0
,
100
)),
(
1
,
0
,
(
0
,
100
)),
(
1
,
1
,
(
0
,
100
)),
(
5
,
5
,
(
0
,
100
)),
(
0
,
'
all
'
,
(
np
.
nan
,
np
.
nan
)),
(
'
all
'
,
0
,
(
np
.
nan
,
np
.
nan
))]
# Test non floating point data as wll
data
=
np
.
linspace
(
0
,
100
,
100
,
dtype
=
np
.
uint32
)
assert
naninfrange
.
naninfrange
(
data
)
==
(
0
,
100
)
for
numinf
,
numnan
,
expected
in
tests
:
data
=
np
.
linspace
(
0
,
100
,
100
)
if
numinf
==
'
all
'
:
data
[:]
=
np
.
inf
elif
numnan
==
'
all
'
:
data
[:]
=
np
.
nan
nanoff
=
1
if
numinf
!=
'
all
'
:
for
i
in
range
(
1
,
numinf
+
1
):
data
[
i
]
=
np
.
inf
nanoff
+=
numinf
if
numnan
!=
'
all
'
:
for
i
in
range
(
nanoff
,
numnan
+
nanoff
):
data
[
i
]
=
np
.
nan
result
=
naninfrange
.
naninfrange
(
data
)
if
np
.
isfinite
(
expected
[
0
]):
assert
result
[
0
]
==
expected
[
0
]
elif
np
.
isnan
(
expected
[
0
]):
assert
np
.
isnan
(
result
[
0
])
elif
np
.
isinf
(
expected
[
0
]):
assert
np
.
isinf
(
result
[
0
])
if
np
.
isfinite
(
expected
[
1
]):
assert
result
[
1
]
==
expected
[
1
]
elif
np
.
isnan
(
expected
[
1
]):
assert
np
.
isnan
(
result
[
1
])
elif
np
.
isinf
(
expected
[
1
]):
assert
np
.
isinf
(
result
[
1
])
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