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
7f7dd1ed
Commit
7f7dd1ed
authored
10 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Documented fsl.data package.
parent
ba84cdf7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
fsl/data/__init__.py
+7
-0
7 additions, 0 deletions
fsl/data/__init__.py
fsl/data/fslimage.py
+215
-144
215 additions, 144 deletions
fsl/data/fslimage.py
fsl/data/imagefile.py
+42
-17
42 additions, 17 deletions
fsl/data/imagefile.py
with
264 additions
and
161 deletions
fsl/data/__init__.py
+
7
−
0
View file @
7f7dd1ed
#!/usr/bin/env python
#
# __init__.py - fsl.data package.
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
"""
Data structures and models.
"""
This diff is collapsed.
Click to expand it.
fsl/data/fslimage.py
+
215
−
144
View file @
7f7dd1ed
This diff is collapsed.
Click to expand it.
fsl/data/imagefile.py
+
42
−
17
View file @
7f7dd1ed
...
@@ -5,28 +5,38 @@
...
@@ -5,28 +5,38 @@
#
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
#
"""
Convenience functions for adding/stripping supported
file extensions to/from image file names.
"""
import
os
import
os
import
os.path
as
op
import
os.path
as
op
# The file extensions which we understand. This list is used
# as the default if if the allowedExts parameter is not passed
# to any of the functions in this module.
_allowedExts
=
[
'
.nii
'
,
'
.img
'
,
'
.hdr
'
,
'
.nii.gz
'
,
'
.img.gz
'
]
_allowedExts
=
[
'
.nii
'
,
'
.img
'
,
'
.hdr
'
,
'
.nii.gz
'
,
'
.img.gz
'
]
"""
The file extensions which we understand. This list is used as the default
if if the ``allowedExts`` parameter is not passed to any of the functions in
this module.
"""
_descriptions
=
[
'
NIFTI1 images
'
,
_descriptions
=
[
'
NIFTI1 images
'
,
'
ANALYZE75 images
'
,
'
ANALYZE75 images
'
,
'
NIFTI1/ANALYZE75 headers
'
,
'
NIFTI1/ANALYZE75 headers
'
,
'
Compressed NIFTI1 images
'
,
'
Compressed NIFTI1 images
'
,
'
Compressed ANALYZE75/NIFTI1 images
'
]
'
Compressed ANALYZE75/NIFTI1 images
'
]
"""
Descriptions for each of the extensions in :data:`_allowedExts`.
"""
# The default file extension (TODO read this from $FSLOUTPUTTYPE)
_defaultExt
=
'
.nii.gz
'
_defaultExt
=
'
.nii.gz
'
"""
The default file extension (TODO read this from ``$FSLOUTPUTTYPE``).
"""
def
wildcard
(
allowedExts
=
None
):
def
wildcard
(
allowedExts
=
None
):
"""
"""
Returns a wildcard string for use in a file dialog, to limit
the acceptable file types.
:arg allowedExts: A list of strings containing the allowed file
extensions.
"""
"""
if
allowedExts
is
None
:
if
allowedExts
is
None
:
...
@@ -38,7 +48,7 @@ def wildcard(allowedExts=None):
...
@@ -38,7 +48,7 @@ def wildcard(allowedExts=None):
exts
=
[
'
*{}
'
.
format
(
ext
)
for
ext
in
allowedExts
]
exts
=
[
'
*{}
'
.
format
(
ext
)
for
ext
in
allowedExts
]
wcParts
=
[
'
|
'
.
join
((
desc
,
ext
))
for
(
desc
,
ext
)
in
zip
(
descs
,
exts
)]
wcParts
=
[
'
|
'
.
join
((
desc
,
ext
))
for
(
desc
,
ext
)
in
zip
(
descs
,
exts
)]
print
'
|
'
.
join
(
wcParts
)
print
'
|
'
.
join
(
wcParts
)
return
'
|
'
.
join
(
wcParts
)
return
'
|
'
.
join
(
wcParts
)
...
@@ -47,8 +57,13 @@ def wildcard(allowedExts=None):
...
@@ -47,8 +57,13 @@ def wildcard(allowedExts=None):
def
isSupported
(
filename
,
allowedExts
=
None
):
def
isSupported
(
filename
,
allowedExts
=
None
):
"""
"""
Returns True if the given file has a supported extension, False
Returns
``
True
``
if the given file has a supported extension,
``
False
``
otherwise.
otherwise.
:arg filename: The file name to test.
:arg allowedExts: A list of strings containing the allowed file
extensions.
"""
"""
if
allowedExts
is
None
:
allowedExts
=
_allowedExts
if
allowedExts
is
None
:
allowedExts
=
_allowedExts
...
@@ -58,8 +73,13 @@ def isSupported(filename, allowedExts=None):
...
@@ -58,8 +73,13 @@ def isSupported(filename, allowedExts=None):
def
removeExt
(
filename
,
allowedExts
=
None
):
def
removeExt
(
filename
,
allowedExts
=
None
):
"""
"""
Removes the extension from the given file name. Raises a ValueError
Removes the extension from the given file name. Raises a
:exc:`
ValueError
`
if the file has an unsupported extension.
if the file has an unsupported extension.
:arg filename: The file name to strip.
:arg allowedExts: A list of strings containing the allowed file
extensions.
"""
"""
if
allowedExts
is
None
:
allowedExts
=
_allowedExts
if
allowedExts
is
None
:
allowedExts
=
_allowedExts
...
@@ -85,22 +105,27 @@ def addExt(
...
@@ -85,22 +105,27 @@ def addExt(
mustExist
=
False
,
mustExist
=
False
,
allowedExts
=
None
,
allowedExts
=
None
,
defaultExt
=
None
):
defaultExt
=
None
):
"""
"""
Adds a file extension to the given file ``prefix``.
Adds a file extension to the given file prefix. If mustExist is False
(the default), and the file does not already have a supported
extension, the default extension is appended and the new file name
returned. If the prefix already has a supported extension, it is
returned unchanged.
If mustExist is True, the function checks to see if any files exist
If ``mustExist`` is False (the default), and the file does not already
that have the given prefix, and a supported file extension. A
have a supported extension, the default extension is appended and the new
ValueError is raised if:
file name returned. If the prefix already has a supported extension,
it is returned unchanged.
If ``mustExist`` is ``True``, the function checks to see if any files
exist that have the given prefix, and a supported file extension. A
:exc:`ValueError` is raised if:
- No files exist with the given prefix and a supported extension.
- No files exist with the given prefix and a supported extension.
- More than one file exists with the given prefix, and a supported
- More than one file exists with the given prefix, and a supported
extension.
extension.
Otherwise the full file name is returned.
Otherwise the full file name is returned.
:arg prefix: The file name refix to modify.
:arg mustExist: Whether the file must exist or not.
:arg allowedExts: List of allowed file extensions.
:arg defaultExt: Default file extension to use.
"""
"""
if
allowedExts
is
None
:
allowedExts
=
_allowedExts
if
allowedExts
is
None
:
allowedExts
=
_allowedExts
...
...
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