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
2fa377ae
Commit
2fa377ae
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
TEST: More basic tests for x5 scripts
parent
1587e85a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_scripts/test_fsl_apply_x5.py
+13
-0
13 additions, 0 deletions
tests/test_scripts/test_fsl_apply_x5.py
tests/test_scripts/test_fsl_convert_x5.py
+83
-0
83 additions, 0 deletions
tests/test_scripts/test_fsl_convert_x5.py
with
96 additions
and
0 deletions
tests/test_scripts/test_fsl_apply_x5.py
+
13
−
0
View file @
2fa377ae
...
...
@@ -3,6 +3,8 @@
import
numpy
as
np
import
pytest
import
fsl.scripts.fsl_apply_x5
as
fsl_apply_x5
import
fsl.data.image
as
fslimage
import
fsl.utils.image.resample
as
resample
...
...
@@ -31,6 +33,17 @@ def _random_image(aff, shape=None):
return
fslimage
.
Image
(
data
,
xform
=
aff
)
def
test_help
():
def
run
(
args
):
with
pytest
.
raises
(
SystemExit
)
as
e
:
fsl_apply_x5
.
main
(
args
)
assert
e
.
value
.
code
==
0
run
([])
run
([
'
-h
'
])
def
test_linear
():
with
tempdir
.
tempdir
():
...
...
This diff is collapsed.
Click to expand it.
tests/test_scripts/test_fsl_convert_x5.py
+
83
−
0
View file @
2fa377ae
...
...
@@ -2,6 +2,9 @@
import
os.path
as
op
import
hashlib
import
pytest
import
numpy
as
np
...
...
@@ -28,6 +31,20 @@ def random_image():
return
fslimage
.
Image
(
data
,
xform
=
aff
)
def
test_convert_flirt_help
():
def
run
(
args
):
with
pytest
.
raises
(
SystemExit
)
as
e
:
fsl_convert_x5
.
main
(
args
)
assert
e
.
value
.
code
==
0
run
([])
run
([
'
-h
'
])
run
([
'
flirt
'
])
run
([
'
fnirt
'
])
run
([
'
flirt
'
,
'
-h
'
])
run
([
'
fnirt
'
,
'
-h
'
])
def
test_convert_flirt
():
with
tempdir
.
tempdir
():
...
...
@@ -60,6 +77,42 @@ def test_convert_flirt():
assert
np
.
all
(
np
.
isclose
(
gotxform
,
xform
))
def
test_convert_flirt_sameformat
():
with
tempdir
.
tempdir
():
src
=
random_image
()
ref
=
random_image
()
src
.
save
(
'
src
'
)
ref
.
save
(
'
ref
'
)
xform
=
affine
.
compose
(
np
.
random
.
randint
(
1
,
10
,
3
),
np
.
random
.
randint
(
-
100
,
100
,
3
),
(
np
.
random
.
random
(
3
)
-
0.5
)
*
np
.
pi
)
np
.
savetxt
(
'
src2ref.mat
'
,
xform
)
# test both .mat and .x5
fsl_convert_x5
.
main
(
'
flirt -s src -r ref
'
'
src2ref.mat src2ref.x5
'
.
split
())
# mat -> mat
fsl_convert_x5
.
main
(
'
flirt -s src -r ref
'
'
src2ref.mat copy.mat
'
.
split
())
# x5 -> x5
fsl_convert_x5
.
main
(
'
flirt -s src -r ref
'
'
src2ref.x5 copy.x5
'
.
split
())
with
open
(
'
src2ref.mat
'
,
'
rb
'
)
as
f
:
origmat
=
hashlib
.
md5
(
f
.
read
()).
digest
()
with
open
(
'
copy.mat
'
,
'
rb
'
)
as
f
:
copymat
=
hashlib
.
md5
(
f
.
read
()).
digest
()
with
open
(
'
src2ref.x5
'
,
'
rb
'
)
as
f
:
origx5
=
hashlib
.
md5
(
f
.
read
()).
digest
()
with
open
(
'
copy.x5
'
,
'
rb
'
)
as
f
:
copyx5
=
hashlib
.
md5
(
f
.
read
()).
digest
()
assert
origmat
==
copymat
assert
origx5
==
copyx5
def
test_convert_fnirt_deformation_field
():
datadir
=
op
.
join
(
op
.
dirname
(
__file__
),
'
..
'
,
...
...
@@ -124,3 +177,33 @@ def test_convert_fnirt_coefficient_field():
diff
=
np
.
abs
(
dfnii
.
data
-
df
.
data
)
tols
=
{
'
rtol
'
:
1e-5
,
'
atol
'
:
1e-5
}
assert
np
.
all
(
np
.
isclose
(
dfnii
.
data
,
df
.
data
,
**
tols
))
def
test_convert_fnirt_sameformat
():
datadir
=
op
.
join
(
op
.
dirname
(
__file__
),
'
..
'
,
'
test_transform
'
,
'
testdata
'
,
'
nonlinear
'
)
srcfile
=
op
.
join
(
datadir
,
'
src.nii.gz
'
)
reffile
=
op
.
join
(
datadir
,
'
ref.nii.gz
'
)
dffile
=
op
.
join
(
datadir
,
'
displacementfield.nii.gz
'
)
with
tempdir
.
tempdir
():
base
=
list
(
'
fnirt -s {} -r {}
'
.
format
(
srcfile
,
reffile
).
split
())
# test both .mat and .x5
fsl_convert_x5
.
main
(
base
+
[
dffile
,
'
src2ref.x5
'
])
# nii -> nii
fsl_convert_x5
.
main
(
base
+
[
dffile
,
'
copy.nii.gz
'
])
# x5 -> x5
fsl_convert_x5
.
main
(
base
+
[
dffile
,
'
copy.x5
'
])
with
open
(
dffile
,
'
rb
'
)
as
f
:
origdef
=
hashlib
.
md5
(
f
.
read
()).
digest
()
with
open
(
'
copy.nii.gz
'
,
'
rb
'
)
as
f
:
copydef
=
hashlib
.
md5
(
f
.
read
()).
digest
()
with
open
(
'
src2ref.x5
'
,
'
rb
'
)
as
f
:
origx5
=
hashlib
.
md5
(
f
.
read
()).
digest
()
with
open
(
'
copy.x5
'
,
'
rb
'
)
as
f
:
copyx5
=
hashlib
.
md5
(
f
.
read
()).
digest
()
assert
origdef
==
copydef
assert
origx5
==
copyx5
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