-
Notifications
You must be signed in to change notification settings - Fork 532
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
ENH: Allow transform to be saved from AFNI 3dWarp #2642
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2642 +/- ##
==========================================
- Coverage 67.62% 67.58% -0.04%
==========================================
Files 340 340
Lines 43003 43033 +30
Branches 5321 5327 +6
==========================================
+ Hits 29080 29086 +6
- Misses 13225 13249 +24
Partials 698 698
Continue to review full report at Codecov.
|
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.
Looks good. Some minor comments.
Just FYI [WIP]
will often be interpreted as "Not ready for review". Do you have other modifications you're planning on making?
nipype/interfaces/afni/preprocess.py
Outdated
@@ -2789,6 +2790,13 @@ class WarpInputSpec(AFNICommandInputSpec): | |||
argstr='-zpad %d') | |||
verbose = traits.Bool( | |||
desc='Print out some information along the way.', argstr='-verb') | |||
save_warp = traits.Bool( | |||
False, usedefault=True, desc='save warp as .mat file') |
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.
The default of a Bool
is already false. You can just have desc
here.
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.
Oh, and RE your initial comment, I would set requires=['verbose']
. I'm not sure what will happen if someone sets verbose=False
, but at least it will catch when verbose
is unset.
nipype/interfaces/afni/preprocess.py
Outdated
warp_file = fname_presuffix(self.inputs.out_file, | ||
suffix='_transform.mat', | ||
use_ext=False) | ||
np.savetxt(warp_file, [runtime.stdout], fmt=str('%s')) |
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.
Rather than calculate the filename twice:
if self.inputs.save_warp:
import numpy as np
warp_file = self._list_outputs()['warp_file']
np.savetxt(warp_file, [runtime.stdout], fmt='%s')
(Not sure why you have str('%s')
. If that's important, feel free to re-add.)
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.
(Not sure why you have str('%s'). If that's important, feel free to re-add.)
When I don't explicit the format, I have an error
TypeError: Mismatch between array dtype ('<U209') and format specifier ('%.18e')
So we need to keep it I think.
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.
Oh, I meant str('%s')
vs '%s'
(or is that also what you meant?). The str()
seems like it should be a null-op, unless there's some weird Python2/3 hackery going on here.
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.
well on python 2.7 I am getting this error with fmt='%s'
ValueError: invalid fmt: u'%s'
nipype/interfaces/afni/preprocess.py
Outdated
|
||
class WarpOutputSpec(TraitedSpec): | ||
out_file = File(desc='Warped file.', exists=True) | ||
warp_file = File(desc='warp transfrom .mat file') |
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.
s/transfrom/transform/
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.
what do you mean ?
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.
Oh, sorry. That's regular expression syntax. I just meant you misspelled "transform".
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.
Sorry ! I am correcting that
nipype/interfaces/afni/preprocess.py
Outdated
use_ext=False) | ||
outputs['warp_file'] = os.path.abspath(warp_file) | ||
|
||
return outputs |
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.
Would the following work:
def _list_outputs(self):
outputs = super(Warp, self)._list_outputs()
if self.inputs.save_warp:
outputs['warp_file'] = fname_presuffix(outputs['out_file'],
suffix='_transform.mat',
use_ext=False)
return outputs
Ok. I was putting the WIP because I was unsure there isn't a better solution to force |
Thanks. The test failures are related to #2650. |
Ok. Thank you for the review ! |
I added an option to save the warp from the stdout because it can be useful. But the warp transform is printed only if
verbose
is set to True, otherwise the saved file is empty. I don't know if there is something like thexor
andrequires
that checks if a required trait is set to True.