Skip to content
Snippets Groups Projects
Commit 346147da authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

RF: make option dicts class attributes

parent 2583c861
No related branches found
No related tags found
No related merge requests found
...@@ -20,53 +20,6 @@ import fsl.data.image as fslimage ...@@ -20,53 +20,6 @@ import fsl.data.image as fslimage
from . import wrapperutils as wutils from . import wrapperutils as wutils
OPTIONS = {
'robust_minmax' : 'r',
'minmax' : 'R',
'mean_entropy' : 'e',
'mean_entropy_nz' : 'E',
'volume' : 'v',
'volume_nz' : 'V',
'mean' : 'm',
'mean_nz' : 'M',
'stddev' : 's',
'stddev_nz' : 'S',
'smallest_roi' : 'w',
'max_vox' : 'x',
'min_vox' : 'X',
'cog_mm' : 'c',
'cog_vox' : 'C',
'abs' : 'a',
'zero_naninf' : 'n',
}
"""This dict contains options which do not require any additional arguments.
They are set via attribute access on the ``fslstats`` object.
"""
ARG_OPTIONS = {
'lower_threshold' : 'l',
'upper_threshold' : 'u',
'percentile' : 'p',
'percentile_nz' : 'P',
'mask' : 'k',
'diff' : 'd',
'hist' : 'h',
'hist_bounded' : 'H',
}
"""This dict contains options which require additional arguments.
They are set via method calls on the ``fslstats`` object (with the
additional arguments passed into the method call).
"""
# add {shortopt : shortopt} mappings
# for all options to simplify code in
# the fslstats class
OPTIONS .update({v : v for v in OPTIONS .values()})
ARG_OPTIONS.update({v : v for v in ARG_OPTIONS.values()})
class fslstats(object): class fslstats(object):
"""The ``fslstats`` class is a wrapper around the ``fslstats`` command-line """The ``fslstats`` class is a wrapper around the ``fslstats`` command-line
tool. It provides an object-oriented interface - options are specified by tool. It provides an object-oriented interface - options are specified by
...@@ -106,6 +59,53 @@ class fslstats(object): ...@@ -106,6 +59,53 @@ class fslstats(object):
imgmin, imgmax = fslstats('image.nii.gz').k('mask.nii.gz').r.run() imgmin, imgmax = fslstats('image.nii.gz').k('mask.nii.gz').r.run()
""" """
OPTIONS = {
'robust_minmax' : 'r',
'minmax' : 'R',
'mean_entropy' : 'e',
'mean_entropy_nz' : 'E',
'volume' : 'v',
'volume_nz' : 'V',
'mean' : 'm',
'mean_nz' : 'M',
'stddev' : 's',
'stddev_nz' : 'S',
'smallest_roi' : 'w',
'max_vox' : 'x',
'min_vox' : 'X',
'cog_mm' : 'c',
'cog_vox' : 'C',
'abs' : 'a',
'zero_naninf' : 'n',
}
"""This dict contains options which do not require any additional
arguments. They are set via attribute access on the ``fslstats``
object.
"""
ARG_OPTIONS = {
'lower_threshold' : 'l',
'upper_threshold' : 'u',
'percentile' : 'p',
'percentile_nz' : 'P',
'mask' : 'k',
'diff' : 'd',
'hist' : 'h',
'hist_bounded' : 'H',
}
"""This dict contains options which require additional arguments.
They are set via method calls on the ``fslstats`` object (with the
additional arguments passed into the method call).
"""
# add {shortopt : shortopt} mappings
# for all options to simplify code in
# the fslstats class
OPTIONS .update({v : v for v in OPTIONS .values()})
ARG_OPTIONS.update({v : v for v in ARG_OPTIONS.values()})
def __init__(self, def __init__(self,
input, input,
...@@ -168,17 +168,17 @@ class fslstats(object): ...@@ -168,17 +168,17 @@ class fslstats(object):
# options which take no args # options which take no args
# are called as attributes # are called as attributes
if name in OPTIONS: if name in fslstats.OPTIONS:
flag = OPTIONS[name] flag = fslstats.OPTIONS[name]
args = False args = False
# options which take args # options which take args
# are called as methods # are called as methods
elif name in ARG_OPTIONS: elif name in fslstats.ARG_OPTIONS:
flag = ARG_OPTIONS[name] flag = fslstats.ARG_OPTIONS[name]
args = True args = True
else: else:
raise AttributeError() raise AttributeError(name)
addFlag = ft.partial(self.__addFlag, flag) addFlag = ft.partial(self.__addFlag, flag)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment