Skip to content

Commit 70b716c

Browse files
committed
feat: Discover pre-computed fieldmaps
1 parent 31c772d commit 70b716c

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

fmriprep/utils/bids.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,31 @@ def collect_derivatives(
9595
return derivs_cache
9696

9797

98+
def collect_fieldmaps(
99+
derivatives_dir: Path,
100+
entities: dict,
101+
spec: dict | None = None,
102+
):
103+
"""Gather existing derivatives and compose a cache."""
104+
if spec is None:
105+
spec = json.loads(load_data.readable('fmap_spec.json').read_text())['queries']
106+
107+
fmap_cache = defaultdict(dict, {})
108+
layout = _get_layout(derivatives_dir)
109+
110+
fmapids = layout.get_fmapids(**entities)
111+
112+
for fmapid in fmapids:
113+
for k, q in spec['fieldmaps'].items():
114+
query = {**entities, **q}
115+
item = layout.get(return_type='filename', fmapid=fmapid, **query)
116+
if not item:
117+
continue
118+
fmap_cache[fmapid][k] = item[0] if len(item) == 1 else item
119+
120+
return fmap_cache
121+
122+
98123
def write_bidsignore(deriv_dir):
99124
bids_ignore = (
100125
'*.html',

fmriprep/workflows/base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,18 @@ def init_single_subject_wf(subject_id: str):
533533
if config.workflow.anat_only:
534534
return clean_datasinks(workflow)
535535

536+
fmap_cache = {}
537+
if config.execution.derivatives:
538+
from fmriprep.utils.bids import collect_fieldmaps
539+
540+
for deriv_dir in config.execution.derivatives.values():
541+
fmap_cache.update(
542+
collect_fieldmaps(
543+
derivatives_dir=deriv_dir,
544+
entities={'subject': subject_id},
545+
)
546+
)
547+
536548
fmap_estimators, estimator_map = map_fieldmap_estimation(
537549
layout=config.execution.layout,
538550
subject_id=subject_id,

0 commit comments

Comments
 (0)