34
34
from .. import fieldmaps as fm
35
35
36
36
37
+ def _normalize_intent (
38
+ intent : str ,
39
+ layout : BIDSLayout ,
40
+ subject : str
41
+ ) -> str | None :
42
+ """Convert BIDS-URI intent to subject-relative intent
43
+
44
+ SDCFlows currently makes strong assumptions about old-style intents,
45
+ and a change to that needs to be carefully considered and tested.
46
+ """
47
+ if intent .startswith ("bids::" ):
48
+ # bids::sub-<subject>/
49
+ # ^- 10 ^- 11
50
+ return intent [11 + len (subject ):]
51
+ return intent
52
+
53
+
37
54
def _resolve_intent (
38
55
intent : str ,
39
56
layout : BIDSLayout ,
@@ -47,6 +64,18 @@ def _resolve_intent(
47
64
return intent
48
65
49
66
67
+ def _filter_metadata (
68
+ metadata : Dict [str , Any ],
69
+ layout : BIDSLayout ,
70
+ subject : str
71
+ ) -> Dict [str , Any ]:
72
+ intents = metadata .get ("IntendedFor" )
73
+ if intents :
74
+ updated = [_normalize_intent (intent , layout , subject ) for intent in listify (intents )]
75
+ return {** metadata , "IntendedFor" : updated }
76
+ return metadata
77
+
78
+
50
79
def find_estimators (
51
80
* ,
52
81
layout : BIDSLayout ,
@@ -377,7 +406,10 @@ def find_estimators(
377
406
):
378
407
try :
379
408
e = fm .FieldmapEstimation (
380
- fm .FieldmapFile (fmap .path , metadata = fmap .get_metadata ())
409
+ fm .FieldmapFile (
410
+ fmap .path ,
411
+ metadata = _filter_metadata (fmap .get_metadata (), layout , subject ),
412
+ )
381
413
)
382
414
except (ValueError , TypeError ) as err :
383
415
_log_debug_estimator_fail (
@@ -405,7 +437,10 @@ def find_estimators(
405
437
if len (dirs ) > 1 :
406
438
by_intent = {}
407
439
for fmap in layout .get (** {** entities , ** {'direction' : dirs }}):
408
- fmapfile = fm .FieldmapFile (fmap .path , metadata = fmap .get_metadata ())
440
+ fmapfile = fm .FieldmapFile (
441
+ fmap .path ,
442
+ metadata = _filter_metadata (fmap .get_metadata (), layout , subject ),
443
+ )
409
444
by_intent .setdefault (
410
445
tuple (fmapfile .metadata .get ('IntendedFor' , ())), []
411
446
).append (fmapfile )
0 commit comments