|
1 | 1 | """Test vector utilities."""
|
2 | 2 | import pytest
|
3 | 3 | import numpy as np
|
| 4 | +import nibabel as nb |
4 | 5 | from dmriprep.utils import vectors as v
|
5 | 6 | from collections import namedtuple
|
6 | 7 |
|
@@ -100,3 +101,25 @@ def mock_func(*args, **kwargs):
|
100 | 101 | # Miscellaneous tests
|
101 | 102 | with pytest.raises(ValueError):
|
102 | 103 | dgt.to_filename("path", filetype="mrtrix")
|
| 104 | + |
| 105 | + |
| 106 | +def test_b0mask_from_data(tmp_path): |
| 107 | + """Check the estimation of bzeros using the dwi data.""" |
| 108 | + |
| 109 | + highb = np.random.normal(100, 5, size=(40, 40, 40, 99)) |
| 110 | + mask_file = tmp_path / 'mask.nii.gz' |
| 111 | + |
| 112 | + # Test 1: no lowb |
| 113 | + dwi_file = tmp_path / 'only_highb.nii.gz' |
| 114 | + nb.Nifti1Image(highb.astype(float), np.eye(4), None).to_filename(dwi_file) |
| 115 | + nb.Nifti1Image(np.ones((40, 40, 40), dtype=np.uint8), |
| 116 | + np.eye(4), None).to_filename(mask_file) |
| 117 | + |
| 118 | + assert v.b0mask_from_data(dwi_file, mask_file).sum() == 0 |
| 119 | + |
| 120 | + # Test 1: one lowb |
| 121 | + lowb = np.random.normal(400, 50, size=(40, 40, 40, 1)) |
| 122 | + dwi_file = tmp_path / 'dwi.nii.gz' |
| 123 | + nb.Nifti1Image(np.concatenate((lowb, highb), axis=3).astype(float), |
| 124 | + np.eye(4), None).to_filename(dwi_file) |
| 125 | + assert v.b0mask_from_data(dwi_file, mask_file).sum() == 1 |
0 commit comments