From bd9bb0d708d1567489d3596ffb78599c9de323f7 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Fri, 26 Jan 2018 10:22:02 -0500 Subject: [PATCH 1/7] ENH: Re-enable spm.Realign to take lists of lists of files --- nipype/interfaces/spm/preprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nipype/interfaces/spm/preprocess.py b/nipype/interfaces/spm/preprocess.py index 47c9fd77a4..defdff1e47 100644 --- a/nipype/interfaces/spm/preprocess.py +++ b/nipype/interfaces/spm/preprocess.py @@ -125,7 +125,7 @@ def _list_outputs(self): class RealignInputSpec(SPMCommandInputSpec): in_files = InputMultiPath( - ImageFileSPM(exists=True), + InputMultiPath(ImageFileSPM(exists=True)), field='data', mandatory=True, copyfile=True, From 3abb67d7787bbc83a4a3f40a858d6a63926e5b6c Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Thu, 1 Feb 2018 10:24:58 -0500 Subject: [PATCH 2/7] Revert "ENH: Re-enable spm.Realign to take lists of lists of files" This reverts commit da966f9303204def40512e13db6db390e1bb3351. --- nipype/interfaces/spm/preprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nipype/interfaces/spm/preprocess.py b/nipype/interfaces/spm/preprocess.py index defdff1e47..47c9fd77a4 100644 --- a/nipype/interfaces/spm/preprocess.py +++ b/nipype/interfaces/spm/preprocess.py @@ -125,7 +125,7 @@ def _list_outputs(self): class RealignInputSpec(SPMCommandInputSpec): in_files = InputMultiPath( - InputMultiPath(ImageFileSPM(exists=True)), + ImageFileSPM(exists=True), field='data', mandatory=True, copyfile=True, From 12f348de41e45a45b0544a02972317a112880382 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Thu, 1 Feb 2018 10:26:36 -0500 Subject: [PATCH 3/7] Revert "changing in_files in RealignInputSpec" This reverts commit f196238673cfbf511f86b9b70fb0c7ee6ccfc92b. --- nipype/interfaces/spm/preprocess.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nipype/interfaces/spm/preprocess.py b/nipype/interfaces/spm/preprocess.py index 47c9fd77a4..d75edb4a1a 100644 --- a/nipype/interfaces/spm/preprocess.py +++ b/nipype/interfaces/spm/preprocess.py @@ -125,7 +125,8 @@ def _list_outputs(self): class RealignInputSpec(SPMCommandInputSpec): in_files = InputMultiPath( - ImageFileSPM(exists=True), + traits.Either(traits.List(ImageFileSPM(exists=True)), + ImageFileSPM(exists=True)), field='data', mandatory=True, copyfile=True, From c0b0f6aa4f49adee6d2c4534644d9fbd30726661 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Thu, 1 Feb 2018 10:49:12 -0500 Subject: [PATCH 4/7] ENH: Simplify listifying logic --- nipype/interfaces/base/traits_extension.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/nipype/interfaces/base/traits_extension.py b/nipype/interfaces/base/traits_extension.py index 5b3e9f94d7..c4eda4ca7f 100644 --- a/nipype/interfaces/base/traits_extension.py +++ b/nipype/interfaces/base/traits_extension.py @@ -322,15 +322,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)): newvalue = [value] value = super(MultiPath, self).validate(object, name, newvalue) From a84c8e8854708de868c49dad8a6ab42efa193a2e Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Thu, 1 Feb 2018 11:20:06 -0500 Subject: [PATCH 5/7] ENH: Add info to ImageFile for better error messages --- nipype/interfaces/base/traits_extension.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/nipype/interfaces/base/traits_extension.py b/nipype/interfaces/base/traits_extension.py index c4eda4ca7f..4b250e3ef2 100644 --- a/nipype/interfaces/base/traits_extension.py +++ b/nipype/interfaces/base/traits_extension.py @@ -214,9 +214,26 @@ def __init__(self, """ self.types = types self.allow_compressed = allow_compressed + self._exts = None 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.exts)) \ + if self.types else '' + return 'a{existing}{comma}{uncompressed} file{with_ext}'.format( + existing=existing, comma=comma, uncompressed=uncompressed, + with_ext=with_ext) + + @property + def exts(self): + if self.types and self._exts is None: + self._exts = self.grab_exts() + return self._exts + def grab_exts(self): # TODO: file type validation exts = [] @@ -243,11 +260,10 @@ 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): + if not any(validated_value.endswith(x) for x in self.exts): raise TraitError( args="{} is not included in allowed types: {}".format( - validated_value, ', '.join(self._exts))) + validated_value, ', '.join(self.exts))) return validated_value From 3cdb657fcc5025f0093e6d77836eb1c668e2aef6 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Thu, 1 Feb 2018 11:37:41 -0500 Subject: [PATCH 6/7] ENH: Reorder traits for better error message --- nipype/interfaces/spm/preprocess.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nipype/interfaces/spm/preprocess.py b/nipype/interfaces/spm/preprocess.py index d75edb4a1a..c08cc46869 100644 --- a/nipype/interfaces/spm/preprocess.py +++ b/nipype/interfaces/spm/preprocess.py @@ -125,8 +125,8 @@ def _list_outputs(self): class RealignInputSpec(SPMCommandInputSpec): in_files = InputMultiPath( - traits.Either(traits.List(ImageFileSPM(exists=True)), - ImageFileSPM(exists=True)), + traits.Either(ImageFileSPM(exists=True), + traits.List(ImageFileSPM(exists=True))), field='data', mandatory=True, copyfile=True, From 47f793eae87f099f0389b0181806981a40db61aa Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Thu, 1 Feb 2018 13:29:09 -0500 Subject: [PATCH 7/7] FIX: Do not cache grab_exts --- nipype/interfaces/base/traits_extension.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/nipype/interfaces/base/traits_extension.py b/nipype/interfaces/base/traits_extension.py index 4b250e3ef2..6dfef8ebfa 100644 --- a/nipype/interfaces/base/traits_extension.py +++ b/nipype/interfaces/base/traits_extension.py @@ -214,26 +214,19 @@ def __init__(self, """ self.types = types self.allow_compressed = allow_compressed - self._exts = None super(ImageFile, self).__init__(value, filter, auto_set, entries, exists, **metadata) def info(self): - existing='n existing' if self.exists else '' + 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.exts)) \ - if self.types 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) - @property - def exts(self): - if self.types and self._exts is None: - self._exts = self.grab_exts() - return self._exts - def grab_exts(self): # TODO: file type validation exts = [] @@ -260,10 +253,11 @@ def validate(self, object, name, value): """ validated_value = super(ImageFile, self).validate(object, name, value) if validated_value and self.types: - 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