Skip to content

Commit 0d07d46

Browse files
committed
rf: move wb surface resample to inside cifti block
1 parent d20a8d1 commit 0d07d46

File tree

1 file changed

+99
-97
lines changed

1 file changed

+99
-97
lines changed

fmriprep/workflows/bold/base.py

Lines changed: 99 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ def init_bold_wf(
280280
spaces = config.workflow.spaces
281281
nonstd_spaces = set(spaces.get_nonstandard())
282282
freesurfer_spaces = spaces.get_fs_spaces()
283+
surf_std = [x for x in spaces.get_standard(dim=(2,)) if x.space != 'fsaverage']
283284

284285
#
285286
# Resampling outputs workflow:
@@ -528,103 +529,6 @@ def init_bold_wf(
528529
]),
529530
]) # fmt:skip
530531

531-
surf_std = spaces.get_standard(dim=(2,))
532-
if surf_std and config.workflow.run_reconall and config.workflow.cifti_output:
533-
workflow.__postdesc__ += """\
534-
Non-gridded (surface) resamplings were performed using the Connectome
535-
Workbench.
536-
"""
537-
config.loggers.workflow.debug('Creating BOLD surface workbench resampling workflow.')
538-
from smriprep.workflows.surfaces import init_resample_surfaces_wf
539-
540-
from .resampling import (
541-
init_wb_surf_surf_wf,
542-
init_wb_vol_surf_wf,
543-
)
544-
545-
wb_vol_surf_wf = init_wb_vol_surf_wf(
546-
omp_nthreads=omp_nthreads,
547-
mem_gb=mem_gb['resampled'],
548-
dilate=True,
549-
)
550-
workflow.connect([
551-
(inputnode, wb_vol_surf_wf,[
552-
('white', 'inputnode.white'),
553-
('pial', 'inputnode.pial'),
554-
('midthickness', 'inputnode.midthickness'),
555-
]),
556-
(bold_anat_wf, wb_vol_surf_wf, [
557-
('outputnode.bold_file', 'inputnode.bold_file'),
558-
]),
559-
]) # fmt:skip
560-
561-
if config.workflow.project_goodvoxels:
562-
workflow.connect([
563-
(goodvoxels_bold_mask_wf, wb_vol_surf_wf, [
564-
('outputnode.goodvoxels_mask', 'inputnode.volume_roi'),
565-
]),
566-
]) # fmt:skip
567-
568-
for ref_ in surf_std:
569-
template = ref_.space
570-
density = ref_.spec.get('density') or ref_.spec.get('den') or None
571-
if density is None:
572-
config.loggers.warning(f'Cannot resample {ref_} without density specified.')
573-
continue
574-
575-
resample_surfaces_wb_wf = init_resample_surfaces_wf(
576-
name=f'resample_surfaces_wb_wf_{template}_{density}',
577-
surfaces=['midthickness'],
578-
template=template,
579-
density=density,
580-
)
581-
582-
wb_surf_surf_wf = init_wb_surf_surf_wf(
583-
template=template,
584-
density=density,
585-
omp_nthreads=omp_nthreads,
586-
mem_gb=mem_gb['resampled'],
587-
)
588-
589-
ds_bold_surf_wb = pe.Node(
590-
DerivativesDataSink(
591-
base_directory=fmriprep_dir,
592-
hemi=['L', 'R'],
593-
dismiss_entities=dismiss_echo(),
594-
space=template,
595-
density=density,
596-
suffix='bold',
597-
TaskName=all_metadata[0].get('TaskName'),
598-
extension='.func.gii',
599-
**prepare_timing_parameters(all_metadata[0]),
600-
),
601-
iterfield=('in_file', 'hemi'),
602-
name=f'ds_bold_surf_wb_{template}_{density}',
603-
run_without_submitting=True,
604-
)
605-
ds_bold_surf_wb.inputs.source_file = bold_file
606-
607-
workflow.connect([
608-
(inputnode, resample_surfaces_wb_wf, [
609-
('midthickness', 'inputnode.midthickness'),
610-
('sphere_reg_fsLR', 'inputnode.sphere_reg_fsLR'),
611-
]),
612-
(wb_vol_surf_wf, wb_surf_surf_wf, [
613-
('outputnode.bold_fsnative', 'inputnode.bold_fsnative'),
614-
]),
615-
(inputnode, wb_surf_surf_wf, [
616-
('midthickness', 'inputnode.midthickness'),
617-
('sphere_reg_fsLR', 'inputnode.sphere_reg_fsLR'),
618-
]),
619-
(resample_surfaces_wb_wf, wb_surf_surf_wf, [
620-
('outputnode.midthickness', 'inputnode.midthickness_resampled'),
621-
]),
622-
(wb_surf_surf_wf, ds_bold_surf_wb, [
623-
('outputnode.bold_resampled', 'in_file'),
624-
# TODO: json metadata?
625-
]),
626-
]) # fmt:skip
627-
628532
if config.workflow.run_reconall and freesurfer_spaces:
629533
workflow.__postdesc__ += """\
630534
Non-gridded (surface) resamplings were performed using `mri_vol2surf`
@@ -761,6 +665,104 @@ def init_bold_wf(
761665
]),
762666
]) # fmt:skip
763667

668+
if surf_std:
669+
from smriprep.workflows.surfaces import init_resample_surfaces_wf
670+
671+
from .resampling import (
672+
init_wb_surf_surf_wf,
673+
init_wb_vol_surf_wf,
674+
)
675+
workflow.__postdesc__ += (
676+
'Non-gridded (surface) resamplings were performed using the Connectome Workbench.'
677+
)
678+
config.loggers.workflow.debug('Creating BOLD surface workbench resampling workflow.')
679+
680+
wb_vol_surf_wf = init_wb_vol_surf_wf(
681+
omp_nthreads=omp_nthreads,
682+
mem_gb=mem_gb['resampled'],
683+
dilate=True,
684+
)
685+
workflow.connect([
686+
(inputnode, wb_vol_surf_wf,[
687+
('white', 'inputnode.white'),
688+
('pial', 'inputnode.pial'),
689+
('midthickness', 'inputnode.midthickness'),
690+
]),
691+
(bold_anat_wf, wb_vol_surf_wf, [
692+
('outputnode.bold_file', 'inputnode.bold_file'),
693+
]),
694+
]) # fmt:skip
695+
696+
if config.workflow.project_goodvoxels:
697+
workflow.connect([
698+
(goodvoxels_bold_mask_wf, wb_vol_surf_wf, [
699+
('outputnode.goodvoxels_mask', 'inputnode.volume_roi'),
700+
]),
701+
]) # fmt:skip
702+
703+
for ref_ in surf_std:
704+
template = ref_.space
705+
density = ref_.spec.get('density') or ref_.spec.get('den') or None
706+
if density is None:
707+
config.loggers.warning(f'Cannot resample {ref_} without density specified.')
708+
continue
709+
710+
resample_surfaces_wf = init_resample_surfaces_wf(
711+
name=f'resample_surfaces_wf_{template}_{density}',
712+
surfaces=['midthickness'],
713+
template=template,
714+
density=density,
715+
)
716+
717+
wb_surf_surf_wf = init_wb_surf_surf_wf(
718+
template=template,
719+
density=density,
720+
omp_nthreads=omp_nthreads,
721+
mem_gb=mem_gb['resampled'],
722+
)
723+
724+
ds_bold_surf_wb = pe.Node(
725+
DerivativesDataSink(
726+
base_directory=fmriprep_dir,
727+
hemi=['L', 'R'],
728+
dismiss_entities=dismiss_echo(),
729+
space=template,
730+
density=density,
731+
suffix='bold',
732+
TaskName=all_metadata[0].get('TaskName'),
733+
extension='.func.gii',
734+
**prepare_timing_parameters(all_metadata[0]),
735+
),
736+
iterfield=('in_file', 'hemi'),
737+
name=f'ds_bold_surf_wb_{template}_{density}',
738+
run_without_submitting=True,
739+
)
740+
ds_bold_surf_wb.inputs.source_file = bold_file
741+
742+
workflow.connect([
743+
(inputnode, resample_surfaces_wf, [
744+
('midthickness', 'inputnode.midthickness'),
745+
('sphere_reg_fsLR', 'inputnode.sphere_reg_fsLR'),
746+
]),
747+
(wb_vol_surf_wf, wb_surf_surf_wf, [
748+
('outputnode.bold_fsnative', 'inputnode.bold_fsnative'),
749+
]),
750+
(inputnode, wb_surf_surf_wf, [
751+
('midthickness', 'inputnode.midthickness'),
752+
('sphere_reg_fsLR', 'inputnode.sphere_reg_fsLR'),
753+
]),
754+
(resample_surfaces_wf, wb_surf_surf_wf, [
755+
(
756+
f'outputnode.midthickness_{template}',
757+
'inputnode.midthickness_resampled'
758+
),
759+
]),
760+
(wb_surf_surf_wf, ds_bold_surf_wb, [
761+
('outputnode.bold_resampled', 'in_file'),
762+
# TODO: json metadata?
763+
]),
764+
]) # fmt:skip
765+
764766
bold_confounds_wf = init_bold_confs_wf(
765767
mem_gb=mem_gb['largemem'],
766768
metadata=all_metadata[0],

0 commit comments

Comments
 (0)