@@ -21,11 +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
2425 """
2526
2627 sub : str
2728 sessions : list [str ]
2829 files : list [Path ]
30+ bold_ref : Path | None
2931
3032
3133def discover_template_inputs (
@@ -56,6 +58,17 @@ def discover_template_inputs(
5658 # the mri_robust_template invocation.
5759 pl .col ("space" ).is_null (),
5860 )
61+ bold_ref_rows = df .filter (
62+ pl .col ("ses" ) != "longitudinal" ,
63+ pl .col ("datatype" ) == "func" ,
64+ pl .col ("suffix" ) == "bold" ,
65+ pl .col ("space" ).is_null (),
66+ )
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+ )
5972
6073 inputs : list [TemplateInputs ] = []
6174 skipped : list [str ] = []
@@ -68,7 +81,9 @@ def discover_template_inputs(
6881 files = [
6982 Path (row ["root" ]) / row ["path" ] for row in sub_group .iter_rows (named = True )
7083 ]
71- inputs .append (TemplateInputs (sub = sub , sessions = sessions , files = files ))
84+ inputs .append (
85+ TemplateInputs (sub = sub , sessions = sessions , files = files , bold_ref = bold_ref )
86+ )
7287 return inputs , skipped
7388
7489
@@ -81,6 +96,8 @@ def export_template(tpl: Bids, outputs: LongitudinalTemplateOutputs) -> None:
8196 outputs: Results from the longitudinal template workflow.
8297 """
8398 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 )
84101 for ses , xfm in zip (outputs .sessions , outputs .transforms , strict = True ):
85102 ses_label = bids_safe_label (ses )
86103 tpl .save (
0 commit comments