Nipype: InvWarp giving me guff

55 views
Skip to first unread message

Eric

unread,
Oct 7, 2013, 3:26:31 PM10/7/13
to nipy...@googlegroups.com
Hey All,

I'm trying to use nipype.interfaces.fsl.utils.InvWarp, but it is requiring I provide an existent filename for the name of the output file (inverse_warp), though the gen_file is set to True.  The problem seems to be due to the fact the the command-line call requires the output filename be provided.

Relevant lines start here:

It looks to me like the problem might be in the definition of the parameter "inverse_warp".
inverse_warp = File(exists=True, desc='Name of output file, containing warps that are the "reverse" of those in --warp. This will be a field-file (rather than a file of spline coefficients), and it will have any affine component included as part of the displacements.', argstr='--out=%s', gen_file=True)

Any help or ideas would be greatly appreciated.  Thanks!
~Eric

Eric

unread,
Oct 7, 2013, 9:09:43 PM10/7/13
to nipy...@googlegroups.com
After troubleshooting this, I found the major typo here is "gen_file=True".  It should read "genfile=True".  That and the _gen_filename method in the InvWarp class shouldn't say, "in_file1 = self.inputs.in_file1".  It should instead maybe be "in_file1 = self.inputs.warp".  For your approval, perhaps insert this code for the _gen_filename method?

    def _gen_filename(self, name):
        if name == 'inverse_warp':
            in_file1 = self.inputs.warp
            fn1,ext1 = os.path.splitext(in_file1)
            fn2,ext2 = os.path.splitext(fn1)
            return fn2 + '_inv' + ext2 + ext1
        else:
            raise NotImplementedError

Thanks!
~Eric

Eric

unread,
Oct 9, 2013, 2:43:55 PM10/9/13
to nipy...@googlegroups.com
Hey All,

I thought I had it, but I don't.  I still can't get the "inverse_warp" field to be anything, but <undefined> though the command line command populates correctly now with _gen_filename.  Any ideas would be appreciated.  Here's some of the relevant code and report.rst output:

REPORT.RST:

Original Inputs
---------------

* absolute : <undefined>
* args : <undefined>
* environ : {'FSLOUTPUTTYPE': 'NIFTI_GZ'}
* ignore_exception : False
* inverse_warp : <undefined>
* jacobian_max : <undefined>
* jacobian_min : <undefined>
* niter : <undefined>
* noconstraint : <undefined>
* output_type : NIFTI_GZ
* reference : /path/to/sequence_mean_chpixdim_brain_chpixdim_flirt.nii.gz
* regularise : <undefined>
* relative : <undefined>
* terminal_output : none
* warp : /path/to/mp_rage_p2_fieldwarp.nii.gz

Execution Inputs
----------------

* absolute : <undefined>
* args : <undefined>
* environ : {'FSLOUTPUTTYPE': 'NIFTI_GZ'}
* ignore_exception : False
* inverse_warp : <undefined>
* jacobian_max : <undefined>
* jacobian_min : <undefined>
* niter : <undefined>
* noconstraint : <undefined>
* output_type : NIFTI_GZ
* reference : /path/to/sequence_mean_chpixdim_brain_chpixdim_flirt.nii.gz
* regularise : <undefined>
* relative : <undefined>
* terminal_output : none
* warp : /path/to/mp_rage_p2_fieldwarp.nii.gz

Execution Outputs
-----------------

* inverse_warp : <undefined>

Runtime info
------------

* command : invwarp --out=/path/to/mp_rage_p2_fieldwarp_inv.nii.gz --ref=/path/to/sequence_mean_chpixdim_brain_chpixdim_flirt.nii.gz --warp=/path/to/mp_rage_p2_fieldwarp.nii.gz
* duration : 844.932158947
* hostname : blah


CODE (in class InvWarp(FSLCommand)):

    def _list_outputs(self):
        outputs = self.output_spec().get()
        if not outputs['inverse_warp']:
            outputs['inverse_warp'] = self.inputs.inverse_warp
        
        return outputs
    
    def _gen_filename(self, name):
        if name == 'inverse_warp':
            in_file1 = self.inputs.warp
            fn1,ext1 = os.path.splitext(in_file1)
            fn2,ext2 = os.path.splitext(fn1)
            old_path,fn3 = os.path.split(fn2)
            return os.path.abspath(fn3 + '_inv' + ext2 + ext1)
        else:
            raise NotImplementedError

Satrajit Ghosh

unread,
Oct 8, 2013, 1:05:15 PM10/8/13
to nipy-user
hi eric,

i will fix this soon. there is a general cleanup that needs to happen with the metadata. i wrote a little script that checks for discrepancies.


cheers,

satra

--
 
---
You received this message because you are subscribed to the Google Groups "NiPy Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nipy-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Satrajit Ghosh

unread,
Oct 9, 2013, 3:15:20 PM10/9/13
to nipy-user
hi eric,

this gave me a chance to refactor and think about filename generation with a cleaner codebased. it started with something basile had implemented and extends the idea. i'm hoping to get some feedback from more devs and will try to go through all the code and refactor using this new model. as you can see in InvWarp, the entire interface code is now fairly trivial, with information encoded in the specs.


cheers,

satra


--

Eric

unread,
Oct 11, 2013, 12:47:47 PM10/11/13
to nipy...@googlegroups.com
That looks excellent!  Thank you, Satra!

~Eric
Reply all
Reply to author
Forward
0 new messages