Skip to content

Commit

Permalink
Edits as per ST suggestions
Browse files Browse the repository at this point in the history
1) New line in _tissue.py to enable proper rendering of example
2) Added space between number and units
3) Warnings for Ktrans=0 and ve=0 removed to avoid warnings during fitting
) Extended_Tofts case for Ktrans or ve =0 changed to correct value (ca*vp) including tests
  • Loading branch information
LucyKershaw committed Feb 16, 2024
1 parent e9d27b3 commit 5ce3ba6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified src/.DS_Store
Binary file not shown.
10 changes: 6 additions & 4 deletions src/osipi/_tissue.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def tofts(t: np.ndarray, ca: np.ndarray, Ktrans: float, ve: float, Ta: float = 3
>>> ca = osipi.aif_parker(t)
Calculate tissue concentrations and plot:
>>> Ktrans = 0.6 # in units of 1/min
>>> ve = 0.2 # takes values from 0 to 1
>>> ct = osipi.tofts(t, ca, Ktrans, ve)
Expand All @@ -60,7 +61,7 @@ def tofts(t: np.ndarray, ca: np.ndarray, Ktrans: float, ve: float, Ta: float = 3

if Ktrans <= 0 or ve <= 0:
ct = 0 * ca
warnings.warn('Tissue concentration will be set to zero if Ktrans or ve are less than or equal to zero.', stacklevel=2)

else:
# Convert units
Ktrans = Ktrans/60 # from 1/min to 1/sec
Expand Down Expand Up @@ -144,7 +145,7 @@ def extended_tofts(t: np.ndarray, ca: np.ndarray, Ktrans: float, ve: float, vp:
Example:
Create an array of time points covering 6min in steps of 1sec, calculate the Parker AIF at these time points, calculate tissue concentrations
Create an array of time points covering 6 min in steps of 1 sec, calculate the Parker AIF at these time points, calculate tissue concentrations
using the Extended Tofts model and plot the results.
Import packages:
Expand All @@ -158,6 +159,7 @@ def extended_tofts(t: np.ndarray, ca: np.ndarray, Ktrans: float, ve: float, vp:
>>> ca = osipi.aif_parker(t)
Calculate tissue concentrations and plot
>>> Ktrans = 0.6 # in units of 1/min
>>> ve = 0.2 # takes values from 0 to 1
>>> vp = 0.3 # takes values from 0 to 1
Expand All @@ -169,8 +171,8 @@ def extended_tofts(t: np.ndarray, ca: np.ndarray, Ktrans: float, ve: float, vp:
warnings.warn('Non-uniform time spacing detected. Time array may be resampled.', stacklevel=2)

if Ktrans <= 0 or ve <= 0:
ct = 0 * ca
warnings.warn('Tissue concentration will be set to zero if Ktrans or ve are less than or equal to zero.', stacklevel=2)
ct = vp * ca

else:
# Convert units
Ktrans = Ktrans/60 # from 1/min to 1/sec
Expand Down
8 changes: 4 additions & 4 deletions tests/test_tissue.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ def test_tissue_extended_tofts():
t = np.arange(0, 6 * 60, 1)
ca = osipi.aif_parker(t)
ct_conv = osipi.extended_tofts(t, ca, Ktrans=0, ve=0.2, vp=0.3)
assert np.count_nonzero(ct_conv) == 0
assert math.allclose(ct_conv,ca*0.3,rtol=1e-4, atol=1e-3)

ct_exp = osipi.extended_tofts(t, ca, Ktrans=0, ve=0.2, vp=0.3, discretization_method='exp')
assert np.count_nonzero(ct_exp) == 0
assert math.allclose(ct_conv,ca*0.3,rtol=1e-4, atol=1e-3)

ct_conv = osipi.extended_tofts(t, ca, Ktrans=0.6, ve=0, vp=0.3)
assert np.count_nonzero(ct_conv) == 0
assert math.allclose(ct_conv,ca*0.3,rtol=1e-4, atol=1e-3)

ct_exp = osipi.extended_tofts(t, ca, Ktrans=0.6, ve=0, vp=0.3, discretization_method='exp')
assert np.count_nonzero(ct_exp) == 0
assert math.allclose(ct_conv,ca*0.3,rtol=1e-4, atol=1e-3)


if __name__ == "__main__":
Expand Down

0 comments on commit 5ce3ba6

Please sign in to comment.