From 9707b368c7131f1335babfd1950bed34506d28a0 Mon Sep 17 00:00:00 2001 From: Chris Gorgolewski Date: Thu, 27 Apr 2017 12:13:37 -0700 Subject: [PATCH 1/4] Output warp fields and jacobian correction files in TOPUP. --- nipype/interfaces/fsl/epi.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/nipype/interfaces/fsl/epi.py b/nipype/interfaces/fsl/epi.py index 2b45d62c2d..9d470f0543 100644 --- a/nipype/interfaces/fsl/epi.py +++ b/nipype/interfaces/fsl/epi.py @@ -26,7 +26,7 @@ from ..base import (traits, TraitedSpec, InputMultiPath, File, isdefined) -from .base import FSLCommand, FSLCommandInputSpec +from .base import FSLCommand, FSLCommandInputSpec, Info class PrepareFieldmapInputSpec(FSLCommandInputSpec): @@ -140,6 +140,13 @@ class TOPUPInputSpec(FSLCommandInputSpec): out_field = File(argstr='--fout=%s', hash_files=False, name_source=['in_file'], name_template='%s_field', desc='name of image file with field (Hz)') + out_warp_prefix = traits.Str("warpfield", argstr='--dfout=%s', hash_files=False, + desc='prefix for the warpfield images (in mm)', + usedefault=True) + out_jac_prefix = traits.Str("jac", argstr='--jacout=%s', + hash_files=False, + desc='prefix for the warpfield images', + usedefault=True) out_corrected = File(argstr='--iout=%s', hash_files=False, name_source=['in_file'], name_template='%s_corrected', desc='name of 4D image file with unwarped images') @@ -212,6 +219,8 @@ class TOPUPOutputSpec(TraitedSpec): out_movpar = File(exists=True, desc='movpar.txt output file') out_enc_file = File(desc='encoding directions file output for applytopup') out_field = File(desc='name of image file with field (Hz)') + out_warps = traits.List(File(exists=True), desc='warpfield images') + out_jacs = traits.List(File(exists=True), desc='Jacobian images') out_corrected = File(desc='name of 4D image file with unwarped images') out_logfile = File(desc='name of log-file') @@ -269,6 +278,13 @@ def _list_outputs(self): cwd=base_path) outputs['out_movpar'] = self._gen_fname(base, suffix='_movpar', ext='.txt', cwd=base_path) + n_vols = nb.load(self.inputs.in_file).shape[-1] + + outputs['out_warps'] = [os.path.abspath(self.inputs.out_warp_prefix + "_%02d" % (i+1) + Info.output_type_to_ext(self.inputs.output_type)) for i in range(n_vols)] + outputs['out_jacs'] = [os.path.abspath( + self.inputs.out_jac_prefix + "_%02d" % ( + i + 1) + Info.output_type_to_ext(self.inputs.output_type)) for i in + range(n_vols)] if isdefined(self.inputs.encoding_direction): outputs['out_enc_file'] = self._get_encfilename() From 3e69cbecf2e2e30c6d8323a52f41baa5951f75d5 Mon Sep 17 00:00:00 2001 From: Chris Gorgolewski Date: Thu, 27 Apr 2017 12:36:59 -0700 Subject: [PATCH 2/4] fixing auto tests --- nipype/interfaces/fsl/tests/test_auto_TOPUP.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nipype/interfaces/fsl/tests/test_auto_TOPUP.py b/nipype/interfaces/fsl/tests/test_auto_TOPUP.py index d43a6c61a9..01f50670ba 100644 --- a/nipype/interfaces/fsl/tests/test_auto_TOPUP.py +++ b/nipype/interfaces/fsl/tests/test_auto_TOPUP.py @@ -54,6 +54,14 @@ def test_TOPUP_inputs(): name_source=['in_file'], name_template='%s_field', ), + out_warp_prefix=dict(argstr='--dfout=%s', + hash_files=False, + usedefault=True, + ), + out_jac_prefix=dict(argstr='--jacout=%s', + hash_files=False, + usedefault=True, + ), out_logfile=dict(argstr='--logout=%s', hash_files=False, keep_extension=True, @@ -98,6 +106,8 @@ def test_TOPUP_outputs(): out_fieldcoef=dict(), out_logfile=dict(), out_movpar=dict(), + out_warps=dict(), + out_jacs=dict(), ) outputs = TOPUP.output_spec() From 83a678296c783a82a08b99d1a23074531ed0d89f Mon Sep 17 00:00:00 2001 From: Chris Gorgolewski Date: Thu, 27 Apr 2017 12:50:00 -0700 Subject: [PATCH 3/4] code readability improvements --- nipype/interfaces/fsl/epi.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/nipype/interfaces/fsl/epi.py b/nipype/interfaces/fsl/epi.py index 9d470f0543..b6e330ac03 100644 --- a/nipype/interfaces/fsl/epi.py +++ b/nipype/interfaces/fsl/epi.py @@ -278,13 +278,16 @@ def _list_outputs(self): cwd=base_path) outputs['out_movpar'] = self._gen_fname(base, suffix='_movpar', ext='.txt', cwd=base_path) - n_vols = nb.load(self.inputs.in_file).shape[-1] - outputs['out_warps'] = [os.path.abspath(self.inputs.out_warp_prefix + "_%02d" % (i+1) + Info.output_type_to_ext(self.inputs.output_type)) for i in range(n_vols)] - outputs['out_jacs'] = [os.path.abspath( - self.inputs.out_jac_prefix + "_%02d" % ( - i + 1) + Info.output_type_to_ext(self.inputs.output_type)) for i in - range(n_vols)] + n_vols = nb.load(self.inputs.in_file).shape[-1] + ext = Info.output_type_to_ext(self.inputs.output_type) + fmt = os.path.abspath('{prefix}_{i:02d}{ext}').format + outputs['out_warps'] = [ + fmt(prefix=self.inputs.out_warp_prefix, i=i, ext=ext) + for i in range(1, n_vols + 1)] + outputs['out_jacs'] = [ + fmt(prefix=self.inputs.out_jac_prefix, i=i, ext=ext) + for i in range(1, n_vols + 1)] if isdefined(self.inputs.encoding_direction): outputs['out_enc_file'] = self._get_encfilename() From 4ecd866da339f44dc5681042b40ad6463d95e36d Mon Sep 17 00:00:00 2001 From: Chris Gorgolewski Date: Thu, 27 Apr 2017 12:53:11 -0700 Subject: [PATCH 4/4] docstrings fix --- nipype/interfaces/fsl/epi.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nipype/interfaces/fsl/epi.py b/nipype/interfaces/fsl/epi.py index b6e330ac03..7e4f2b8f49 100644 --- a/nipype/interfaces/fsl/epi.py +++ b/nipype/interfaces/fsl/epi.py @@ -246,7 +246,8 @@ class TOPUP(FSLCommand): >>> topup.cmdline # doctest: +ELLIPSIS +ALLOW_UNICODE 'topup --config=b02b0.cnf --datain=topup_encoding.txt \ --imain=b0_b0rev.nii --out=b0_b0rev_base --iout=b0_b0rev_corrected.nii.gz \ ---fout=b0_b0rev_field.nii.gz --logout=b0_b0rev_topup.log' +--fout=b0_b0rev_field.nii.gz --jacout=jac --logout=b0_b0rev_topup.log \ +--dfout=warpfield' >>> res = topup.run() # doctest: +SKIP """