Skip to content

Commit b2c3eb6

Browse files
committed
TST: Add CIFTI test
1 parent 633d141 commit b2c3eb6

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import json
2+
from pathlib import Path
3+
4+
import nibabel as nb
5+
import numpy as np
6+
import pytest
7+
8+
from ..cifti import GenerateCifti, CIFTI_STRUCT_WITH_LABELS
9+
10+
11+
@pytest.fixture(scope="module")
12+
def cifti_data():
13+
out = Path().absolute()
14+
volume_file = str(out / "volume.nii.gz")
15+
left_gii = str(out / "left.gii")
16+
right_gii = str(out / "right.gii")
17+
surface_data = [nb.gifti.GiftiDataArray(np.ones(32492)) for _ in range(4)]
18+
vol = nb.Nifti1Image(np.ones((91, 109, 91, 4)), np.eye(4))
19+
gii = nb.GiftiImage(darrays=surface_data)
20+
21+
vol.to_filename(volume_file)
22+
gii.to_filename(left_gii)
23+
gii.to_filename(right_gii)
24+
yield volume_file, left_gii, right_gii
25+
for f in (volume_file, left_gii, right_gii):
26+
Path(f).unlink()
27+
28+
29+
def test_GenerateCifti(tmpdir, cifti_data):
30+
tmpdir.chdir()
31+
32+
bold_volume = cifti_data[0]
33+
bold_surfaces = list(cifti_data[1:])
34+
35+
gen = GenerateCifti(
36+
bold_file=bold_volume,
37+
surface_bolds=bold_surfaces,
38+
surface_density='32k',
39+
TR=1,
40+
)
41+
res = gen.run().outputs
42+
43+
cifti = nb.load(res.out_file)
44+
assert cifti.shape == (4, 91282)
45+
matrix = cifti.header.matrix
46+
assert matrix.mapped_indices == [0, 1]
47+
series_map = matrix.get_index_map(0)
48+
bm_map = matrix.get_index_map(1)
49+
assert series_map.indices_map_to_data_type == 'CIFTI_INDEX_TYPE_SERIES'
50+
assert bm_map.indices_map_to_data_type == 'CIFTI_INDEX_TYPE_BRAIN_MODELS'
51+
assert len(list(bm_map.brain_models)) == len(CIFTI_STRUCT_WITH_LABELS)
52+
53+
metadata = json.loads(Path(res.out_metadata).read_text())
54+
assert 'Density' in metadata
55+
assert 'SpatialReference' in metadata
56+
for key in ('VolumeReference', 'CIFTI_STRUCTURE_LEFT_CORTEX', 'CIFTI_STRUCTURE_RIGHT_CORTEX'):
57+
assert key in metadata['SpatialReference']

0 commit comments

Comments
 (0)