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
35aa3ba7
Commit
35aa3ba7
authored
6 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
RF,ENH: fileOrThing uses file basename as names in results dictionary for
prefixed-outputs. Bet wrapper uses new outprefix option.
parent
547512ad
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/wrappers/bet.py
+1
-1
1 addition, 1 deletion
fsl/wrappers/bet.py
fsl/wrappers/wrapperutils.py
+47
-21
47 additions, 21 deletions
fsl/wrappers/wrapperutils.py
with
48 additions
and
22 deletions
fsl/wrappers/bet.py
+
1
−
1
View file @
35aa3ba7
...
...
@@ -14,7 +14,7 @@ import fsl.utils.assertions as asrt
from
.
import
wrapperutils
as
wutils
@wutils.fileOrImage
(
'
input
'
,
'
output
'
)
@wutils.fileOrImage
(
'
input
'
,
'
output
'
,
outprefix
=
'
output
'
)
@wutils.fslwrapper
def
bet
(
input
,
output
,
**
kwargs
):
"""
Wrapper for the ``bet`` command.
...
...
This diff is collapsed.
Click to expand it.
fsl/wrappers/wrapperutils.py
+
47
−
21
View file @
35aa3ba7
...
...
@@ -102,8 +102,9 @@ import six
import
nibabel
as
nib
import
numpy
as
np
import
fsl.utils.tempdir
as
tempdir
import
fsl.utils.run
as
run
import
fsl.utils.path
as
fslpath
import
fsl.utils.tempdir
as
tempdir
import
fsl.data.image
as
fslimage
...
...
@@ -504,7 +505,14 @@ class _FileOrThing(object):
return
self
.
__output
def
__init__
(
self
,
func
,
prepIn
,
prepOut
,
load
,
*
things
,
outprefix
=
None
):
def
__init__
(
self
,
func
,
prepIn
,
prepOut
,
load
,
removeExt
,
*
things
,
outprefix
=
None
):
"""
Initialise a ``_FileOrThing`` decorator.
:arg func: The function to be decorated.
...
...
@@ -519,6 +527,9 @@ class _FileOrThing(object):
that were set to :data:`LOAD`. Must accept a file path
as its sole argument.
:arg removeExt: Function which can remove a file extension from a file
path.
:arg things: Names of all arguments which will be handled by
this ``_FileOrThing`` decorator. If not provided,
*all* arguments passed to the function will be
...
...
@@ -526,9 +537,8 @@ class _FileOrThing(object):
:arg outprefix: The name of a positional or keyword argument to the
function, which specifies an output file name prefix.
All other arguments which begin with this prefix (
more specifically, which begin with ``[prefix]_``)
may be interpreted as things to load.
All other arguments with names that begin with this
prefix may be interpreted as things to ``LOAD``.
The ``prepIn`` and ``prepOut`` functions must accept the following
positional arguments:
...
...
@@ -544,6 +554,7 @@ class _FileOrThing(object):
self
.
__prepIn
=
prepIn
self
.
__prepOut
=
prepOut
self
.
__load
=
load
self
.
__removeExt
=
removeExt
self
.
__things
=
things
self
.
__outprefix
=
outprefix
...
...
@@ -570,7 +581,7 @@ class _FileOrThing(object):
# Replace any things with file names.
# Also get a list of LOAD outputs
args
=
self
.
__prepareArgs
(
td
,
argnames
,
args
,
kwargs
)
args
,
kwargs
,
p
refix
,
outfiles
,
prefixe
dFile
s
=
args
args
,
kwargs
,
baseP
refix
,
outfiles
,
prefixes
=
args
# Call the function
result
=
func
(
*
args
,
**
kwargs
)
...
...
@@ -594,29 +605,31 @@ class _FileOrThing(object):
result
[
oname
]
=
oval
# Load or move output-prefixed files
if
p
refix
is
not
None
:
if
baseP
refix
is
not
None
:
prefixDir
=
op
.
abspath
(
op
.
dirname
(
p
refix
))
p
refix
=
op
.
basename
(
p
refix
)
allPrefixed
=
glob
.
glob
(
op
.
join
(
td
,
'
{}
_
*
'
.
format
(
p
refix
)))
prefixDir
=
op
.
abspath
(
op
.
dirname
(
baseP
refix
))
baseP
refix
=
op
.
basename
(
baseP
refix
)
allPrefixed
=
glob
.
glob
(
op
.
join
(
td
,
'
{}*
'
.
format
(
baseP
refix
)))
for
filename
in
allPrefixed
:
basename
=
op
.
basename
(
filename
)
for
argname
in
prefixe
dFile
s
:
if
fnmatch
.
fnmatch
(
basename
,
'
{}*
'
.
format
(
argname
)):
for
prefix
in
prefixes
:
if
fnmatch
.
fnmatch
(
basename
,
'
{}*
'
.
format
(
prefix
)):
log
.
debug
(
'
Loading prefixed output %s: %s
'
,
argname
,
filename
)
fval
=
self
.
__load
(
filename
)
prefix
,
filename
)
if
argname
in
result
:
result
[
argname
].
append
(
fval
)
else
:
result
[
argname
]
=
[
fval
]
fval
=
self
.
__load
(
filename
)
basename
=
self
.
__removeExt
(
basename
)
result
[
basename
]
=
fval
break
# if file did not match any pattern,
# move it into real prefix
# move it into the real prefix, where
# the function would have saved it
# if we had not modified the prefix
# (see __prepareArgs)
else
:
log
.
debug
(
'
Moving prefixed output %s into %s
'
,
filename
,
prefixDir
)
...
...
@@ -691,7 +704,7 @@ class _FileOrThing(object):
for
name
,
val
in
list
(
allargs
.
items
()):
# is this argument referring
# to a prefixd output?
# to a prefix
e
d output?
isprefixed
=
(
prefix
is
not
None
and
name
.
startswith
(
prefix
))
...
...
@@ -722,6 +735,7 @@ class _FileOrThing(object):
outfiles
[
name
]
=
outfile
allargs
[
name
]
=
outfile
# Assumed to be an input file
else
:
infile
=
self
.
__prepIn
(
workdir
,
name
,
val
)
...
...
@@ -791,7 +805,13 @@ def fileOrImage(*args, **kwargs):
raise
RuntimeError
(
'
Cannot handle type: {}
'
.
format
(
intypes
))
def
decorator
(
func
):
fot
=
_FileOrThing
(
func
,
prepIn
,
prepOut
,
load
,
*
args
,
**
kwargs
)
fot
=
_FileOrThing
(
func
,
prepIn
,
prepOut
,
load
,
fslimage
.
removeExt
,
*
args
,
**
kwargs
)
def
wrapper
(
*
args
,
**
kwargs
):
result
=
fot
(
*
args
,
**
kwargs
)
...
...
@@ -825,7 +845,13 @@ def fileOrArray(*args, **kwargs):
load
=
np
.
loadtxt
def
decorator
(
func
):
fot
=
_FileOrThing
(
func
,
prepIn
,
prepOut
,
load
,
*
args
,
**
kwargs
)
fot
=
_FileOrThing
(
func
,
prepIn
,
prepOut
,
load
,
fslpath
.
removeExt
,
*
args
,
**
kwargs
)
def
wrapper
(
*
args
,
**
kwargs
):
return
fot
(
*
args
,
**
kwargs
)
...
...
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