Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Michiel Cottaar
fslpy
Commits
33a9763a
Commit
33a9763a
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
More little adjustments to assertions module
parent
c9cc1dec
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/utils/assertions.py
+10
-6
10 additions, 6 deletions
fsl/utils/assertions.py
with
10 additions
and
6 deletions
fsl/utils/assertions.py
+
10
−
6
View file @
33a9763a
...
...
@@ -12,6 +12,7 @@
import
os.path
as
op
import
nibabel
as
nib
import
fsl.utils.ensure
as
ensure
import
fsl.data.melodicanalysis
as
fslma
...
...
@@ -25,7 +26,7 @@ def assertIsNifti3D(*args):
"""
Raise an exception if the specified file/s are not 3D nifti.
"""
for
f
in
args
:
assertIsNifti
(
f
)
d
=
nib
.
load
(
f
)
d
=
ensure
.
ensureIsImage
(
f
)
assert
len
(
d
.
shape
)
==
3
,
\
'
incorrect shape for 3D nifti: {}:{}
'
.
format
(
d
.
shape
,
f
)
...
...
@@ -34,7 +35,7 @@ def assertIsNifti4D(*args):
"""
Raise an exception if the specified file/s are not 4D nifti.
"""
for
f
in
args
:
assertIsNifti
(
f
)
d
=
nib
.
load
(
f
)
d
=
ensure
.
ensureIsImage
(
f
)
assert
len
(
d
.
shape
)
==
4
,
\
'
incorrect shape for 4D nifti: {}:{}
'
.
format
(
d
.
shape
,
f
)
...
...
@@ -42,16 +43,19 @@ def assertIsNifti4D(*args):
def
assertIsNifti
(
*
args
):
"""
Raise an exception if the specified file/s are not nifti.
"""
for
f
in
args
:
assert
isinstance
(
f
,
nib
.
nifti1
.
Nifti1Image
)
or
\
f
.
endswith
(
'
.nii.gz
'
)
or
f
.
endswith
(
'
.nii
'
),
\
f
=
ensure
.
ensureIsImage
(
f
)
# Nifti2Image derives from Nifti1Image,
# so we only need to test the latter.
assert
isinstance
(
f
,
nib
.
nifti1
.
Nifti1Image
),
\
'
file must be a nifti (.nii or .nii.gz): {}
'
.
format
(
f
)
def
assertNiftiShape
(
shape
,
*
args
):
"""
Raise an exception if the specified nifti/s are not specified shape.
"""
for
fname
in
args
:
d
=
nib
.
load
(
fname
)
assert
d
.
shape
==
shape
,
\
d
=
ensure
.
ensureIsImage
(
fname
)
assert
tuple
(
d
.
shape
)
==
tuple
(
shape
)
,
\
'
incorrect shape ({}) for nifti: {}:{}
'
.
format
(
shape
,
d
.
shape
,
fname
)
...
...
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