Skip to content

Commit cf912a5

Browse files
committed
all_peb_pipeline with only one interpolation
1 parent 32577f2 commit cf912a5

File tree

1 file changed

+68
-25
lines changed
  • nipype/workflows/dmri/preprocess

1 file changed

+68
-25
lines changed

nipype/workflows/dmri/preprocess/epi.py

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ def all_peb_pipeline(name='hmc_sdc_ecc',
104104
inputnode = pe.Node(niu.IdentityInterface(fields=['in_file', 'in_bvec', 'in_bval',
105105
'alt_file']), name='inputnode')
106106

107-
outputnode = pe.Node(niu.IdentityInterface(fields=['out_file', 'out_mask', 'out_bvec']),
108-
name='outputnode')
107+
outputnode = pe.Node(niu.IdentityInterface(fields=['out_file', 'out_mask',
108+
'out_bvec']), name='outputnode')
109109

110110
avg_b0_0 = pe.Node(niu.Function(input_names=['in_dwi', 'in_bval'],
111111
output_names=['out_file'], function=b0_average), name='b0_avg_pre')
@@ -118,6 +118,8 @@ def all_peb_pipeline(name='hmc_sdc_ecc',
118118
sdc = sdc_peb(epi_params=epi_params, altepi_params=altepi_params)
119119
ecc = ecc_pipeline()
120120

121+
unwarp = apply_all_corrections()
122+
121123
wf = pe.Workflow('dMRI_Artifacts')
122124
wf.connect([
123125
(inputnode, hmc, [('in_file', 'inputnode.in_file'),
@@ -137,8 +139,15 @@ def all_peb_pipeline(name='hmc_sdc_ecc',
137139
,(ecc, avg_b0_1, [('outputnode.out_file', 'in_dwi')])
138140
,(inputnode, avg_b0_1, [('in_bval', 'in_bval')])
139141
,(avg_b0_1, bet_dwi1, [('out_file','in_file')])
140-
,(ecc, outputnode, [('outputnode.out_file', 'out_file')])
142+
143+
144+
,(inputnode, unwarp, [('in_file', 'inputnode.in_dwi')])
145+
,(hmc, unwarp, [('outputnode.out_xfms', 'inputnode.in_hmc')])
146+
,(ecc, unwarp, [('outputnode.out_xfms', 'inputnode.in_ecc')])
147+
,(sdc, unwarp, [('outputnode.out_warp', 'inputnode.in_sdc')])
148+
141149
,(hmc, outputnode, [('outputnode.out_bvec', 'out_bvec')])
150+
,(unwarp, outputnode, [('outputnode.out_file', 'out_file')])
142151
,(bet_dwi1, outputnode, [('mask_file', 'out_mask')])
143152
])
144153
return wf
@@ -575,13 +584,16 @@ def sdc_peb(name='peb_correction',
575584
enc_dir='y',
576585
epi_factor=1)):
577586
"""
578-
SDC stands for susceptibility distortion correction. PEB stands for phase-encoding-based.
579-
580-
The phase-encoding-based (PEB) method implements SDC by acquiring diffusion images with
581-
two different enconding directions [Andersson2003]_. The most typical case is acquiring
582-
with opposed phase-gradient blips (e.g. *A>>>P* and *P>>>A*, or equivalently, *-y* and *y*)
583-
as in [Chiou2000]_, but it is also possible to use orthogonal configurations [Cordes2000]_
584-
(e.g. *A>>>P* and *L>>>R*, or equivalently *-y* and *x*).
587+
SDC stands for susceptibility distortion correction. PEB stands for
588+
phase-encoding-based.
589+
590+
The phase-encoding-based (PEB) method implements SDC by acquiring
591+
diffusion images with two different enconding directions [Andersson2003]_.
592+
The most typical case is acquiring with opposed phase-gradient blips
593+
(e.g. *A>>>P* and *P>>>A*, or equivalently, *-y* and *y*)
594+
as in [Chiou2000]_, but it is also possible to use orthogonal
595+
configurations [Cordes2000]_ (e.g. *A>>>P* and *L>>>R*,
596+
or equivalently *-y* and *x*).
585597
This workflow uses the implementation of FSL
586598
(`TOPUP <http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/TOPUP>`_).
587599
@@ -597,39 +609,47 @@ def sdc_peb(name='peb_correction',
597609
598610
.. admonition:: References
599611
600-
.. [Andersson2003] Andersson JL et al., `How to correct susceptibility distortions in
601-
spin-echo echo-planar images: application to diffusion tensor imaging
602-
<http://dx.doi.org/10.1016/S1053-8119(03)00336-7>`_.
612+
.. [Andersson2003] Andersson JL et al., `How to correct susceptibility
613+
distortions in spin-echo echo-planar images: application to diffusion
614+
tensor imaging <http://dx.doi.org/10.1016/S1053-8119(03)00336-7>`_.
603615
Neuroimage. 2003 Oct;20(2):870-88. doi: 10.1016/S1053-8119(03)00336-7
604616
605-
.. [Cordes2000] Cordes D et al., Geometric distortion correction in EPI using two
606-
images with orthogonal phase-encoding directions, in Proc. ISMRM (8), p.1712,
607-
Denver, US, 2000.
617+
.. [Cordes2000] Cordes D et al., Geometric distortion correction in EPI
618+
using two images with orthogonal phase-encoding directions, in Proc.
619+
ISMRM (8), p.1712, Denver, US, 2000.
608620
609-
.. [Chiou2000] Chiou JY, and Nalcioglu O, A simple method to correct off-resonance
610-
related distortion in echo planar imaging, in Proc. ISMRM (8), p.1712, Denver, US,
611-
2000.
621+
.. [Chiou2000] Chiou JY, and Nalcioglu O, A simple method to correct
622+
off-resonance related distortion in echo planar imaging, in Proc.
623+
ISMRM (8), p.1712, Denver, US, 2000.
612624
613625
"""
614626

615-
inputnode = pe.Node(niu.IdentityInterface(fields=['in_file', 'in_bval', 'in_mask',
616-
'alt_file', 'ref_num']),
627+
inputnode = pe.Node(niu.IdentityInterface(fields=['in_file', 'in_bval',
628+
'in_mask', 'alt_file', 'ref_num']),
617629
name='inputnode')
618-
outputnode = pe.Node(niu.IdentityInterface(fields=['out_file', 'out_vsm']),
619-
name='outputnode')
630+
outputnode = pe.Node(niu.IdentityInterface(fields=['out_file', 'out_vsm',
631+
'out_warp']), name='outputnode')
620632

621633
b0_ref = pe.Node(fsl.ExtractROI(t_size=1), name='b0_ref')
622634
b0_alt = pe.Node(fsl.ExtractROI(t_size=1), name='b0_alt')
623635
b0_comb = pe.Node(niu.Merge(2), name='b0_list')
624636
b0_merge = pe.Node(fsl.Merge(dimension='t'), name='b0_merged')
625637

626638
topup = pe.Node(fsl.TOPUP(), name='topup')
627-
topup.inputs.encoding_direction = [epi_params['enc_dir'], altepi_params['enc_dir']]
639+
topup.inputs.encoding_direction = [epi_params['enc_dir'],
640+
altepi_params['enc_dir']]
628641
topup.inputs.readout_times = [compute_readout(epi_params),
629642
compute_readout(altepi_params)]
630643

631644
unwarp = pe.Node(fsl.ApplyTOPUP(in_index=[1], method='jac'), name='unwarp')
632645

646+
scaling = pe.Node(niu.Function(input_names=['in_file', 'enc_dir'],
647+
output_names=['factor'], function=_get_zoom),
648+
name='GetZoom')
649+
scaling.inputs.enc_dir = epi_params['enc_dir']
650+
vsm2dfm = vsm2warp()
651+
vsm2dfm.inputs.inputnode.enc_dir = epi_params['enc_dir']
652+
633653
wf = pe.Workflow(name=name)
634654
wf.connect([
635655
(inputnode, b0_ref, [('in_file', 'in_file'),
@@ -645,6 +665,13 @@ def sdc_peb(name='peb_correction',
645665
('out_enc_file', 'encoding_file')])
646666
,(inputnode, unwarp, [('in_file', 'in_files')])
647667
,(unwarp, outputnode, [('out_corrected', 'out_file')])
668+
669+
,(b0_ref, scaling, [('roi_file', 'in_file')])
670+
,(b0_ref, vsm2dfm, [('roi_file', 'inputnode.in_ref')])
671+
,(scaling, vsm2dfm, [('factor', 'inputnode.scaling')])
672+
,(topup, vsm2dfm, [('out_field', 'inputnode.in_vsm')])
673+
,(topup, outputnode, [('out_field', 'out_vsm')])
674+
,(vsm2dfm, outputnode, [('outputnode.out_warp', 'out_warp')])
648675
])
649676
return wf
650677

@@ -706,9 +733,25 @@ def _checkrnum(ref_num):
706733
def _nonb0(in_bval):
707734
import numpy as np
708735
bvals = np.loadtxt(in_bval)
709-
return np.where(bvals!=0)[0].tolist()
736+
return np.where(bvals != 0)[0].tolist()
737+
710738

711739
def _xfm_jacobian(in_xfm):
712740
import numpy as np
713741
from math import fabs
714742
return [fabs(np.linalg.det(np.loadtxt(xfm))) for xfm in in_xfm]
743+
744+
745+
def _get_zoom(in_file, enc_dir):
746+
import nibabel as nb
747+
748+
zooms = nb.load(in_file).get_zooms()
749+
750+
if 'y' in enc_dir:
751+
return zooms[1]
752+
elif 'x' in enc_dir:
753+
return zooms[0]
754+
elif 'z' in enc_dir:
755+
return zooms[2]
756+
else:
757+
raise ValueError('Wrong encoding direction string')

0 commit comments

Comments
 (0)