Skip to content

Commit b8ee572

Browse files
authored
clean HEAD
1 parent 57c64f5 commit b8ee572

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 10 20 30 40 50 60 70 80 90 100 120 140 160 180 200 10 20 30 40 50 60 70 80 90 100 120 140 160 180 200
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.471 0.666 0.816 0.942 1.054 1.154 1.247 1.333 1.414 1.490 1.632 1.763 1.885 1.999 2.107
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 10 20 30 40 80 110 140 170 200 300 400 500 600 700 800 900

tests/IVIMmodels/data/__init__.py

Whitespace-only changes.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import numpy as np
2+
import numpy.testing as npt
3+
import pytest
4+
#import torch
5+
6+
from utilities.data_simulation.GenerateData import GenerateData
7+
8+
#run using python -m pytest from the root folder
9+
10+
test_monoexponential_data = [
11+
pytest.param(0, np.linspace(0, 1000, 11), id='0'),
12+
pytest.param(0.1, np.linspace(0, 1000, 11), id='0.1'),
13+
pytest.param(0.2, np.linspace(0, 1000, 11), id='0.2'),
14+
pytest.param(0.3, np.linspace(0, 1000, 11), id='0.3'),
15+
pytest.param(0.4, np.linspace(0, 1000, 11), id='0.4'),
16+
pytest.param(0.5, np.linspace(0, 1000, 11), id='0.5'),
17+
pytest.param(0.8, np.linspace(0, 1000, 11), id='0.8'),
18+
pytest.param(1, np.linspace(0, 1000, 11), id='1'),
19+
]
20+
@pytest.mark.parametrize("D, bvals", test_monoexponential_data)
21+
def test_monoexponential(D, bvals):
22+
gd = GenerateData()
23+
gd_signal = gd.exponential_signal(D, bvals)
24+
testing_signal = np.exp(-D * np.asarray(bvals, dtype='float64'))
25+
npt.assert_allclose(gd_signal, testing_signal)
26+
assert(gd_signal[0] >= testing_signal[0])
27+
28+
test_ivim_data = [
29+
pytest.param(0.01, 0.0, 1, 1, np.linspace(0, 1000, 11), None, False),
30+
pytest.param(0.01, 0.1, 0.05, 1, np.linspace(0, 1000, 11), None, False),
31+
pytest.param(0.05, 0.2, 0.1, 1, np.linspace(0, 800, 11), None, False),
32+
pytest.param(0.04, 0.15, 0.25, 1.5, np.linspace(0, 1000, 2), 10, True),
33+
pytest.param(0.1, 0.5, 0.5, 0.5, np.linspace(0, 1500, 5), 100, True),
34+
pytest.param(0.01, 0.2, 0.1, 1, np.linspace(10, 1500, 11), 100, False),
35+
pytest.param(0.1, 0.15, 0.05, 1, np.linspace(10, 1000, 8), 5, False)
36+
]
37+
@pytest.mark.parametrize('D, Dp, f, S0, bvals, snr, rician_noise', test_ivim_data)
38+
def test_ivim(D, Dp, f, S0, bvals, snr, rician_noise):
39+
gd = GenerateData()
40+
gd_signal = gd.ivim_signal(D, Dp, f, S0, bvals, snr, rician_noise)
41+
testing_signal = S0 * ((1 - f) * np.exp(-D * bvals) + f * np.exp(-Dp * bvals))
42+
atol = 0.0
43+
if snr is not None:
44+
atol = 4 / snr
45+
npt.assert_allclose(gd_signal, testing_signal, atol=atol)
46+
47+
48+
test_linear_data = [
49+
pytest.param(0, np.linspace(0, 1000, 11), 0, id='0'),
50+
pytest.param(0.1, np.linspace(0, 1000, 11), 10, id='0.1'),
51+
pytest.param(0.2, np.linspace(0, 1000, 11), -10, id='0.2'),
52+
pytest.param(0.3, np.linspace(0, 1000, 11), 0, id='0.3'),
53+
pytest.param(0.4, np.linspace(0, 1000, 11), 0, id='0.4'),
54+
pytest.param(0.5, np.linspace(0, 1000, 11), 0, id='0.5'),
55+
pytest.param(0.8, np.linspace(0, 1000, 11), 0, id='0.8'),
56+
pytest.param(1, np.linspace(0, 1000, 11), 0, id='1'),
57+
]
58+
@pytest.mark.parametrize("D, bvals, offset", test_linear_data)
59+
def test_linear(D, bvals, offset):
60+
gd = GenerateData()
61+
gd_signal = gd.linear_signal(D, bvals, offset)
62+
testing_signal = -D * np.asarray(bvals, dtype='float64')
63+
testing_signal += offset
64+
npt.assert_allclose(gd_signal, testing_signal)
65+
assert(gd_signal[0] >= testing_signal[0])
66+
67+
gd_exponential = gd.exponential_signal(D, bvals)
68+
gd_log_exponential = np.log(gd_exponential) + offset
69+
real_mask = np.isfinite(gd_log_exponential)
70+
71+
npt.assert_allclose(gd_log_exponential[real_mask], gd_signal[real_mask])

0 commit comments

Comments
 (0)