Skip to content

Commit

Permalink
FIX: Correctly generate resampling reference, pass to downstream resa…
Browse files Browse the repository at this point in the history
…mplers
  • Loading branch information
effigies committed Nov 18, 2023
1 parent b323eb0 commit 4647b6e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
16 changes: 15 additions & 1 deletion fmriprep/workflows/bold/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def init_bold_volumetric_resample_wf(
-------
bold_file
The ``bold_file`` input, resampled to ``target_ref_file`` space.
resampling_reference
An empty reference image with the correct affine and header for resampling
further images into the BOLD series' space.
"""
workflow = pe.Workflow(name=name)
Expand All @@ -102,12 +105,17 @@ def init_bold_volumetric_resample_wf(
"boldref2anat_xfm",
# Template
"anat2std_xfm",
# Entity for selecting target resolution
"resolution",
],
),
name='inputnode',
)

outputnode = pe.Node(niu.IdentityInterface(fields=["bold_file"]), name='outputnode')
outputnode = pe.Node(

Check warning on line 115 in fmriprep/workflows/bold/apply.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/workflows/bold/apply.py#L115

Added line #L115 was not covered by tests
niu.IdentityInterface(fields=["bold_file", "resampling_reference"]),
name='outputnode',
)

gen_ref = pe.Node(GenerateSamplingReference(), name='gen_ref', mem_gb=0.3)

Expand All @@ -120,6 +128,7 @@ def init_bold_volumetric_resample_wf(
('bold_ref_file', 'moving_image'),
('target_ref_file', 'fixed_image'),
('target_mask', 'fov_mask'),
(('resolution', _is_native), 'keep_native'),
]),
(inputnode, boldref2target, [
('boldref2anat_xfm', 'in1'),
Expand All @@ -130,6 +139,7 @@ def init_bold_volumetric_resample_wf(
(gen_ref, resample, [('out_file', 'ref_file')]),
(boldref2target, bold2target, [('out', 'in2')]),
(bold2target, resample, [('out', 'transforms')]),
(gen_ref, outputnode, [('out_file', 'resampling_reference')]),
(resample, outputnode, [('out_file', 'bold_file')]),
]) # fmt:skip

Expand Down Expand Up @@ -190,3 +200,7 @@ def _gen_inverses(inlist: list) -> list[bool]:
if not inlist:
return [True]
return [True] + [False] * len(listify(inlist))


def _is_native(value):
return value == "native"

Check warning on line 206 in fmriprep/workflows/bold/apply.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/workflows/bold/apply.py#L206

Added line #L206 was not covered by tests
15 changes: 9 additions & 6 deletions fmriprep/workflows/bold/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,16 +426,16 @@ def init_bold_wf(
ds_bold_t1_wf.inputs.inputnode.space = 'T1w'

workflow.connect([
(inputnode, ds_bold_t1_wf, [
('t1w_preproc', 'inputnode.ref_file'),
]),
(bold_fit_wf, ds_bold_t1_wf, [
('outputnode.bold_mask', 'inputnode.bold_mask'),
('outputnode.coreg_boldref', 'inputnode.bold_ref'),
('outputnode.boldref2anat_xfm', 'inputnode.boldref2anat_xfm'),
]),
(bold_native_wf, ds_bold_t1_wf, [('outputnode.t2star_map', 'inputnode.t2star')]),
(bold_anat_wf, ds_bold_t1_wf, [('outputnode.bold_file', 'inputnode.bold')]),
(bold_anat_wf, ds_bold_t1_wf, [
('outputnode.bold_file', 'inputnode.bold'),
('outputnode.resampling_reference', 'inputnode.ref_file'),
]),
]) # fmt:skip

if spaces.cached.get_spaces(nonstandard=False, dim=(3,)):
Expand All @@ -462,6 +462,7 @@ def init_bold_wf(
("std_t1w", "inputnode.target_ref_file"),
("std_mask", "inputnode.target_mask"),
("anat2std_xfm", "inputnode.anat2std_xfm"),
('std_resolution', 'inputnode.resolution'),
("fmap_ref", "inputnode.fmap_ref"),
("fmap_coeff", "inputnode.fmap_coeff"),
("fmap_id", "inputnode.fmap_id"),
Expand All @@ -476,7 +477,6 @@ def init_bold_wf(
("outputnode.motion_xfm", "inputnode.motion_xfm"),
]),
(inputnode, ds_bold_std_wf, [
('std_t1w', 'inputnode.ref_file'),
('anat2std_xfm', 'inputnode.anat2std_xfm'),
('std_space', 'inputnode.space'),
('std_resolution', 'inputnode.resolution'),
Expand All @@ -488,7 +488,10 @@ def init_bold_wf(
('outputnode.boldref2anat_xfm', 'inputnode.boldref2anat_xfm'),
]),
(bold_native_wf, ds_bold_std_wf, [('outputnode.t2star_map', 'inputnode.t2star')]),
(bold_std_wf, ds_bold_std_wf, [('outputnode.bold_file', 'inputnode.bold')]),
(bold_std_wf, ds_bold_std_wf, [
('outputnode.bold_file', 'inputnode.bold'),
('outputnode.resampling_reference', 'inputnode.ref_file'),
]),
]) # fmt:skip

if config.workflow.run_reconall and freesurfer_spaces:
Expand Down

0 comments on commit 4647b6e

Please sign in to comment.