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