Skip to content

Commit 24b04e3

Browse files
committed
feat: Add debugging output to indicate what files are reused
1 parent 68f2079 commit 24b04e3

File tree

2 files changed

+39
-25
lines changed

2 files changed

+39
-25
lines changed

fmriprep/workflows/base.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ def init_single_subject_wf(subject_id: str):
338338

339339
# allow to run with anat-fast-track on fMRI-only dataset
340340
if 't1w_preproc' in anatomical_cache and not subject_data['t1w']:
341+
workflow.debug(
342+
'No T1w image found; using precomputed T1w image: %s', anatomical_cache['t1w_preproc']
343+
)
341344
workflow.connect([
342345
(bidssrc, bids_info, [(('bold', fix_multi_T1w_source_name), 'in_file')]),
343346
(anat_fit_wf, summary, [('outputnode.t1w_preproc', 't1w')]),
@@ -539,12 +542,14 @@ def init_single_subject_wf(subject_id: str):
539542
from fmriprep.utils.bids import collect_fieldmaps
540543

541544
for deriv_dir in config.execution.derivatives.values():
542-
fmap_cache.update(
543-
collect_fieldmaps(
544-
derivatives_dir=deriv_dir,
545-
entities={'subject': subject_id},
546-
)
545+
fmaps = collect_fieldmaps(
546+
derivatives_dir=deriv_dir,
547+
entities={'subject': subject_id},
547548
)
549+
config.loggers.workflow.debug(
550+
'Detected precomputed fieldmaps in %d for fieldmap IDs: %s', deriv_dir, list(fmaps)
551+
)
552+
fmap_cache.update(fmaps)
548553

549554
all_estimators, estimator_map = map_fieldmap_estimation(
550555
layout=config.execution.layout,
@@ -578,15 +583,17 @@ def init_single_subject_wf(subject_id: str):
578583
f'{len(pared_cache)} estimator(s): {list(pared_cache)}.'
579584
)
580585

581-
fmap_buffers['fmap'].inputs.in1 = [
582-
pared_cache[fmapid]['fieldmap'] for fmapid in pared_cache
583-
]
584-
fmap_buffers['fmap_ref'].inputs.in1 = [
585-
pared_cache[fmapid]['magnitude'] for fmapid in pared_cache
586-
]
587-
fmap_buffers['fmap_coeff'].inputs.in1 = [
588-
pared_cache[fmapid]['coeffs'] for fmapid in pared_cache
589-
]
586+
fieldmaps = [fmap['fieldmap'] for fmap in pared_cache.values()]
587+
refs = [fmap['magnitude'] for fmap in pared_cache.values()]
588+
coeffs = [fmap['coeffs'] for fmap in pared_cache.values()]
589+
config.loggers.workflow.debug('Reusing fieldmaps: %s', fieldmaps)
590+
config.loggers.workflow.debug('Reusing references: %s', refs)
591+
config.loggers.workflow.debug('Reusing coefficients: %s', coeffs)
592+
593+
fmap_buffers['fmap'].inputs.in1 = fieldmaps
594+
fmap_buffers['fmap_ref'].inputs.in1 = refs
595+
fmap_buffers['fmap_coeff'].inputs.in1 = coeffs
596+
590597
# Note that masks are not emitted. The BOLD-fmap transforms cannot be
591598
# computed with precomputed fieldmaps until we either start emitting masks
592599
# or start skull-stripping references on the fly.

fmriprep/workflows/bold/fit.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ def init_bold_fit_wf(
236236
# Boolean used to update workflow self-descriptions
237237
multiecho = len(bold_series) > 1
238238

239-
have_hmcref = 'hmc_boldref' in precomputed
240-
have_coregref = 'coreg_boldref' in precomputed
239+
hmc_boldref = precomputed.get('hmc_boldref')
240+
coreg_boldref = precomputed.get('coreg_boldref')
241241
# Can contain
242242
# 1) boldref2fmap
243243
# 2) boldref2anat
@@ -304,12 +304,19 @@ def init_bold_fit_wf(
304304
niu.IdentityInterface(fields=['boldref', 'boldmask']), name='regref_buffer'
305305
)
306306

307-
# Set default buffer values; can be overridden by workflows
308-
hmcref_buffer.inputs.boldref = precomputed.get('hmc_boldref')
307+
if hmc_boldref:
308+
hmcref_buffer.inputs.boldref = hmc_boldref
309+
config.loggers.workflow.debug('Reusing motion correction reference: %s', hmc_boldref)
310+
if hmc_xforms:
311+
hmc_buffer.inputs.hmc_xforms = hmc_xforms
312+
config.loggers.workflow.debug('Reusing motion correction transforms: %s', hmc_xforms)
313+
if boldref2fmap_xform:
314+
fmapreg_buffer.inputs.boldref2fmap_xfm = boldref2fmap_xform
315+
config.loggers.workflow.debug('Reusing BOLD-to-fieldmap transform: %s', boldref2fmap_xform)
316+
if coreg_boldref:
317+
regref_buffer.inputs.boldref = coreg_boldref
318+
config.loggers.workflow.debug('Reusing coregistration reference: %s', coreg_boldref)
309319
fmapref_buffer.inputs.sbref_files = sbref_files
310-
hmc_buffer.inputs.hmc_xforms = hmc_xforms
311-
fmapreg_buffer.inputs.boldref2fmap_xfm = boldref2fmap_xform
312-
regref_buffer.inputs.boldref = precomputed.get('coreg_boldref')
313320

314321
summary = pe.Node(
315322
FunctionalSummary(
@@ -344,7 +351,7 @@ def init_bold_fit_wf(
344351

345352
func_fit_reports_wf = init_func_fit_reports_wf(
346353
# TODO: Enable sdc report even if we find coregref
347-
sdc_correction=not (have_coregref or fieldmap_id is None),
354+
sdc_correction=not (coreg_boldref or fieldmap_id is None),
348355
freesurfer=config.workflow.run_reconall,
349356
output_dir=config.execution.fmriprep_dir,
350357
)
@@ -384,7 +391,7 @@ def init_bold_fit_wf(
384391
niu.IdentityInterface(fields=['in_file']),
385392
name='hmc_boldref_source_buffer',
386393
)
387-
if not have_hmcref:
394+
if not hmc_boldref:
388395
config.loggers.workflow.info('Stage 1: Adding HMC boldref workflow')
389396
hmc_boldref_wf = init_raw_boldref_wf(
390397
name='hmc_boldref_wf',
@@ -458,7 +465,7 @@ def init_bold_fit_wf(
458465

459466
# Stage 3: Create coregistration reference
460467
# Fieldmap correction only happens during fit if this stage is needed
461-
if not have_coregref:
468+
if not coreg_boldref:
462469
config.loggers.workflow.info('Stage 3: Adding coregistration boldref workflow')
463470

464471
# Select initial boldref, enhance contrast, and generate mask
@@ -600,7 +607,7 @@ def init_bold_fit_wf(
600607
# TODO: Allow precomputed bold masks to be passed
601608
# Also needs consideration for how it interacts above
602609
skullstrip_precomp_ref_wf = init_skullstrip_bold_wf(name='skullstrip_precomp_ref_wf')
603-
skullstrip_precomp_ref_wf.inputs.inputnode.in_file = precomputed['coreg_boldref']
610+
skullstrip_precomp_ref_wf.inputs.inputnode.in_file = coreg_boldref
604611
workflow.connect([
605612
(skullstrip_precomp_ref_wf, regref_buffer, [('outputnode.mask_file', 'boldmask')])
606613
]) # fmt:skip

0 commit comments

Comments
 (0)