Skip to content

ENH: Re-enable spm.Realign to take lists of lists of files #2409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions nipype/interfaces/base/traits_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ def __init__(self,
super(ImageFile, self).__init__(value, filter, auto_set, entries,
exists, **metadata)

def info(self):
existing = 'n existing' if self.exists else ''
comma = ',' if self.exists and not self.allow_compressed else ''
uncompressed = ' uncompressed' if not self.allow_compressed else ''
with_ext = ' (valid extensions: [{}])'.format(
', '.join(self.grab_exts())) if self.types else ''
return 'a{existing}{comma}{uncompressed} file{with_ext}'.format(
existing=existing, comma=comma, uncompressed=uncompressed,
with_ext=with_ext)

def grab_exts(self):
# TODO: file type validation
exts = []
Expand All @@ -243,11 +253,11 @@ def validate(self, object, name, value):
"""
validated_value = super(ImageFile, self).validate(object, name, value)
if validated_value and self.types:
self._exts = self.grab_exts()
if not any(validated_value.endswith(x) for x in self._exts):
_exts = self.grab_exts()
if not any(validated_value.endswith(x) for x in _exts):
raise TraitError(
args="{} is not included in allowed types: {}".format(
validated_value, ', '.join(self._exts)))
validated_value, ', '.join(_exts)))
return validated_value


Expand Down Expand Up @@ -322,15 +332,11 @@ def validate(self, object, name, value):

newvalue = value

inner_trait = self.inner_traits()[0]
if not isinstance(value, list) \
or (self.inner_traits() and
isinstance(self.inner_traits()[0].trait_type,
traits.List) and not
isinstance(self.inner_traits()[0].trait_type,
InputMultiPath) and
isinstance(value, list) and
value and not
isinstance(value[0], list)):
or (isinstance(inner_trait.trait_type, traits.List) and
not isinstance(inner_trait.trait_type, InputMultiPath) and
not isinstance(value[0], list)):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify:

  • self.inner_traits() is always True for a traits.List (default value: (traits.Any(),))
  • isinstance(value, list) is always True at this point in the short-circuit
  • bool(value) is always True, or we would have returned Undefined already

These changes aren't really related to the rest of the PR, but I thought I would be modifying code in here at first, so factoring the inner_trait local variable led to this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@effigies what if value = []?

Copy link
Collaborator

@djarecka djarecka Feb 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, sorry, it would return undefined in l.331

newvalue = [value]
value = super(MultiPath, self).validate(object, name, newvalue)

Expand Down
3 changes: 2 additions & 1 deletion nipype/interfaces/spm/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ def _list_outputs(self):

class RealignInputSpec(SPMCommandInputSpec):
in_files = InputMultiPath(
ImageFileSPM(exists=True),
traits.Either(ImageFileSPM(exists=True),
traits.List(ImageFileSPM(exists=True))),
field='data',
mandatory=True,
copyfile=True,
Expand Down