Skip to content

Commit d5a282e

Browse files
committed
ENH: Add option to force t2w
1 parent 91265b0 commit d5a282e

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

fmriprep/cli/parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,11 @@ def _slice_time_ref(value, parser):
347347
)
348348
g_conf.add_argument(
349349
"--bold2anat-init",
350-
choices=["auto", "t1w", "header"],
350+
choices=["auto", "t1w", "t2w", "header"],
351351
default="auto",
352-
help="Method of initial BOLD to anatomical coregistration. If `auto`, a T2w image is used if "
353-
"available, otherwise the T1w image. `t1w` forces use of the T1w, and `header` uses "
354-
"the BOLD header information without an initial registration.",
352+
help="Method of initial BOLD to anatomical coregistration. If `auto`, a T2w image is used "
353+
"if available, otherwise the T1w image. `t1w` forces use of the T1w, `t2w` forces use of "
354+
"the T2w, and `header` uses the BOLD header information without an initial registration.",
355355
)
356356
g_conf.add_argument(
357357
"--bold2anat-dof",

fmriprep/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,9 @@ class workflow(_Config):
528528
bold2anat_dof = None
529529
"""Degrees of freedom of the BOLD-to-anatomical registration steps."""
530530
bold2anat_init = "auto"
531-
"""Method of BOLD to anatomical coregistration. The target anatomical (``'t1w'``, ``'t2w'``)
532-
can be specified, otherwise ``'auto'`` will prefer a T2w image but fall back to T1w if none
533-
are available. Alternatively, ``'header'`` will use the T1w header information."""
531+
"""Method of initial BOLD to anatomical coregistration. If `auto`, a T2w image is used
532+
if available, otherwise the T1w image. `t1w` forces use of the T1w, `t2w` forces use of
533+
the T2w, and `header` uses the BOLD header information without an initial registration."""
534534
cifti_output = None
535535
"""Generate HCP Grayordinates, accepts either ``'91k'`` (default) or ``'170k'``."""
536536
dummy_scans = None

fmriprep/workflows/base.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,13 @@ def init_single_subject_wf(subject_id: str):
624624
)
625625

626626
# Before initializing BOLD workflow, select/verify anatomical target for coregistration
627-
if config.workflow.bold2anat_init == 'auto':
628-
config.workflow.bold2anat_init = 't2w' if subject_data['t2w'] else 't1w'
627+
if config.workflow.bold2anat_init in ('auto', 't2w'):
628+
has_t2w = subject_data['t2w'] or 't2w_preproc' in anatomical_cache
629+
if config.workflow.bold2anat_init == 't2w' and not has_t2w:
630+
raise OSError(
631+
"A T2w image is expected for BOLD-to-anatomical coregistration and was not found"
632+
)
633+
config.workflow.bold2anat_init = 't2w' if has_t2w else 't1w'
629634

630635
for bold_series in bold_runs:
631636
bold_file = bold_series[0]
@@ -673,7 +678,6 @@ def init_single_subject_wf(subject_id: str):
673678
f'outputnode.sphere_reg_{"msm" if msm_sulc else "fsLR"}',
674679
'inputnode.sphere_reg_fsLR',
675680
),
676-
('outputnode.t2w_preproc', 'inputnode.t2w_preproc'), # Optional
677681
]),
678682
]) # fmt:skip
679683
if fieldmap_id:

fmriprep/workflows/bold/registration.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,7 @@ def init_bbreg_wf(
288288

289289
use_t2w = bold2anat_init == 't2w'
290290
if use_t2w:
291-
workflow.__desc__ += (
292-
" The aligned T2w image was used for initial co-registration."
293-
)
291+
workflow.__desc__ += " The aligned T2w image was used for initial co-registration."
294292

295293
inputnode = pe.Node(
296294
niu.IdentityInterface(
@@ -356,8 +354,6 @@ def init_bbreg_wf(
356354
concat_xfm = pe.Node(ConcatenateXFMs(inverse=True), name='concat_xfm')
357355

358356
workflow.connect([
359-
(inputnode, fssource, [('subjects_dir', 'subjects_dir'),
360-
('subject_id', 'subject_id')]),
361357
(inputnode, merge_ltas, [('fsnative2t1w_xfm', 'in2')]),
362358
# Wire up the co-registration alternatives
363359
(transforms, select_transform, [('out', 'inlist')]),
@@ -377,7 +373,11 @@ def init_bbreg_wf(
377373
]) # fmt:skip
378374

379375
if use_t2w:
380-
workflow.connect(fssource, 'T2', mri_coreg, 'reference_file')
376+
workflow.connect([
377+
(inputnode, fssource, [('subjects_dir', 'subjects_dir'),
378+
('subject_id', 'subject_id')]),
379+
(fssource, mri_coreg, [('T2', 'reference_file')]),
380+
]) # fmt:skip
381381

382382
# Short-circuit workflow building, use initial registration
383383
if use_bbr is False:

0 commit comments

Comments
 (0)