42
42
43
43
import os
44
44
import sys
45
+ import typing as ty
45
46
from copy import deepcopy
46
- from typing import Optional
47
47
48
48
from nipype .interfaces import utility as niu
49
49
from nipype .pipeline import engine as pe
55
55
from nibabies .utils .bids import parse_bids_for_age_months
56
56
from nibabies .workflows .bold import init_func_preproc_wf
57
57
58
+ if ty .TYPE_CHECKING :
59
+ from niworkflows .utils .spaces import SpatialReferences
60
+
58
61
59
62
def init_nibabies_wf (subworkflows_list ):
60
63
"""
@@ -155,9 +158,9 @@ def init_nibabies_wf(subworkflows_list):
155
158
156
159
def init_single_subject_wf (
157
160
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 ,
161
164
):
162
165
"""
163
166
Organize the preprocessing pipeline for a single subject, at a single session.
@@ -200,6 +203,7 @@ def init_single_subject_wf(
200
203
from niworkflows .utils .bids import collect_data
201
204
from niworkflows .utils .spaces import Reference
202
205
206
+ from ..utils .bids import Derivatives
203
207
from ..utils .misc import fix_multi_source_name
204
208
from .anatomical import init_infant_anat_wf
205
209
@@ -223,7 +227,7 @@ def init_single_subject_wf(
223
227
subject_data ["t2w" ] = []
224
228
225
229
anat_only = config .workflow .anat_only
226
- derivatives = config . execution . derivatives or {}
230
+ derivatives = Derivatives ()
227
231
anat_modality = "t1w" if subject_data ["t1w" ] else "t2w"
228
232
# Make sure we always go through these two checks
229
233
if not anat_only and not subject_data ["bold" ]:
@@ -235,15 +239,14 @@ def init_single_subject_wf(
235
239
)
236
240
)
237
241
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
+ )
247
250
config .loggers .workflow .info (f"Found precomputed derivatives: { derivatives } " )
248
251
249
252
workflow = Workflow (name = name )
@@ -348,7 +351,7 @@ def init_single_subject_wf(
348
351
t1w = subject_data ["t1w" ],
349
352
t2w = subject_data ["t2w" ],
350
353
bids_root = config .execution .bids_dir ,
351
- existing_derivatives = derivatives ,
354
+ derivatives = derivatives ,
352
355
freesurfer = config .workflow .run_reconall ,
353
356
hires = config .workflow .hires ,
354
357
longitudinal = config .workflow .longitudinal ,
@@ -558,7 +561,7 @@ def _prefix(subid):
558
561
return subid if subid .startswith ("sub-" ) else f"sub-{ subid } "
559
562
560
563
561
- def init_workflow_spaces (execution_spaces , age_months ):
564
+ def init_workflow_spaces (execution_spaces : SpatialReferences , age_months : int ):
562
565
"""
563
566
Create output spaces at a per-subworkflow level.
564
567
0 commit comments