Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/standardized/ASD_MemorialSloanKettering_QAMPER_IVIM.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from src.wrappers.OsipiBase import OsipiBase
import warnings
import numpy as np
import matlab.engine

Expand Down Expand Up @@ -47,7 +48,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
self.use_initial_guess = {"f" : True, "D" : True, "Dp" : True, "S0" : True}

if eng is None:
print('initiating matlab; this may take some time. For repeated testing one could use the optional input eng as an already initiated matlab engine')
warnings.warn('Initiating MATLAB; this may take some time. For repeated testing one could use the optional input eng as an already initiated MATLAB engine', UserWarning, stacklevel=2)
self.eng=matlab.engine.start_matlab()
self.keep_alive=False
else:
Expand Down Expand Up @@ -100,7 +101,7 @@ def clean(self):
try:
self.eng.quit()
except Exception as e:
print(f"Warning: Failed to quit MATLAB engine cleanly: {e}")
warnings.warn(f"Failed to quit MATLAB engine cleanly: {e}", UserWarning, stacklevel=2)

def __del__(self):
self.clean()
Expand Down
2 changes: 1 addition & 1 deletion src/standardized/ETP_SRI_LinearFitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non

super(ETP_SRI_LinearFitting, self).__init__(bvalues, thresholds, bounds, initial_guess)
if bounds is not None:
print('warning, bounds from wrapper are not (yet) used in this algorithm')
warnings.warn('Bounds from wrapper are not (yet) used in this algorithm', UserWarning, stacklevel=2)
self.use_bounds = {"f": False, "Dp": False, "D": False, "S0": False}
self.use_initial_guess = {"f": False, "Dp": False, "D": False, "S0": False}

Expand Down
3 changes: 2 additions & 1 deletion src/standardized/IAR_LU_modified_topopro.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
import numpy as np
from dipy.core.gradients import gradient_table
from src.wrappers.OsipiBase import OsipiBase
Expand Down Expand Up @@ -53,7 +54,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non

# Check the inputs
if self.bounds["Dp"][0] == self.bounds["D"][1]:
print('warning, bounds for D* and D are equal, this will likely cause fitting errors. Setting D_upper to 99 percent of D_upper')
warnings.warn('Bounds for D* and D are equal, this will likely cause fitting errors. Setting D_upper to 99 percent of D_upper', UserWarning, stacklevel=2)
self.bounds["D"][1] = self.bounds["D"][1]*0.99
# Check the inputs

Expand Down
2 changes: 1 addition & 1 deletion src/standardized/IVIM_NEToptim.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def initialize(self, bounds, initial_guess, fitS0, traindata, SNR, n):
SNR = (5, 100)
self.training_data(self.bvalues,n=n,SNR=SNR)
self.arg=Arg()
print('note that the bounds in the network are soft bounds and implemented by a sigmoid transform. In order for the network to be sensitive over the range, we extend the bounds ny 30%')
warnings.warn('Note that the bounds in the network are soft bounds and implemented by a sigmoid transform. In order for the network to be sensitive over the range, we extend the bounds by 30%', UserWarning, stacklevel=2)
if bounds is not None:
self.bounds = bounds
else:
Expand Down
5 changes: 3 additions & 2 deletions src/standardized/OGC_AmsterdamUMC_Bayesian_biexp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from src.wrappers.OsipiBase import OsipiBase
from src.original.OGC_AmsterdamUMC.LSQ_fitting import flat_neg_log_prior, fit_bayesian, empirical_neg_log_prior, fit_segmented, fit_bayesian_array, fit_segmented_array
import warnings
import numpy as np

