Skip to content

Commit

Permalink
fix: add freesurfer legacy spaces names
Browse files Browse the repository at this point in the history
  • Loading branch information
oesteban committed Nov 22, 2019
1 parent 24ec785 commit cfbc59a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
10 changes: 5 additions & 5 deletions smriprep/cli/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ def test_template_parser(monkeypatch):
with pytest.raises(ValueError):
u._template(['MNI152NLin6Asym:res-2', 'func'])

u.set_nonstandard_spaces('func')
assert u._template(['MNI152NLin6Asym:res-2', 'fsnative']) == \
OrderedDict([('MNI152NLin6Asym', {'res': '2'}), ('fsnative', None)])

u.ParseTemplates.set_nonstandard_spaces('func')
assert u._template(['MNI152NLin2009cAsym:res-2', 'func']) == \
OrderedDict([('MNI152NLin2009cAsym', {'res': '2'}), ('func', None)])

with pytest.raises(ValueError):
u._template(['MNI152NLin6Asym:res-2', 'fsnative'])

u.set_nonstandard_spaces(['func', 'fsnative'])
u.ParseTemplates.set_nonstandard_spaces(['func', 'fsnative'])
assert u._template(['MNI152NLin2009cAsym:res-2', 'func', 'fsnative']) == \
OrderedDict([('MNI152NLin2009cAsym', {'res': '2'}),
('func', None), ('fsnative', None)])
29 changes: 15 additions & 14 deletions smriprep/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""CLI Utilities."""
from argparse import Action
from ..conf import TF_TEMPLATES as _TF_TEMPLATES

EXCEPTIONS = None
from ..conf import TF_TEMPLATES as _TF_TEMPLATES, LEGACY_SPACES


class ParseTemplates(Action):
"""Manipulate a string of templates with modifiers."""

EXCEPTIONS = tuple()

def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, _template(values))

@classmethod
def set_nonstandard_spaces(cls, inlist):
"""Set permissible nonstandard spaces names."""
if isinstance(inlist, str):
inlist = [inlist]

cls.EXCEPTIONS = tuple(inlist)


def _template(inlist):
"""Return an OrderedDict with templates."""
Expand All @@ -29,15 +37,17 @@ def _template(inlist):

def output_space(value):
"""Parse one element of ``--output-spaces``."""
global EXCEPTIONS
tpl_args = value.split(':')
template = tpl_args[0]
spec = {}
for modifier in tpl_args[1:]:
mitems = modifier.split('-', 1)
spec[mitems[0]] = len(mitems) == 1 or mitems[1]

if EXCEPTIONS and template in EXCEPTIONS:
if template in ParseTemplates.EXCEPTIONS:
return template, None

if template in LEGACY_SPACES:
return template, None

if template not in _TF_TEMPLATES:
Expand All @@ -46,12 +56,3 @@ def output_space(value):
correctly installed and contains the given template identifiers.""".format(template))

return template, spec


def set_nonstandard_spaces(inlist):
"""Set permissible nonstandard spaces names."""
global EXCEPTIONS
if isinstance(inlist, str):
inlist = [inlist]

EXCEPTIONS = tuple(inlist)
2 changes: 2 additions & 0 deletions smriprep/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
from templateflow.api import templates as _get_templates

TF_TEMPLATES = tuple(_get_templates())
LEGACY_SPACES = ('fsnative', 'fsaverage4', 'fsaverage5',
'fsaverage6', 'fsaverage')

0 comments on commit cfbc59a

Please sign in to comment.