-
Notifications
You must be signed in to change notification settings - Fork 533
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
Conversation
Before working on these tests, is there a semantic difference between |
@effigies - i will take a look later today, but i'm still not sure how my changes could be responsible for issue with ver 0.13... but will read more about the issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also not sure how this would affect version 0.13 - however I would prefer the interface to work as intended and raise a cryptic error message rather than vice-versa. perhaps we should also add an additional realign test that handles a list of lists as input?
this was the original formulation: nipype/nipype/interfaces/spm/preprocess.py Line 122 in 8946bca
so as a first pass we could switch back to this. in terms of tests we would really have to check this against the matlab file that's created, so that would be a little involved. |
Okay, I'll just revert #2375 for now, rather than try to be fancy and concise with nested |
there are a few things here:
|
|
aa1d482
to
a84c8e8
Compare
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)): |
There was a problem hiding this comment.
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 alwaysTrue
for atraits.List
(default value:(traits.Any(),)
)isinstance(value, list)
is alwaysTrue
at this point in the short-circuitbool(value)
is always True, or we would have returnedUndefined
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@effigies what if value = []
?
There was a problem hiding this comment.
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
New error message: In [1]: from nipype.interfaces import spm
In [2]: realign = spm.Realign()
In [3]: realign.inputs.in_files = ['test.nii.gz', 'test.img']
---------------------------------------------------------------------------
TraitError Traceback (most recent call last)
<ipython-input-3-b45a253e48c2> in <module>()
----> 1 realign.inputs.in_files = [['test.nii.gz', 'test.img']]
/data/cjmarkie/Projects/nipype/nipype/interfaces/base/traits_extension.py in validate(self, object, name, value)
345 newvalue = [value]
346
--> 347 value = super(MultiPath, self).validate(object, name, newvalue)
348 # try:
349 # except TraitError as excp:
~/.anaconda3/lib/python3.6/site-packages/traits/trait_types.py in validate(self, object, name, value)
2334 return value
2335
-> 2336 return TraitListObject( self, object, name, value )
2337
2338 self.error( object, name, value )
~/.anaconda3/lib/python3.6/site-packages/traits/trait_handlers.py in __init__(self, trait, object, name, value)
2311 except TraitError as excp:
2312 excp.set_prefix( 'Each element of the' )
-> 2313 raise excp
2314
2315 self.len_error( len( value ) )
~/.anaconda3/lib/python3.6/site-packages/traits/trait_handlers.py in __init__(self, trait, object, name, value)
2303 validate = trait.item_trait.handler.validate
2304 if validate is not None:
-> 2305 value = [ validate( object, name, val ) for val in value ]
2306
2307 list.__setitem__(self, slice(0, 0), value )
~/.anaconda3/lib/python3.6/site-packages/traits/trait_handlers.py in <listcomp>(.0)
2303 validate = trait.item_trait.handler.validate
2304 if validate is not None:
-> 2305 value = [ validate( object, name, val ) for val in value ]
2306
2307 list.__setitem__(self, slice(0, 0), value )
~/.anaconda3/lib/python3.6/site-packages/traits/trait_handlers.py in validate(self, object, name, value)
1981 except TraitError:
1982 pass
-> 1983 return self.slow_validate( object, name, value )
1984
1985 def slow_validate ( self, object, name, value ):
~/.anaconda3/lib/python3.6/site-packages/traits/trait_handlers.py in slow_validate(self, object, name, value)
1989 except TraitError:
1990 pass
-> 1991 self.error( object, name, value )
1992
1993 def full_info ( self, object, name, value ):
~/.anaconda3/lib/python3.6/site-packages/traits/trait_handlers.py in error(self, object, name, value)
170 """
171 raise TraitError( object, name, self.full_info( object, name, value ),
--> 172 value )
173
174 def full_info ( self, object, name, value ):
TraitError: Each element of the 'in_files' trait of a RealignInputSpec instance must be a list of
items which are an existing, uncompressed file (valid extensions: [.img, .nii, .hdr]) or an existing,
uncompressed file (valid extensions: [.img, .nii, .hdr]), but a value of 'test.nii.gz' <class 'str'> was
specified. |
Last change I think makes the grammar a little smoother.
|
lgtm |
Fixes #2406. Essentially reverts #2375, but using
InputMultiPath
instead ofEither
.Changes proposed in this pull request
InputMultiPath
s.