-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_plotting.py
More file actions
140 lines (126 loc) · 6.28 KB
/
test_plotting.py
File metadata and controls
140 lines (126 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import os
import numpy as np
import importlib.util
from brainplotlib import brain_plot
class TestPlotting:
def test_icoorder5_masked(self, tmp_path):
values = np.arange(9372), np.arange(9370)
img = brain_plot(*values, vmax=18741, vmin=0, cmap=None)
assert img.shape in [(1560, 1728, 4), (1560, 1728, 3)]
assert img.dtype == np.float64
assert np.all(img <= 1)
assert np.all(img >= 0)
if importlib.util.find_spec('cv2'):
import cv2
cv2.imwrite(os.path.join(tmp_path, 'test_icoorder5_masked.png'), np.round(img * 255).astype(np.uint8)[:, :, [2, 1, 0, 3]])
def test_icoorder5_masked_random(self, tmp_path):
rng = np.random.default_rng()
values = rng.random((9372, )), rng.random((9370, ))
img = brain_plot(*values, vmax=1, vmin=0, cmap=None)
assert img.shape in [(1560, 1728, 4), (1560, 1728, 3)]
assert img.dtype == np.float64
assert np.all(img <= 1)
assert np.all(img >= 0)
if importlib.util.find_spec('cv2'):
import cv2
cv2.imwrite(os.path.join(tmp_path, 'test_icoorder5_masked_random.png'), np.round(img * 255).astype(np.uint8)[:, :, [2, 1, 0, 3]])
def test_icoorder5_nonmasked(self, tmp_path):
values = np.arange(10242), np.arange(10242)
img = brain_plot(*values, vmax=20483, vmin=0, cmap=None)
assert img.shape in [(1560, 1728, 4), (1560, 1728, 3)]
assert img.dtype == np.float64
assert np.all(img <= 1)
assert np.all(img >= 0)
if importlib.util.find_spec('cv2'):
import cv2
cv2.imwrite(os.path.join(tmp_path, 'test_icoorder5_nonmasked.png'), np.round(img * 255).astype(np.uint8)[:, :, [2, 1, 0, 3]])
def test_icoorder5_nonmasked_random(self, tmp_path):
rng = np.random.default_rng()
values = rng.random((10242, )), rng.random((10242, ))
img = brain_plot(*values, vmax=1, vmin=0, cmap=None)
assert img.shape in [(1560, 1728, 4), (1560, 1728, 3)]
assert img.dtype == np.float64
assert np.all(img <= 1)
assert np.all(img >= 0)
if importlib.util.find_spec('cv2'):
import cv2
cv2.imwrite(os.path.join(tmp_path, 'test_icoorder5_nonmasked_random.png'), np.round(img * 255).astype(np.uint8)[:, :, [2, 1, 0, 3]])
def test_icoorder3_masked(self, tmp_path):
values = np.arange(588), np.arange(587)
img = brain_plot(*values, vmax=1174, vmin=0, cmap=None)
assert img.shape in [(1560, 1728, 4), (1560, 1728, 3)]
assert img.dtype == np.float64
assert np.all(img <= 1)
assert np.all(img >= 0)
if importlib.util.find_spec('cv2'):
import cv2
cv2.imwrite(os.path.join(tmp_path, 'test_icoorder3_masked.png'), np.round(img * 255).astype(np.uint8)[:, :, [2, 1, 0, 3]])
def test_icoorder3_masked_random(self, tmp_path):
rng = np.random.default_rng()
values = rng.random((588, )), rng.random((587, ))
img = brain_plot(*values, vmax=1, vmin=0, cmap=None)
assert img.shape in [(1560, 1728, 4), (1560, 1728, 3)]
assert img.dtype == np.float64
assert np.all(img <= 1)
assert np.all(img >= 0)
if importlib.util.find_spec('cv2'):
import cv2
cv2.imwrite(os.path.join(tmp_path, 'test_icoorder3_masked_random.png'), np.round(img * 255).astype(np.uint8)[:, :, [2, 1, 0, 3]])
def test_icoorder3_nonmasked(self, tmp_path):
values = np.arange(642), np.arange(642)
img = brain_plot(*values, vmax=1283, vmin=0, cmap=None)
assert img.shape in [(1560, 1728, 4), (1560, 1728, 3)]
assert img.dtype == np.float64
assert np.all(img <= 1)
assert np.all(img >= 0)
if importlib.util.find_spec('cv2'):
import cv2
cv2.imwrite(os.path.join(tmp_path, 'test_icoorder3_nonmasked.png'), np.round(img * 255).astype(np.uint8)[:, :, [2, 1, 0, 3]])
def test_icoorder3_nonmasked(self, tmp_path):
rng = np.random.default_rng()
values = rng.random((642, )), rng.random((642, ))
img = brain_plot(*values, vmax=1, vmin=0, cmap=None)
assert img.shape in [(1560, 1728, 4), (1560, 1728, 3)]
assert img.dtype == np.float64
assert np.all(img <= 1)
assert np.all(img >= 0)
if importlib.util.find_spec('cv2'):
import cv2
cv2.imwrite(os.path.join(tmp_path, 'test_icoorder3_nonmasked_random.png'), np.round(img * 255).astype(np.uint8)[:, :, [2, 1, 0, 3]])
class TestColormaps:
def test_bwr_cmap(self, tmp_path):
rng = np.random.default_rng()
values = rng.random((588, )), rng.random((587, ))
img = brain_plot(*values, vmax=1, vmin=0, cmap='bwr')
assert img.shape in [(1560, 1728, 4), (1560, 1728, 3)]
assert img.dtype == np.float64
assert np.all(img <= 1)
assert np.all(img >= 0)
if importlib.util.find_spec('cv2'):
import cv2
cv2.imwrite(os.path.join(tmp_path, 'test_bwr_cmap.png'), np.round(img * 255).astype(np.uint8)[:, :, [2, 1, 0, 3]])
def test_jet_cmap(self, tmp_path):
rng = np.random.default_rng()
values = rng.random((588, )), rng.random((587, ))
img = brain_plot(*values, vmax=1, vmin=0, cmap='jet')
assert img.shape in [(1560, 1728, 4), (1560, 1728, 3)]
assert img.dtype == np.float64
assert np.all(img <= 1)
assert np.all(img >= 0)
if importlib.util.find_spec('cv2'):
import cv2
cv2.imwrite(os.path.join(tmp_path, 'test_jet_cmap.png'), np.round(img * 255).astype(np.uint8)[:, :, [2, 1, 0, 3]])
class TestScale:
def test_color_scale(self, tmp_path):
rng = np.random.default_rng()
values = rng.random((588, )), rng.random((587, ))
img, scale = brain_plot(*values, vmax=1, vmin=0, cmap='viridis', return_scale=True)
from matplotlib import cm
assert isinstance(scale, cm.ScalarMappable)
assert img.shape in [(1560, 1728, 4), (1560, 1728, 3)]
assert img.dtype == np.float64
assert np.all(img <= 1)
assert np.all(img >= 0)
if importlib.util.find_spec('cv2'):
import cv2
cv2.imwrite(os.path.join(tmp_path, 'test_colorscale.png'), np.round(img * 255).astype(np.uint8)[:, :, [2, 1, 0, 3]])