3434from .. import fieldmaps as fm
3535
3636
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+
3754def _resolve_intent (
3855 intent : str ,
3956 layout : BIDSLayout ,
@@ -47,6 +64,18 @@ def _resolve_intent(
4764 return intent
4865
4966
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+
5079def find_estimators (
5180 * ,
5281 layout : BIDSLayout ,
@@ -377,7 +406,10 @@ def find_estimators(
377406 ):
378407 try :
379408 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+ )
381413 )
382414 except (ValueError , TypeError ) as err :
383415 _log_debug_estimator_fail (
@@ -405,7 +437,10 @@ def find_estimators(
405437 if len (dirs ) > 1 :
406438 by_intent = {}
407439 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+ )
409444 by_intent .setdefault (
410445 tuple (fmapfile .metadata .get ('IntendedFor' , ())), []
411446 ).append (fmapfile )
0 commit comments