class OGC_AmsterdamUMC_Bayesian_biexp(OsipiBase):
Expand Down Expand Up @@ -62,10 +63,10 @@ def initialize(self, bounds=None, initial_guess=None, fitS0=True, prior_in=None,
self.thresholds = thresholds

if prior_in is None:
print('using a flat prior between bounds')
warnings.warn('Using a flat prior between bounds', UserWarning, stacklevel=2)
self.neg_log_prior=flat_neg_log_prior([self.bounds["D"][0],self.bounds["D"][1]],[self.bounds["f"][0],self.bounds["f"][1]],[self.bounds["Dp"][0],self.bounds["Dp"][1]],[self.bounds["S0"][0],self.bounds["S0"][1]])
else:
print('warning, bounds are not used, as a prior is used instead')
warnings.warn('Bounds are not used, as a prior is used instead', UserWarning, stacklevel=2)
if len(prior_in) == 4:
self.neg_log_prior = empirical_neg_log_prior(prior_in[0], prior_in[1], prior_in[2],prior_in[3])
else:
Expand Down
3 changes: 2 additions & 1 deletion src/standardized/OGC_AmsterdamUMC_biexp_segmented.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from src.wrappers.OsipiBase import OsipiBase
from src.original.OGC_AmsterdamUMC.LSQ_fitting import fit_segmented, fit_segmented_array
import warnings
import numpy as np

class OGC_AmsterdamUMC_biexp_segmented(OsipiBase):
Expand Down Expand Up @@ -53,7 +54,7 @@ def initialize(self, thresholds):

if self.thresholds is None:
self.thresholds = 150
print('warning, no thresholds were defined, so default threshold of 150 was used')
warnings.warn('No thresholds were defined, so default threshold of 150 was used', UserWarning, stacklevel=2)
else:
self.thresholds = thresholds

Expand Down
5 changes: 3 additions & 2 deletions src/standardized/OJ_GU_bayesMATLAB.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from src.wrappers.OsipiBase import OsipiBase
import warnings
import numpy as np
import matlab.engine

Expand Down Expand Up @@ -49,7 +50,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
self.use_bounds = {"f" : True, "D" : True, "Dp" : True, "S0" : True}

if eng is None:
print('initiating matlab; this may take some time. For repeated testing one could use the optional input eng as an already initiated matlab engine')
warnings.warn('Initiating MATLAB; this may take some time. For repeated testing one could use the optional input eng as an already initiated MATLAB engine', UserWarning, stacklevel=2)
self.eng=matlab.engine.start_matlab()
self.keep_alive=False
else:
Expand Down Expand Up @@ -101,7 +102,7 @@ def clean(self):
try:
self.eng.quit()
except Exception as e:
print(f"Warning: Failed to quit MATLAB engine cleanly: {e}")
warnings.warn(f"Failed to quit MATLAB engine cleanly: {e}", UserWarning, stacklevel=2)

def __del__(self):
self.clean()
Expand Down
5 changes: 3 additions & 2 deletions src/standardized/OJ_GU_segMATLAB.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from src.wrappers.OsipiBase import OsipiBase
import warnings
import numpy as np
import matlab.engine

Expand Down Expand Up @@ -47,7 +48,7 @@ def __init__(self, bvalues=None, thresholds=200, bounds=None, initial_guess=None
self.use_bounds = {"f" : True, "D" : True, "Dp" : True, "S0" : True}
self.use_initial_guess = {"f" : False, "D" : False, "Dp" : False, "S0" : False}
if eng is None:
print('initiating matlab; this may take some time. For repeated testing one could use the optional input eng as an already initiated matlab engine')
warnings.warn('Initiating MATLAB; this may take some time. For repeated testing one could use the optional input eng as an already initiated MATLAB engine', UserWarning, stacklevel=2)
self.eng=matlab.engine.start_matlab()
self.keep_alive=False
else:
Expand Down Expand Up @@ -95,7 +96,7 @@ def clean(self):
try:
self.eng.quit()
except Exception as e:
print(f"Warning: Failed to quit MATLAB engine cleanly: {e}")
warnings.warn(f"Failed to quit MATLAB engine cleanly: {e}", UserWarning, stacklevel=2)

def __del__(self):
self.clean()
Expand Down
2 changes: 1 addition & 1 deletion src/standardized/PvH_KB_NKI_IVIMfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, bvalues=None, thresholds=None,bounds=None,initial_guess=None)
super(PvH_KB_NKI_IVIMfit, self).__init__(bvalues=bvalues, thresholds=thresholds,bounds=bounds,initial_guess=initial_guess)
self.NKI_algorithm = generate_IVIMmaps_standalone
if bounds is not None:
print('warning, bounds from wrapper are not (yet) used in this algorithm')
warnings.warn('Bounds from wrapper are not (yet) used in this algorithm', UserWarning, stacklevel=2)
self.use_bounds = {"f" : False, "D" : False, "Dp" : False, "S0" : False}
self.use_initial_guess = {"f" : False, "D" : False, "Dp" : False, "S0" : False}

Expand Down
2 changes: 1 addition & 1 deletion src/standardized/TCML_TechnionIIT_SLS.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def initialize(self, bounds, fitS0,thresholds):
self.fitS0=fitS0
if thresholds is None:
self.thresholds = 150
print('warning, no thresholds were defined, so default bounds are used of 150')
warnings.warn('No thresholds were defined, so default threshold of 150 is used', UserWarning, stacklevel=2)
else:
self.thresholds = thresholds

Expand Down
3 changes: 2 additions & 1 deletion src/standardized/TCML_TechnionIIT_lsq_sls_BOBYQA.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from src.wrappers.OsipiBase import OsipiBase
from super_ivim_dc.source.Classsic_ivim_fit import IVIM_fit_sls_BOBYQA
import warnings
import numpy as np

class TCML_TechnionIIT_lsq_sls_BOBYQA(OsipiBase):
Expand Down Expand Up @@ -50,7 +51,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
def initialize(self, bounds, fitS0, thresholds):
if self.thresholds is None:
self.thresholds = 200
print('warning, no thresholds were defined, so default bounds are used of 200')
warnings.warn('No thresholds were defined, so default threshold of 200 is used', UserWarning, stacklevel=2)
else:
self.thresholds = thresholds
self.fitS0=fitS0
Expand Down
2 changes: 1 addition & 1 deletion src/standardized/TCML_TechnionIIT_lsq_sls_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def initialize(self, bounds, fitS0,thresholds):

if thresholds is None:
self.thresholds = 150
print('warning, no thresholds were defined, so default bounds are used of 150')
warnings.warn('No thresholds were defined, so default threshold of 150 is used', UserWarning, stacklevel=2)
else:
self.thresholds = thresholds
self.fitS0=fitS0
Expand Down
3 changes: 2 additions & 1 deletion src/standardized/TCML_TechnionIIT_lsq_sls_trf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from src.wrappers.OsipiBase import OsipiBase
from super_ivim_dc.source.Classsic_ivim_fit import IVIM_fit_sls_trf
import warnings
import numpy as np

class TCML_TechnionIIT_lsq_sls_trf(OsipiBase):
Expand Down Expand Up @@ -56,7 +57,7 @@ def initialize(self, bounds, fitS0, thresholds):

if thresholds is None:
self.thresholds = 200
print('warning, no thresholds were defined, so default bounds are used of 200')
warnings.warn('No thresholds were defined, so default threshold of 200 is used', UserWarning, stacklevel=2)
else:
self.thresholds = thresholds
self.fitS0=fitS0
Expand Down
5 changes: 3 additions & 2 deletions src/standardized/TF_reference_IVIMfit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from src.wrappers.OsipiBase import OsipiBase
from src.original.TF_reference.segmented_IVIMfit import segmented_IVIM_fit
import warnings
import numpy as np

class TF_reference_IVIMfit(OsipiBase):
Expand Down Expand Up @@ -51,7 +52,7 @@ def initialize(self, bounds, thresholds):
self.use_bounds = {"f" : True, "D" : True, "Dp" : True, "S0" : True}
if self.thresholds is None:
self.thresholds = 200
print('warning, no thresholds were defined, so default threshold are used of 200')
warnings.warn('No thresholds were defined, so default threshold of 200 is used', UserWarning, stacklevel=2)
else:
self.thresholds = thresholds

Expand All @@ -73,7 +74,7 @@ def ivim_fit(self, signals, bvalues=None):

if np.any(signals < 0):
signals = np.clip(signals,0.01, None)
print('warning, negative values in signal: values clipped to 0.01')
warnings.warn('Negative values in signal: values clipped to 0.01', UserWarning, stacklevel=2)


fit_results = self.TF_reference_algorithm(bvalues,signals,b_cutoff=self.thresholds, bounds=bounds)
Expand Down
5 changes: 3 additions & 2 deletions src/wrappers/OsipiBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from scipy.stats import norm
import pathlib
import sys
import warnings
from tqdm import tqdm
from joblib import Parallel, delayed

Expand Down Expand Up @@ -149,12 +150,12 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
else:
# Generic defaults (original behavior)
if self.bounds is None:
print('warning, no bounds were defined, so default bounds are used of [0, 0, 0.005, 0.7],[0.005, 1.0, 0.2, 1.3]')
warnings.warn('No bounds were defined, so default bounds are used of [0, 0, 0.005, 0.7],[0.005, 1.0, 0.2, 1.3]', UserWarning, stacklevel=2)
self.bounds = {"S0" : [0.7, 1.3], "f" : [0, 1.0], "Dp" : [0.005, 0.2], "D" : [0, 0.005]} # These are defined as [lower, upper]
self.forced_default_bounds = True

if self.initial_guess is None:
print('warning, no initial guesses were defined, so default initial guesses are used of [0.001, 0.001, 0.01, 1]')
warnings.warn('No initial guesses were defined, so default initial guesses are used of [0.001, 0.001, 0.01, 1]', UserWarning, stacklevel=2)
self.initial_guess = {"S0" : 1, "f" : 0.1, "Dp" : 0.01, "D" : 0.001}
self.forced_default_initial_guess = True

Expand Down
Loading