Skip to content

Commit ce081da

Browse files
committed
Merge remote-tracking branch 'origin/testing/wrapper' into testing/add_ETP_and_add_configuration
2 parents 719032f + d65aa4d commit ce081da

19 files changed

+139
-91
lines changed

conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ def pytest_addoption(parser):
1313
type=int,
1414
help="Evaluation test SNR",
1515
)
16+
parser.addoption(
17+
"--ricianNoise",
18+
default=False,
19+
type=bool,
20+
help="Use Rician noise, non-rician is gaussian",
21+
)
1622
parser.addoption(
1723
"--algorithmFile",
1824
default="tests/IVIMmodels/unit_tests/algorithms.json",
@@ -100,6 +106,10 @@ def atol(request):
100106
def fit_count(request):
101107
return request.config.getoption("--fitCount")
102108

109+
@pytest.fixture(scope="session")
110+
def rician_noise(request):
111+
return request.config.getoption("--ricianNoise")
112+
103113

104114
def pytest_generate_tests(metafunc):
105115
if "SNR" in metafunc.fixturenames:

doc/code_contributions_record.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ IVIM,Fitting,Variable projection,See referenced article. Supports units in mm2/s
1515
IVIM,Fitting,Linear fit,Linear fit for D with extrapolation for f. Supports units in mm2/s and µm2/ms,IAR_LundUniversity,TF2.4_IVIM-MRI_CodeCollection/src/original/IAR_LundUniversity/ivim_fit_method_modified_linear.py,Modified by Ivan A. Rashid,Lund University,IvimModelLinear,tba,tbd,
1616
IVIM,Fitting,sIVIM fit,NLLS of the simplified IVIM model (sIVIM). Supports units in mm2/s and µm2/ms,IAR_LundUniversity,TF2.4_IVIM-MRI_CodeCollection/src/original/IAR_LundUniversity/ivim_fit_method_modified_sivim.py,Modified by Ivan A. Rashid,Lund University,IvimModelsIVIM,tba,tbd,
1717
IVIM,Fitting,Segmented NLLS fitting,MATLAB code,OJ_GU,TF2.4_IVIM-MRI_CodeCollection/src/original/OJ_GU/,Oscar Jalnefjord,University of Gothenburg,IVIM_seg,https://doi.org/10.1007/s10334-018-0697-5,tbd,
18-
IVIM,Fitting,Bayesian,MATLAB code,OJ_GU,TF2.4_IVIM-MRI_CodeCollection/src/original/OJ_GU/,Oscar Jalnefjord,University of Gothenburg,IVIM_bayes,https://doi.org/10.1002/mrm.26783,tbd,
18+
IVIM,Fitting,Bayesian,MATLAB code,OJ_GU,TF2.4_IVIM-MRI_CodeCollection/src/original/OJ_GU/,Oscar Jalnefjord,University of Gothenburg,IVIM_bayes,https://doi.org/10.1002/mrm.26783,tbd,
19+
IVIM,Fitting,Linear fit,Linear fit for D and D* and f. Intended to be extremely fast but not always accurate,ETP_SRI,TF2.4_IVIM-MRI_CodeCollection/src/original/ETP_SRI/LinearFitting.py,Eric Peterson,SRI International,,,tbd,

src/original/PV_MUMC/two_step_IVIM_fit.py

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -75,45 +75,48 @@ def fit_least_squares(bvalues, dw_data, IR=False, S0_output=False, fitS0=True,
7575
:return Dmv: scalar with Dmv of the specific voxel
7676
"""
7777

78-
try:
79-
def monofit(bvalues, Dpar):
80-
return np.exp(-bvalues * Dpar)
81-
82-
high_b = bvalues[bvalues >= cutoff]
83-
high_dw_data = dw_data[bvalues >= cutoff]
84-
boundspar = ([bounds[0][1]], [bounds[1][1]])
85-
params, _ = curve_fit(monofit, high_b, high_dw_data, p0=[(bounds[1][1]-bounds[0][1])/2], bounds=boundspar)
86-
Dpar1 = params[0]
78+
#try:
79+
def monofit(bvalues, Dpar):
80+
return np.exp(-bvalues * Dpar)
81+
82+
high_b = bvalues[bvalues >= cutoff]
83+
high_dw_data = dw_data[bvalues >= cutoff]
84+
boundspar = ([bounds[0][1]], [bounds[1][1]])
85+
params, _ = curve_fit(monofit, high_b, high_dw_data, p0=[(bounds[1][1]-bounds[0][1])/2], bounds=boundspar)
86+
Dpar = params[0]
8787

88-
if not fitS0:
89-
boundsupdated=([Dpar1 , bounds[0][2] , bounds[0][3] ],
90-
[Dpar1 , bounds[1][2] , bounds[1][3] ])
91-
params, _ = curve_fit(two_exp_noS0, bvalues, dw_data, p0=[Dpar1, (bounds[0][2]+bounds[1][2])/2, (bounds[0][3]+bounds[1][3])/2], bounds=boundsupdated)
92-
Dpar, Fmv, Dmv = params[0], params[1], params[2]
93-
#when the fraction of a compartment equals zero (or very very small), the corresponding diffusivity is non-existing (=NaN)
94-
if Fmv < 1e-4:
95-
Dmv = float("NaN")
88+
if not fitS0:
89+
boundsupdated=([Dpar1 , bounds[0][2] , bounds[0][3] ],
90+
[Dpar1 , bounds[1][2] , bounds[1][3] ])
91+
params, _ = curve_fit(two_exp_noS0, bvalues, dw_data, p0=[Dpar1, (bounds[0][2]+bounds[1][2])/2, (bounds[0][3]+bounds[1][3])/2], bounds=boundsupdated)
92+
Dpar1, Fmv, Dmv = params[0], params[1], params[2]
93+
#when the fraction of a compartment equals zero (or very very small), the corresponding diffusivity is non-existing (=NaN)
94+
if Fmv < 1e-4:
95+
Dmv = float("NaN")
96+
97+
else:
98+
#boundsupdated = ([bounds[0][0] , Dpar1 , bounds[0][2] , bounds[0][3] ],
99+
# [bounds[1][0] , Dpar1, bounds[1][2] , bounds[1][3] ])
100+
#params, _ = curve_fit(two_exp, bvalues, dw_data, p0=[1, Dpar1, (bounds[0][2]+bounds[1][2])/2, (bounds[0][3]+bounds[1][3])/2], bounds=boundsupdated)
101+
boundsupdated = ([bounds[0][0] , bounds[0][2] , bounds[0][3] ],
102+
[bounds[1][0] , bounds[1][2] , bounds[1][3] ])
103+
params, _ = curve_fit(lambda bvalues, S0, Fmv, Dmv: two_exp(bvalues, S0, Dpar, Fmv, Dmv), bvalues, dw_data, p0=[1, (bounds[0][2]+bounds[1][2])/2, (bounds[0][3]+bounds[1][3])/2], bounds=boundsupdated)
104+
S0 = params[0]
105+
Fmv, Dmv = params[1] , params[2]
106+
#when the fraction of a compartment equals zero (or very very small), the corresponding diffusivity is non-existing (=NaN)
107+
if Fmv < 1e-4:
108+
Dmv = float("NaN")
96109

97-
else:
98-
boundsupdated = ([bounds[0][0] , Dpar1 , bounds[0][2] , bounds[0][3] ],
99-
[bounds[1][0] , Dpar1, bounds[1][2] , bounds[1][3] ])
100-
params, _ = curve_fit(two_exp, bvalues, dw_data, p0=[1, Dpar1, (bounds[0][2]+bounds[1][2])/2, (bounds[0][3]+bounds[1][3])/2], bounds=boundsupdated)
101-
S0 = params[0]
102-
Dpar, Fmv, Dmv = params[1] , params[2] , params[3]
103-
#when the fraction of a compartment equals zero (or very very small), the corresponding diffusivity is non-existing (=NaN)
104-
if Fmv < 1e-4:
105-
Dmv = float("NaN")
106-
107-
if S0_output:
108-
return Dpar, Fmv, Dmv, S0
109-
else:
110-
return Dpar, Fmv, Dmv
111-
except:
110+
if S0_output:
111+
return Dpar, Fmv, Dmv, S0
112+
else:
113+
return Dpar, Fmv, Dmv
114+
#except:
112115

113-
if S0_output:
114-
return 0, 0, 0, 0, 0, 0
115-
else:
116-
return 0, 0, 0, 0, 0
116+
if S0_output:
117+
return 0, 0, 0, 0, 0, 0
118+
else:
119+
return 0, 0, 0, 0, 0
117120

118121

119122

src/standardized/ETP_SRI_LinearFitting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
4646
# Check the inputs
4747

4848

49-
def ivim_fit(self, signals, bvalues=None, linear_fit_option=False):
49+
def ivim_fit(self, signals, bvalues=None, linear_fit_option=False, **kwargs):
5050
"""Perform the IVIM fit
5151
5252
Args:

src/standardized/IAR_LU_biexp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
5151
self.IAR_algorithm = None
5252

5353

54-
def ivim_fit(self, signals, bvalues=None):
54+
def ivim_fit(self, signals, bvalues, **kwargs):
5555
"""Perform the IVIM fit
5656
5757
Args:

src/standardized/IAR_LU_modified_mix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
5151
self.IAR_algorithm = None
5252

5353

54-
def ivim_fit(self, signals, bvalues=None):
54+
def ivim_fit(self, signals, bvalues, **kwargs):
5555
"""Perform the IVIM fit
5656
5757
Args:

src/standardized/IAR_LU_modified_topopro.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
5151
self.IAR_algorithm = None
5252

5353

54-
def ivim_fit(self, signals, bvalues=None):
54+
def ivim_fit(self, signals, bvalues, **kwargs):
5555
"""Perform the IVIM fit
5656
5757
Args:

src/standardized/IAR_LU_segmented_2step.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class IAR_LU_segmented_2step(OsipiBase):
2828
required_initial_guess_optional = True
2929
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
3030

31-
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None, weighting=None, stats=False):
31+
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None):
3232
"""
3333
Everything this algorithm requires should be implemented here.
3434
Number of segmentation thresholds, bounds, etc.
@@ -51,7 +51,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
5151
self.IAR_algorithm = None
5252

5353

54-
def ivim_fit(self, signals, bvalues=None):
54+
def ivim_fit(self, signals, bvalues, thresholds=None, **kwargs):
5555
"""Perform the IVIM fit
5656
5757
Args:
@@ -61,6 +61,7 @@ def ivim_fit(self, signals, bvalues=None):
6161
Returns:
6262
_type_: _description_
6363
"""
64+
print(thresholds)
6465

6566
if self.IAR_algorithm is None:
6667
if bvalues is None:

src/standardized/IAR_LU_segmented_3step.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
5151
self.IAR_algorithm = None
5252

5353

54-
def ivim_fit(self, signals, bvalues=None):
54+
def ivim_fit(self, signals, bvalues, **kwargs):
5555
"""Perform the IVIM fit
5656
5757
Args:

src/standardized/IAR_LU_subtracted.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class IAR_LU_subtracted(OsipiBase):
2828
required_initial_guess_optional = True
2929
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
3030

31-
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None, weighting=None, stats=False):
31+
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None):
3232
"""
3333
Everything this algorithm requires should be implemented here.
3434
Number of segmentation thresholds, bounds, etc.
@@ -51,7 +51,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
5151
self.IAR_algorithm = None
5252

5353

54-
def ivim_fit(self, signals, bvalues=None):
54+
def ivim_fit(self, signals, bvalues, **kwargs):
5555
"""Perform the IVIM fit
5656
5757
Args:

0 commit comments

Comments
 (0)