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
Package registry
Model registry
Operate
Environments
Terraform modules
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
Evan Edmond
fslpy
Commits
e9ebbb4a
Commit
e9ebbb4a
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
TEST: Rename modules/functions in tests, new test for fsl_convert_x5
parent
172a6490
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_fsl_convert_x5.py
+55
-0
55 additions, 0 deletions
tests/test_fsl_convert_x5.py
tests/test_transform_nonlinear.py
+14
-14
14 additions, 14 deletions
tests/test_transform_nonlinear.py
with
69 additions
and
14 deletions
tests/test_fsl_convert_x5.py
0 → 100644
+
55
−
0
View file @
e9ebbb4a
#!/usr/bin/env python
import
numpy
as
np
import
fsl.utils.tempdir
as
tempdir
import
fsl.utils.transform
as
transform
import
fsl.data.image
as
fslimage
import
fsl.scripts.fsl_convert_x5
as
fsl_convert_x5
def
random_image
():
vx
,
vy
,
vz
=
np
.
random
.
randint
(
10
,
50
,
3
)
dx
,
dy
,
dz
=
np
.
random
.
randint
(
1
,
10
,
3
)
data
=
(
np
.
random
.
random
((
vx
,
vy
,
vz
))
-
0.5
)
*
10
aff
=
transform
.
compose
(
(
dx
,
dy
,
dz
),
np
.
random
.
randint
(
1
,
100
,
3
),
np
.
random
.
random
(
3
)
*
np
.
pi
/
2
)
return
fslimage
.
Image
(
data
,
xform
=
aff
)
def
test_convert_flirt
():
with
tempdir
.
tempdir
():
src
=
random_image
()
ref
=
random_image
()
src
.
save
(
'
src
'
)
ref
.
save
(
'
ref
'
)
xform
=
transform
.
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
)
fsl_convert_x5
.
main
(
'
flirt -s src -r ref
'
'
src2ref.mat src2ref.x5
'
.
split
())
expxform
=
transform
.
concat
(
ref
.
getAffine
(
'
fsl
'
,
'
world
'
),
xform
,
src
.
getAffine
(
'
world
'
,
'
fsl
'
))
gotxform
,
gotsrc
,
gotref
=
transform
.
readFlirtX5
(
'
src2ref.x5
'
)
assert
np
.
all
(
np
.
isclose
(
gotxform
,
expxform
))
assert
src
.
sameSpace
(
gotsrc
)
assert
ref
.
sameSpace
(
gotref
)
fsl_convert_x5
.
main
(
'
flirt -s src -r ref src2ref.x5
'
'
src2ref_copy.mat
'
.
split
())
gotxform
=
transform
.
readFlirt
(
'
src2ref_copy.mat
'
)
assert
np
.
all
(
np
.
isclose
(
gotxform
,
xform
))
This diff is collapsed.
Click to expand it.
tests/test_transform_nonlinear.py
+
14
−
14
View file @
e9ebbb4a
...
@@ -6,7 +6,7 @@ import nibabel as nib
...
@@ -6,7 +6,7 @@ import nibabel as nib
import
fsl.data.image
as
fslimage
import
fsl.data.image
as
fslimage
import
fsl.utils.transform
as
transform
import
fsl.utils.transform
as
transform
import
fsl.utils.transform.
dispfield
as
dispfield
import
fsl.utils.transform.
nonlinear
as
nonlinear
def
_random_field
():
def
_random_field
():
...
@@ -19,7 +19,7 @@ def _random_field():
...
@@ -19,7 +19,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
dispfield
.
DisplacementField
(
field
,
xform
=
aff
)
return
nonlinear
.
DisplacementField
(
field
,
xform
=
aff
)
def
_field_coords
(
field
):
def
_field_coords
(
field
):
...
@@ -33,29 +33,29 @@ def _field_coords(field):
...
@@ -33,29 +33,29 @@ def _field_coords(field):
field
.
getAffine
(
'
voxel
'
,
'
fsl
'
)).
reshape
(
field
.
shape
)
field
.
getAffine
(
'
voxel
'
,
'
fsl
'
)).
reshape
(
field
.
shape
)
def
test_detectType
():
def
test_detect
Displacement
Type
():
relfield
=
_random_field
()
relfield
=
_random_field
()
coords
=
_field_coords
(
relfield
)
coords
=
_field_coords
(
relfield
)
absfield
=
dispfield
.
DisplacementField
(
absfield
=
nonlinear
.
DisplacementField
(
relfield
.
data
+
coords
,
xform
=
relfield
.
voxToWorldMat
)
relfield
.
data
+
coords
,
xform
=
relfield
.
voxToWorldMat
)
assert
dispfield
.
detec
tType
(
relfield
)
==
'
relative
'
assert
nonlinear
.
detectDisplacemen
tType
(
relfield
)
==
'
relative
'
assert
dispfield
.
detec
tType
(
absfield
)
==
'
absolute
'
assert
nonlinear
.
detectDisplacemen
tType
(
absfield
)
==
'
absolute
'
def
test_convertType
():
def
test_convert
Displacemeny
Type
():
relfield
=
dispfield
.
DisplacementField
(
_random_field
())
relfield
=
nonlinear
.
DisplacementField
(
_random_field
())
coords
=
_field_coords
(
relfield
)
coords
=
_field_coords
(
relfield
)
absfield
=
fslimage
.
Image
(
absfield
=
fslimage
.
Image
(
relfield
.
data
+
coords
,
xform
=
relfield
.
voxToWorldMat
)
relfield
.
data
+
coords
,
xform
=
relfield
.
voxToWorldMat
)
relfield
=
dispfield
.
DisplacementField
(
relfield
)
relfield
=
nonlinear
.
DisplacementField
(
relfield
)
absfield
=
dispfield
.
DisplacementField
(
absfield
)
absfield
=
nonlinear
.
DisplacementField
(
absfield
)
gotconvrel1
=
dispfield
.
conver
tType
(
relfield
)
gotconvrel1
=
nonlinear
.
convertDisplacemen
tType
(
relfield
)
gotconvabs1
=
dispfield
.
conver
tType
(
absfield
)
gotconvabs1
=
nonlinear
.
convertDisplacemen
tType
(
absfield
)
gotconvrel2
=
dispfield
.
conver
tType
(
relfield
,
'
absolute
'
)
gotconvrel2
=
nonlinear
.
convertDisplacemen
tType
(
relfield
,
'
absolute
'
)
gotconvabs2
=
dispfield
.
conver
tType
(
absfield
,
'
relative
'
)
gotconvabs2
=
nonlinear
.
convertDisplacemen
tType
(
absfield
,
'
relative
'
)
assert
np
.
all
(
np
.
isclose
(
gotconvrel1
,
absfield
.
data
))
assert
np
.
all
(
np
.
isclose
(
gotconvrel1
,
absfield
.
data
))
assert
np
.
all
(
np
.
isclose
(
gotconvabs1
,
relfield
.
data
))
assert
np
.
all
(
np
.
isclose
(
gotconvabs1
,
relfield
.
data
))
...
...
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