Skip to content

Commit cfe6c9c

Browse files
committed
feat(t1t2): Add init_myelinmap_fsLR_wf
1 parent 2af47dd commit cfe6c9c

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed

src/smriprep/workflows/surfaces.py

+152
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import typing as ty
3232

33+
from nibabel.processing import fwhm2sigma
3334
from nipype.interfaces import freesurfer as fs
3435
from nipype.interfaces import io as nio
3536
from nipype.interfaces import utility as niu
@@ -1568,6 +1569,157 @@ def init_morph_grayords_wf(
15681569
return workflow
15691570

15701571

1572+
def init_myelinmap_fsLR_wf(
1573+
grayord_density: ty.Literal['91k', '170k'],
1574+
omp_nthreads: int,
1575+
mem_gb: float,
1576+
name: str = 'myelinmap_fsLR_wf',
1577+
):
1578+
"""Resample myelinmap volume to fsLR surface.
1579+
1580+
Workflow Graph
1581+
.. workflow::
1582+
:graph2use: colored
1583+
:simple_form: yes
1584+
1585+
from smriprep.workflows.surfaces import init_myelinmap_fsLR_wf
1586+
wf = init_myelinmap_fsLR_wf(grayord_density='91k', omp_nthreads=1, mem_gb=1)
1587+
1588+
Parameters
1589+
----------
1590+
grayord_density : :class:`str`
1591+
Either ``"91k"`` or ``"170k"``, representing the total *grayordinates*.
1592+
omp_nthreads : :class:`int`
1593+
Maximum number of threads an individual process may use
1594+
mem_gb : :class:`float`
1595+
Size of BOLD file in GB
1596+
name : :class:`str`
1597+
Name of workflow (default: ``"myelinmap_fsLR_wf"``)
1598+
1599+
Inputs
1600+
------
1601+
in_file : :class:`str`
1602+
Path to the myelin map in subject volume space
1603+
thickness : :class:`list` of :class:`str`
1604+
Path to left and right hemisphere thickness GIFTI shape files
1605+
midthickness : :class:`list` of :class:`str`
1606+
Path to left and right hemisphere midthickness GIFTI surface files
1607+
midthickness_fsLR : :class:`list` of :class:`str`
1608+
Path to left and right hemisphere midthickness GIFTI surface files in fsLR space
1609+
sphere_reg_fsLR : :class:`list` of :class:`str`
1610+
Path to left and right hemisphere sphere.reg GIFTI surface files,
1611+
mapping from subject to fsLR
1612+
cortex_mask : :class:`list` of :class:`str`
1613+
Path to left and right hemisphere cortex mask GIFTI files
1614+
1615+
Outputs
1616+
-------
1617+
out_fsLR : :class:`str`
1618+
Path to the resampled myelin map in fsLR space
1619+
1620+
"""
1621+
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
1622+
from niworkflows.interfaces.utility import KeySelect
1623+
from niworkflows.interfaces.workbench import VolumeToSurfaceMapping
1624+
1625+
workflow = Workflow(name=name)
1626+
1627+
inputnode = pe.Node(
1628+
niu.IdentityInterface(
1629+
fields=[
1630+
'in_file',
1631+
'thickness',
1632+
'midthickness',
1633+
'midthickness_fsLR',
1634+
'sphere_reg_fsLR',
1635+
'cortex_mask',
1636+
'volume_roi',
1637+
]
1638+
),
1639+
name='inputnode',
1640+
)
1641+
1642+
outputnode = pe.Node(
1643+
niu.IdentityInterface(fields=['out_file', 'out_metadata']),
1644+
name='outputnode',
1645+
)
1646+
1647+
hemisource = pe.Node(
1648+
niu.IdentityInterface(fields=['hemi']),
1649+
name='hemisource',
1650+
iterables=[('hemi', ['L', 'R'])],
1651+
)
1652+
1653+
select_surfaces = pe.Node(
1654+
KeySelect(
1655+
fields=[
1656+
'thickness',
1657+
'midthickness',
1658+
],
1659+
keys=['L', 'R'],
1660+
),
1661+
name='select_surfaces',
1662+
run_without_submitting=True,
1663+
)
1664+
1665+
volume_to_surface = pe.Node(
1666+
VolumeToSurfaceMapping(method='myelin-style', sigma=fwhm2sigma(5)),
1667+
name='volume_to_surface',
1668+
mem_gb=mem_gb * 3,
1669+
n_procs=omp_nthreads,
1670+
)
1671+
# For SmoothedMyelinMap
1672+
# smooth = pe.Node(
1673+
# MetricSmooth(sigma=fwhm2sigma(4), nearest=True),
1674+
# name='metric_dilate',
1675+
# mem_gb=1,
1676+
# n_procs=omp_nthreads,
1677+
# )
1678+
resample_and_mask_wf = init_resample_and_mask_wf(
1679+
grayord_density=grayord_density,
1680+
omp_nthreads=omp_nthreads,
1681+
mem_gb=mem_gb,
1682+
)
1683+
cifti_myelinmap = pe.JoinNode(
1684+
GenerateDScalar(grayordinates=grayord_density, scalar_name='MyelinMap'),
1685+
name='cifti_myelinmap',
1686+
joinfield=['scalar_surfs'],
1687+
joinsource='hemisource',
1688+
)
1689+
1690+
workflow.connect([
1691+
(inputnode, select_surfaces, [
1692+
('midthickness', 'midthickness'),
1693+
('thickness', 'thickness'),
1694+
]),
1695+
(hemisource, select_surfaces, [('hemi', 'key')]),
1696+
# Resample volume to native surface
1697+
(inputnode, volume_to_surface, [
1698+
('in_file', 'volume_file'),
1699+
('ribbon_file', 'ribbon_roi'),
1700+
]),
1701+
(select_surfaces, volume_to_surface, [
1702+
('midthickness', 'surface_file'),
1703+
('thickness', 'thickness'),
1704+
]),
1705+
(inputnode, resample_and_mask_wf, [
1706+
('midthickness', 'inputnode.midthickness'),
1707+
('midthickness_fsLR', 'inputnode.midthickness_fsLR'),
1708+
('sphere_reg_fsLR', 'inputnode.sphere_reg_fsLR'),
1709+
('cortex_mask', 'inputnode.cortex_mask'),
1710+
]),
1711+
(hemisource, resample_and_mask_wf, [('hemi', 'inputnode.hemi')]),
1712+
(volume_to_surface, resample_and_mask_wf, [('out_file', 'inputnode.in_file')]),
1713+
(resample_and_mask_wf, cifti_myelinmap, [('outputnode.out_file', 'scalar_surfs')]),
1714+
(cifti_myelinmap, outputnode, [
1715+
('out_file', 'out_file'),
1716+
('out_metadata', 'out_metadata'),
1717+
]),
1718+
]) # fmt:skip
1719+
1720+
return workflow
1721+
1722+
15711723
def init_resample_and_mask_wf(
15721724
grayord_density: ty.Literal['91k', '170k'],
15731725
omp_nthreads: int,

0 commit comments

Comments
 (0)