Skip to content

Commit 9be14e0

Browse files
committed
feat: Resample to surface template spaces using the Connectome Workbench.
1 parent e3c6cdc commit 9be14e0

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

fmriprep/workflows/bold/base.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,115 @@ def init_bold_wf(
498498
]),
499499
]) # fmt:skip
500500

501+
surf_std = spaces.get_standard(dim=(2,))
502+
if surf_std: # Probably ensure reconall and msmsulc are run
503+
workflow.__postdesc__ += """\
504+
Non-gridded (surface) resamplings were performed using the Connectome
505+
Workbench.
506+
"""
507+
config.loggers.workflow.debug('Creating BOLD surface workbench resampling workflow.')
508+
from smriprep.workflows.surfaces import init_resample_surfaces_wb_wf
509+
510+
from .resampling import (
511+
init_goodvoxels_bold_mask_wf,
512+
init_wb_surf_surf_wf,
513+
init_wb_vol_surf_wf,
514+
)
515+
516+
wb_vol_surf_wf = init_wb_vol_surf_wf(
517+
name='wb_vol_surf_wf',
518+
omp_nthreads=omp_nthreads,
519+
mem_gb=mem_gb['resampled'],
520+
dilate=True,
521+
)
522+
workflow.connect([
523+
(inputnode, wb_vol_surf_wf,[
524+
('white', 'inputnode.white'),
525+
('pial', 'inputnode.pial'),
526+
('midthickness', 'inputnode.midthickness'),
527+
]),
528+
(bold_anat_wf, wb_vol_surf_wf, [
529+
('outputnode.bold_file', 'inputnode.bold_file'),
530+
]),
531+
]) # fmt:skip
532+
533+
if config.workflow.project_goodvoxels:
534+
goodvoxels_bold_mask_wf = init_goodvoxels_bold_mask_wf(mem_gb['resampled'])
535+
536+
workflow.connect([
537+
(inputnode, goodvoxels_bold_mask_wf, [('anat_ribbon', 'inputnode.anat_ribbon')]),
538+
(bold_anat_wf, goodvoxels_bold_mask_wf, [
539+
('outputnode.bold_file', 'inputnode.bold_file'),
540+
]),
541+
(goodvoxels_bold_mask_wf, wb_vol_surf_wf, [
542+
('outputnode.goodvoxels_mask', 'inputnode.volume_roi'),
543+
]),
544+
]) # fmt:skip
545+
workflow.__desc__ += """\
546+
A "goodvoxels" mask was applied during volume-to-surface sampling, excluding
547+
voxels whose time-series have a locally high coefficient of variation.
548+
"""
549+
550+
for ref_ in surf_std:
551+
space, den = ref_.space, ref_.spec['den']
552+
553+
resample_surfaces_wb_wf = init_resample_surfaces_wb_wf(
554+
name=f'resample_surfaces_wb_wf_{space}_{den}',
555+
surfaces=['midthickness'],
556+
space=space,
557+
density=den,
558+
)
559+
560+
wb_surf_surf_wf = init_wb_surf_surf_wf(
561+
space=space,
562+
density=den,
563+
name=f'wb_surf_surf_wf_{space}_{den}',
564+
omp_nthreads=omp_nthreads,
565+
mem_gb=mem_gb['resampled'],
566+
)
567+
568+
ds_bold_surf_wb = pe.Node(
569+
DerivativesDataSink(
570+
base_directory=fmriprep_dir,
571+
hemi=['L', 'R'],
572+
dismiss_entities=dismiss_echo(),
573+
space=space,
574+
density=den,
575+
suffix='bold',
576+
# compress=False, # not sure if needed for gii.
577+
TaskName=all_metadata[0].get('TaskName'),
578+
extension='.func.gii',
579+
**prepare_timing_parameters(all_metadata[0]),
580+
),
581+
iterfield=('in_file', 'hemi'),
582+
name=f'ds_bold_surf_wb_{space}_{den}',
583+
run_without_submitting=True,
584+
)
585+
ds_bold_surf_wb.inputs.source_file = bold_file
586+
587+
workflow.connect([
588+
(inputnode, resample_surfaces_wb_wf, [
589+
('midthickness', 'inputnode.midthickness'),
590+
('sphere_reg_fsLR', 'inputnode.sphere_reg_fsLR'),
591+
]),
592+
(wb_vol_surf_wf, wb_surf_surf_wf, [
593+
('outputnode.bold_fsnative', 'inputnode.bold_fsnative'),
594+
]),
595+
(inputnode, wb_surf_surf_wf, [
596+
('midthickness', 'inputnode.midthickness'),
597+
# # TODO: check inputnode.midthickness_resampled
598+
# ('midthickness_resampled', 'inputnode.midthickness_resampled'),
599+
('sphere_reg_fsLR', 'inputnode.sphere_reg_fsLR'),
600+
]),
601+
(resample_surfaces_wb_wf, wb_surf_surf_wf, [
602+
('outputnode.midthickness_resampled', 'inputnode.midthickness_resampled'),
603+
]),
604+
(wb_surf_surf_wf, ds_bold_surf_wb, [
605+
('outputnode.bold_resampled', 'in_file'),
606+
# TODO: json metadata?
607+
]),
608+
]) # fmt:skip
609+
501610
if config.workflow.run_reconall and freesurfer_spaces:
502611
workflow.__postdesc__ += """\
503612
Non-gridded (surface) resamplings were performed using `mri_vol2surf`

0 commit comments

Comments
 (0)