Skip to content

[ENH] added slice_encoding_direction input to TShift #2753

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

Merged
merged 7 commits into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 24 additions & 1 deletion nipype/interfaces/afni/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -2618,6 +2618,14 @@ 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-',
usedefault=True,
desc='Direction in which slice_timing is specified (default: k). If negative,'
'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')
Expand Down Expand Up @@ -2660,6 +2668,17 @@ class TShift(AFNICommand):
>>> tshift._list_outputs()['timing_file'] # doctest: +ELLIPSIS
'.../slice_timing.1D'

>>> 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:

>>> 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']).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``.
A pre-existing slice-timing file may be used in the same way:

Expand Down Expand Up @@ -2723,9 +2742,13 @@ 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 = list(self.inputs.slice_timing)
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, self.inputs.slice_timing)))
fobj.write('\t'.join(map(str, slice_timing)))
return fname

def _list_outputs(self):
Expand Down