Skip to content

Commit 814767b

Browse files
committed
RF: Associate single-direction EPI fieldmaps with sbrefs if possible
1 parent e26665b commit 814767b

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

sdcflows/utils/wrangler.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ def find_estimators(
129129
[FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PHASEDIFF: 3>,
130130
bids_id='auto_00006'),
131131
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PEPOLAR: 2>,
132-
bids_id='auto_00007')]
132+
bids_id='auto_00007'),
133+
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PEPOLAR: 2>,
134+
bids_id='auto_00008')]
133135
134136
Finally, *SDCFlows*' "*dataset A*" and "*dataset B*" contain BIDS structures
135137
with zero-byte NIfTI files and some corresponding metadata:
@@ -399,23 +401,43 @@ def find_estimators(
399401
logger.debug("Found single PE fieldmap %s", epi_fmap.relpath)
400402
epi_base_md = epi_fmap.get_metadata()
401403

402-
# There are two possible interpretations of an IntendedFor list:
403-
# 1) The fieldmap and each intended target are combined separately
404-
# 2) The fieldmap and all intended targets are combined at once
405-
#
406-
# (1) has been the historical interpretation of NiPreps,
407-
# so construct a separate estimator for each target.
404+
# Find existing IntendedFor targets and warn if missing
405+
all_targets = []
408406
for intent in listify(epi_base_md["IntendedFor"]):
409407
target = layout.get_file(str(subject_root / intent))
410408
if target is None:
411409
logger.debug("Single PE target %s not found", intent)
412410
continue
411+
all_targets.append(target)
412+
413+
# If sbrefs are targets, then the goal is generally to estimate with epi+sbref
414+
# and correct bold/dwi
415+
sbrefs = [
416+
target for target in all_targets if target.entities["suffix"] == "sbref"
417+
]
418+
if sbrefs:
419+
targets = sbrefs
420+
intent_map = []
421+
for sbref in sbrefs:
422+
ents = sbref.entities.copy()
423+
ents["suffix"] = ["bold", "dwi"]
424+
intent_map.append(
425+
[
426+
target
427+
for target in layout.get(**ents)
428+
if target in all_targets
429+
]
430+
)
431+
else:
432+
targets = all_targets
433+
intent_map = [[target] for target in all_targets]
413434

435+
for target, intent in zip(targets, intent_map):
414436
logger.debug("Found single PE target %s", target.relpath)
415437
# The new estimator is IntendedFor the individual targets,
416438
# even if the EPI file is IntendedFor multiple
417439
estimator_md = epi_base_md.copy()
418-
estimator_md["IntendedFor"] = [intent]
440+
estimator_md["IntendedFor"] = intent
419441
try:
420442
e = fm.FieldmapEstimation(
421443
[

0 commit comments

Comments
 (0)