@@ -129,7 +129,9 @@ def find_estimators(
129
129
[FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PHASEDIFF: 3>,
130
130
bids_id='auto_00006'),
131
131
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PEPOLAR: 2>,
132
- bids_id='auto_00007')]
132
+ bids_id='auto_00007'),
133
+ FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PEPOLAR: 2>,
134
+ bids_id='auto_00008')]
133
135
134
136
Finally, *SDCFlows*' "*dataset A*" and "*dataset B*" contain BIDS structures
135
137
with zero-byte NIfTI files and some corresponding metadata:
@@ -363,21 +365,22 @@ def find_estimators(
363
365
)
364
366
dirs = layout .get_directions (** entities )
365
367
if len (dirs ) > 1 :
366
- fieldmaps = layout .get (** {** entities , ** {"direction" : dirs }})
367
- try :
368
- e = fm .FieldmapEstimation (
369
- [
370
- fm .FieldmapFile (fmap .path , metadata = fmap .get_metadata ())
371
- for fmap in fieldmaps
372
- ]
373
- )
374
- except ValueError as err :
375
- _log_debug_estimator_fail (
376
- logger , "unnamed PEPOLAR" , fieldmaps , layout .root , str (err )
377
- )
378
- else :
379
- _log_debug_estimation (logger , e , layout .root )
380
- estimators .append (e )
368
+ by_intent = {}
369
+ for fmap in layout .get (** {** entities , ** {'direction' : dirs }}):
370
+ fmapfile = fm .FieldmapFile (fmap .path , metadata = fmap .get_metadata ())
371
+ by_intent .setdefault (
372
+ tuple (fmapfile .metadata .get ('IntendedFor' , ())), []
373
+ ).append (fmapfile )
374
+ for collection in by_intent .values ():
375
+ try :
376
+ e = fm .FieldmapEstimation (collection )
377
+ except (ValueError , TypeError ) as err :
378
+ _log_debug_estimator_fail (
379
+ logger , "unnamed PEPOLAR" , collection , layout .root , str (err )
380
+ )
381
+ else :
382
+ _log_debug_estimation (logger , e , layout .root )
383
+ estimators .append (e )
381
384
382
385
# At this point, only single-PE _epi files WITH ``IntendedFor`` can
383
386
# be automatically processed.
@@ -398,23 +401,43 @@ def find_estimators(
398
401
logger .debug ("Found single PE fieldmap %s" , epi_fmap .relpath )
399
402
epi_base_md = epi_fmap .get_metadata ()
400
403
401
- # There are two possible interpretations of an IntendedFor list:
402
- # 1) The fieldmap and each intended target are combined separately
403
- # 2) The fieldmap and all intended targets are combined at once
404
- #
405
- # (1) has been the historical interpretation of NiPreps,
406
- # so construct a separate estimator for each target.
404
+ # Find existing IntendedFor targets and warn if missing
405
+ all_targets = []
407
406
for intent in listify (epi_base_md ["IntendedFor" ]):
408
407
target = layout .get_file (str (subject_root / intent ))
409
408
if target is None :
410
409
logger .debug ("Single PE target %s not found" , intent )
411
410
continue
411
+ all_targets .append (target )
412
+
413
+ # If sbrefs are targets, then the goal is generally to estimate with epi+sbref
414
+ # and correct bold/dwi
415
+ sbrefs = [
416
+ target for target in all_targets if target .entities ["suffix" ] == "sbref"
417
+ ]
418
+ if sbrefs :
419
+ targets = sbrefs
420
+ intent_map = []
421
+ for sbref in sbrefs :
422
+ ents = sbref .entities .copy ()
423
+ ents ["suffix" ] = ["bold" , "dwi" ]
424
+ intent_map .append (
425
+ [
426
+ target
427
+ for target in layout .get (** ents )
428
+ if target in all_targets
429
+ ]
430
+ )
431
+ else :
432
+ targets = all_targets
433
+ intent_map = [[target ] for target in all_targets ]
412
434
435
+ for target , intent in zip (targets , intent_map ):
413
436
logger .debug ("Found single PE target %s" , target .relpath )
414
437
# The new estimator is IntendedFor the individual targets,
415
438
# even if the EPI file is IntendedFor multiple
416
439
estimator_md = epi_base_md .copy ()
417
- estimator_md ["IntendedFor" ] = [ intent ]
440
+ estimator_md ["IntendedFor" ] = intent
418
441
try :
419
442
e = fm .FieldmapEstimation (
420
443
[
0 commit comments