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
9715cb4c
Commit
9715cb4c
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Changes to tests.testdir and make_random_image utility functions
parent
33a9763a
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/__init__.py
+43
-8
43 additions, 8 deletions
tests/__init__.py
with
43 additions
and
8 deletions
tests/__init__.py
+
43
−
8
View file @
9715cb4c
...
@@ -94,7 +94,7 @@ class CaptureStdout(object):
...
@@ -94,7 +94,7 @@ class CaptureStdout(object):
def
testdir
(
contents
=
None
):
def
testdir
(
contents
=
None
,
suffix
=
None
):
"""
Returnsa context manager which creates, changes to, and returns a
"""
Returnsa context manager which creates, changes to, and returns a
temporary directory, and then deletes it on exit.
temporary directory, and then deletes it on exit.
"""
"""
...
@@ -109,7 +109,7 @@ def testdir(contents=None):
...
@@ -109,7 +109,7 @@ def testdir(contents=None):
def
__enter__
(
self
):
def
__enter__
(
self
):
self
.
testdir
=
tempfile
.
mkdtemp
()
self
.
testdir
=
tempfile
.
mkdtemp
(
suffix
=
suffix
)
self
.
prevdir
=
os
.
getcwd
()
self
.
prevdir
=
os
.
getcwd
()
os
.
chdir
(
self
.
testdir
)
os
.
chdir
(
self
.
testdir
)
...
@@ -194,21 +194,56 @@ def random_voxels(shape, nvoxels=1):
...
@@ -194,21 +194,56 @@ def random_voxels(shape, nvoxels=1):
return
randVoxels
return
randVoxels
def
make_random_image
(
filename
,
dims
=
(
10
,
10
,
10
),
xform
=
None
):
def
make_random_image
(
filename
=
None
,
"""
Creates a NIFTI1 image with random data, saves and
dims
=
(
10
,
10
,
10
),
returns it.
xform
=
None
,
imgtype
=
1
,
pixdims
=
None
,
dtype
=
np
.
float32
):
"""
Convenience function which makes an image containing random data.
Saves and returns the nibabel object.
imgtype == 0: ANALYZE
imgtype == 1: NIFTI1
imgtype == 2: NIFTI2
"""
"""
if
imgtype
==
0
:
hdr
=
nib
.
AnalyzeHeader
()
elif
imgtype
==
1
:
hdr
=
nib
.
Nifti1Header
()
elif
imgtype
==
2
:
hdr
=
nib
.
Nifti2Header
()
if
pixdims
is
None
:
pixdims
=
[
1
]
*
len
(
dims
)
pixdims
=
pixdims
[:
len
(
dims
)]
zooms
=
[
abs
(
p
)
for
p
in
pixdims
]
hdr
.
set_data_dtype
(
dtype
)
hdr
.
set_data_shape
(
dims
)
hdr
.
set_zooms
(
zooms
)
if
xform
is
None
:
if
xform
is
None
:
xform
=
np
.
eye
(
4
)
xform
=
np
.
eye
(
4
)
for
i
,
p
in
enumerate
(
pixdims
[:
3
]):
xform
[
i
,
i
]
=
p
data
=
np
.
array
(
np
.
random
.
random
(
dims
)
*
100
,
dtype
=
np
.
float32
)
data
=
np
.
array
(
np
.
random
.
random
(
dims
)
*
100
,
dtype
=
dtype
)
img
=
nib
.
Nifti1Image
(
data
,
xform
)
nib
.
save
(
img
,
filename
)
if
imgtype
==
0
:
img
=
nib
.
AnalyzeImage
(
data
,
xform
,
hdr
)
elif
imgtype
==
1
:
img
=
nib
.
Nifti1Image
(
data
,
xform
,
hdr
)
elif
imgtype
==
2
:
img
=
nib
.
Nifti2Image
(
data
,
xform
,
hdr
)
if
filename
is
not
None
:
if
op
.
splitext
(
filename
)[
1
]
==
''
:
if
imgtype
==
0
:
filename
=
'
{}.img
'
.
format
(
filename
)
else
:
filename
=
'
{}.nii
'
.
format
(
filename
)
nib
.
save
(
img
,
filename
)
return
img
return
img
def
make_mock_feat_analysis
(
featdir
,
def
make_mock_feat_analysis
(
featdir
,
testdir
,
testdir
,
shape4D
,
shape4D
,
...
...
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