Skip to content

Commit e6c972e

Browse files
committed
RF: Replace fslmaths chain with MakeRibbon
1 parent df4d369 commit e6c972e

File tree

3 files changed

+24
-121
lines changed

3 files changed

+24
-121
lines changed

smriprep/workflows/anatomical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def init_anat_preproc_wf(
310310
('outputnode.fsnative2t1w_xfm', 'inputnode.fsnative2t1w_xfm'),
311311
]),
312312
(anat_fit_wf, anat_ribbon_wf, [
313-
('outputnode.t1w_mask', 'inputnode.t1w_mask'),
313+
('outputnode.t1w_mask', 'inputnode.ref_file'),
314314
]),
315315
(surface_derivatives_wf, anat_ribbon_wf, [
316316
('outputnode.white', 'inputnode.white'),

smriprep/workflows/surfaces.py

Lines changed: 10 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@
3131
from nipype.pipeline import engine as pe
3232
from nipype.interfaces.base import Undefined
3333
from nipype.interfaces import (
34-
fsl,
3534
io as nio,
3635
utility as niu,
3736
freesurfer as fs,
3837
workbench as wb,
3938
)
4039

40+
from smriprep.interfaces.surf import MakeRibbon
41+
4142
from ..data import load_resource
4243
from ..interfaces.freesurfer import ReconAll, MakeMidthickness
4344

@@ -1049,23 +1050,10 @@ def init_anat_ribbon_wf(name="anat_ribbon_wf"):
10491050
workflow = pe.Workflow(name=name)
10501051

10511052
inputnode = pe.Node(
1052-
niu.IdentityInterface(
1053-
fields=[
1054-
"white",
1055-
"pial",
1056-
"t1w_mask",
1057-
]
1058-
),
1053+
niu.IdentityInterface(fields=["white", "pial", "ref_file"]),
10591054
name="inputnode",
10601055
)
1061-
outputnode = pe.Node(
1062-
niu.IdentityInterface(
1063-
fields=[
1064-
"anat_ribbon",
1065-
]
1066-
),
1067-
name="outputnode",
1068-
)
1056+
outputnode = pe.Node(niu.IdentityInterface(fields=["anat_ribbon"]), name="outputnode")
10691057

10701058
create_wm_distvol = pe.MapNode(
10711059
CreateSignedDistanceVolume(),
@@ -1079,102 +1067,22 @@ def init_anat_ribbon_wf(name="anat_ribbon_wf"):
10791067
name="create_pial_distvol",
10801068
)
10811069

1082-
thresh_wm_distvol = pe.MapNode(
1083-
fsl.maths.MathsCommand(args="-thr 0 -bin -mul 255"),
1084-
iterfield=["in_file"],
1085-
name="thresh_wm_distvol",
1086-
mem_gb=DEFAULT_MEMORY_MIN_GB,
1087-
)
1088-
1089-
uthresh_pial_distvol = pe.MapNode(
1090-
fsl.maths.MathsCommand(args="-uthr 0 -abs -bin -mul 255"),
1091-
iterfield=["in_file"],
1092-
name="uthresh_pial_distvol",
1093-
mem_gb=DEFAULT_MEMORY_MIN_GB,
1094-
)
1095-
1096-
bin_wm_distvol = pe.MapNode(
1097-
fsl.maths.UnaryMaths(operation="bin"),
1098-
iterfield=["in_file"],
1099-
name="bin_wm_distvol",
1100-
mem_gb=DEFAULT_MEMORY_MIN_GB,
1101-
)
1102-
1103-
bin_pial_distvol = pe.MapNode(
1104-
fsl.maths.UnaryMaths(operation="bin"),
1105-
iterfield=["in_file"],
1106-
name="bin_pial_distvol",
1107-
mem_gb=DEFAULT_MEMORY_MIN_GB,
1108-
)
1109-
1110-
split_wm_distvol = pe.Node(
1111-
niu.Split(splits=[1, 1]),
1112-
name="split_wm_distvol",
1113-
mem_gb=DEFAULT_MEMORY_MIN_GB,
1114-
run_without_submitting=True,
1115-
)
1116-
1117-
merge_wm_distvol_no_flatten = pe.Node(
1118-
niu.Merge(2),
1119-
no_flatten=True,
1120-
name="merge_wm_distvol_no_flatten",
1121-
mem_gb=DEFAULT_MEMORY_MIN_GB,
1122-
run_without_submitting=True,
1123-
)
1124-
1125-
make_ribbon_vol = pe.MapNode(
1126-
fsl.maths.MultiImageMaths(op_string="-mas %s -mul 255"),
1127-
iterfield=["in_file", "operand_files"],
1128-
name="make_ribbon_vol",
1129-
mem_gb=DEFAULT_MEMORY_MIN_GB,
1130-
)
1131-
1132-
bin_ribbon_vol = pe.MapNode(
1133-
fsl.maths.UnaryMaths(operation="bin"),
1134-
iterfield=["in_file"],
1135-
name="bin_ribbon_vol",
1136-
mem_gb=DEFAULT_MEMORY_MIN_GB,
1137-
)
1138-
1139-
split_squeeze_ribbon_vol = pe.Node(
1140-
niu.Split(splits=[1, 1], squeeze=True),
1141-
name="split_squeeze_ribbon",
1142-
mem_gb=DEFAULT_MEMORY_MIN_GB,
1143-
run_without_submitting=True,
1144-
)
1145-
1146-
combine_ribbon_vol_hemis = pe.Node(
1147-
fsl.maths.BinaryMaths(operation="add"),
1148-
name="combine_ribbon_vol_hemis",
1149-
mem_gb=DEFAULT_MEMORY_MIN_GB,
1150-
)
1070+
make_ribbon = pe.Node(MakeRibbon(), name="make_ribbon", mem_gb=DEFAULT_MEMORY_MIN_GB)
11511071

1152-
# make HCP-style ribbon volume in T1w space
11531072
# fmt: off
11541073
workflow.connect(
11551074
[
11561075
(inputnode, create_wm_distvol, [
11571076
("white", "surf_file"),
1158-
("t1w_mask", "ref_file"),
1077+
("ref_file", "ref_file"),
11591078
]),
11601079
(inputnode, create_pial_distvol, [
11611080
("pial", "surf_file"),
1162-
("t1w_mask", "ref_file"),
1081+
("ref_file", "ref_file"),
11631082
]),
1164-
(create_wm_distvol, thresh_wm_distvol, [("out_file", "in_file")]),
1165-
(create_pial_distvol, uthresh_pial_distvol, [("out_file", "in_file")]),
1166-
(thresh_wm_distvol, bin_wm_distvol, [("out_file", "in_file")]),
1167-
(uthresh_pial_distvol, bin_pial_distvol, [("out_file", "in_file")]),
1168-
(bin_wm_distvol, split_wm_distvol, [("out_file", "inlist")]),
1169-
(split_wm_distvol, merge_wm_distvol_no_flatten, [("out1", "in1")]),
1170-
(split_wm_distvol, merge_wm_distvol_no_flatten, [("out2", "in2")]),
1171-
(bin_pial_distvol, make_ribbon_vol, [("out_file", "in_file")]),
1172-
(merge_wm_distvol_no_flatten, make_ribbon_vol, [("out", "operand_files")]),
1173-
(make_ribbon_vol, bin_ribbon_vol, [("out_file", "in_file")]),
1174-
(bin_ribbon_vol, split_squeeze_ribbon_vol, [("out_file", "inlist")]),
1175-
(split_squeeze_ribbon_vol, combine_ribbon_vol_hemis, [("out1", "in_file")]),
1176-
(split_squeeze_ribbon_vol, combine_ribbon_vol_hemis, [("out2", "operand_file")]),
1177-
(combine_ribbon_vol_hemis, outputnode, [("out_file", "anat_ribbon")]),
1083+
(create_wm_distvol, make_ribbon, [("out_file", "white_distvols")]),
1084+
(create_pial_distvol, make_ribbon, [("out_file", "pial_distvols")]),
1085+
(make_ribbon, outputnode, [("ribbon", "anat_ribbon")]),
11781086
]
11791087
)
11801088
# fmt: on

smriprep/workflows/tests/test_surfaces.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from pathlib import Path
23
from shutil import which
34

45
import nibabel as nb
@@ -10,7 +11,7 @@
1011
from ...data import load_resource
1112

1213

13-
def test_ribbon_workflow(tmp_path):
14+
def test_ribbon_workflow(tmp_path: Path):
1415
"""Create ribbon mask for fsaverage subject"""
1516

1617
for command in ("mris_convert", "wb_command", "fslmaths"):
@@ -28,32 +29,26 @@ def test_ribbon_workflow(tmp_path):
2829

2930
gifti_surfaces_wf = init_gifti_surfaces_wf(surfaces=['white', 'pial'])
3031
anat_ribbon_wf = init_anat_ribbon_wf()
31-
anat_ribbon_wf.inputs.inputnode.t1w_mask = test_ribbon
32+
anat_ribbon_wf.inputs.inputnode.ref_file = test_ribbon
3233

3334
gifti_surfaces_wf.inputs.inputnode.subjects_dir = os.getenv('SUBJECTS_DIR')
3435
gifti_surfaces_wf.inputs.inputnode.subject_id = 'fsaverage'
3536

3637
wf = pe.Workflow(name='test_ribbon_wf', base_dir=tmp_path)
37-
wf.connect(
38-
[
39-
(
40-
gifti_surfaces_wf,
41-
anat_ribbon_wf,
42-
[
43-
('outputnode.white', 'inputnode.white'),
44-
('outputnode.pial', 'inputnode.pial'),
45-
],
46-
),
47-
]
48-
)
38+
# fmt: off
39+
wf.connect([
40+
(gifti_surfaces_wf, anat_ribbon_wf, [
41+
('outputnode.white', 'inputnode.white'),
42+
('outputnode.pial', 'inputnode.pial'),
43+
]),
44+
])
45+
# fmt: on
4946
result = wf.run()
5047

51-
combine_ribbon_vol_hemis = next(
52-
node for node in result.nodes() if node.name == 'combine_ribbon_vol_hemis'
53-
)
48+
make_ribbon = next(node for node in result.nodes() if node.name == 'make_ribbon')
5449

5550
expected = nb.load(test_ribbon)
56-
ribbon = nb.load(combine_ribbon_vol_hemis.result.outputs.out_file)
51+
ribbon = nb.load(make_ribbon.result.outputs.ribbon)
5752

5853
assert ribbon.shape == expected.shape
5954
assert np.allclose(ribbon.affine, expected.affine)

0 commit comments

Comments
 (0)