-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_projdata_profiles.py
More file actions
79 lines (75 loc) · 2.72 KB
/
test_projdata_profiles.py
File metadata and controls
79 lines (75 loc) · 2.72 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
import numpy as np
import pytest
from examples.python.plot_projdata_profiles import compress_and_extract_1d_from_nd_array
def test_generate_1d_from_4d():
"""
Test the generation of a 1D array from a 4D array.
Primarily, this is a test of compress_and_extract_1d_from_nd_array that is used in plot_sinogram_profiles script.
Given a 4D array, the function should compress the array to a 1D array based on the configuration provided.
"""
np_4d = np.random.rand(2, 3, 4, 5)
configs = [
{
"display_axis": 0,
"projdata_indices": [None, None, None, None],
"result_shape": (np_4d.shape[0],),
"result_sum": np_4d.sum()
},
{
"display_axis": 1,
"projdata_indices": [None, None, None, None],
"result_shape": (np_4d.shape[1],),
"result_sum": np_4d.sum()
},
{
"display_axis": 2,
"projdata_indices": [None, None, None, None],
"result_shape": (np_4d.shape[2],),
"result_sum": np_4d.sum()
},
{
"display_axis": 3,
"projdata_indices": [None, None, None, None],
"result_shape": (np_4d.shape[3],),
"result_sum": np_4d.sum()
},
# Extracting a single value from certain dimensions
# in some cases add an index in the display axis dimension to be ignored.
{
"display_axis": 0,
"projdata_indices": [0, None, None, None],
"result_shape": (np_4d.shape[0],),
"result_sum": None
},
{
"display_axis": 0,
"projdata_indices": [0, 1, None, None],
"result_shape": (np_4d.shape[0],),
"result_sum": None
},
{
"display_axis": 1,
"projdata_indices": [None, 1, None, None],
"result_shape": (np_4d.shape[1],),
"result_sum": None
},
{
"display_axis": 2,
"projdata_indices": [None, None, 1, None],
"result_shape": (np_4d.shape[2],),
"result_sum": None
},
{
"display_axis": 3,
"projdata_indices": [None, None, None, 1],
"result_shape": (np_4d.shape[3],),
"result_sum": None
},
]
for config in configs:
result = compress_and_extract_1d_from_nd_array(np_4d,
config["display_axis"],
config["projdata_indices"])
assert result.shape == config["result_shape"]
if config["result_sum"] is not None:
pytest.approx(result.sum(), config["result_sum"], 1e-6)