Source code for dmriprep.workflows.dwi.eddy

# -*- coding: utf-8 -*-

"""
Head motion, eddy current distortion and EPI distortion correction
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: init_dwi_eddy_wf

"""

from nipype.pipeline import engine as pe
from nipype.interfaces import utility as niu
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
from numba import cuda

from ...interfaces import fsl


[docs]def init_dwi_eddy_wf(omp_nthreads, sdc_method=None, name='dwi_eddy_wf'): """ This workflow runs eddy on the input dwi image. .. workflow:: :graph2use: orig :simple_form: yes from dmriprep.workflows.dwi import init_dwi_eddy_wf wf = init_dwi_eddy_wf(omp_nthreads=1) **Parameters** omp_nthreads: int Number of threads to run eddy sdc_method: str Synthetic distortion correction method (may include 'fieldmap or 'topup') **Inputs** dwi_file dwi NIfTI file bvec_file bvec file bval_file bval file mask_file brain mask file fieldmap_file fieldmap file topup_fieldcoef topup file containing field coefficients topup_movpar topup movpar.txt file acqp acquisition parameters file index index file slspec slspec file **Outputs** out_file output eddy-corrected dwi image out_bvec output rotated bvecs after eddy correction """ workflow = Workflow(name=name) # workflow.__desc__ = """\ # dwi runs were distortion corrected using `eddy` from FSL {fsl_ver}. # """.format(fsl_ver=''.join(['%02d' %v for v in fsl.Info().version() or []])) inputnode = pe.Node(niu.IdentityInterface(fields=['dwi_file', 'bvec_file', 'bval_file', 'mask_file', 'fieldmap_file', 'topup_fieldcoef', 'topup_movpar', 'acqp', 'index', 'slspec']), name='inputnode') outputnode = pe.Node(niu.IdentityInterface(fields=['out_file', 'out_bvec']), name='outputnode') ecc = pe.Node( fsl.Eddy(num_threads=omp_nthreads, repol=True, cnr_maps=True, residuals=True), name='fsl_eddy') try: if cuda.gpus: ecc.inputs.use_cuda = True ecc.inputs.mporder = 16 ecc.inputs.slice2vol_niter = 5 ecc.inputs.slice2vol_lambda = 1 except: pass workflow.connect([ (inputnode, ecc, [('dwi_file', 'in_file'), ('bval_file', 'in_bval'), ('bvec_file', 'in_bvec'), ('acqp', 'in_acqp'), ('index', 'in_index'), ('mask_file', 'in_mask')]), (ecc, outputnode, [('out_corrected', 'out_file'), ('out_rotated_bvecs', 'out_bvec')]) ]) if sdc_method == 'fieldmap': workflow.connect([ (inputnode, ecc, [('fieldmap_file', 'field')]) ]) if sdc_method == 'topup': workflow.connect([ (inputnode, ecc, [('topup_fieldcoef', 'in_topup_fieldcoef'), ('topup_movpar', 'in_topup_movpar')]) ]) return workflow