From f14d269bcf8ff0ac088f566508cfa859a6c145c2 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Wed, 27 Nov 2019 15:17:58 -0500 Subject: [PATCH] TEST: Smoke-test FSInjectBrainExtracted interface --- .../interfaces/tests/test_freesurfer.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 niworkflows/interfaces/tests/test_freesurfer.py diff --git a/niworkflows/interfaces/tests/test_freesurfer.py b/niworkflows/interfaces/tests/test_freesurfer.py new file mode 100644 index 00000000000..dee6ad284b5 --- /dev/null +++ b/niworkflows/interfaces/tests/test_freesurfer.py @@ -0,0 +1,30 @@ +from pathlib import Path +import numpy as np +import nibabel as nb +from ..freesurfer import FSInjectBrainExtracted + + +def test_inject_skullstrip(tmp_path): + t1_mgz = tmp_path / 'sub-01' / 'mri' / 'T1.mgz' + t1_mgz.parent.mkdir(parents=True) + # T1.mgz images are uint8 + nb.MGHImage(np.ones((5,5,5), dtype=np.uint8), np.eye(4)).to_filename(str(t1_mgz)) + + mask_nii = tmp_path / 'mask.nii.gz' + # Masks may be in a different space (and need resampling), but should be boolean, + # or uint8 in NIfTI + nb.Nifti1Image(np.ones((6,6,6), dtype=np.uint8), + np.eye(4)).to_filename(str(mask_nii)) + + res = FSInjectBrainExtracted(subjects_dir=str(tmp_path), + subject_id='sub-01', + in_brain=str(mask_nii)).run() + + assert Path.exists(tmp_path / 'sub-01' / 'mri' / 'brainmask.auto.mgz') + assert Path.exists(tmp_path / 'sub-01' / 'mri' / 'brainmask.mgz') + + # Run a second time to hit "already exists" condition + res = FSInjectBrainExtracted(subjects_dir=str(tmp_path), + subject_id='sub-01', + in_brain=str(mask_nii)).run() +