Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD 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
FSL
fslpy
Commits
7485f176
Commit
7485f176
authored
4 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
TEST: test fslstats wrapper
parent
195cb21f
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
tests/test_wrappers/test_fslstats.py
+94
-0
94 additions, 0 deletions
tests/test_wrappers/test_fslstats.py
with
94 additions
and
0 deletions
tests/test_wrappers/test_fslstats.py
0 → 100644
+
94
−
0
View file @
7485f176
#!/usr/bin/env python
import
os
import
os.path
as
op
import
sys
import
contextlib
import
numpy
as
np
import
fsl.utils.run
as
run
import
fsl.utils.tempdir
as
tempdir
import
fsl.wrappers
as
fw
from
..
import
mockFSLDIR
as
mockFSLDIR_base
,
make_random_image
mock_fslstats
=
"""
#!{}
shape = {{outshape}}
import sys
import numpy as np
data = np.random.randint(1, 10, shape)
if len(shape) == 1:
data = data.reshape(1, -1)
np.savetxt(sys.stdout, data, fmt=
'
%i
'
)
"""
.
format
(
sys
.
executable
).
strip
()
@contextlib.contextmanager
def
mockFSLDIR
(
shape
):
with
mockFSLDIR_base
()
as
fd
:
fname
=
op
.
join
(
fd
,
'
bin
'
,
'
fslstats
'
)
script
=
mock_fslstats
.
format
(
outshape
=
shape
)
with
open
(
fname
,
'
wt
'
)
as
f
:
f
.
write
(
script
)
os
.
chmod
(
fname
,
0o755
)
yield
fd
def
test_fslstats_cmdline
():
with
tempdir
.
tempdir
(),
run
.
dryrun
(),
mockFSLDIR
(
1
)
as
fsldir
:
make_random_image
(
'
image
'
)
cmd
=
op
.
join
(
fsldir
,
'
bin
'
,
'
fslstats
'
)
result
=
fw
.
fslstats
(
'
image
'
).
m
.
r
.
mask
(
'
mask
'
).
k
(
'
mask
'
).
r
.
run
(
True
)
expected
=
cmd
+
'
image -m -r -k mask -k mask -r
'
assert
result
[
0
]
==
expected
result
=
fw
.
fslstats
(
'
image
'
,
t
=
True
,
K
=
'
mask
'
).
m
.
R
.
u
(
123
).
s
.
volume
.
run
(
True
)
expected
=
cmd
+
'
-t -K mask image -m -R -u 123 -s -v
'
assert
result
[
0
]
==
expected
result
=
fw
.
fslstats
(
'
image
'
,
K
=
'
mask
'
).
n
.
V
.
p
(
1
).
run
(
True
)
expected
=
cmd
+
'
-K mask image -n -V -p 1
'
assert
result
[
0
]
==
expected
result
=
fw
.
fslstats
(
'
image
'
,
t
=
True
).
H
(
10
,
1
,
99
).
d
(
'
diff
'
).
run
(
True
)
expected
=
cmd
+
'
-t image -H 10 1 99 -d diff
'
assert
result
[
0
]
==
expected
def
test_fslstats_result
():
with
tempdir
.
tempdir
():
with
mockFSLDIR
(
'
(1,)
'
)
as
fsldir
:
result
=
fw
.
fslstats
(
'
image
'
).
run
()
assert
np
.
isscalar
(
result
)
with
mockFSLDIR
(
'
(2,)
'
)
as
fsldir
:
result
=
fw
.
fslstats
(
'
image
'
).
run
()
assert
result
.
shape
==
(
2
,)
# 3 mask lbls, 2 values
with
mockFSLDIR
(
'
(3, 2)
'
)
as
fsldir
:
result
=
fw
.
fslstats
(
'
image
'
,
K
=
'
mask
'
).
run
()
assert
result
.
shape
==
(
3
,
2
)
# 5 vols, 2 values
with
mockFSLDIR
(
'
(5, 2)
'
)
as
fsldir
:
result
=
fw
.
fslstats
(
'
image
'
,
t
=
True
).
run
()
assert
result
.
shape
==
(
5
,
2
)
# 5 vols, 3 mask lbls, 2 values
with
mockFSLDIR
(
'
(15, 2)
'
)
as
fsldir
:
make_random_image
(
'
image
'
,
(
10
,
10
,
10
,
5
))
result
=
fw
.
fslstats
(
'
image
'
,
K
=
'
mask
'
,
t
=
True
).
run
()
assert
result
.
shape
==
(
5
,
3
,
2
)
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