Skip to content

Commit 29e2932

Browse files
authored
Merge pull request #473 from feilong/master
Resample surfaces to any space/density using Connectome Workbench.
2 parents 82f1bc5 + add4d97 commit 29e2932

File tree

2 files changed

+48
-21
lines changed

2 files changed

+48
-21
lines changed

src/smriprep/workflows/anatomical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def init_anat_preproc_wf(
384384
hcp_morphometrics_wf = init_hcp_morphometrics_wf(omp_nthreads=omp_nthreads)
385385
resample_surfaces_wf = init_resample_surfaces_wf(
386386
surfaces=['white', 'pial', 'midthickness'],
387-
grayord_density=cifti_output,
387+
density='32k' if cifti_output == '91k' else '59k',
388388
)
389389
morph_grayords_wf = init_morph_grayords_wf(
390390
grayord_density=cifti_output, omp_nthreads=omp_nthreads

src/smriprep/workflows/surfaces.py

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"""
3030

3131
import typing as ty
32+
import warnings
3233

3334
from nipype.interfaces import freesurfer as fs
3435
from nipype.interfaces import io as nio
@@ -1398,11 +1399,16 @@ def init_anat_ribbon_wf(name='anat_ribbon_wf'):
13981399

13991400
def init_resample_surfaces_wf(
14001401
surfaces: list[str],
1401-
grayord_density: ty.Literal['91k', '170k'],
1402+
template: str = 'fsLR',
1403+
cohort: str | None = None,
1404+
space: str | None = 'fsLR',
1405+
density: str | None = None,
1406+
grayord_density: str | None = None,
14021407
name: str = 'resample_surfaces_wf',
14031408
):
14041409
"""
1405-
Resample subject surfaces surface to specified density.
1410+
Resample subject surfaces surface to specified template space and density,
1411+
using a given registration space.
14061412
14071413
Workflow Graph
14081414
.. workflow::
@@ -1412,44 +1418,64 @@ def init_resample_surfaces_wf(
14121418
from smriprep.workflows.surfaces import init_resample_surfaces_wf
14131419
wf = init_resample_surfaces_wf(
14141420
surfaces=['white', 'pial', 'midthickness'],
1415-
grayord_density='91k',
1421+
template='onavg',
1422+
density='10k',
14161423
)
14171424
14181425
Parameters
14191426
----------
14201427
surfaces : :class:`list` of :class:`str`
14211428
Names of surfaces (e.g., ``'white'``) to resample. Both hemispheres will be resampled.
1422-
grayord_density : :class:`str`
1423-
Either `91k` or `170k`, representing the total of vertices or *grayordinates*.
1429+
template : :class:`str`
1430+
The template space to resample to, e.g., ``'onavg'``, ``'fsLR'``.
1431+
cohort : :class:`str` or :obj:`None`
1432+
The template cohort to use, if the template provides multiple.
1433+
space : :class:`str` or :obj:`None`
1434+
The registration space for which there are both subject and template
1435+
registration spheres.
1436+
If ``None``, the template space is used.
1437+
density : :class:`str`
1438+
The density to resample to, e.g., ``'10k'``, ``'41k'``. Number of vertices per hemisphere.
14241439
name : :class:`str`
14251440
Unique name for the subworkflow (default: ``"resample_surfaces_wf"``)
14261441
14271442
Inputs
14281443
------
14291444
``<surface>``
1430-
Left and right GIFTIs for each surface name passed to ``surfaces``
1431-
sphere_reg_fsLR
1432-
GIFTI surface mesh corresponding to the subject's fsLR registration sphere
1445+
Left and right GIFTIs for each surface name passed to ``surfaces``.
1446+
``sphere_reg_<space>``
1447+
GIFTI surface mesh corresponding to the subject's registration sphere to ``space``.
14331448
14341449
Outputs
14351450
-------
1436-
``<surface>``
1437-
Left and right GIFTI surface mesh corresponding to the input surface, resampled to fsLR
1451+
``<surface>_<template>``
1452+
Left and right GIFTI surface mesh corresponding to the input surface, resampled to the
1453+
specified space and density.
14381454
"""
14391455
import templateflow.api as tf
14401456
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
14411457

1442-
workflow = Workflow(name=name)
1458+
if density is None:
1459+
if grayord_density is None:
1460+
raise ValueError('No density specified. Set density argument.')
1461+
density = '32k' if grayord_density == '91k' else '59k'
1462+
warnings.warn(
1463+
'Deprecated grayord_density passed. Replace with\n\t'
1464+
"density='32k' if grayord_density == '91k' else '59k'",
1465+
DeprecationWarning,
1466+
stacklevel=2,
1467+
)
14431468

1444-
fslr_density = '32k' if grayord_density == '91k' else '59k'
1469+
workflow = Workflow(name=name)
14451470

14461471
inputnode = pe.Node(
1447-
niu.IdentityInterface(fields=[*surfaces, 'sphere_reg_fsLR']),
1472+
niu.IdentityInterface(fields=[*surfaces, f'sphere_reg_{space}']),
14481473
name='inputnode',
14491474
)
14501475

14511476
outputnode = pe.Node(
1452-
niu.IdentityInterface(fields=[f'{surf}_fsLR' for surf in surfaces]), name='outputnode'
1477+
niu.IdentityInterface(fields=[f'{surf}_{template}' for surf in surfaces]),
1478+
name='outputnode',
14531479
)
14541480

14551481
surface_list = pe.Node(
@@ -1466,11 +1492,12 @@ def init_resample_surfaces_wf(
14661492
resampler.inputs.new_sphere = [
14671493
str(
14681494
tf.get(
1469-
template='fsLR',
1470-
density=fslr_density,
1471-
suffix='sphere',
1495+
template=template,
1496+
cohort=cohort,
1497+
space=space if space != template else None,
14721498
hemi=hemi,
1473-
space=None,
1499+
density=density,
1500+
suffix='sphere',
14741501
extension='.surf.gii',
14751502
)
14761503
)
@@ -1491,12 +1518,12 @@ def init_resample_surfaces_wf(
14911518
for i, surf in enumerate(surfaces, start=1)
14921519
]),
14931520
(inputnode, resampler, [
1494-
(('sphere_reg_fsLR', _repeat, len(surfaces)), 'current_sphere'),
1521+
((f'sphere_reg_{space}', _repeat, len(surfaces)), 'current_sphere'),
14951522
]),
14961523
(surface_list, resampler, [('out', 'surface_in')]),
14971524
(resampler, surface_groups, [('surface_out', 'inlist')]),
14981525
(surface_groups, outputnode, [
1499-
(f'out{i}', f'{surf}_fsLR') for i, surf in enumerate(surfaces, start=1)
1526+
(f'out{i}', f'{surf}_{template}') for i, surf in enumerate(surfaces, start=1)
15001527
]),
15011528
]) # fmt:skip
15021529

0 commit comments

Comments
 (0)