Skip to content

Commit 44edcb9

Browse files
committed
ENH: Use dedicated Derivatives class
1 parent 9fc9575 commit 44edcb9

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

nibabies/workflows/base.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242

4343
import os
4444
import sys
45+
import typing as ty
4546
from copy import deepcopy
46-
from typing import Optional
4747

4848
from nipype.interfaces import utility as niu
4949
from nipype.pipeline import engine as pe
@@ -55,6 +55,9 @@
5555
from nibabies.utils.bids import parse_bids_for_age_months
5656
from nibabies.workflows.bold import init_func_preproc_wf
5757

58+
if ty.TYPE_CHECKING:
59+
from niworkflows.utils.spaces import SpatialReferences
60+
5861

5962
def init_nibabies_wf(subworkflows_list):
6063
"""
@@ -155,9 +158,9 @@ def init_nibabies_wf(subworkflows_list):
155158

156159
def init_single_subject_wf(
157160
subject_id: str,
158-
session_id: Optional[str] = None,
159-
age: Optional[int] = None,
160-
spaces=None,
161+
session_id: str | None = None,
162+
age: int | None = None,
163+
spaces: SpatialReferences | None = None,
161164
):
162165
"""
163166
Organize the preprocessing pipeline for a single subject, at a single session.
@@ -200,6 +203,7 @@ def init_single_subject_wf(
200203
from niworkflows.utils.bids import collect_data
201204
from niworkflows.utils.spaces import Reference
202205

206+
from ..utils.bids import Derivatives
203207
from ..utils.misc import fix_multi_source_name
204208
from .anatomical import init_infant_anat_wf
205209

@@ -223,7 +227,7 @@ def init_single_subject_wf(
223227
subject_data["t2w"] = []
224228

225229
anat_only = config.workflow.anat_only
226-
derivatives = config.execution.derivatives or {}
230+
derivatives = Derivatives()
227231
anat_modality = "t1w" if subject_data["t1w"] else "t2w"
228232
# Make sure we always go through these two checks
229233
if not anat_only and not subject_data["bold"]:
@@ -235,15 +239,14 @@ def init_single_subject_wf(
235239
)
236240
)
237241

238-
if derivatives:
239-
from ..utils.bids import collect_precomputed_derivatives
240-
241-
derivatives = collect_precomputed_derivatives(
242-
config.execution.layout,
243-
subject_id,
244-
derivatives_filters=config.execution.derivatives_filters,
245-
# session_id=None, # TODO: Ensure session is visible at workflow level
246-
)
242+
if config.execution.derivatives:
243+
for deriv_path in config.execution.derivatives:
244+
config.loggers.workflow.debug("Searching for derivatives in %s", deriv_path)
245+
derivatives.populate(
246+
deriv_path,
247+
subject_id,
248+
session_id=session_id,
249+
)
247250
config.loggers.workflow.info(f"Found precomputed derivatives: {derivatives}")
248251

249252
workflow = Workflow(name=name)
@@ -348,7 +351,7 @@ def init_single_subject_wf(
348351
t1w=subject_data["t1w"],
349352
t2w=subject_data["t2w"],
350353
bids_root=config.execution.bids_dir,
351-
existing_derivatives=derivatives,
354+
derivatives=derivatives,
352355
freesurfer=config.workflow.run_reconall,
353356
hires=config.workflow.hires,
354357
longitudinal=config.workflow.longitudinal,
@@ -558,7 +561,7 @@ def _prefix(subid):
558561
return subid if subid.startswith("sub-") else f"sub-{subid}"
559562

560563

561-
def init_workflow_spaces(execution_spaces, age_months):
564+
def init_workflow_spaces(execution_spaces: SpatialReferences, age_months: int):
562565
"""
563566
Create output spaces at a per-subworkflow level.
564567

0 commit comments

Comments
 (0)