Skip to content

Commit 640e62e

Browse files
authored
Merge branch 'main' into preproc-main
2 parents e597001 + 7c84913 commit 640e62e

25 files changed

Lines changed: 550 additions & 70 deletions

.github/workflows/unit_test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ jobs:
3131
python -m pip install --upgrade pip
3232
pip install torch --extra-index-url https://download.pytorch.org/whl/cpu
3333
pip install -r requirements.txt
34+
- name: Install libomp (macOS)
35+
if: runner.os == 'macOS'
36+
run: brew install libomp
3437
- name: Test with pytest
3538
run: |
3639
pip install pytest pytest-cov
37-
python -m pytest --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml --cov-report=html -r w
40+
python -m pytest --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml --cov-report=html -r w ${{ runner.os == 'macOS' && '-k "not test_deep_learning_algorithms"' || '' }}
3841
python -m pytest --doctest-modules --junitxml=junit/test-results-brain.xml --cov=. --cov-report=xml --cov-report=html --dataFile tests/IVIMmodels/unit_tests/generic_brain.json -r w -k test_ivim_fit_saved
3942

conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ def pytest_addoption(parser):
1919
)
2020
parser.addoption(
2121
"--ricianNoise",
22+
action="store_true",
2223
default=False,
23-
type=bool,
2424
help="Use Rician noise, non-rician is gaussian",
2525
)
2626
parser.addoption(
2727
"--usePrior",
28+
action="store_true",
2829
default=False,
29-
type=bool,
3030
help="Use a prior where accepted",
3131
)
3232
parser.addoption(

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_biexp.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
6060
bvec = np.zeros((self.bvalues.size, 3))
6161
bvec[:,2] = 1
6262
gtab = gradient_table(self.bvalues, bvecs=bvec, b0_threshold=0)
63-
64-
self.IAR_algorithm = IvimModelBiExp(gtab, bounds=self.bounds, initial_guess=self.initial_guess)
63+
64+
# Convert dict bounds/initial_guess to list-of-lists as expected by IvimModelBiExp
65+
bounds_list = [[self.bounds["S0"][0], self.bounds["f"][0], self.bounds["Dp"][0], self.bounds["D"][0]],
66+
[self.bounds["S0"][1], self.bounds["f"][1], self.bounds["Dp"][1], self.bounds["D"][1]]]
67+
initial_guess_list = [self.initial_guess["S0"], self.initial_guess["f"], self.initial_guess["Dp"], self.initial_guess["D"]]
68+
69+
self.IAR_algorithm = IvimModelBiExp(gtab, bounds=bounds_list, initial_guess=initial_guess_list)
6570
else:
6671
self.IAR_algorithm = None
6772

@@ -104,6 +109,7 @@ def ivim_fit(self, signals, bvalues, **kwargs):
104109

105110
return results
106111

112+
107113
def ivim_fit_full_volume(self, signals, bvalues, **kwargs):
108114
"""Perform the IVIM fit
109115

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/IAR_LU_segmented_3step.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
6262
bvec[:,2] = 1
6363
gtab = gradient_table(self.bvalues, bvecs=bvec, b0_threshold=0)
6464

65-
# Adapt the bounds to the format needed for the algorithm
66-
bounds = [[self.bounds["S0"][0], self.bounds["f"][0], self.bounds["Dp"][0], self.bounds["D"][0]], \
67-
[self.bounds["S0"][1], self.bounds["f"][1], self.bounds["Dp"][1], self.bounds["D"][1]]]
68-
65+
# Adapt the bounds to the format needed for the algorithm (list-of-lists)
66+
bounds = [[self.bounds["S0"][0], self.bounds["f"][0], self.bounds["Dp"][0], self.bounds["D"][0]],
67+
[self.bounds["S0"][1], self.bounds["f"][1], self.bounds["Dp"][1], self.bounds["D"][1]]]
68+
6969
# Adapt the initial guess to the format needed for the algorithm
7070
initial_guess = [self.initial_guess["S0"], self.initial_guess["f"], self.initial_guess["Dp"], self.initial_guess["D"]]
71-
72-
self.IAR_algorithm = IvimModelSegmented3Step(gtab, bounds=self.bounds, initial_guess=self.initial_guess)
71+
72+
# Use the converted list-of-lists bounds and initial_guess, NOT the raw dicts
73+
self.IAR_algorithm = IvimModelSegmented3Step(gtab, bounds=bounds, initial_guess=initial_guess)
7374
else:
7475
self.IAR_algorithm = None
7576

@@ -100,7 +101,7 @@ def ivim_fit(self, signals, bvalues, **kwargs):
100101
bvec = np.zeros((bvalues.size, 3))
101102
bvec[:,2] = 1
102103
gtab = gradient_table(bvalues, bvecs=bvec, b0_threshold=0)
103-
104+
104105
self.IAR_algorithm = IvimModelSegmented3Step(gtab, bounds=bounds, initial_guess=initial_guess)
105106

106107
fit_results = self.IAR_algorithm.fit(signals)
@@ -115,4 +116,4 @@ def ivim_fit(self, signals, bvalues, **kwargs):
115116
results["Dp"] = fit_results.model_params[2]
116117
results["D"] = fit_results.model_params[3]
117118

118-
return results
119+
return results

src/standardized/IAR_LU_subtracted.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def ivim_fit(self, signals, bvalues, **kwargs):
9898
bvec = np.zeros((bvalues.size, 3))
9999
bvec[:,2] = 1
100100
gtab = gradient_table(bvalues, bvecs=bvec, b0_threshold=0)
101-
101+
102102
self.IAR_algorithm = IvimModelSubtracted(gtab, bounds=bounds, initial_guess=initial_guess)
103103

104104
fit_results = self.IAR_algorithm.fit(signals)

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.fitting.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:

0 commit comments

Comments
 (0)