Skip to content
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

REF: Split final boldref generation from BOLD-BOLD resampling, eliminate extra per-echo computation #2181

Merged
merged 17 commits into from
Aug 18, 2020
Merged
Changes from 7 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
85 changes: 58 additions & 27 deletions fmriprep/workflows/bold/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def init_func_preproc_wf(bold_file):
* :py:func:`~fmriprep.workflows.bold.t2s.init_bold_t2s_wf`
* :py:func:`~fmriprep.workflows.bold.registration.init_bold_t1_trans_wf`
* :py:func:`~fmriprep.workflows.bold.registration.init_bold_reg_wf`
* :py:func:`~fmriprep.workflows.bold.confounds.init_bold_confounds_wf`
* :py:func:`~fmriprep.workflows.bold.confounds.init_bold_confs_wf`
effigies marked this conversation as resolved.
Show resolved Hide resolved
* :py:func:`~fmriprep.workflows.bold.confounds.init_ica_aroma_wf`
* :py:func:`~fmriprep.workflows.bold.resampling.init_bold_std_trans_wf`
* :py:func:`~fmriprep.workflows.bold.resampling.init_bold_preproc_trans_wf`
Expand Down Expand Up @@ -404,7 +404,7 @@ def init_func_preproc_wf(bold_file):

inputnode.inputs.bold_file = ref_file # Replace reference w first echo

join_echos = pe.JoinNode(niu.IdentityInterface(fields=['bold_files']),
join_echos = pe.JoinNode(niu.IdentityInterface(fields=['bold_files', 'bold_masks']),
joinsource=('meepi_echos' if run_stc is True else 'boldbuffer'),
joinfield=['bold_files'],
name='join_echos')
Expand Down Expand Up @@ -479,9 +479,6 @@ def init_func_preproc_wf(bold_file):
('outputnode.itk_t1_to_bold', 'inputnode.t1_bold_xform')]),
(bold_reference_wf, bold_confounds_wf, [
('outputnode.skip_vols', 'inputnode.skip_vols')]),
(bold_bold_trans_wf, bold_confounds_wf, [
('outputnode.bold_mask', 'inputnode.bold_mask'),
]),
(bold_confounds_wf, outputnode, [
tsalo marked this conversation as resolved.
Show resolved Hide resolved
('outputnode.confounds_file', 'confounds'),
]),
Expand All @@ -503,7 +500,8 @@ def init_func_preproc_wf(bold_file):
(inputnode, func_derivatives_wf, [
('bold_file', 'inputnode.source_file')]),
(bold_bold_trans_wf, bold_confounds_wf, [
('outputnode.bold', 'inputnode.bold')]),
('outputnode.bold', 'inputnode.bold'),
('outputnode.bold_mask', 'inputnode.bold_mask')]),
(bold_split, bold_t1_trans_wf, [
('out_files', 'inputnode.bold_split')]),
(bold_hmc_wf, bold_t1_trans_wf, [
Expand All @@ -528,6 +526,10 @@ def init_func_preproc_wf(bold_file):
('outputnode.bold', 'in_file')]),
(split_opt_comb, bold_t1_trans_wf, [
('out_files', 'inputnode.bold_split')]),
(bold_bold_trans_wf, join_echos, [
('outputnode.bold_mask', 'bold_masks')]),
(join_echos, bold_confounds_wf, [
(('bold_masks', pop_file), 'inputnode.bold_mask')])
])

# Already applied in bold_bold_trans_wf, which inputs to bold_t2s_wf
Expand Down Expand Up @@ -607,20 +609,38 @@ def init_func_preproc_wf(bold_file):
('outputnode.itk_bold_to_t1', 'transforms')]),
(bold_t1_trans_wf, boldmask_to_t1w, [
('outputnode.bold_mask_t1', 'reference_image')]),
(bold_bold_trans_wf, boldmask_to_t1w, [
('outputnode.bold_mask', 'input_image')]),
(boldmask_to_t1w, outputnode, [
('output_image', 'bold_mask_t1')]),
])
if not multiecho:
workflow.connect([
(bold_bold_trans_wf, boldmask_to_t1w, [
('outputnode.bold_mask', 'input_image')]),
])
else:
workflow.connect([
(join_echos, boldmask_to_t1w, [
(('bold_masks', pop_file), 'input_image')]),
])

