Skip to content

Commit 64b2b68

Browse files
committed
Add tests from httomolib-data
1 parent f2d3075 commit 64b2b68

File tree

4 files changed

+141
-1
lines changed

4 files changed

+141
-1
lines changed

.github/workflows/httomolibgpu_tests_run_iris.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ jobs:
4545
pip install .[dev]
4646
micromamba list
4747
48-
- name: Run tests
48+
- name: Run unit tests on small data
4949
run: |
5050
pytest tests/
51+
52+
- name: Run Zenodo tests
53+
run: |
54+
pytest zenodo-tests/

zenodo-tests/conftest.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import os
2+
import cupy as cp
3+
import numpy as np
4+
import pytest
5+
6+
CUR_DIR = os.path.abspath(os.path.dirname(__file__))
7+
8+
9+
@pytest.fixture(scope="session")
10+
def test_data_path():
11+
return os.path.join(CUR_DIR, "large_data_archive")
12+
13+
14+
@pytest.fixture(scope="session")
15+
def data_i12LFOV_file(test_data_path):
16+
in_file = os.path.join(test_data_path, "i12LFOV.npz")
17+
return np.load(in_file)
18+
19+
20+
@pytest.fixture(scope="session")
21+
def data_i12_sandstone_file(test_data_path):
22+
in_file = os.path.join(test_data_path, "i12_sandstone_50sinoslices.npz")
23+
return np.load(in_file)
24+
25+
26+
@pytest.fixture(scope="session")
27+
def data_geant4sim_file(test_data_path):
28+
in_file = os.path.join(test_data_path, "geant4_640_540_proj360.npz")
29+
return np.load(in_file)
30+
31+
@pytest.fixture
32+
def i12LFOV_data(data_i12LFOV_file):
33+
return (
34+
cp.asarray(data_i12LFOV_file["projdata"]),
35+
data_i12LFOV_file["angles"],
36+
cp.asarray(data_i12LFOV_file["flats"]),
37+
cp.asarray(data_i12LFOV_file["darks"]),
38+
)
39+
40+
41+
@pytest.fixture
42+
def i12sandstone_data(data_i12_sandstone_file):
43+
return (
44+
cp.asarray(data_i12_sandstone_file["projdata"]),
45+
data_i12_sandstone_file["angles"],
46+
cp.asarray(data_i12_sandstone_file["flats"]),
47+
cp.asarray(data_i12_sandstone_file["darks"]),
48+
)
49+
50+
51+
@pytest.fixture
52+
def geantsim_data(data_geant4sim_file):
53+
return (
54+
cp.asarray(data_geant4sim_file["projdata"]),
55+
data_geant4sim_file["angles"],
56+
cp.asarray(data_geant4sim_file["flats"]),
57+
cp.asarray(data_geant4sim_file["darks"]),
58+
)
59+
60+
61+
@pytest.fixture
62+
def ensure_clean_memory():
63+
cp.get_default_memory_pool().free_all_blocks()
64+
cp.get_default_pinned_memory_pool().free_all_blocks()
65+
yield None
66+
cp.get_default_memory_pool().free_all_blocks()
67+
cp.get_default_pinned_memory_pool().free_all_blocks()

zenodo-tests/test_recon/__init__.py

Whitespace-only changes.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import cupy as cp
2+
import numpy as np
3+
import pytest
4+
5+
from httomolibgpu.prep.normalize import normalize
6+
from httomolibgpu.recon.rotation import find_center_vo
7+
8+
9+
def test_center_vo_i12LFOV(i12LFOV_data, ensure_clean_memory):
10+
projdata = i12LFOV_data[0]
11+
flats = i12LFOV_data[2]
12+
darks = i12LFOV_data[3]
13+
del i12LFOV_data
14+
15+
data_normalised = normalize(projdata, flats, darks, minus_log=False)
16+
del flats, darks, projdata
17+
18+
mid_slice = data_normalised.shape[1] // 2
19+
cor = find_center_vo(data_normalised[:, mid_slice, :])
20+
21+
assert cor == 1197.75
22+
assert cor.dtype == np.float32
23+
24+
25+
def test_center_vo_average_i12LFOV(i12LFOV_data, ensure_clean_memory):
26+
projdata = i12LFOV_data[0]
27+
flats = i12LFOV_data[2]
28+
darks = i12LFOV_data[3]
29+
del i12LFOV_data
30+
31+
data_normalised = normalize(projdata, flats, darks, minus_log=False)
32+
del flats, darks, projdata
33+
34+
cor = find_center_vo(data_normalised[:, 10:25, :], average_radius=5)
35+
36+
assert cor == 1199.25
37+
assert cor.dtype == np.float32
38+
39+
40+
def test_center_vo_i12_sandstone(i12sandstone_data, ensure_clean_memory):
41+
projdata = i12sandstone_data[0]
42+
flats = i12sandstone_data[2]
43+
darks = i12sandstone_data[3]
44+
del i12sandstone_data
45+
46+
data_normalised = normalize(projdata, flats, darks, minus_log=True)
47+
del flats, darks, projdata
48+
49+
mid_slice = data_normalised.shape[1] // 2
50+
cor = find_center_vo(data_normalised[:, mid_slice, :])
51+
52+
assert cor == 1253.75
53+
assert cor.dtype == np.float32
54+
55+
56+
def test_center_vo_i12_geantsim(geantsim_data, ensure_clean_memory):
57+
projdata = geantsim_data[0]
58+
flats = geantsim_data[2]
59+
darks = geantsim_data[3]
60+
del geantsim_data
61+
62+
data_normalised = normalize(projdata, flats, darks, minus_log=True)
63+
del flats, darks, projdata
64+
65+
mid_slice = data_normalised.shape[1] // 2
66+
cor = find_center_vo(data_normalised[:, mid_slice, :])
67+
68+
assert cor == 319.5
69+
assert cor.dtype == np.float32

0 commit comments

Comments
 (0)