Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedNasser8 committed Sep 1, 2024
1 parent 5216dad commit 1a91070
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/osipi/_tissue.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def two_cxm(
# Convolve impulse response with AIF
convolution = np.convolve(ca, imp) * t[1]

ct = Fp * convolution
ct = Fp * convolution[0 : len(t)]

else:
# Resample at the smallest spacing
Expand Down
20 changes: 20 additions & 0 deletions tests/test_tissue.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,31 @@ def test_tissue_extended_tofts():


def test_tissue_2compartment_model():
# 1. Basic operation of the function - test that the peak tissue
t = np.arange(0, 6 * 60, 1, dtype=float)
ca = osipi.aif_parker(t)
ct = osipi.two_cxm(t, ca, E=0.15, Fp=0.2, Ve=0.2, Vp=0.3)
assert np.round(np.max(ct)) < np.round(np.max(ca))

# 2. Basic operation of the function - test with non-uniform spacing of
t = np.geomspace(1, 6 * 60 + 1, num=360) - 1
ca = osipi.aif_parker(t)
ct = osipi.two_cxm(t, ca, E=0.15, Fp=0.2, Ve=0.2, Vp=0.3)
assert np.round(np.max(ct)) < np.round(np.max(ca))

# 3. The offset option - test that the tissue concentration is shifted
t = np.arange(0, 6 * 60, 1)
ca = osipi.aif_parker(t)
ct = osipi.two_cxm(t, ca, E=0.15, Fp=0.2, Ve=0.2, Vp=0.3, Ta=60.0)
assert (np.min(np.where(ct > 0.0)) - np.min(np.where(ca > 0.0)) - 1) * 1 == 60.0

# 4. Test that the area under the ct curve is approximately the sum of
# the extracellular volume and the plasma volume
t = np.arange(0, 6 * 60, 1)
ca = osipi.aif_parker(t)
ct = osipi.two_cxm(t, ca, E=0.15, Fp=0.2, Ve=0.2, Vp=0.3)
assert math.isclose(np.trapz(ct, t)/np.trapz(ca, t), 0.2 + 0.3, abs_tol=1e-1)


if __name__ == "__main__":
test_tissue_tofts()
Expand Down

0 comments on commit 1a91070

Please sign in to comment.