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
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
Branches containing commit
No related tags found
Tags containing commit
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:
...
@@ -23,7 +23,7 @@ file names:
.. autosummary::
.. autosummary::
:nosignatures:
:nosignatures:
isSupported
looksLikeImage
removeExt
removeExt
addExt
addExt
loadImage
loadImage
...
@@ -556,8 +556,8 @@ DEFAULT_EXTENSION = '.nii.gz'
...
@@ -556,8 +556,8 @@ DEFAULT_EXTENSION = '.nii.gz'
"""
The default file extension (TODO read this from ``$FSLOUTPUTTYPE``).
"""
"""
The default file extension (TODO read this from ``$FSLOUTPUTTYPE``).
"""
def
isSupported
(
filename
,
allowedExts
=
None
):
def
looksLikeImage
(
filename
,
allowedExts
=
None
):
"""
Returns ``True`` if the given file
has a supported extension
, ``False``
"""
Returns ``True`` if the given file
looks like an image
, ``False``
otherwise.
otherwise.
:arg filename: The file name to test.
:arg filename: The file name to test.
...
@@ -568,6 +568,9 @@ def isSupported(filename, allowedExts=None):
...
@@ -568,6 +568,9 @@ def isSupported(filename, allowedExts=None):
if
allowedExts
is
None
:
allowedExts
=
ALLOWED_EXTENSIONS
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
))
return
any
(
map
(
lambda
ext
:
filename
.
endswith
(
ext
),
allowedExts
))
...
@@ -787,7 +790,8 @@ def saveImage(image, fromDir=None):
...
@@ -787,7 +790,8 @@ def saveImage(image, fromDir=None):
path
=
dlg
.
GetPath
()
path
=
dlg
.
GetPath
()
nibImage
=
image
.
nibImage
nibImage
=
image
.
nibImage
if
not
isSupported
(
path
):
# Add a file extension if not specified
if
not
looksLikeImage
(
path
):
path
=
addExt
(
path
,
False
)
path
=
addExt
(
path
,
False
)
# this is an image which has been
# 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):
...
@@ -34,26 +34,46 @@ def getTensorDataPrefix(path):
fas
=
glob
.
glob
(
op
.
join
(
path
,
'
*_FA.*
'
))
fas
=
glob
.
glob
(
op
.
join
(
path
,
'
*_FA.*
'
))
mds
=
glob
.
glob
(
op
.
join
(
path
,
'
*_MD.*
'
))
mds
=
glob
.
glob
(
op
.
join
(
path
,
'
*_MD.*
'
))
files
=
[
v1s
,
v2s
,
v3s
,
l1s
,
l2s
,
l3s
,
fas
,
mds
]
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
]
# Gather all of the existing file
# prefixes into a dictionary of
# Make sure that all of the above
# prefix : [file list] mappings.
# files have the same prefix
pattern
=
'
^(.*)_(?:V1|V2|V3|L1|L2|L3|FA|MD).*$
'
pattern
=
'
^(.*)_(?:V1|V2|V3|L1|L2|L3|FA|MD).*$
'
prefixes
=
[
re
.
findall
(
pattern
,
f
)[
0
]
for
f
in
files
]
prefixes
=
{}
if
any
([
p
!=
prefixes
[
0
]
for
p
in
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
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
])
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