1
1
import numpy as np
2
2
import numpy .typing as npt
3
3
4
- def seg (Y : npt . NDArray [ np . float64 ] , b : npt . NDArray [ np . float64 ] , bthr : float = 200 , verbose : bool = False ) -> dict :
4
+ def seg (Y , b , bthr = 200 , verbose = False ):
5
5
"""
6
6
Segmented fitting of the IVIM model.
7
7
@@ -12,7 +12,7 @@ def seg(Y: npt.NDArray[np.float64], b: npt.NDArray[np.float64], bthr: float = 20
12
12
verbose: (optional) if True, diagnostics during fitting is printet to terminal
13
13
"""
14
14
15
- def valid_signal (Y : npt . NDArray [ np . float64 ]) -> npt . NDArray [ np . float64 ] :
15
+ def valid_signal (Y ) :
16
16
"""
17
17
Return a mask representing all rows in Y with valid values (not non-positive, NaN or infinite).
18
18
@@ -26,7 +26,7 @@ def valid_signal(Y: npt.NDArray[np.float64]) -> npt.NDArray[np.float64]:
26
26
mask = ~ np .any ((Y <= 0 ) | np .isnan (Y ) | np .isinf (Y ), axis = 1 )
27
27
return mask
28
28
29
- def monoexp_model (b : npt . NDArray [ np . float64 ] , D : npt . NDArray [ np . float64 ]) -> npt . NDArray [ np . float64 ] :
29
+ def monoexp_model (b , D ) :
30
30
"""
31
31
Return the monoexponential e^(-b*D).
32
32
@@ -43,7 +43,7 @@ def monoexp_model(b: npt.NDArray[np.float64], D: npt.NDArray[np.float64]) -> npt
43
43
return np .reshape (S , list (D .shape ) + [b .size ]) # reshape as np.outer flattens D is ndim > 1
44
44
45
45
46
- def _monoexp (Y : npt . NDArray [ np . float64 ] , b : npt . NDArray [ np . float64 ] , lim : list = [0 , 3e-3 ], validate : bool = True , verbose : bool = False ) -> tuple [ npt . NDArray [ np . float64 ], npt . NDArray [ np . float64 ]] :
46
+ def _monoexp (Y , b , lim = [0 , 3e-3 ], validate = True , verbose = False ):
47
47
""" Estimate D and A (y axis intercept) from a monoexponential model. """
48
48
49
49
if validate :
@@ -70,18 +70,13 @@ def _monoexp(Y: npt.NDArray[np.float64], b: npt.NDArray[np.float64], lim: list =
70
70
71
71
return D , A
72
72
73
- def _get_S0 (Y : npt .NDArray [np .float64 ], b : npt .NDArray [np .float64 ]) -> npt .NDArray [np .float64 ]:
74
- """ Return the signal values at b = 0."""
75
- return np .mean (Y [:, b == 0 ], axis = 1 )
76
-
77
-
78
- def _f_from_intercept (A : npt .NDArray [np .float64 ], S0 : npt .NDArray [np .float64 ]) -> npt .NDArray [np .float64 ]:
73
+ def _f_from_intercept (A , S0 ):
79
74
""" Calculate f from S(b=0) and extrapolated y axis intercept A."""
80
75
f = 1 - A / S0
81
76
f [f < 0 ] = 0
82
77
return f
83
78
84
- def _optimizeD (Y : npt . NDArray [ np . float64 ] , b : npt . NDArray [ np . float64 ] , lim : list , optlim : float = 1e-6 , disp_prog : bool = False ) -> tuple [ npt . NDArray [ np . float64 ], npt . NDArray [ np . float64 ]] :
79
+ def _optimizeD (Y , b , lim , optlim = 1e-6 , disp_prog = False ):
85
80
""" Specfically tailored function for finding the least squares solution of monoexponenital fit. """
86
81
87
82
n = Y .shape [0 ]
@@ -177,7 +172,7 @@ def _optimizeD(Y: npt.NDArray[np.float64], b: npt.NDArray[np.float64], lim: list
177
172
return D , A
178
173
179
174
180
- def _Ddiff (Y : npt . NDArray [ np . float64 ] , yb : npt . NDArray [ np . float64 ] , b : npt . NDArray [ np . float64 ] , D : npt . NDArray [ np . float64 ] ):
175
+ def _Ddiff (Y , yb , b , D ):
181
176
"""
182
177
Return the difference between q1 = e^(-2*b*D)*yb*e^(-b*D) and
183
178
q2 = Y*e^(-b*D)*b*e^(-2*b*D) summed over b as well as the ratio q1/q2
0 commit comments