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
3099f2fe
Commit
3099f2fe
authored
4 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
ENH: new imtest script
parent
f03d3780
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/scripts/imtest.py
+61
-0
61 additions, 0 deletions
fsl/scripts/imtest.py
with
61 additions
and
0 deletions
fsl/scripts/imtest.py
0 → 100644
+
61
−
0
View file @
3099f2fe
#!/usr/bin/env python
#
# imtest.py - Test whether an image file exists or not.
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
"""
The ``imtest`` script can be used to test whether an image file exists or
not, without having to know the file suffix (.nii, .nii.gz, etc).
"""
import
os.path
as
op
import
sys
import
warnings
import
fsl.utils.path
as
fslpath
# See atlasq.py for explanation
with
warnings
.
catch_warnings
():
warnings
.
filterwarnings
(
"
ignore
"
,
category
=
FutureWarning
)
import
fsl.data.image
as
fslimage
ALLOWED_EXTENSIONS
=
fslimage
.
ALLOWED_EXTENSIONS
+
[
'
.mnc
'
,
'
.mnc.gz
'
]
"""
List of file extensions that are supported by ``imln``.
"""
def
main
(
argv
=
None
):
"""
Test if an image path exists, and prints ``
'
1
'
`` if it does or ``
'
0
'
``
if it doesn
'
t.
"""
if
argv
is
None
:
argv
=
sys
.
argv
[
1
:]
# emulate old fslio/imtest - always return 0
if
len
(
argv
)
!=
1
:
print
(
'
0
'
)
return
0
path
=
fslpath
.
removeExt
(
argv
[
0
],
ALLOWED_EXTENSIONS
)
path
=
op
.
realpath
(
path
)
# getFileGroup will raise an error
# if the image (including all
# components - i.e. header and
# image) does not exist
try
:
fslpath
.
getFileGroup
(
path
,
allowedExts
=
ALLOWED_EXTENSIONS
,
fileGroups
=
fslimage
.
FILE_GROUPS
,
unambiguous
=
True
)
print
(
'
1
'
)
except
fslpath
.
PathError
:
print
(
'
0
'
)
return
0
if
__name__
==
'
__main__
'
:
sys
.
exit
(
main
())
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