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 4 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
90 changes: 62 additions & 28 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 @@ -400,10 +400,11 @@ 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')
# join_echos2 = join_echos.clone(name='join_echos2')

# create optimal combination, adaptive T2* map
bold_t2s_wf = init_bold_t2s_wf(echo_times=tes,
Expand Down Expand Up @@ -482,9 +483,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 @@ -509,6 +507,9 @@ def init_func_preproc_wf(bold_file):
('outputnode.bold', 'inputnode.bold')]),
(bold_split, bold_t1_trans_wf, [
('out_files', 'inputnode.bold_split')]),
(bold_bold_trans_wf, bold_confounds_wf, [
('outputnode.bold_mask', 'inputnode.bold_mask'),
]),
])
else: # for meepi, create and use optimal combination
workflow.connect([
Expand All @@ -521,6 +522,11 @@ def init_func_preproc_wf(bold_file):
('outputnode.bold', 'inputnode.bold')]),
(bold_t2s_wf, bold_t1_trans_wf, [
('outputnode.bold', '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')
])
])

if fmaps:
Expand Down Expand Up @@ -596,20 +602,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 @@ -634,39 +658,40 @@ def init_func_preproc_wf(bold_file):
('outputnode.xforms', 'inputnode.hmc_xforms')]),
(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_sdc_wf, bold_std_trans_wf, [
('outputnode.out_warp', 'inputnode.fieldwarp')]),
(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')])
('out_files', 'inputnode.bold_split')]),
])
else:
split_opt_comb = bold_split.clone(name='split_opt_comb')
workflow.connect([
(join_echos, bold_std_trans_wf, [
(('bold_masks', pop_file), 'inputnode.bold_mask')]),
(bold_t2s_wf, split_opt_comb, [
('outputnode.bold', 'in_file')]),
(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
])

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.
Expand Down Expand Up @@ -806,15 +831,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