Skip to content

Commit 177af26

Browse files
authored
Merge pull request #341 from effigies/fix/log_incomplete
FIX: Log incomplete fieldmaps, rather than erroring
2 parents 188bc87 + 8173e92 commit 177af26

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

sdcflows/utils/wrangler.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from contextlib import suppress
2828
from pathlib import Path
2929
from typing import Optional, Union, List
30-
from bids.layout import BIDSLayout
30+
from bids.layout import BIDSLayout, BIDSFile
3131
from bids.utils import listify
3232

3333
from .. import fieldmaps as fm
@@ -317,12 +317,20 @@ def find_estimators(
317317
B0FieldIdentifier=f'"{b0_id}"', # Double quotes to match JSON, not Python repr
318318
regex_search=True,
319319
)
320-
e = fm.FieldmapEstimation([
321-
fm.FieldmapFile(fmap.path, metadata=fmap.get_metadata())
322-
for fmap in bare_ids + listed_ids
323-
])
324-
_log_debug_estimation(logger, e, layout.root)
325-
estimators.append(e)
320+
try:
321+
e = fm.FieldmapEstimation(
322+
[
323+
fm.FieldmapFile(fmap.path, metadata=fmap.get_metadata())
324+
for fmap in bare_ids + listed_ids
325+
]
326+
)
327+
except ValueError as err:
328+
_log_debug_estimator_fail(
329+
logger, b0_id, listed_ids, layout.root, str(err)
330+
)
331+
else:
332+
_log_debug_estimation(logger, e, layout.root)
333+
estimators.append(e)
326334

327335
# Step 2. If no B0FieldIdentifiers were found, try several heuristics
328336
if not estimators:
@@ -484,3 +492,20 @@ def _log_debug_estimation(
484492
len(estimation.sources),
485493
"\n- ".join([str(s.path.relative_to(bids_root)) for s in estimation.sources]),
486494
)
495+
496+
497+
def _log_debug_estimator_fail(
498+
logger: logging.Logger,
499+
b0_id: str,
500+
files: List[BIDSFile],
501+
bids_root: str,
502+
message: str
503+
) -> None:
504+
"""A helper function to log failures to build an estimator when running with verbosity."""
505+
logger.debug(
506+
"Failed to construct %s estimation from %d sources:\n- %s\nError: %s",
507+
b0_id,
508+
len(files),
509+
"\n- ".join([str(s.path.relative_to(bids_root)) for s in files]),
510+
message,
511+
)

0 commit comments

Comments
 (0)