-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #363 from effigies/enh/simplify-ribbon
RF: Replace most of anat_ribbon_wf with a Python function
- Loading branch information
Showing
13 changed files
with
183 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Binary file added
BIN
+8.19 KB
smriprep/interfaces/tests/data/sub-fsaverage_res-4_desc-cropped_ribbon.nii.gz
Binary file not shown.
Binary file added
BIN
+85.5 KB
smriprep/interfaces/tests/data/sub-fsaverage_res-4_hemi-L_desc-cropped_pialdist.nii.gz
Binary file not shown.
Binary file added
BIN
+73.4 KB
smriprep/interfaces/tests/data/sub-fsaverage_res-4_hemi-L_desc-cropped_wmdist.nii.gz
Binary file not shown.
Binary file added
BIN
+85.3 KB
smriprep/interfaces/tests/data/sub-fsaverage_res-4_hemi-R_desc-cropped_pialdist.nii.gz
Binary file not shown.
Binary file added
BIN
+73.2 KB
smriprep/interfaces/tests/data/sub-fsaverage_res-4_hemi-R_desc-cropped_wmdist.nii.gz
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import nibabel as nb | ||
from nipype.pipeline import engine as pe | ||
import numpy as np | ||
|
||
from ...data import load_resource | ||
from ..surf import MakeRibbon | ||
|
||
|
||
def test_MakeRibbon(tmp_path): | ||
res_template = "{path}/sub-fsaverage_res-4_hemi-{hemi}_desc-cropped_{surf}dist.nii.gz" | ||
white, pial = [ | ||
[ | ||
load_resource( | ||
res_template.format(path="../interfaces/tests/data", hemi=hemi, surf=surf) | ||
) | ||
for hemi in "LR" | ||
] | ||
for surf in ("wm", "pial") | ||
] | ||
|
||
make_ribbon = pe.Node( | ||
MakeRibbon(white_distvols=white, pial_distvols=pial), | ||
name="make_ribbon", | ||
base_dir=tmp_path, | ||
) | ||
|
||
result = make_ribbon.run() | ||
|
||
ribbon = nb.load(result.outputs.ribbon) | ||
expected = nb.load( | ||
load_resource("../interfaces/tests/data/sub-fsaverage_res-4_desc-cropped_ribbon.nii.gz") | ||
) | ||
|
||
assert ribbon.shape == expected.shape | ||
assert np.allclose(ribbon.affine, expected.affine) | ||
assert np.array_equal(ribbon.dataobj, expected.dataobj) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import os | ||
from pathlib import Path | ||
from shutil import which | ||
|
||
import nibabel as nb | ||
import numpy as np | ||
import pytest | ||
from nipype.pipeline import engine as pe | ||
|
||
from ..surfaces import init_anat_ribbon_wf, init_gifti_surfaces_wf | ||
from ...data import load_resource | ||
|
||
|
||
def test_ribbon_workflow(tmp_path: Path): | ||
"""Create ribbon mask for fsaverage subject""" | ||
|
||
for command in ("mris_convert", "wb_command"): | ||
if not which(command): | ||
pytest.skip(f"Could not find {command} in PATH") | ||
|
||
if not os.path.exists(os.getenv('SUBJECTS_DIR')): | ||
pytest.skip("Could not find $SUBJECTS_DIR") | ||
|
||
# Low-res file that includes the fsaverage surfaces in its bounding box | ||
# We will use it both as a template and a comparison. | ||
test_ribbon = load_resource( | ||
"../interfaces/tests/data/sub-fsaverage_res-4_desc-cropped_ribbon.nii.gz" | ||
) | ||
|
||
gifti_surfaces_wf = init_gifti_surfaces_wf(surfaces=['white', 'pial']) | ||
anat_ribbon_wf = init_anat_ribbon_wf() | ||
anat_ribbon_wf.inputs.inputnode.ref_file = test_ribbon | ||
|
||
gifti_surfaces_wf.inputs.inputnode.subjects_dir = os.getenv('SUBJECTS_DIR') | ||
gifti_surfaces_wf.inputs.inputnode.subject_id = 'fsaverage' | ||
|
||
wf = pe.Workflow(name='test_ribbon_wf', base_dir=tmp_path) | ||
# fmt: off | ||
wf.connect([ | ||
(gifti_surfaces_wf, anat_ribbon_wf, [ | ||
('outputnode.white', 'inputnode.white'), | ||
('outputnode.pial', 'inputnode.pial'), | ||
]), | ||
]) | ||
# fmt: on | ||
result = wf.run() | ||
|
||
make_ribbon = next(node for node in result.nodes() if node.name == 'make_ribbon') | ||
|
||
expected = nb.load(test_ribbon) | ||
ribbon = nb.load(make_ribbon.result.outputs.ribbon) | ||
|
||
assert ribbon.shape == expected.shape | ||
assert np.allclose(ribbon.affine, expected.affine) | ||
# Mask data is binary, so we can use np.array_equal | ||
assert np.array_equal(ribbon.dataobj, expected.dataobj) |