Skip to content

Commit 0c76e4e

Browse files
committed
Add tests for different surface types.
1 parent 830201c commit 0c76e4e

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

tests/test_surf_types.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import os
2+
import numpy as np
3+
import importlib.util
4+
from brainplotlib import brain_plot
5+
6+
7+
class TestSurfaceTypes:
8+
def test_inflated_surface(self, tmp_path):
9+
rng = np.random.default_rng()
10+
values = rng.random((588, )), rng.random((587, ))
11+
img, scale = brain_plot(*values, vmax=1, vmin=0, cmap='viridis', return_scale=True, surf_type='inflated')
12+
from matplotlib import cm
13+
assert isinstance(scale, cm.ScalarMappable)
14+
assert img.shape in [(1560, 1728, 4), (1560, 1728, 3)]
15+
assert img.dtype == np.float64
16+
assert np.all(img <= 1)
17+
assert np.all(img >= 0)
18+
if importlib.util.find_spec('cv2'):
19+
import cv2
20+
cv2.imwrite(os.path.join(tmp_path, 'test_inflated.png'), np.round(img * 255).astype(np.uint8)[:, :, [2, 1, 0, 3]])
21+
22+
def test_pial_surface(self, tmp_path):
23+
rng = np.random.default_rng()
24+
values = rng.random((588, )), rng.random((587, ))
25+
img, scale = brain_plot(*values, vmax=1, vmin=0, cmap='viridis', return_scale=True, surf_type='pial')
26+
from matplotlib import cm
27+
assert isinstance(scale, cm.ScalarMappable)
28+
assert img.shape in [(1560, 1728, 4), (1560, 1728, 3)]
29+
assert img.dtype == np.float64
30+
assert np.all(img <= 1)
31+
assert np.all(img >= 0)
32+
if importlib.util.find_spec('cv2'):
33+
import cv2
34+
cv2.imwrite(os.path.join(tmp_path, 'test_pial.png'), np.round(img * 255).astype(np.uint8)[:, :, [2, 1, 0, 3]])
35+
36+
def test_midthickness_surface(self, tmp_path):
37+
rng = np.random.default_rng()
38+
values = rng.random((588, )), rng.random((587, ))
39+
img, scale = brain_plot(*values, vmax=1, vmin=0, cmap='viridis', return_scale=True, surf_type='midthickness')
40+
from matplotlib import cm
41+
assert isinstance(scale, cm.ScalarMappable)
42+
assert img.shape in [(1560, 1728, 4), (1560, 1728, 3)]
43+
assert img.dtype == np.float64
44+
assert np.all(img <= 1)
45+
assert np.all(img >= 0)
46+
if importlib.util.find_spec('cv2'):
47+
import cv2
48+
cv2.imwrite(os.path.join(tmp_path, 'test_midthickness.png'), np.round(img * 255).astype(np.uint8)[:, :, [2, 1, 0, 3]])
49+
50+
def test_white_surface(self, tmp_path):
51+
rng = np.random.default_rng()
52+
values = rng.random((588, )), rng.random((587, ))
53+
img, scale = brain_plot(*values, vmax=1, vmin=0, cmap='viridis', return_scale=True, surf_type='white')
54+
from matplotlib import cm
55+
assert isinstance(scale, cm.ScalarMappable)
56+
assert img.shape in [(1560, 1728, 4), (1560, 1728, 3)]
57+
assert img.dtype == np.float64
58+
assert np.all(img <= 1)
59+
assert np.all(img >= 0)
60+
if importlib.util.find_spec('cv2'):
61+
import cv2
62+
cv2.imwrite(os.path.join(tmp_path, 'test_white.png'), np.round(img * 255).astype(np.uint8)[:, :, [2, 1, 0, 3]])

0 commit comments

Comments
 (0)