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
8c69d1bb
Commit
8c69d1bb
authored
3 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
MNT: Improve imglob performance by avoiding expensive imports (numpy/nibabel/etc)
parent
2306f558
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
fsl/scripts/imglob.py
+17
-10
17 additions, 10 deletions
fsl/scripts/imglob.py
fsl/utils/path.py
+1
-2
1 addition, 2 deletions
fsl/utils/path.py
with
18 additions
and
12 deletions
fsl/scripts/imglob.py
+
17
−
10
View file @
8c69d1bb
...
...
@@ -10,14 +10,10 @@ NIFTI/ANALYZE image files.
import
sys
import
warnings
import
glob
import
itertools
as
it
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
usage
=
"""
Usage: imglob [-extension/extensions] <list of names>
...
...
@@ -25,8 +21,17 @@ Usage: imglob [-extension/extensions] <list of names>
-extensions for image list with full extensions
"""
.
strip
()
exts
=
fslimage
.
ALLOWED_EXTENSIONS
groups
=
fslimage
.
FILE_GROUPS
# The lists below are defined in the
# fsl.data.image class, but are duplicated
# here for performance (to avoid import of
# nibabel/numpy/etc).
exts
=
[
'
.nii.gz
'
,
'
.nii
'
,
'
.img
'
,
'
.hdr
'
,
'
.img.gz
'
,
'
.hdr.gz
'
]
"""
List of supported image file extensions.
"""
groups
=
[(
'
.hdr
'
,
'
.img
'
),
(
'
.hdr.gz
'
,
'
.img.gz
'
)]
"""
List of known image file groups (image/header file pairs).
"""
def
imglob
(
paths
,
output
=
None
):
...
...
@@ -76,8 +81,10 @@ def imglob(paths, output=None):
# hdr and img and otherwise) that match
for
path
in
paths
:
try
:
path
=
fslimage
.
removeExt
(
path
)
imgfiles
.
extend
(
fslimage
.
addExt
(
path
,
unambiguous
=
False
))
path
=
fslpath
.
removeExt
(
path
,
allowedExts
=
exts
)
imgfiles
.
extend
(
fslpath
.
addExt
(
path
,
allowedExts
=
exts
,
unambiguous
=
False
))
except
fslpath
.
PathError
:
continue
...
...
This diff is collapsed.
Click to expand it.
fsl/utils/path.py
+
1
−
2
View file @
8c69d1bb
...
...
@@ -37,8 +37,6 @@ import re
from
typing
import
Sequence
,
Tuple
,
Union
from
fsl.utils.platform
import
platform
PathLike
=
Union
[
str
,
pathlib
.
Path
]
...
...
@@ -596,6 +594,7 @@ def winpath(path):
This requires WSL2 which supports the ``
\\
wsl$
\\
`` network path.
wslpath is assumed to be an absolute path.
"""
from
fsl.utils.platform
import
platform
# pylint: disable=import-outside-toplevel # noqa: E501
if
not
platform
.
fslwsl
:
return
path
else
:
...
...
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