File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,31 @@ def collect_derivatives(
95
95
return derivs_cache
96
96
97
97
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
+
98
123
def write_bidsignore (deriv_dir ):
99
124
bids_ignore = (
100
125
'*.html' ,
Original file line number Diff line number Diff line change @@ -533,6 +533,18 @@ def init_single_subject_wf(subject_id: str):
533
533
if config .workflow .anat_only :
534
534
return clean_datasinks (workflow )
535
535
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
+
536
548
fmap_estimators , estimator_map = map_fieldmap_estimation (
537
549
layout = config .execution .layout ,
538
550
subject_id = subject_id ,
You can’t perform that action at this time.
0 commit comments