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
2fb312ae
Commit
2fb312ae
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
TEST: Update transform tests
parent
66c008d5
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/test_transform/test_fnirt.py
+3
-3
3 additions, 3 deletions
tests/test_transform/test_fnirt.py
tests/test_transform/test_nonlinear.py
+32
-62
32 additions, 62 deletions
tests/test_transform/test_nonlinear.py
tests/test_transform/test_x5.py
+33
-77
33 additions, 77 deletions
tests/test_transform/test_x5.py
with
68 additions
and
142 deletions
tests/test_transform/test_fnirt.py
+
3
−
3
View file @
2fb312ae
...
@@ -39,7 +39,7 @@ def test_readFnirt():
...
@@ -39,7 +39,7 @@ def test_readFnirt():
fnirt
.
readFnirt
(
src
,
src
,
ref
)
fnirt
.
readFnirt
(
src
,
src
,
ref
)
assert
isinstance
(
coef
,
nonlinear
.
CoefficientField
)
assert
isinstance
(
coef
,
nonlinear
.
CoefficientField
)
assert
isinstance
(
disp
,
nonlinear
.
D
isplacement
Field
)
assert
isinstance
(
disp
,
nonlinear
.
D
eformation
Field
)
assert
coef
.
src
.
sameSpace
(
src
)
assert
coef
.
src
.
sameSpace
(
src
)
assert
coef
.
ref
.
sameSpace
(
ref
)
assert
coef
.
ref
.
sameSpace
(
ref
)
...
@@ -68,7 +68,7 @@ def test_toFnirt():
...
@@ -68,7 +68,7 @@ def test_toFnirt():
spaces
=
it
.
permutations
((
'
voxel
'
,
'
fsl
'
,
'
world
'
),
2
)
spaces
=
it
.
permutations
((
'
voxel
'
,
'
fsl
'
,
'
world
'
),
2
)
for
from_
,
to
in
spaces
:
for
from_
,
to
in
spaces
:
field
=
nonlinear
.
convertD
isplacement
Space
(
basefield
,
from_
,
to
)
field
=
nonlinear
.
convertD
eformation
Space
(
basefield
,
from_
,
to
)
got
=
fnirt
.
toFnirt
(
field
)
got
=
fnirt
.
toFnirt
(
field
)
check
(
got
,
basefield
)
check
(
got
,
basefield
)
...
@@ -122,6 +122,6 @@ def test_fromFnirt():
...
@@ -122,6 +122,6 @@ def test_fromFnirt():
for
from_
,
to
in
spaces
:
for
from_
,
to
in
spaces
:
cnv
=
fnirt
.
fromFnirt
(
coef
,
from_
,
to
)
cnv
=
fnirt
.
fromFnirt
(
coef
,
from_
,
to
)
exp
=
nonlinear
.
convertD
isplacement
Space
(
disp
,
from_
,
to
)
exp
=
nonlinear
.
convertD
eformation
Space
(
disp
,
from_
,
to
)
tol
=
dict
(
atol
=
1e-5
,
rtol
=
1e-5
)
tol
=
dict
(
atol
=
1e-5
,
rtol
=
1e-5
)
assert
np
.
all
(
np
.
isclose
(
cnv
.
data
,
exp
.
data
,
**
tol
))
assert
np
.
all
(
np
.
isclose
(
cnv
.
data
,
exp
.
data
,
**
tol
))
This diff is collapsed.
Click to expand it.
tests/test_transform/test_nonlinear.py
+
32
−
62
View file @
2fb312ae
...
@@ -38,7 +38,7 @@ def _random_field():
...
@@ -38,7 +38,7 @@ def _random_field():
np
.
random
.
randint
(
1
,
100
,
3
),
np
.
random
.
randint
(
1
,
100
,
3
),
np
.
random
.
random
(
3
)
*
np
.
pi
/
2
)
np
.
random
.
random
(
3
)
*
np
.
pi
/
2
)
return
nonlinear
.
D
isplacement
Field
(
field
,
src
=
src
,
xform
=
aff
)
return
nonlinear
.
D
eformation
Field
(
field
,
src
=
src
,
xform
=
aff
)
def
_random_affine_field
():
def
_random_affine_field
():
...
@@ -61,9 +61,9 @@ def _random_affine_field():
...
@@ -61,9 +61,9 @@ def _random_affine_field():
field
=
np
.
zeros
(
list
(
ref
.
shape
[:
3
])
+
[
3
])
field
=
np
.
zeros
(
list
(
ref
.
shape
[:
3
])
+
[
3
])
field
[:]
=
(
scoords
-
rcoords
).
reshape
(
*
it
.
chain
(
ref
.
shape
,
[
3
]))
field
[:]
=
(
scoords
-
rcoords
).
reshape
(
*
it
.
chain
(
ref
.
shape
,
[
3
]))
field
=
nonlinear
.
D
isplacement
Field
(
field
,
src
,
ref
,
field
=
nonlinear
.
D
eformation
Field
(
field
,
src
,
ref
,
header
=
ref
.
header
,
header
=
ref
.
header
,
disp
Type
=
'
relative
'
)
def
Type
=
'
relative
'
)
return
field
,
xform
return
field
,
xform
...
@@ -78,31 +78,31 @@ def _field_coords(field):
...
@@ -78,31 +78,31 @@ def _field_coords(field):
field
.
getAffine
(
'
voxel
'
,
'
fsl
'
)).
reshape
(
field
.
shape
)
field
.
getAffine
(
'
voxel
'
,
'
fsl
'
)).
reshape
(
field
.
shape
)
def
test_detectD
isplacement
Type
():
def
test_detectD
eformation
Type
():
relfield
=
_random_field
()
relfield
=
_random_field
()
coords
=
_field_coords
(
relfield
)
coords
=
_field_coords
(
relfield
)
absfield
=
nonlinear
.
D
isplacement
Field
(
absfield
=
nonlinear
.
D
eformation
Field
(
relfield
.
data
+
coords
,
relfield
.
data
+
coords
,
src
=
relfield
.
src
,
src
=
relfield
.
src
,
xform
=
relfield
.
voxToWorldMat
)
xform
=
relfield
.
voxToWorldMat
)
assert
nonlinear
.
detectD
isplacement
Type
(
relfield
)
==
'
relative
'
assert
nonlinear
.
detectD
eformation
Type
(
relfield
)
==
'
relative
'
assert
nonlinear
.
detectD
isplacement
Type
(
absfield
)
==
'
absolute
'
assert
nonlinear
.
detectD
eformation
Type
(
absfield
)
==
'
absolute
'
def
test_convertD
isplacement
Type
():
def
test_convertD
eformation
Type
():
relfield
=
_random_field
()
relfield
=
_random_field
()
coords
=
_field_coords
(
relfield
)
coords
=
_field_coords
(
relfield
)
absfield
=
nonlinear
.
D
isplacement
Field
(
absfield
=
nonlinear
.
D
eformation
Field
(
relfield
.
data
+
coords
,
relfield
.
data
+
coords
,
src
=
relfield
.
src
,
src
=
relfield
.
src
,
xform
=
relfield
.
voxToWorldMat
)
xform
=
relfield
.
voxToWorldMat
)
gotconvrel1
=
nonlinear
.
convertD
isplacement
Type
(
relfield
)
gotconvrel1
=
nonlinear
.
convertD
eformation
Type
(
relfield
)
gotconvabs1
=
nonlinear
.
convertD
isplacement
Type
(
absfield
)
gotconvabs1
=
nonlinear
.
convertD
eformation
Type
(
absfield
)
gotconvrel2
=
nonlinear
.
convertD
isplacement
Type
(
relfield
,
'
absolute
'
)
gotconvrel2
=
nonlinear
.
convertD
eformation
Type
(
relfield
,
'
absolute
'
)
gotconvabs2
=
nonlinear
.
convertD
isplacement
Type
(
absfield
,
'
relative
'
)
gotconvabs2
=
nonlinear
.
convertD
eformation
Type
(
absfield
,
'
relative
'
)
tol
=
dict
(
atol
=
1e-5
,
rtol
=
1e-5
)
tol
=
dict
(
atol
=
1e-5
,
rtol
=
1e-5
)
...
@@ -112,7 +112,7 @@ def test_convertDisplacementType():
...
@@ -112,7 +112,7 @@ def test_convertDisplacementType():
assert
np
.
all
(
np
.
isclose
(
gotconvabs2
,
relfield
.
data
,
**
tol
))
assert
np
.
all
(
np
.
isclose
(
gotconvabs2
,
relfield
.
data
,
**
tol
))
def
test_convertD
isplacement
Space
():
def
test_convertD
eformation
Space
():
basefield
,
xform
=
_random_affine_field
()
basefield
,
xform
=
_random_affine_field
()
src
=
basefield
.
src
src
=
basefield
.
src
...
@@ -137,7 +137,7 @@ def test_convertDisplacementSpace():
...
@@ -137,7 +137,7 @@ def test_convertDisplacementSpace():
refcoords
=
affine
.
transform
(
refcoords
,
ref
.
voxToScaledVoxMat
)
refcoords
=
affine
.
transform
(
refcoords
,
ref
.
voxToScaledVoxMat
)
srccoords
=
basefield
.
transform
(
refcoords
)
srccoords
=
basefield
.
transform
(
refcoords
)
field
=
nonlinear
.
convertD
isplacement
Space
(
basefield
,
from_
,
to
)
field
=
nonlinear
.
convertD
eformation
Space
(
basefield
,
from_
,
to
)
premat
=
ref
.
getAffine
(
'
fsl
'
,
from_
)
premat
=
ref
.
getAffine
(
'
fsl
'
,
from_
)
postmat
=
src
.
getAffine
(
'
fsl
'
,
to
)
postmat
=
src
.
getAffine
(
'
fsl
'
,
to
)
...
@@ -152,7 +152,7 @@ def test_convertDisplacementSpace():
...
@@ -152,7 +152,7 @@ def test_convertDisplacementSpace():
assert
np
.
all
(
np
.
isclose
(
expect
[
~
enan
],
got
[
~
gnan
]))
assert
np
.
all
(
np
.
isclose
(
expect
[
~
enan
],
got
[
~
gnan
]))
def
test_D
isplacement
Field_transform
():
def
test_D
eformation
Field_transform
():
relfield
,
xform
=
_random_affine_field
()
relfield
,
xform
=
_random_affine_field
()
src
=
relfield
.
src
src
=
relfield
.
src
...
@@ -168,9 +168,9 @@ def test_DisplacementField_transform():
...
@@ -168,9 +168,9 @@ def test_DisplacementField_transform():
absfield
=
np
.
zeros
(
list
(
ref
.
shape
[:
3
])
+
[
3
])
absfield
=
np
.
zeros
(
list
(
ref
.
shape
[:
3
])
+
[
3
])
absfield
[:]
=
scoords
.
reshape
(
*
it
.
chain
(
ref
.
shape
,
[
3
]))
absfield
[:]
=
scoords
.
reshape
(
*
it
.
chain
(
ref
.
shape
,
[
3
]))
absfield
=
nonlinear
.
D
isplacement
Field
(
absfield
,
src
,
ref
,
absfield
=
nonlinear
.
D
eformation
Field
(
absfield
,
src
,
ref
,
header
=
ref
.
header
,
header
=
ref
.
header
,
disp
Type
=
'
absolute
'
)
def
Type
=
'
absolute
'
)
got
=
relfield
.
transform
(
rcoords
)
got
=
relfield
.
transform
(
rcoords
)
assert
np
.
all
(
np
.
isclose
(
got
,
scoords
))
assert
np
.
all
(
np
.
isclose
(
got
,
scoords
))
...
@@ -279,7 +279,7 @@ def test_CoefficientField_transform():
...
@@ -279,7 +279,7 @@ def test_CoefficientField_transform():
assert
np
.
all
(
np
.
isclose
(
gotnp
,
srccoordsnp
[
srcspace
],
**
tol
))
assert
np
.
all
(
np
.
isclose
(
gotnp
,
srccoordsnp
[
srcspace
],
**
tol
))
def
test_coefficientFieldToD
isplacement
Field
():
def
test_coefficientFieldToD
eformation
Field
():
nldir
=
op
.
join
(
datadir
,
'
nonlinear
'
)
nldir
=
op
.
join
(
datadir
,
'
nonlinear
'
)
src
=
op
.
join
(
nldir
,
'
src.nii.gz
'
)
src
=
op
.
join
(
nldir
,
'
src.nii.gz
'
)
...
@@ -293,50 +293,20 @@ def test_coefficientFieldToDisplacementField():
...
@@ -293,50 +293,20 @@ def test_coefficientFieldToDisplacementField():
cf
=
fnirt
.
readFnirt
(
cf
,
src
,
ref
)
cf
=
fnirt
.
readFnirt
(
cf
,
src
,
ref
)
rdf
=
fnirt
.
readFnirt
(
df
,
src
,
ref
)
rdf
=
fnirt
.
readFnirt
(
df
,
src
,
ref
)
rdfnp
=
fnirt
.
readFnirt
(
dfnp
,
src
,
ref
)
rdfnp
=
fnirt
.
readFnirt
(
dfnp
,
src
,
ref
)
adf
=
nonlinear
.
convertD
isplacement
Type
(
rdf
)
adf
=
nonlinear
.
convertD
eformation
Type
(
rdf
)
adfnp
=
nonlinear
.
convertD
isplacement
Type
(
rdfnp
)
adfnp
=
nonlinear
.
convertD
eformation
Type
(
rdfnp
)
rcnv
=
nonlinear
.
coefficientFieldToD
isplacement
Field
(
cf
)
rcnv
=
nonlinear
.
coefficientFieldToD
eformation
Field
(
cf
)
acnv
=
nonlinear
.
coefficientFieldToD
isplacement
Field
(
cf
,
acnv
=
nonlinear
.
coefficientFieldToD
eformation
Field
(
cf
,
disp
Type
=
'
absolute
'
)
def
Type
=
'
absolute
'
)
acnvnp
=
nonlinear
.
coefficientFieldToD
isplacement
Field
(
cf
,
acnvnp
=
nonlinear
.
coefficientFieldToD
eformation
Field
(
cf
,
disp
Type
=
'
absolute
'
,
def
Type
=
'
absolute
'
,
premat
=
False
)
premat
=
False
)
rcnvnp
=
nonlinear
.
coefficientFieldToD
isplacement
Field
(
cf
,
rcnvnp
=
nonlinear
.
coefficientFieldToD
eformation
Field
(
cf
,
premat
=
False
)
premat
=
False
)
tol
=
dict
(
atol
=
1e-5
,
rtol
=
1e-5
)
tol
=
dict
(
atol
=
1e-5
,
rtol
=
1e-5
)
assert
np
.
all
(
np
.
isclose
(
rcnv
.
data
,
rdf
.
data
,
**
tol
))
assert
np
.
all
(
np
.
isclose
(
rcnv
.
data
,
rdf
.
data
,
**
tol
))
assert
np
.
all
(
np
.
isclose
(
acnv
.
data
,
adf
.
data
,
**
tol
))
assert
np
.
all
(
np
.
isclose
(
acnv
.
data
,
adf
.
data
,
**
tol
))
assert
np
.
all
(
np
.
isclose
(
rcnvnp
.
data
,
rdfnp
.
data
,
**
tol
))
assert
np
.
all
(
np
.
isclose
(
rcnvnp
.
data
,
rdfnp
.
data
,
**
tol
))
assert
np
.
all
(
np
.
isclose
(
acnvnp
.
data
,
adfnp
.
data
,
**
tol
))
assert
np
.
all
(
np
.
isclose
(
acnvnp
.
data
,
adfnp
.
data
,
**
tol
))
def
test_DisplacementFIeld_srcToRefMat
():
field1
=
_random_field
()
xform
=
affine
.
compose
(
np
.
random
.
randint
(
1
,
10
,
3
),
np
.
random
.
randint
(
1
,
100
,
3
),
np
.
random
.
random
(
3
)
*
np
.
pi
/
2
)
field2
=
nonlinear
.
DisplacementField
(
field1
.
data
,
xform
=
field1
.
voxToWorldMat
,
src
=
field1
.
src
,
ref
=
field1
.
ref
,
srcToRefMat
=
xform
)
x
=
np
.
random
.
randint
(
0
,
field1
.
shape
[
0
],
100
)
y
=
np
.
random
.
randint
(
0
,
field1
.
shape
[
1
],
100
)
z
=
np
.
random
.
randint
(
0
,
field1
.
shape
[
2
],
100
)
coords
=
np
.
array
([
x
,
y
,
z
]).
T
coords
=
affine
.
transform
(
coords
,
field1
.
ref
.
getAffine
(
'
voxel
'
,
'
fsl
'
))
coordsf1
=
field1
.
transform
(
coords
)
coordsf2
=
field2
.
transform
(
coords
)
coordsf1
=
affine
.
transform
(
coordsf1
,
affine
.
invert
(
xform
))
assert
np
.
all
(
np
.
isclose
(
coordsf1
,
coordsf2
))
This diff is collapsed.
Click to expand it.
tests/test_transform/test_x5.py
+
33
−
77
View file @
2fb312ae
...
@@ -9,6 +9,8 @@
...
@@ -9,6 +9,8 @@
import
os.path
as
op
import
os.path
as
op
import
numpy
as
np
import
numpy
as
np
import
pytest
import
h5py
import
h5py
import
fsl.data.image
as
fslimage
import
fsl.data.image
as
fslimage
...
@@ -27,8 +29,8 @@ def _check_metadata(group):
...
@@ -27,8 +29,8 @@ def _check_metadata(group):
def
_check_affine
(
group
,
xform
):
def
_check_affine
(
group
,
xform
):
assert
group
.
attrs
[
'
Type
'
]
==
'
l
ine
ar
'
assert
group
.
attrs
[
'
Type
'
]
==
'
aff
ine
'
gotxform
=
np
.
array
(
group
[
'
Transform
'
])
gotxform
=
np
.
array
(
group
[
'
Matrix
'
])
assert
np
.
all
(
np
.
isclose
(
gotxform
,
xform
))
assert
np
.
all
(
np
.
isclose
(
gotxform
,
xform
))
...
@@ -39,28 +41,12 @@ def _check_space(group, img):
...
@@ -39,28 +41,12 @@ def _check_space(group, img):
_check_affine
(
group
[
'
Mapping
'
],
img
.
voxToWorldMat
)
_check_affine
(
group
[
'
Mapping
'
],
img
.
voxToWorldMat
)
def
_check_nonlinear_common
(
group
,
field
):
def
_check_deformation
(
group
,
field
):
assert
group
.
attrs
[
'
Type
'
]
==
'
nonlinear
'
assert
group
.
attrs
[
'
Type
'
]
==
'
deformation
'
assert
group
.
attrs
[
'
SubType
'
]
==
field
.
deformationType
if
isinstance
(
field
,
nonlinear
.
DisplacementField
):
xform
=
np
.
array
(
group
[
'
Matrix
'
])
assert
group
.
attrs
[
'
SubType
'
]
==
'
displacement
'
assert
np
.
all
(
np
.
isclose
(
xform
,
field
.
data
))
assert
group
.
attrs
[
'
Representation
'
]
==
field
.
displacementType
_check_affine
(
group
[
'
Mapping
'
],
field
.
voxToWorldMat
)
elif
isinstance
(
field
,
nonlinear
.
CoefficientField
):
assert
group
.
attrs
[
'
SubType
'
]
==
'
coefficient
'
if
field
.
fieldType
==
'
cubic
'
:
assert
group
.
attrs
[
'
Representation
'
]
==
'
cubic bspline
'
elif
field
.
fieldType
==
'
quadratic
'
:
assert
group
.
attrs
[
'
Representation
'
]
==
'
quadratic bspline
'
_check_space
(
group
[
'
From
'
],
field
.
src
)
_check_space
(
group
[
'
To
'
],
field
.
ref
)
pre
=
field
.
ref
.
getAffine
(
'
world
'
,
'
fsl
'
)
post
=
field
.
src
.
getAffine
(
'
fsl
'
,
'
world
'
)
_check_affine
(
group
[
'
Pre
'
],
pre
)
_check_affine
(
group
[
'
Post
'
],
post
)
def
test_readWriteLinearX5
():
def
test_readWriteLinearX5
():
...
@@ -84,73 +70,43 @@ def test_readWriteLinearX5():
...
@@ -84,73 +70,43 @@ def test_readWriteLinearX5():
with
h5py
.
File
(
'
linear.x5
'
,
'
r
'
)
as
f
:
with
h5py
.
File
(
'
linear.x5
'
,
'
r
'
)
as
f
:
_check_metadata
(
f
)
_check_metadata
(
f
)
_check_affine
(
f
[
'
/
'
],
xform
)
assert
f
.
attrs
[
'
Type
'
]
==
'
linear
'
_check_space
(
f
[
'
/From
'
],
src
)
_check_affine
(
f
[
'
/Transform
'
],
xform
)
_check_space
(
f
[
'
/To
'
],
ref
)
_check_space
(
f
[
'
/A
'
],
src
)
_check_space
(
f
[
'
/B
'
],
ref
)
def
test_readWriteNonLinearX5
_DisplacementField
():
def
test_readWriteNonLinearX5
():
datadir
=
op
.
join
(
op
.
dirname
(
__file__
),
'
testdata
'
,
'
nonlinear
'
)
datadir
=
op
.
join
(
op
.
dirname
(
__file__
),
'
testdata
'
,
'
nonlinear
'
)
dffile
=
op
.
join
(
datadir
,
'
displacementfield.nii.gz
'
)
dffile
=
op
.
join
(
datadir
,
'
displacementfield.nii.gz
'
)
srcfile
=
op
.
join
(
datadir
,
'
src.nii.gz
'
)
srcfile
=
op
.
join
(
datadir
,
'
src.nii.gz
'
)
reffile
=
op
.
join
(
datadir
,
'
ref.nii.gz
'
)
reffile
=
op
.
join
(
datadir
,
'
ref.nii.gz
'
)
src
=
fslimage
.
Image
(
srcfile
)
src
=
fslimage
.
Image
(
srcfile
)
ref
=
fslimage
.
Image
(
reffile
)
ref
=
fslimage
.
Image
(
reffile
)
dfield
=
fnirt
.
readFnirt
(
dffile
,
src
,
ref
)
dfield
=
fnirt
.
readFnirt
(
df
f
i
le
,
src
,
ref
)
w
dfield
=
nonlinear
.
convertDeformationSpace
(
dfi
eld
,
'
world
'
,
'
world
'
)
with
tempdir
.
tempdir
():
with
tempdir
.
tempdir
():
x5
.
writeNonLinearX5
(
'
nonlinear.x5
'
,
dfield
)
# field must be world->world
with
pytest
.
raises
(
x5
.
X5Error
):
x5
.
writeNonLinearX5
(
'
nonlinear.x5
'
,
dfield
)
x5
.
writeNonLinearX5
(
'
nonlinear.x5
'
,
wdfield
)
gotdfield
=
x5
.
readNonLinearX5
(
'
nonlinear.x5
'
)
gotdfield
=
x5
.
readNonLinearX5
(
'
nonlinear.x5
'
)
assert
gotdfield
.
src
.
sameSpace
(
src
)
assert
gotdfield
.
src
.
sameSpace
(
src
)
assert
gotdfield
.
ref
.
sameSpace
(
ref
)
assert
gotdfield
.
ref
.
sameSpace
(
ref
)
assert
gotdfield
.
srcSpace
==
dfield
.
srcSpace
assert
gotdfield
.
srcSpace
==
w
dfield
.
srcSpace
assert
gotdfield
.
refSpace
==
dfield
.
refSpace
assert
gotdfield
.
refSpace
==
w
dfield
.
refSpace
assert
gotdfield
.
d
isplacement
Type
==
dfield
.
d
isplacement
Type
assert
gotdfield
.
d
eformation
Type
==
w
dfield
.
d
eformation
Type
assert
np
.
all
(
np
.
isclose
(
gotdfield
.
data
,
dfield
.
data
))
assert
np
.
all
(
np
.
isclose
(
gotdfield
.
data
,
w
dfield
.
data
))
with
h5py
.
File
(
'
nonlinear.x5
'
,
'
r
'
)
as
f
:
with
h5py
.
File
(
'
nonlinear.x5
'
,
'
r
'
)
as
f
:
assert
f
.
attrs
[
'
Type
'
]
==
'
nonlinear
'
_check_metadata
(
f
)
_check_metadata
(
f
)
_check_nonlinear_common
(
f
[
'
/
'
],
dfield
)
_check_deformation
(
f
[
'
/Transform
'
],
wdfield
)
_check_space
(
f
[
'
/A
'
],
ref
)
xform
=
np
.
array
(
f
[
'
/Transform
'
])
_check_space
(
f
[
'
/B
'
],
src
)
assert
np
.
all
(
np
.
isclose
(
xform
,
dfield
.
data
))
def
test_readWriteNonLinearX5_CoefficientField
():
datadir
=
op
.
join
(
op
.
dirname
(
__file__
),
'
testdata
'
,
'
nonlinear
'
)
cffile
=
op
.
join
(
datadir
,
'
coefficientfield.nii.gz
'
)
srcfile
=
op
.
join
(
datadir
,
'
src.nii.gz
'
)
reffile
=
op
.
join
(
datadir
,
'
ref.nii.gz
'
)
src
=
fslimage
.
Image
(
srcfile
)
ref
=
fslimage
.
Image
(
reffile
)
cfield
=
fnirt
.
readFnirt
(
cffile
,
src
,
ref
)
with
tempdir
.
tempdir
():
x5
.
writeNonLinearX5
(
'
nonlinear.x5
'
,
cfield
)
gotcfield
=
x5
.
readNonLinearX5
(
'
nonlinear.x5
'
)
assert
gotcfield
.
src
.
sameSpace
(
src
)
assert
gotcfield
.
ref
.
sameSpace
(
ref
)
assert
gotcfield
.
srcSpace
==
cfield
.
srcSpace
assert
gotcfield
.
refSpace
==
cfield
.
refSpace
assert
gotcfield
.
knotSpacing
==
cfield
.
knotSpacing
assert
np
.
all
(
np
.
isclose
(
gotcfield
.
fieldToRefMat
,
cfield
.
fieldToRefMat
))
assert
np
.
all
(
np
.
isclose
(
gotcfield
.
srcToRefMat
,
cfield
.
srcToRefMat
))
assert
np
.
all
(
np
.
isclose
(
gotcfield
.
data
,
cfield
.
data
))
with
h5py
.
File
(
'
nonlinear.x5
'
,
'
r
'
)
as
f
:
_check_metadata
(
f
)
_check_nonlinear_common
(
f
[
'
/
'
],
cfield
)
_check_affine
(
f
[
'
/InitialAlignment
'
],
cfield
.
srcToRefMat
)
_check_affine
(
f
[
'
/Parameters/ReferenceToField
'
],
cfield
.
refToFieldMat
)
assert
np
.
all
(
np
.
isclose
(
f
[
'
/Parameters
'
].
attrs
[
'
Spacing
'
],
cfield
.
knotSpacing
))
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