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
fe8f3227
Commit
fe8f3227
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
imglob made into a standalone function
parent
7c6ce4a8
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/imglob.py
+50
-17
50 additions, 17 deletions
fsl/scripts/imglob.py
with
50 additions
and
17 deletions
fsl/scripts/imglob.py
+
50
−
17
View file @
fe8f3227
...
@@ -26,24 +26,33 @@ exts = fslimage.ALLOWED_EXTENSIONS
...
@@ -26,24 +26,33 @@ exts = fslimage.ALLOWED_EXTENSIONS
groups
=
fslimage
.
FILE_GROUPS
groups
=
fslimage
.
FILE_GROUPS
def
main
(
argv
=
None
):
def
imglob
(
paths
,
output
=
None
):
"""
The ``imglob`` utility. Given a list of file names, identifies and prints
"""
Given a list of file names, identifies and returns the unique
the unique NIFTI/ANALYZE image files.
NIFTI/ANALYZE image files that exist.
:arg paths: Sequence of paths/prefixes to glob.
:arg output: One of ``
'
prefix
'
`` (the default), ``
'
all
'
``, or
``
'
primary
'
``:
- ``
'
prefix
'
``: Returns the files without extensions.
- ``
'
all
'
``: Returns all files that match (e.g. both
``.img`` and ``.hdr`` files will be
returned).
- ``
'
primary
'
``: Returns only the primary file of each
matching file group, e.g. only the
``.hdr`` file would be returned from
an ``.img``/``.hdr`` pair.
:returns: A sequence of resolved path names, in the form specified
by the ``output`` parameter.
"""
"""
if
argv
is
None
:
if
output
is
None
:
argv
=
sys
.
argv
[
1
:]
output
=
'
prefix
'
if
len
(
argv
)
<
1
:
print
(
usage
)
return
1
if
argv
[
0
]
==
'
-extension
'
:
output
=
'
primary
'
elif
argv
[
0
]
==
'
-extensions
'
:
output
=
'
all
'
else
:
output
=
'
prefix
'
if
output
==
'
prefix
'
:
paths
=
argv
if
output
not
in
(
'
prefix
'
,
'
all
'
,
'
primary
'
):
else
:
paths
=
argv
[
1
:]
raise
ValueError
(
'
Unsupported output format: {}
'
.
format
(
output
))
imgfiles
=
[]
imgfiles
=
[]
...
@@ -51,6 +60,7 @@ def main(argv=None):
...
@@ -51,6 +60,7 @@ def main(argv=None):
# hdr and img and otherwise) that match
# hdr and img and otherwise) that match
for
path
in
paths
:
for
path
in
paths
:
try
:
try
:
path
=
fslimage
.
removeExt
(
path
)
imgfiles
.
extend
(
fslimage
.
addExt
(
path
,
unambiguous
=
False
))
imgfiles
.
extend
(
fslimage
.
addExt
(
path
,
unambiguous
=
False
))
except
fslpath
.
PathError
:
except
fslpath
.
PathError
:
continue
continue
...
@@ -66,9 +76,32 @@ def main(argv=None):
...
@@ -66,9 +76,32 @@ def main(argv=None):
allowedExts
=
exts
,
allowedExts
=
exts
,
fileGroups
=
groups
)
fileGroups
=
groups
)
imgfiles
=
sorted
(
set
(
imgfiles
))
return
list
(
sorted
(
set
(
imgfiles
)))
def
main
(
argv
=
None
):
"""
The ``imglob`` application. Given a list of file names, identifies and
prints the unique NIFTI/ANALYZE image files.
"""
if
argv
is
None
:
argv
=
sys
.
argv
[
1
:]
if
len
(
argv
)
<
1
:
print
(
usage
)
return
1
if
argv
[
0
]
==
'
-extension
'
:
output
=
'
primary
'
elif
argv
[
0
]
==
'
-extensions
'
:
output
=
'
all
'
else
:
output
=
'
prefix
'
if
output
==
'
prefix
'
:
paths
=
argv
else
:
paths
=
argv
[
1
:]
imgfiles
=
imglob
(
paths
,
output
)
print
(
'
'
.
join
(
imgfiles
))
if
len
(
imgfiles
)
>
0
:
print
(
'
'
.
join
(
imgfiles
))
return
0
return
0
...
...
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