Skip to content

Commit 872d749

Browse files
authored
Merge pull request #2409 from effigies/enh/spm_realign_in_list_of_lists
ENH: Re-enable spm.Realign to take lists of lists of files
2 parents c7492c8 + 47f793e commit 872d749

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

nipype/interfaces/base/traits_extension.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,16 @@ def __init__(self,
217217
super(ImageFile, self).__init__(value, filter, auto_set, entries,
218218
exists, **metadata)
219219

220+
def info(self):
221+
existing = 'n existing' if self.exists else ''
222+
comma = ',' if self.exists and not self.allow_compressed else ''
223+
uncompressed = ' uncompressed' if not self.allow_compressed else ''
224+
with_ext = ' (valid extensions: [{}])'.format(
225+
', '.join(self.grab_exts())) if self.types else ''
226+
return 'a{existing}{comma}{uncompressed} file{with_ext}'.format(
227+
existing=existing, comma=comma, uncompressed=uncompressed,
228+
with_ext=with_ext)
229+
220230
def grab_exts(self):
221231
# TODO: file type validation
222232
exts = []
@@ -243,11 +253,11 @@ def validate(self, object, name, value):
243253
"""
244254
validated_value = super(ImageFile, self).validate(object, name, value)
245255
if validated_value and self.types:
246-
self._exts = self.grab_exts()
247-
if not any(validated_value.endswith(x) for x in self._exts):
256+
_exts = self.grab_exts()
257+
if not any(validated_value.endswith(x) for x in _exts):
248258
raise TraitError(
249259
args="{} is not included in allowed types: {}".format(
250-
validated_value, ', '.join(self._exts)))
260+
validated_value, ', '.join(_exts)))
251261
return validated_value
252262

253263

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

323333
newvalue = value
324334

335+
inner_trait = self.inner_traits()[0]
325336
if not isinstance(value, list) \
326-
or (self.inner_traits() and
327-
isinstance(self.inner_traits()[0].trait_type,
328-
traits.List) and not
329-
isinstance(self.inner_traits()[0].trait_type,
330-
InputMultiPath) and
331-
isinstance(value, list) and
332-
value and not
333-
isinstance(value[0], list)):
337+
or (isinstance(inner_trait.trait_type, traits.List) and
338+
not isinstance(inner_trait.trait_type, InputMultiPath) and
339+
not isinstance(value[0], list)):
334340
newvalue = [value]
335341
value = super(MultiPath, self).validate(object, name, newvalue)
336342

nipype/interfaces/spm/preprocess.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ def _list_outputs(self):
125125

126126
class RealignInputSpec(SPMCommandInputSpec):
127127
in_files = InputMultiPath(
128-
ImageFileSPM(exists=True),
128+
traits.Either(ImageFileSPM(exists=True),
129+
traits.List(ImageFileSPM(exists=True))),
129130
field='data',
130131
mandatory=True,
131132
copyfile=True,

0 commit comments

Comments
 (0)