From 57ae723459152b6240cc9d79b2ef7b326c701a7f Mon Sep 17 00:00:00 2001 From: fliem Date: Thu, 25 Oct 2018 16:46:25 +0200 Subject: [PATCH 1/7] added slice_encoding_direction input to TShift --- nipype/interfaces/afni/preprocess.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index edb3e01c1a..bd9296fa92 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -2618,6 +2618,10 @@ class TShiftInputSpec(AFNICommandInputSpec): desc='time offsets from the volume acquisition onset for each slice', argstr='-tpattern @%s', xor=['tpattern']) + slice_encoding_direction = traits.Enum( + ('k', 'k-'), + desc='Direction in which slice_timing is specified (default: k). If negative,' + 'slice_timing is defined in reverse order -- see BIDS specification for details.',) rlt = traits.Bool( desc='Before shifting, remove the mean and linear trend', argstr='-rlt') @@ -2723,9 +2727,17 @@ def _format_arg(self, name, trait_spec, value): return super(TShift, self)._format_arg(name, trait_spec, value) def _write_slice_timing(self): + slice_timing = self.inputs.slice_timing.copy() + if not self.inputs.slice_encoding_direction: + slice_encoding_direction = "k" + else: + slice_encoding_direction = self.inputs.slice_encoding_direction + if slice_encoding_direction.endswith("-"): + slice_timing.reverse() + fname = 'slice_timing.1D' with open(fname, 'w') as fobj: - fobj.write('\t'.join(map(str, self.inputs.slice_timing))) + fobj.write('\t'.join(map(str, slice_timing))) return fname def _list_outputs(self): From 169e827b53959bee14ad9967a14fd3aa4f548b57 Mon Sep 17 00:00:00 2001 From: fliem Date: Thu, 25 Oct 2018 16:54:04 +0200 Subject: [PATCH 2/7] updated orcid --- .zenodo.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.zenodo.json b/.zenodo.json index 3efcfa9c87..9424961ab8 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -320,7 +320,9 @@ "name": "Ghayoor, Ali" }, { - "name": "Liem, Franz" + "affiliation": "University of Zurich", + "name": "Liem, Franz", + "orcid": "0000-0003-0646-4810" }, { "name": "Millman, Jarrod" From 3c7d0c20b2a04ae2728604c995b5ac81b23f8f66 Mon Sep 17 00:00:00 2001 From: fliem Date: Thu, 25 Oct 2018 19:24:05 +0200 Subject: [PATCH 3/7] better handle default values of slice_encoding_direction --- nipype/interfaces/afni/preprocess.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index bd9296fa92..c227def99e 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -2619,7 +2619,8 @@ class TShiftInputSpec(AFNICommandInputSpec): argstr='-tpattern @%s', xor=['tpattern']) slice_encoding_direction = traits.Enum( - ('k', 'k-'), + 'k', 'k-', + usedefault=True, desc='Direction in which slice_timing is specified (default: k). If negative,' 'slice_timing is defined in reverse order -- see BIDS specification for details.',) rlt = traits.Bool( @@ -2728,13 +2729,9 @@ def _format_arg(self, name, trait_spec, value): def _write_slice_timing(self): slice_timing = self.inputs.slice_timing.copy() - if not self.inputs.slice_encoding_direction: - slice_encoding_direction = "k" - else: - slice_encoding_direction = self.inputs.slice_encoding_direction - if slice_encoding_direction.endswith("-"): + if self.inputs.slice_encoding_direction.endswith("-"): slice_timing.reverse() - + fname = 'slice_timing.1D' with open(fname, 'w') as fobj: fobj.write('\t'.join(map(str, slice_timing))) From d67d6608d6ef229f05091c1617b16bc43137f902 Mon Sep 17 00:00:00 2001 From: fliem Date: Thu, 25 Oct 2018 19:42:30 +0200 Subject: [PATCH 4/7] docstring testing slice_encoding_direction --- nipype/interfaces/afni/preprocess.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index c227def99e..0cb2d0017f 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -2665,6 +2665,17 @@ class TShift(AFNICommand): >>> tshift._list_outputs()['timing_file'] # doctest: +ELLIPSIS '.../slice_timing.1D' + >>> np.loadtxt(tshift._list_outputs()['timing_file'])[:5] + [0.0, 0.4, 0.8, 1.2, 1.6] + + If ``slice_encoding_direction`` is set to ``'k-'``, the slice timing is reversed: + + >>> tshift.inputs.slice_encoding_direction = 'k-' + >>> tshift.cmdline + '3dTshift -prefix functional_tshift -tpattern @slice_timing.1D -TR 2.5s -tzero 0.0 functional.nii' + >>> np.loadtxt(tshift._list_outputs()['timing_file'])[:5] + [15.6, 15.2, 14.8, 14.4, 14.0] + This method creates a ``slice_timing.1D`` file to be passed to ``3dTshift``. A pre-existing slice-timing file may be used in the same way: From daf1f25521d97c12c1aca60270b4e6e7862c616b Mon Sep 17 00:00:00 2001 From: fliem Date: Thu, 25 Oct 2018 19:46:11 +0200 Subject: [PATCH 5/7] remove bids reference from desc --- nipype/interfaces/afni/preprocess.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 0cb2d0017f..278d6d1915 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -2622,7 +2622,10 @@ class TShiftInputSpec(AFNICommandInputSpec): 'k', 'k-', usedefault=True, desc='Direction in which slice_timing is specified (default: k). If negative,' - 'slice_timing is defined in reverse order -- see BIDS specification for details.',) + 'slice_timing is defined in reverse order, that is, the first entry ' + 'corresponds to the slice with the largest index, and the final entry ' + 'corresponds to slice index zero. Only in effect when slice_timing is ' + 'passed as list, not when it is passed as file.',) rlt = traits.Bool( desc='Before shifting, remove the mean and linear trend', argstr='-rlt') From 27c944825faf0e6262dc25ed3ca7ba160f547590 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Thu, 25 Oct 2018 14:20:22 -0400 Subject: [PATCH 6/7] FIX: Cast TraitList to a list --- nipype/interfaces/afni/preprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 278d6d1915..062b62ae8d 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -2742,7 +2742,7 @@ def _format_arg(self, name, trait_spec, value): return super(TShift, self)._format_arg(name, trait_spec, value) def _write_slice_timing(self): - slice_timing = self.inputs.slice_timing.copy() + slice_timing = list(self.inputs.slice_timing) if self.inputs.slice_encoding_direction.endswith("-"): slice_timing.reverse() From 27bbfc15e89d093a576c185b4cf4e6cf2585f30f Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Thu, 25 Oct 2018 16:26:23 -0400 Subject: [PATCH 7/7] TEST: Print lists, not arrays --- nipype/interfaces/afni/preprocess.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 062b62ae8d..5e4b54e09c 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -2668,7 +2668,7 @@ class TShift(AFNICommand): >>> tshift._list_outputs()['timing_file'] # doctest: +ELLIPSIS '.../slice_timing.1D' - >>> np.loadtxt(tshift._list_outputs()['timing_file'])[:5] + >>> np.loadtxt(tshift._list_outputs()['timing_file']).tolist()[:5] [0.0, 0.4, 0.8, 1.2, 1.6] If ``slice_encoding_direction`` is set to ``'k-'``, the slice timing is reversed: @@ -2676,7 +2676,7 @@ class TShift(AFNICommand): >>> tshift.inputs.slice_encoding_direction = 'k-' >>> tshift.cmdline '3dTshift -prefix functional_tshift -tpattern @slice_timing.1D -TR 2.5s -tzero 0.0 functional.nii' - >>> np.loadtxt(tshift._list_outputs()['timing_file'])[:5] + >>> np.loadtxt(tshift._list_outputs()['timing_file']).tolist()[:5] [15.6, 15.2, 14.8, 14.4, 14.0] This method creates a ``slice_timing.1D`` file to be passed to ``3dTshift``.