Skip to content

Commit 68f2079

Browse files
committed
rf: Rework pared_cache/fmap_estimator logic
1 parent a47b5a0 commit 68f2079

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

fmriprep/workflows/base.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ def init_single_subject_wf(subject_id: str):
546546
)
547547
)
548548

549-
fmap_estimators, estimator_map = map_fieldmap_estimation(
549+
all_estimators, estimator_map = map_fieldmap_estimation(
550550
layout=config.execution.layout,
551551
subject_id=subject_id,
552552
bold_data=bold_runs,
@@ -561,15 +561,16 @@ def init_single_subject_wf(subject_id: str):
561561
for field in ['fmap', 'fmap_ref', 'fmap_coeff', 'fmap_mask', 'fmap_id', 'sdc_method']
562562
}
563563

564-
missing_estimators = []
565-
if fmap_estimators:
566-
# Map fmapid entity to internal bids_id
567-
fmapid_map = {re.sub(r'[^a-zA-Z0-9]', '', e.bids_id): e.bids_id for e in fmap_estimators}
568-
pared_cache = {
569-
fmapid_map[fmapid]: fmap_cache[fmapid] for fmapid in fmap_cache if fmapid in fmapid_map
570-
}
571-
572-
missing_estimators = [e for e in fmap_estimators if e.bids_id not in pared_cache]
564+
fmap_estimators = []
565+
if all_estimators:
566+
# Find precomputed fieldmaps that apply to this workflow
567+
pared_cache = {}
568+
for est in all_estimators:
569+
fmapid = re.sub(r'[^a-zA-Z0-9]', '', est.bids_id)
570+
if fmapid in fmap_cache:
571+
pared_cache[fmapid] = fmap_cache[fmapid]
572+
else:
573+
fmap_estimators.append(est)
573574

574575
if pared_cache:
575576
config.loggers.workflow.info(
@@ -595,11 +596,12 @@ def init_single_subject_wf(subject_id: str):
595596
fmap_buffers['fmap_id'].inputs.in1 = list(pared_cache)
596597
fmap_buffers['sdc_method'].inputs.in1 = ['precomputed'] * len(pared_cache)
597598

598-
if missing_estimators:
599+
# Estimators without precomputed fieldmaps
600+
if fmap_estimators:
599601
config.loggers.workflow.info(
600602
'B0 field inhomogeneity map will be estimated with the following '
601-
f'{len(missing_estimators)} estimator(s): '
602-
f'{[e.method for e in missing_estimators]}.'
603+
f'{len(fmap_estimators)} estimator(s): '
604+
f'{[e.method for e in fmap_estimators]}.'
603605
)
604606

605607
from sdcflows import fieldmaps as fm

0 commit comments

Comments
 (0)