Skip to content

Commit 4a7e415

Browse files
committed
ENH: Take in bids root to build reference path, add warnings
1 parent 2ba3d18 commit 4a7e415

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

nibabies/utils/bids.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def __getattribute__(self, attr):
4747
except AttributeError:
4848
return None
4949

50-
def __init__(self, spec: dict | Path | str | None = None, **args):
50+
def __init__(self, bids_root: Path | str, spec: dict | Path | str | None = None, **args):
51+
self.bids_root = Path(bids_root)
5152
self.spec = _spec
5253
if spec is not None:
5354
if not isinstance(spec, dict):
@@ -81,23 +82,24 @@ def populate(
8182
**query,
8283
)
8384
if not items or len(items) > 1:
85+
warnings.warn(f"Could not find {name}")
8486
continue
8587
item = items[0]
8688

8789
# Skip if derivative does not have valid metadata
8890
metadata = item.get_metadata()
8991
if not metadata or not (reference := metadata.get('SpatialReference')):
90-
# raise warning
92+
warnings.warn(f"No metadata found for {item}")
9193
continue
9294
if isinstance(reference, list):
9395
if len(reference) > 1:
94-
# raise warning
96+
warnings.warn(f"Multiple reference found: {reference}")
9597
continue
9698
reference = reference[0]
9799

98-
reference = (Path(deriv_path) / reference).absolute()
100+
reference = self.bids_root / reference
99101
if not self.validate(item.path, str(reference)):
100-
# raise warning
102+
warnings.warn(f"Validation failed between: {item.path} and {reference}")
101103
continue
102104

103105
setattr(self, name, Path(item.path))

nibabies/workflows/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
.. autofunction:: init_single_subject_wf
4040
4141
"""
42+
from __future__ import annotations
4243

4344
import os
4445
import sys
@@ -227,7 +228,7 @@ def init_single_subject_wf(
227228
subject_data["t2w"] = []
228229

229230
anat_only = config.workflow.anat_only
230-
derivatives = Derivatives()
231+
derivatives = Derivatives(bids_root=config.execution.layout.root)
231232
anat_modality = "t1w" if subject_data["t1w"] else "t2w"
232233
# Make sure we always go through these two checks
233234
if not anat_only and not subject_data["bold"]:
@@ -241,13 +242,13 @@ def init_single_subject_wf(
241242

242243
if config.execution.derivatives:
243244
for deriv_path in config.execution.derivatives:
244-
config.loggers.workflow.debug("Searching for derivatives in %s", deriv_path)
245+
config.loggers.workflow.info("Searching for derivatives in %s", deriv_path)
245246
derivatives.populate(
246247
deriv_path,
247248
subject_id,
248249
session_id=session_id,
249250
)
250-
config.loggers.workflow.info(f"Found precomputed derivatives: {derivatives}")
251+
config.loggers.workflow.info("Found precomputed derivatives %s", derivatives)
251252

252253
workflow = Workflow(name=name)
253254
workflow.__desc__ = """

0 commit comments

Comments
 (0)