Skip to content

Commit 4a2ea31

Browse files
committed
ENH: Use single-band reference images when available
1 parent 5701fa5 commit 4a2ea31

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

fmriprep/workflows/bold/base.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,26 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer,
257257
'magnitude2': 'sub-03/ses-2/fmap/sub-03_ses-2_run-1_magnitude2.nii.gz',
258258
}]
259259
run_stc = True
260+
sbref_file = None
260261
multiecho = False
261262
else:
263+
# Find associated sbref, if possible
264+
entities = layout.parse_file_entities(ref_file)
265+
entities['type'] = 'sbref'
266+
files = layout.get(**entities)
267+
refbase = os.path.basename(ref_file)
268+
if files:
269+
sbref_file = files[0].filename
270+
sbbase = os.path.basename(sbref_file)
271+
if len(files) > 1:
272+
LOGGER.warning(
273+
"Multiple single-band reference files found for {}; using "
274+
"{}".format(refbase, sbbase))
275+
else:
276+
LOGGER.log(25, "Using single-band reference file {}".format(sbbase)
277+
else:
278+
LOGGER.log(25, "No single-band-reference found for {}".format(refbase))
279+
262280
metadata = layout.get_metadata(ref_file)
263281

264282
# Find fieldmaps. Options: (phase1|phase2|phasediff|epi|fieldmap|syn)
@@ -312,13 +330,15 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer,
312330
"""
313331

314332
inputnode = pe.Node(niu.IdentityInterface(
315-
fields=['bold_file', 'subjects_dir', 'subject_id',
333+
fields=['bold_file', 'sbref_file', 'subjects_dir', 'subject_id',
316334
't1_preproc', 't1_brain', 't1_mask', 't1_seg', 't1_tpms',
317335
't1_aseg', 't1_aparc',
318336
't1_2_mni_forward_transform', 't1_2_mni_reverse_transform',
319337
't1_2_fsnative_forward_transform', 't1_2_fsnative_reverse_transform']),
320338
name='inputnode')
321339
inputnode.inputs.bold_file = bold_file
340+
if sbref_file is not None:
341+
inputnode.inputs.sbref_file = sbref_file
322342

323343
outputnode = pe.Node(niu.IdentityInterface(
324344
fields=['bold_t1', 'bold_mask_t1', 'bold_aseg_t1', 'bold_aparc_t1', 'cifti_variant',
@@ -441,7 +461,8 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer,
441461
# MAIN WORKFLOW STRUCTURE #######################################################
442462
workflow.connect([
443463
# Generate early reference
444-
(inputnode, bold_reference_wf, [('bold_file', 'inputnode.bold_file')]),
464+
(inputnode, bold_reference_wf, [('bold_file', 'inputnode.bold_file'),
465+
('sbref_file', 'inputnode.sbref_file')]),
445466
# BOLD buffer has slice-time corrected if it was run, original otherwise
446467
(boldbuffer, bold_split, [('bold_file', 'in_file')]),
447468
# HMC

fmriprep/workflows/bold/util.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def init_bold_reference_wf(omp_nthreads, bold_file=None, name='bold_reference_wf
8787
First, a reference volume and its skull-stripped version were generated
8888
using a custom methodology of *fMRIPrep*.
8989
"""
90-
inputnode = pe.Node(niu.IdentityInterface(fields=['bold_file']), name='inputnode')
90+
inputnode = pe.Node(niu.IdentityInterface(fields=['bold_file', 'sbref_file']), name='inputnode')
9191
outputnode = pe.Node(
9292
niu.IdentityInterface(fields=['bold_file', 'raw_ref_image', 'skip_vols', 'ref_image',
9393
'ref_image_brain', 'bold_mask', 'validation_report',
@@ -102,16 +102,20 @@ def init_bold_reference_wf(omp_nthreads, bold_file=None, name='bold_reference_wf
102102

103103
gen_ref = pe.Node(EstimateReferenceImage(), name="gen_ref",
104104
mem_gb=1) # OE: 128x128x128x50 * 64 / 8 ~ 900MB.
105+
# Re-run validation; no effect if no sbref; otherwise apply same validation to sbref as bold
106+
validate_ref = pe.Node(ValidateImage(), name='validate_ref', mem_gb=DEFAULT_MEMORY_MIN_GB)
105107
enhance_and_skullstrip_bold_wf = init_enhance_and_skullstrip_bold_wf(omp_nthreads=omp_nthreads)
106108

107109
workflow.connect([
108110
(inputnode, validate, [('bold_file', 'in_file')]),
111+
(inputnode, gen_ref, [('sbref_file', 'sbref_file')]),
109112
(validate, gen_ref, [('out_file', 'in_file')]),
110-
(gen_ref, enhance_and_skullstrip_bold_wf, [('ref_image', 'inputnode.in_file')]),
113+
(gen_ref, validate_ref, [('ref_image', 'in_file')]),
114+
(validate_ref, enhance_and_skullstrip_bold_wf, [('out_file', 'inputnode.in_file')]),
111115
(validate, outputnode, [('out_file', 'bold_file'),
112116
('out_report', 'validation_report')]),
113-
(gen_ref, outputnode, [('ref_image', 'raw_ref_image'),
114-
('n_volumes_to_discard', 'skip_vols')]),
117+
(gen_ref, outputnode, [('n_volumes_to_discard', 'skip_vols')]),
118+
(validate_ref, outputnode, [('ref_image', 'raw_ref_image')]),
115119
(enhance_and_skullstrip_bold_wf, outputnode, [
116120
('outputnode.bias_corrected_file', 'ref_image'),
117121
('outputnode.mask_file', 'bold_mask'),

0 commit comments

Comments
 (0)