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
1cd1392f
Commit
1cd1392f
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
TEST: Initial tests for dispfield module
parent
175bf746
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_transform_dispfield.py
+63
-0
63 additions, 0 deletions
tests/test_transform_dispfield.py
with
63 additions
and
0 deletions
tests/test_transform_dispfield.py
0 → 100644
+
63
−
0
View file @
1cd1392f
#!/usr/bin/env python
import
numpy
as
np
import
nibabel
as
nib
import
fsl.data.image
as
fslimage
import
fsl.utils.transform
as
transform
import
fsl.utils.transform.dispfield
as
dispfield
def
_random_field
():
vx
,
vy
,
vz
=
np
.
random
.
randint
(
10
,
50
,
3
)
dx
,
dy
,
dz
=
np
.
random
.
randint
(
1
,
10
,
3
)
field
=
(
np
.
random
.
random
((
vx
,
vy
,
vz
,
3
))
-
0.5
)
*
10
aff
=
transform
.
compose
(
(
dx
,
dy
,
dz
),
np
.
random
.
randint
(
1
,
100
,
3
),
np
.
random
.
random
(
3
)
*
np
.
pi
/
2
)
return
dispfield
.
DisplacementField
(
field
,
xform
=
aff
)
def
_field_coords
(
field
):
vx
,
vy
,
vz
=
field
.
shape
[
:
3
]
coords
=
np
.
meshgrid
(
np
.
arange
(
vx
),
np
.
arange
(
vy
),
np
.
arange
(
vz
),
indexing
=
'
ij
'
)
coords
=
np
.
array
(
coords
).
transpose
((
1
,
2
,
3
,
0
))
return
transform
.
transform
(
coords
.
reshape
(
-
1
,
3
),
field
.
getAffine
(
'
voxel
'
,
'
fsl
'
)).
reshape
(
field
.
shape
)
def
test_detectType
():
relfield
=
_random_field
()
coords
=
_field_coords
(
relfield
)
absfield
=
dispfield
.
DisplacementField
(
relfield
.
data
+
coords
,
xform
=
relfield
.
voxToWorldMat
)
assert
dispfield
.
detectType
(
relfield
)
==
'
relative
'
assert
dispfield
.
detectType
(
absfield
)
==
'
absolute
'
def
test_convertType
():
relfield
=
dispfield
.
DisplacementField
(
_random_field
())
coords
=
_field_coords
(
relfield
)
absfield
=
fslimage
.
Image
(
relfield
.
data
+
coords
,
xform
=
relfield
.
voxToWorldMat
)
relfield
=
dispfield
.
DisplacementField
(
relfield
)
absfield
=
dispfield
.
DisplacementField
(
absfield
)
gotconvrel1
=
dispfield
.
convertType
(
relfield
)
gotconvabs1
=
dispfield
.
convertType
(
absfield
)
gotconvrel2
=
dispfield
.
convertType
(
relfield
,
'
absolute
'
)
gotconvabs2
=
dispfield
.
convertType
(
absfield
,
'
relative
'
)
assert
np
.
all
(
np
.
isclose
(
gotconvrel1
,
absfield
.
data
))
assert
np
.
all
(
np
.
isclose
(
gotconvabs1
,
relfield
.
data
))
assert
np
.
all
(
np
.
isclose
(
gotconvrel2
,
absfield
.
data
))
assert
np
.
all
(
np
.
isclose
(
gotconvabs2
,
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