Skip to content
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

Merged
merged 3 commits into from Jul 25, 2018

Conversation

salma1601
Copy link
Contributor

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 the xor and requires that checks if a required trait is set to True.

@codecov-io
Copy link

codecov-io commented Jul 19, 2018

Codecov Report

Merging #2642 into master will decrease coverage by 0.03%.
The diff coverage is 22.58%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#smoketests 50.52% <ø> (ø) ⬆️
#unittests 65.05% <22.58%> (-0.04%) ⬇️
Impacted Files Coverage Δ
nipype/interfaces/afni/preprocess.py 79.34% <22.58%> (-2.17%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ad506f2...3dc803c. Read the comment docs.

Copy link
Member

@effigies effigies left a 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?

@@ -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')
Copy link
Member

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.

Copy link
Member

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.

warp_file = fname_presuffix(self.inputs.out_file,
suffix='_transform.mat',
use_ext=False)
np.savetxt(warp_file, [runtime.stdout], fmt=str('%s'))
Copy link
Member

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.)

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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'


class WarpOutputSpec(TraitedSpec):
out_file = File(desc='Warped file.', exists=True)
warp_file = File(desc='warp transfrom .mat file')
Copy link
Member

Choose a reason for hiding this comment

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

s/transfrom/transform/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what do you mean ?

Copy link
Member

@effigies effigies Jul 24, 2018

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".

Copy link
Contributor Author

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

use_ext=False)
outputs['warp_file'] = os.path.abspath(warp_file)

return outputs
Copy link
Member

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

@effigies effigies added this to the 1.1.1 milestone Jul 23, 2018
@salma1601
Copy link
Contributor Author

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.

Ok. I was putting the WIP because I was unsure there isn't a better solution to force verbose to True when save_warp is set to True. Then I will remove it

@effigies effigies changed the title [WIP] Afni warp transform ENH: Allow transform to be saved from AFNI 3dWarp Jul 25, 2018
@effigies
Copy link
Member

Thanks. The test failures are related to #2650.

@salma1601
Copy link
Contributor Author

The test failures are related to #2650.

Ok. Thank you for the review !

@effigies effigies merged commit c505903 into nipy:master Jul 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants