@@ -21,13 +21,13 @@ class TemplateInputs(NamedTuple):
2121 sub: Subject label.
2222 sessions: Per-input session labels (parallel to ``files``).
2323 files: Per-session preprocessed T1w brain volumes.
24- bold_ref: First BOLD volume for grid reference .
24+ bold_ref: Per-session preprocessed BOLD volumes (all tasks) .
2525 """
2626
2727 sub : str
2828 sessions : list [str ]
2929 files : list [Path ]
30- bold_ref : Path | None
30+ bold_files : dict [ str , Path ]
3131
3232
3333def discover_template_inputs (
@@ -58,17 +58,13 @@ def discover_template_inputs(
5858 # the mri_robust_template invocation.
5959 pl .col ("space" ).is_null (),
6060 )
61- bold_ref_rows = df .filter (
61+ bold_rows = df .filter (
6262 pl .col ("ses" ) != "longitudinal" ,
6363 pl .col ("datatype" ) == "func" ,
64+ pl .col ("desc" ) == "preproc" ,
6465 pl .col ("suffix" ) == "bold" ,
6566 pl .col ("space" ).is_null (),
6667 )
67- bold_ref = (
68- None
69- if bold_ref_rows .is_empty ()
70- else Path (bold_ref_rows ["root" ][0 ]) / bold_ref_rows ["path" ][0 ]
71- )
7268
7369 inputs : list [TemplateInputs ] = []
7470 skipped : list [str ] = []
@@ -81,8 +77,18 @@ def discover_template_inputs(
8177 files = [
8278 Path (row ["root" ]) / row ["path" ] for row in sub_group .iter_rows (named = True )
8379 ]
80+ # Filter for first found session; only single reference per task is needed
81+ sub_bold = bold_rows .filter (
82+ (pl .col ("sub" ) == sub ) & (pl .col ("ses" ) == sessions [0 ])
83+ )
84+ bold_files = {
85+ row ["task" ]: Path (row ["root" ]) / row ["path" ]
86+ for row in sub_bold .iter_rows (named = True )
87+ }
8488 inputs .append (
85- TemplateInputs (sub = sub , sessions = sessions , files = files , bold_ref = bold_ref )
89+ TemplateInputs (
90+ sub = sub , sessions = sessions , files = files , bold_files = bold_files
91+ )
8692 )
8793 return inputs , skipped
8894
@@ -96,8 +102,8 @@ def export_template(tpl: Bids, outputs: LongitudinalTemplateOutputs) -> None:
96102 outputs: Results from the longitudinal template workflow.
97103 """
98104 tpl .save (outputs .template , suffix = Suffix .T1W )
99- if outputs . bold_template is not None :
100- tpl .save (outputs . bold_template , res = "bold" , suffix = Suffix .T1W )
105+ for btask , bold_template in outputs . bold_templates . items () :
106+ tpl .save (bold_template , res = btask , suffix = Suffix .T1W )
101107 for ses , xfm in zip (outputs .sessions , outputs .transforms , strict = True ):
102108 ses_label = bids_safe_label (ses )
103109 tpl .save (
0 commit comments