Skip to content

Commit 1290af0

Browse files
Merge pull request #164 from Devguru-codes/fix-print-to-warnings
Replace print() with warnings.warn() for warning messages
2 parents 906d86e + 2121d34 commit 1290af0

15 files changed

Lines changed: 31 additions & 21 deletions

src/standardized/ASD_MemorialSloanKettering_QAMPER_IVIM.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from src.wrappers.OsipiBase import OsipiBase
2+
import warnings
23
import numpy as np
34
import matlab.engine
45

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

4950
if eng is None:
50-
print('initiating matlab; this may take some time. For repeated testing one could use the optional input eng as an already initiated matlab engine')
51+
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)
5152
self.eng=matlab.engine.start_matlab()
5253
self.keep_alive=False
5354
else:
@@ -100,7 +101,7 @@ def clean(self):
100101
try:
101102
self.eng.quit()
102103
except Exception as e:
103-
print(f"Warning: Failed to quit MATLAB engine cleanly: {e}")
104+
warnings.warn(f"Failed to quit MATLAB engine cleanly: {e}", UserWarning, stacklevel=2)
104105

105106
def __del__(self):
106107
self.clean()

src/standardized/ETP_SRI_LinearFitting.py

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

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

src/standardized/IAR_LU_modified_topopro.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
import numpy as np
23
from dipy.core.gradients import gradient_table
34
from src.wrappers.OsipiBase import OsipiBase
@@ -53,7 +54,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
5354

5455
# Check the inputs
5556
if self.bounds["Dp"][0] == self.bounds["D"][1]:
56-
print('warning, bounds for D* and D are equal, this will likely cause fitting errors. Setting D_upper to 99 percent of D_upper')
57+
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)
5758
self.bounds["D"][1] = self.bounds["D"][1]*0.99
5859
# Check the inputs
5960

src/standardized/IVIM_NEToptim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def initialize(self, bounds, initial_guess, fitS0, traindata, SNR, n):
6666
SNR = (5, 100)
6767
self.training_data(self.bvalues,n=n,SNR=SNR)
6868
self.arg=Arg()
69-
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%')
69+
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)
7070
if bounds is not None:
7171
self.bounds = bounds
7272
else:

src/standardized/OGC_AmsterdamUMC_Bayesian_biexp.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from src.wrappers.OsipiBase import OsipiBase
22
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
3+
import warnings
34
import numpy as np
45

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

6465
if prior_in is None:
65-
print('using a flat prior between bounds')
66+
warnings.warn('Using a flat prior between bounds', UserWarning, stacklevel=2)
6667
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]])
6768
else:
68-
print('warning, bounds are not used, as a prior is used instead')
69+
warnings.warn('Bounds are not used, as a prior is used instead', UserWarning, stacklevel=2)
6970
if len(prior_in) == 4:
7071
self.neg_log_prior = empirical_neg_log_prior(prior_in[0], prior_in[1], prior_in[2],prior_in[3])
7172
else:

src/standardized/OGC_AmsterdamUMC_biexp_segmented.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from src.wrappers.OsipiBase import OsipiBase
22
from src.original.OGC_AmsterdamUMC.LSQ_fitting import fit_segmented, fit_segmented_array
3+
import warnings
34
import numpy as np
45

56
class OGC_AmsterdamUMC_biexp_segmented(OsipiBase):
@@ -53,7 +54,7 @@ def initialize(self, thresholds):
5354

5455
if self.thresholds is None:
5556
self.thresholds = 150
56-
print('warning, no thresholds were defined, so default threshold of 150 was used')
57+
warnings.warn('No thresholds were defined, so default threshold of 150 was used', UserWarning, stacklevel=2)
5758
else:
5859
self.thresholds = thresholds
5960

src/standardized/OJ_GU_bayesMATLAB.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from src.wrappers.OsipiBase import OsipiBase
2+
import warnings
23
import numpy as np
34
import matlab.engine
45

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

5152
if eng is None:
52-
print('initiating matlab; this may take some time. For repeated testing one could use the optional input eng as an already initiated matlab engine')
53+
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)
5354
self.eng=matlab.engine.start_matlab()
5455
self.keep_alive=False
5556
else:
@@ -101,7 +102,7 @@ def clean(self):
101102
try:
102103
self.eng.quit()
103104
except Exception as e:
104-
print(f"Warning: Failed to quit MATLAB engine cleanly: {e}")
105+
warnings.warn(f"Failed to quit MATLAB engine cleanly: {e}", UserWarning, stacklevel=2)
105106

106107
def __del__(self):
107108
self.clean()

src/standardized/OJ_GU_segMATLAB.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from src.wrappers.OsipiBase import OsipiBase
2+
import warnings
23
import numpy as np
34
import matlab.engine
45

@@ -47,7 +48,7 @@ def __init__(self, bvalues=None, thresholds=200, bounds=None, initial_guess=None
4748
self.use_bounds = {"f" : True, "D" : True, "Dp" : True, "S0" : True}
4849
self.use_initial_guess = {"f" : False, "D" : False, "Dp" : False, "S0" : False}
4950
if eng is None:
50-
print('initiating matlab; this may take some time. For repeated testing one could use the optional input eng as an already initiated matlab engine')
51+
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)
5152
self.eng=matlab.engine.start_matlab()
5253
self.keep_alive=False
5354
else:
@@ -95,7 +96,7 @@ def clean(self):
9596
try:
9697
self.eng.quit()
9798
except Exception as e:
98-
print(f"Warning: Failed to quit MATLAB engine cleanly: {e}")
99+
warnings.warn(f"Failed to quit MATLAB engine cleanly: {e}", UserWarning, stacklevel=2)
99100

100101
def __del__(self):
101102
self.clean()

src/standardized/PvH_KB_NKI_IVIMfit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(self, bvalues=None, thresholds=None,bounds=None,initial_guess=None)
4747
super(PvH_KB_NKI_IVIMfit, self).__init__(bvalues=bvalues, thresholds=thresholds,bounds=bounds,initial_guess=initial_guess)
4848
self.NKI_algorithm = generate_IVIMmaps_standalone
4949
if bounds is not None:
50-
print('warning, bounds from wrapper are not (yet) used in this algorithm')
50+
warnings.warn('Bounds from wrapper are not (yet) used in this algorithm', UserWarning, stacklevel=2)
5151
self.use_bounds = {"f" : False, "D" : False, "Dp" : False, "S0" : False}
5252
self.use_initial_guess = {"f" : False, "D" : False, "Dp" : False, "S0" : False}
5353

src/standardized/TCML_TechnionIIT_SLS.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def initialize(self, bounds, fitS0,thresholds):
5555
self.fitS0=fitS0
5656
if thresholds is None:
5757
self.thresholds = 150
58-
print('warning, no thresholds were defined, so default bounds are used of 150')
58+
warnings.warn('No thresholds were defined, so default threshold of 150 is used', UserWarning, stacklevel=2)
5959
else:
6060
self.thresholds = thresholds
6161

0 commit comments

Comments
 (0)