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
e1afbc10
Commit
e1afbc10
authored
9 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Made tensor data prefix function a bit more robust.
parent
344993ed
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/data/image.py
+8
-4
8 additions, 4 deletions
fsl/data/image.py
fsl/data/tensorimage.py
+36
-16
36 additions, 16 deletions
fsl/data/tensorimage.py
with
44 additions
and
20 deletions
fsl/data/image.py
+
8
−
4
View file @
e1afbc10
...
...
@@ -23,7 +23,7 @@ file names:
.. autosummary::
:nosignatures:
isSupported
looksLikeImage
removeExt
addExt
loadImage
...
...
@@ -556,8 +556,8 @@ DEFAULT_EXTENSION = '.nii.gz'
"""
The default file extension (TODO read this from ``$FSLOUTPUTTYPE``).
"""
def
isSupported
(
filename
,
allowedExts
=
None
):
"""
Returns ``True`` if the given file
has a supported extension
, ``False``
def
looksLikeImage
(
filename
,
allowedExts
=
None
):
"""
Returns ``True`` if the given file
looks like an image
, ``False``
otherwise.
:arg filename: The file name to test.
...
...
@@ -568,6 +568,9 @@ def isSupported(filename, allowedExts=None):
if
allowedExts
is
None
:
allowedExts
=
ALLOWED_EXTENSIONS
# TODO A much more robust approach would be
# to try loading the file using nibabel.
return
any
(
map
(
lambda
ext
:
filename
.
endswith
(
ext
),
allowedExts
))
...
...
@@ -787,7 +790,8 @@ def saveImage(image, fromDir=None):
path
=
dlg
.
GetPath
()
nibImage
=
image
.
nibImage
if
not
isSupported
(
path
):
# Add a file extension if not specified
if
not
looksLikeImage
(
path
):
path
=
addExt
(
path
,
False
)
# this is an image which has been
...
...
This diff is collapsed.
Click to expand it.
fsl/data/tensorimage.py
+
36
−
16
View file @
e1afbc10
...
...
@@ -34,26 +34,46 @@ def getTensorDataPrefix(path):
fas
=
glob
.
glob
(
op
.
join
(
path
,
'
*_FA.*
'
))
mds
=
glob
.
glob
(
op
.
join
(
path
,
'
*_MD.*
'
))
files
=
[
v1s
,
v2s
,
v3s
,
l1s
,
l2s
,
l3s
,
fas
,
mds
]
# Make sure there is exactly one
# of each of the above files
def
lenone
(
l
):
return
len
(
l
)
==
1
if
not
all
(
map
(
lenone
,
files
)):
return
None
files
=
[
f
[
0
]
for
f
in
files
]
# Make sure that all of the above
# files have the same prefix
# Gather all of the existing file
# prefixes into a dictionary of
# prefix : [file list] mappings.
pattern
=
'
^(.*)_(?:V1|V2|V3|L1|L2|L3|FA|MD).*$
'
prefixes
=
[
re
.
findall
(
pattern
,
f
)[
0
]
for
f
in
files
]
if
any
([
p
!=
prefixes
[
0
]
for
p
in
prefixes
]):
prefixes
=
{}
for
f
in
[
f
for
flist
in
files
for
f
in
flist
]:
prefix
=
re
.
findall
(
pattern
,
f
)[
0
]
if
prefix
not
in
prefixes
:
prefixes
[
prefix
]
=
[
f
]
else
:
prefixes
[
prefix
].
append
(
f
)
# Discard any prefixes which are
# not present for every file type.
for
prefix
,
files
in
list
(
prefixes
.
items
()):
if
len
(
files
)
!=
8
:
prefixes
.
pop
(
prefix
)
# Discard any prefixes which
# match any files that do
# not look like image files
for
prefix
,
files
in
list
(
prefixes
.
items
()):
if
not
all
([
fslimage
.
looksLikeImage
(
f
)
for
f
in
files
]):
prefixes
.
pop
(
prefix
)
prefixes
=
list
(
prefixes
.
keys
())
# No more prefixes remaining -
# this is probably not a dtifit
# directory
if
len
(
prefixes
)
==
0
:
return
None
# And there's our prefix
# If there's more than one remaining
# prefix, I don't know what to do -
# just return the first one.
if
len
(
prefixes
)
>
1
:
log
.
warning
(
'
Multiple dtifit prefixes detected: {}
'
.
format
(
prefixes
))
return
op
.
basename
(
prefixes
[
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