Skip to content

Commit

Permalink
RF: Separate midthickness resampling from morphometry resampling
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Nov 19, 2023
1 parent 5edd05f commit 9fd8116
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 14 deletions.
12 changes: 12 additions & 0 deletions smriprep/workflows/anatomical.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
init_surface_derivatives_wf,
init_surface_recon_wf,
init_refinement_wf,
init_resample_midthickness_wf,
)

LOGGER = logging.getLogger("nipype.workflow")
Expand Down Expand Up @@ -368,6 +369,7 @@ def init_anat_preproc_wf(

if cifti_output:
hcp_morphometrics_wf = init_hcp_morphometrics_wf(omp_nthreads=omp_nthreads)
resample_midthickness_wf = init_resample_midthickness_wf()
morph_grayords_wf = init_morph_grayords_wf(

Check warning on line 373 in smriprep/workflows/anatomical.py

View check run for this annotation

Codecov / codecov/patch

smriprep/workflows/anatomical.py#L371-L373

Added lines #L371 - L373 were not covered by tests
grayord_density=cifti_output, omp_nthreads=omp_nthreads
)
Expand All @@ -382,6 +384,13 @@ def init_anat_preproc_wf(
(surface_derivatives_wf, hcp_morphometrics_wf, [
('outputnode.curv', 'inputnode.curv'),
]),
(anat_fit_wf, resample_midthickness_wf, [
('outputnode.midthickness', 'inputnode.midthickness'),
(
f"outputnode.sphere_reg_{'msm' if msm_sulc else 'fsLR'}",
"inputnode.sphere_reg_fsLR",
),
]),
(anat_fit_wf, morph_grayords_wf, [
('outputnode.midthickness', 'inputnode.midthickness'),
(
Expand All @@ -395,6 +404,9 @@ def init_anat_preproc_wf(
('outputnode.thickness', 'inputnode.thickness'),
('outputnode.roi', 'inputnode.roi'),
]),
(resample_midthickness_wf, morph_grayords_wf, [
('outputnode.midthickness_fsLR', 'inputnode.midthickness_fsLR'),
]),
]) # fmt:skip

return workflow
Expand Down
99 changes: 85 additions & 14 deletions smriprep/workflows/surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,84 @@ def init_anat_ribbon_wf(name="anat_ribbon_wf"):
return workflow


def init_resample_midthickness_wf(
grayord_density: ty.Literal['91k', '170k'],
name: str = "resample_midthickness_wf",
):
"""
Resample subject midthickness surface to specified density.
Workflow Graph
.. workflow::
:graph2use: colored
:simple_form: yes
from smriprep.workflows.surfaces import init_resample_midthickness_wf
wf = init_resample_midthickness_wf(grayord_density="91k")
Parameters
----------
grayord_density : :obj:`str`
Either `91k` or `170k`, representing the total of vertices or *grayordinates*.
name : :obj:`str`
Unique name for the subworkflow (default: ``"resample_midthickness_wf"``)
Inputs
------
midthickness
GIFTI surface mesh corresponding to the midthickness surface
sphere_reg_fsLR
GIFTI surface mesh corresponding to the subject's fsLR registration sphere
Outputs
-------
midthickness
GIFTI surface mesh corresponding to the midthickness surface, resampled to fsLR
"""
import templateflow.api as tf
from niworkflows.engine.workflows import LiterateWorkflow as Workflow

Check warning on line 1347 in smriprep/workflows/surfaces.py

View check run for this annotation

Codecov / codecov/patch

smriprep/workflows/surfaces.py#L1346-L1347

Added lines #L1346 - L1347 were not covered by tests

workflow = Workflow(name=name)

Check warning on line 1349 in smriprep/workflows/surfaces.py

View check run for this annotation

Codecov / codecov/patch

smriprep/workflows/surfaces.py#L1349

Added line #L1349 was not covered by tests

fslr_density = "32k" if grayord_density == "91k" else "59k"

Check warning on line 1351 in smriprep/workflows/surfaces.py

View check run for this annotation

Codecov / codecov/patch

smriprep/workflows/surfaces.py#L1351

Added line #L1351 was not covered by tests

inputnode = pe.Node(

Check warning on line 1353 in smriprep/workflows/surfaces.py

View check run for this annotation

Codecov / codecov/patch

smriprep/workflows/surfaces.py#L1353

Added line #L1353 was not covered by tests
niu.IdentityInterface(fields=["midthickness", "sphere_reg_fsLR"]),
name="inputnode",
)

outputnode = pe.Node(niu.IdentityInterface(fields=["midthickness_fsLR"]), name="outputnode")

Check warning on line 1358 in smriprep/workflows/surfaces.py

View check run for this annotation

Codecov / codecov/patch

smriprep/workflows/surfaces.py#L1358

Added line #L1358 was not covered by tests

resampler = pe.MapNode(

Check warning on line 1360 in smriprep/workflows/surfaces.py

View check run for this annotation

Codecov / codecov/patch

smriprep/workflows/surfaces.py#L1360

Added line #L1360 was not covered by tests
SurfaceResample(method='BARYCENTRIC'),
iterfield=['surface_in', 'current_sphere', 'new_sphere'],
name="resampler",
)
resampler.inputs.new_sphere = [
str(
tf.get(
template='fsLR',
density=fslr_density,
suffix='sphere',
hemi=hemi,
space=None,
extension='.surf.gii',
)
)
for hemi in ['L', 'R']
]

workflow.connect([

Check warning on line 1379 in smriprep/workflows/surfaces.py

View check run for this annotation

Codecov / codecov/patch

smriprep/workflows/surfaces.py#L1379

Added line #L1379 was not covered by tests
(inputnode, resampler, [
('midthickness', 'surface_in'),
('sphere_reg_fsLR', 'current_sphere'),
]),
(resampler, outputnode, [('surface_out', 'midthickness_fsLR')]),
]) # fmt:skip

return workflow

Check warning on line 1387 in smriprep/workflows/surfaces.py

View check run for this annotation

Codecov / codecov/patch

smriprep/workflows/surfaces.py#L1387

Added line #L1387 was not covered by tests


def init_morph_grayords_wf(
grayord_density: ty.Literal['91k', '170k'],
omp_nthreads: int,
Expand Down Expand Up @@ -1383,6 +1461,7 @@ def init_morph_grayords_wf(
"thickness",
"roi",
"midthickness",
"midthickness_fsLR",
"sphere_reg_fsLR",
]
),
Expand Down Expand Up @@ -1421,7 +1500,8 @@ def init_morph_grayords_wf(
"thickness",
"roi",
"midthickness",
"sphere_reg",
"midthickness_fsLR",
"sphere_reg_fsLR",
"template_sphere",
"template_roi",
],
Expand All @@ -1448,26 +1528,17 @@ def init_morph_grayords_wf(
str(atlases / f'R.atlasroi.{fslr_density}_fs_LR.shape.gii'),
]

downsampled_midthickness = pe.Node(
SurfaceResample(method='BARYCENTRIC'),
name="downsampled_midthickness",
)

workflow.connect([
(inputnode, select_surfaces, [
('curv', 'curv'),
('sulc', 'sulc'),
('thickness', 'thickness'),
('roi', 'roi'),
('midthickness', 'midthickness'),
('sphere_reg_fsLR', 'sphere_reg'),
('midthickness_fsLR', 'midthickness_fsLR'),
('sphere_reg_fsLR', 'sphere_reg_fsLR'),
]),
(hemisource, select_surfaces, [('hemi', 'key')]),
(select_surfaces, downsampled_midthickness, [
('midthickness', 'surface_in'),
('sphere_reg', 'current_sphere'),
('template_sphere', 'new_sphere'),
]),
]) # fmt:skip

for metric in ('curv', 'sulc', 'thickness'):
Expand All @@ -1491,12 +1562,12 @@ def init_morph_grayords_wf(
workflow.connect([

Check warning on line 1562 in smriprep/workflows/surfaces.py

View check run for this annotation

Codecov / codecov/patch

smriprep/workflows/surfaces.py#L1562

Added line #L1562 was not covered by tests
(select_surfaces, resampler, [
(metric, 'in_file'),
('sphere_reg', 'current_sphere'),
('sphere_reg_fsLR', 'current_sphere'),
('template_sphere', 'new_sphere'),
('midthickness', 'current_area'),
('midthickness_fsLR', 'new_area'),
('roi', 'roi_metric'),
]),
(downsampled_midthickness, resampler, [('surface_out', 'new_area')]),
(select_surfaces, mask_fsLR, [('template_roi', 'mask')]),
(resampler, mask_fsLR, [('out_file', 'in_file')]),
(mask_fsLR, cifti_metric, [('out_file', 'scalar_surfs')]),
Expand Down

0 comments on commit 9fd8116

Please sign in to comment.