if nonstd_spaces.intersection(('func', 'run', 'bold', 'boldref', 'sbref')):
workflow.connect([
(bold_bold_trans_wf, outputnode, [
('outputnode.bold', 'bold_native')]),
(bold_bold_trans_wf, func_derivatives_wf, [
('outputnode.bold_ref', 'inputnode.bold_native_ref'),
('outputnode.bold_mask', 'inputnode.bold_mask_native')]),
('outputnode.bold_ref', 'inputnode.bold_native_ref')
tsalo marked this conversation as resolved.
Show resolved Hide resolved
]),
])
if not multiecho:
workflow.connect([
(bold_bold_trans_wf, func_derivatives_wf, [
('outputnode.bold_mask', 'inputnode.bold_mask_native')]),
])
else:
workflow.connect([
(join_echos, func_derivatives_wf, [
(('bold_masks', pop_file), 'inputnode.bold_mask_native')]),
])

if spaces.get_spaces(nonstandard=False, dim=(3,)):
# Apply transforms in 1 shot
Expand All @@ -642,26 +662,15 @@ def init_func_preproc_wf(bold_file):
('t1w_aparc', 'inputnode.bold_aparc')]),
(bold_reg_wf, bold_std_trans_wf, [
('outputnode.itk_bold_to_t1', 'inputnode.itk_bold_to_t1')]),
(bold_bold_trans_wf, bold_std_trans_wf, [
('outputnode.bold_mask', 'inputnode.bold_mask')]),
(bold_std_trans_wf, outputnode, [('outputnode.bold_std', 'bold_std'),
('outputnode.bold_std_ref', 'bold_std_ref'),
('outputnode.bold_mask_std', 'bold_mask_std')]),
])

if freesurfer:
workflow.connect([
(bold_std_trans_wf, func_derivatives_wf, [
('outputnode.bold_aseg_std', 'inputnode.bold_aseg_std'),
('outputnode.bold_aparc_std', 'inputnode.bold_aparc_std'),
]),
(bold_std_trans_wf, outputnode, [
('outputnode.bold_aseg_std', 'bold_aseg_std'),
('outputnode.bold_aparc_std', 'bold_aparc_std')]),
])

if not multiecho:
workflow.connect([
(bold_bold_trans_wf, bold_std_trans_wf, [
('outputnode.bold_mask', 'inputnode.bold_mask')]),
(bold_split, bold_std_trans_wf, [
('out_files', 'inputnode.bold_split')]),
(bold_sdc_wf, bold_std_trans_wf, [
Expand All @@ -671,14 +680,27 @@ def init_func_preproc_wf(bold_file):
])
else:
workflow.connect([
(join_echos, bold_std_trans_wf, [
(('bold_masks', pop_file), 'inputnode.bold_mask')]),
(split_opt_comb, bold_std_trans_wf, [
('out_files', 'inputnode.bold_split')])
('out_files', 'inputnode.bold_split')]),
tsalo marked this conversation as resolved.
Show resolved Hide resolved
])

# Already applied in bold_bold_trans_wf, which inputs to bold_t2s_wf
bold_std_trans_wf.inputs.inputnode.fieldwarp = 'identity'
bold_std_trans_wf.inputs.inputnode.hmc_xforms = 'identity'

if freesurfer:
workflow.connect([
(bold_std_trans_wf, func_derivatives_wf, [
('outputnode.bold_aseg_std', 'inputnode.bold_aseg_std'),
('outputnode.bold_aparc_std', 'inputnode.bold_aparc_std'),
]),
tsalo marked this conversation as resolved.
Show resolved Hide resolved
(bold_std_trans_wf, outputnode, [
('outputnode.bold_aseg_std', 'bold_aseg_std'),
('outputnode.bold_aparc_std', 'bold_aparc_std')]),
])

# func_derivatives_wf internally parametrizes over snapshotted spaces.
workflow.connect([
(bold_std_trans_wf, func_derivatives_wf, [
Expand Down Expand Up @@ -815,15 +837,24 @@ def init_func_preproc_wf(bold_file):
('std2anat_xfm', 'inputnode.std2anat_xfm')]),
(bold_bold_trans_wf if not multiecho else bold_t2s_wf, carpetplot_wf, [
('outputnode.bold', 'inputnode.bold')]),
(bold_bold_trans_wf, carpetplot_wf, [
('outputnode.bold_mask', 'inputnode.bold_mask')]),
(bold_reg_wf, carpetplot_wf, [
('outputnode.itk_t1_to_bold', 'inputnode.t1_bold_xform')]),
])
if not multiecho:
workflow.connect([
(bold_bold_trans_wf, carpetplot_wf, [
('outputnode.bold_mask', 'inputnode.bold_mask')]),
])
else:
workflow.connect([
(join_echos, carpetplot_wf, [
(('bold_masks', pop_file), 'inputnode.bold_mask')]),
])

workflow.connect([
(bold_confounds_wf, carpetplot_wf, [
('outputnode.confounds_file', 'inputnode.confounds_file')])
('outputnode.confounds_file', 'inputnode.confounds_file')
])
])

# REPORTING ############################################################
Expand Down