Skip to content

Commit 49190d2

Browse files
authored
Merge pull request #343 from effigies/fix/debuggability
ENH: Consistently log failures to form fieldmaps
2 parents 177af26 + 208b4cd commit 49190d2

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

sdcflows/utils/wrangler.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ def find_estimators(
324324
for fmap in bare_ids + listed_ids
325325
]
326326
)
327-
except ValueError as err:
327+
except (ValueError, TypeError) as err:
328328
_log_debug_estimator_fail(
329-
logger, b0_id, listed_ids, layout.root, str(err)
329+
logger, b0_id, bare_ids + listed_ids, layout.root, str(err)
330330
)
331331
else:
332332
_log_debug_estimation(logger, e, layout.root)
@@ -363,14 +363,21 @@ def find_estimators(
363363
)
364364
dirs = layout.get_directions(**entities)
365365
if len(dirs) > 1:
366-
e = fm.FieldmapEstimation(
367-
[
368-
fm.FieldmapFile(fmap.path, metadata=fmap.get_metadata())
369-
for fmap in layout.get(**{**entities, **{'direction': dirs}})
370-
]
371-
)
372-
_log_debug_estimation(logger, e, layout.root)
373-
estimators.append(e)
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)
374381

375382
# At this point, only single-PE _epi files WITH ``IntendedFor`` can
376383
# be automatically processed.
@@ -400,21 +407,30 @@ def find_estimators(
400407
for intent in listify(epi_base_md["IntendedFor"]):
401408
target = layout.get_file(str(subject_root / intent))
402409
if target is None:
403-
logger.debug("Single PE target %s not found", target)
410+
logger.debug("Single PE target %s not found", intent)
404411
continue
405412

406413
logger.debug("Found single PE target %s", target.relpath)
407414
# The new estimator is IntendedFor the individual targets,
408415
# even if the EPI file is IntendedFor multiple
409416
estimator_md = epi_base_md.copy()
410417
estimator_md["IntendedFor"] = [intent]
411-
with suppress(ValueError, TypeError, fm.MetadataError):
418+
try:
412419
e = fm.FieldmapEstimation(
413420
[
414421
fm.FieldmapFile(epi_fmap.path, metadata=estimator_md),
415422
fm.FieldmapFile(target.path, metadata=target.get_metadata())
416423
]
417424
)
425+
except (ValueError, TypeError) as err:
426+
_log_debug_estimator_fail(
427+
logger,
428+
"unnamed PEPOLAR",
429+
[epi_fmap, target],
430+
layout.root,
431+
str(err)
432+
)
433+
else:
418434
_log_debug_estimation(logger, e, layout.root)
419435
estimators.append(e)
420436

@@ -490,7 +506,9 @@ def _log_debug_estimation(
490506
"Found %s estimation from %d sources:\n- %s",
491507
estimation.method.name,
492508
len(estimation.sources),
493-
"\n- ".join([str(s.path.relative_to(bids_root)) for s in estimation.sources]),
509+
"\n- ".join(
510+
[str(Path(s.path).relative_to(bids_root)) for s in estimation.sources]
511+
),
494512
)
495513

496514

@@ -506,6 +524,6 @@ def _log_debug_estimator_fail(
506524
"Failed to construct %s estimation from %d sources:\n- %s\nError: %s",
507525
b0_id,
508526
len(files),
509-
"\n- ".join([str(s.path.relative_to(bids_root)) for s in files]),
527+
"\n- ".join([str(Path(s.path).relative_to(bids_root)) for s in files]),
510528
message,
511529
)

0 commit comments

Comments
 (0)