Skip to content

Commit 806517d

Browse files
authored
Merge pull request #12 from OSIPI/testing/wrapper
Testing/wrapper
2 parents e030c14 + 2bbd603 commit 806517d

24 files changed

+1061
-88
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ __pycache__/
99
.cache
1010
nosetests.xml
1111
coverage.xml
12+
*.pyc

src/original/ETP_SRI/LinearFitting.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import numpy as np
22
import numpy.polynomial.polynomial as poly
33

4-
from utils.data_simulation.GenerateData import GenerateData
5-
6-
4+
from utilities.data_simulation.GenerateData import GenerateData
75

86
class LinearFit:
97
"""
@@ -17,6 +15,9 @@ def __init__(self, linear_cutoff=500):
1715
The b-value after which it can be assumed that the perfusion value is negligible
1816
"""
1917
self.linear_cutoff = linear_cutoff
18+
19+
def accepted_dimensions(self):
20+
return (1, 1)
2021

2122
def linear_fit(self, bvalues, signal, weighting=None, stats=False):
2223
"""

src/original/IAR_LundUniversity/ivim_fit_method_modified_topopro.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class IvimModelTopoPro(ReconstModel):
1010

11-
def __init__(self, gtab, bounds=[[0,1], [0.005, 0.1], [1e-5, 0.004]], \
11+
def __init__(self, gtab, bounds=[[0, 0.005, 1e-5], [1, 0.1, 0.004]], \
1212
rescale_units=False, shgo_iters=5, rescale_results_to_mm2_s=False):
1313
r""" Initialize an IvimModelTP class.
1414
This particular script was modified as the DIPY version has stringent
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import numpy as np
2+
from src.wrappers.OsipiBase import OsipiBase
3+
from src.original.ETP_SRI.LinearFitting import LinearFit
4+
5+
6+
class ETP_SRI_LinearFitting(OsipiBase):
7+
"""WIP
8+
Implementation and execution of the submitted algorithm
9+
"""
10+
11+
# I'm thinking that we define default attributes for each submission like this
12+
# And in __init__, we can call the OsipiBase control functions to check whether
13+
# the user inputs fulfil the requirements
14+
15+
# Some basic stuff that identifies the algorithm
16+
id_author = "Eric T. Peterson, SRI"
17+
id_algorithm_type = "Linear fit"
18+
id_return_parameters = "f, D*, D"
19+
id_units = "seconds per milli metre squared"
20+
21+
# Algorithm requirements
22+
required_bvalues = 3
23+
required_thresholds = [0,1] # Interval from 1 to 1, in case submissions allow a custom number of thresholds
24+
required_bounds = False
25+
required_bounds_optional = True # Bounds may not be required but are optional
26+
required_initial_guess = False
27+
required_initial_guess_optional = False
28+
accepted_dimensions = 1
29+
# Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
30+
31+
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None, weighting=None, stats=False):
32+
"""
33+
Everything this method requires should be implemented here.
34+
Number of segmentation thresholds, bounds, etc.
35+
36+
Our OsipiBase object could contain functions that compare the inputs with
37+
the requirements.
38+
"""
39+
super(ETP_SRI_LinearFitting, self).__init__(bvalues, thresholds, bounds, initial_guess)
40+
41+
# Could be a good idea to have all the submission-specfic variable be
42+
# defined with initials?
43+
self.ETP_weighting = weighting
44+
self.ETP_stats = stats
45+
46+
# Check the inputs
47+
48+
49+
def ivim_fit(self, signals, bvalues=None, linear_fit_option=False):
50+
"""Perform the IVIM fit
51+
52+
Args:
53+
signals (array-like)
54+
bvalues (array-like, optional): b-values for the signals. If None, self.bvalues will be used. Default is None.
55+
linear_fit_option (bool, optional): This fit has an option to only run a linear fit. Defaults to False.
56+
57+
Returns:
58+
_type_: _description_
59+
"""
60+
if bvalues is None:
61+
bvalues = self.bvalues
62+
63+
if self.thresholds is None:
64+
ETP_object = LinearFit()
65+
else:
66+
ETP_object = LinearFit(self.thresholds[0])
67+
68+
if linear_fit_option:
69+
f, Dstar = ETP_object.linear_fit(bvalues, signals)
70+
return f, Dstar
71+
else:
72+
f, D, Dstar = ETP_object.ivim_fit(bvalues, signals)
73+
return f, Dstar, D
74+

src/standardized wip/IAR_LU_linear.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import numpy as np
2+
from dipy.core.gradients import gradient_table
3+
from src.wrappers.OsipiBase import OsipiBase
4+
from src.original.IAR_LundUniversity.ivim_fit_method_linear import IvimModelLinear
5+
6+
7+
class IAR_LU_linear(OsipiBase):
8+
"""
9+
Bi-exponential fitting algorithm by Ivan A. Rashid, Lund University
10+
"""
11+
12+
# I'm thinking that we define default attributes for each submission like this
13+
# And in __init__, we can call the OsipiBase control functions to check whether
14+
# the user inputs fulfil the requirements
15+
16+
# Some basic stuff that identifies the algorithm
17+
id_author = "Ivan A. Rashid, LU"
18+
id_algorithm_type = "Linear fit"
19+
id_return_parameters = "f, D"
20+
id_units = "seconds per milli metre squared or milliseconds per micro metre squared"
21+
22+
# Algorithm requirements
23+
required_bvalues = 3
24+
required_thresholds = [0,0] # Interval from "at least" to "at most", in case submissions allow a custom number of thresholds
25+
required_bounds = False
26+
required_bounds_optional = True # Bounds may not be required but are optional
27+
required_initial_guess = False
28+
required_initial_guess_optional = True
29+
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
30+
31+
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None, weighting=None, stats=False):
32+
"""
33+
Everything this algorithm requires should be implemented here.
34+
Number of segmentation thresholds, bounds, etc.
35+
36+
Our OsipiBase object could contain functions that compare the inputs with
37+
the requirements.
38+
"""
39+
super(IAR_LU_linear, self).__init__(bvalues, thresholds, bounds, initial_guess)
40+
41+
# Check the inputs
42+
43+
# Initialize the algorithm
44+
if self.bvalues is not None:
45+
bvec = np.zeros((self.bvalues.size, 3))
46+
bvec[:,2] = 1
47+
gtab = gradient_table(self.bvalues, bvec, b0_threshold=0)
48+
49+
self.IAR_algorithm = IvimModelLinear(gtab)
50+
else:
51+
self.IAR_algorithm = None
52+
53+
54+
def ivim_fit(self, signals, bvalues=None):
55+
"""Perform the IVIM fit
56+
57+
Args:
58+
signals (array-like)
59+
bvalues (array-like, optional): b-values for the signals. If None, self.bvalues will be used. Default is None.
60+
61+
Returns:
62+
_type_: _description_
63+
"""
64+
65+
if self.IAR_algorithm is None:
66+
if bvalues is None:
67+
bvalues = self.bvalues
68+
else:
69+
bvalues = np.asarray(bvalues)
70+
71+
bvec = np.zeros((bvalues.size, 3))
72+
bvec[:,2] = 1
73+
gtab = gradient_table(bvalues, bvec, b0_threshold=0)
74+
75+
self.IAR_algorithm = IvimModelLinear(gtab)
76+
77+
fit_results = self.IAR_algorithm.fit(signals)
78+
79+
f = fit_results.model_params[1]
80+
D = fit_results.model_params[2]
81+
82+
return f, D

src/standardized/IAR_LU_biexp.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import numpy as np
2+
from dipy.core.gradients import gradient_table
3+
from src.wrappers.OsipiBase import OsipiBase
4+
from src.original.IAR_LundUniversity.ivim_fit_method_biexp import IvimModelBiExp
5+
6+
7+
class IAR_LU_biexp(OsipiBase):
8+
"""
9+
Bi-exponential fitting algorithm by Ivan A. Rashid, Lund University
10+
"""
11+
12+
# I'm thinking that we define default attributes for each submission like this
13+
# And in __init__, we can call the OsipiBase control functions to check whether
14+
# the user inputs fulfil the requirements
15+
16+
# Some basic stuff that identifies the algorithm
17+
id_author = "Ivan A. Rashid, LU"
18+
id_algorithm_type = "Bi-exponential fit"
19+
id_return_parameters = "f, D*, D"
20+
id_units = "seconds per milli metre squared or milliseconds per micro metre squared"
21+
22+
# Algorithm requirements
23+
required_bvalues = 4
24+
required_thresholds = [0,0] # Interval from "at least" to "at most", in case submissions allow a custom number of thresholds
25+
required_bounds = False
26+
required_bounds_optional = True # Bounds may not be required but are optional
27+
required_initial_guess = False
28+
required_initial_guess_optional = True
29+
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
30+
31+
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None, weighting=None, stats=False):
32+
"""
33+
Everything this algorithm requires should be implemented here.
34+
Number of segmentation thresholds, bounds, etc.
35+
36+
Our OsipiBase object could contain functions that compare the inputs with
37+
the requirements.
38+
"""
39+
super(IAR_LU_biexp, self).__init__(bvalues, thresholds, bounds, initial_guess)
40+
41+
# Check the inputs
42+
43+
# Initialize the algorithm
44+
if self.bvalues is not None:
45+
bvec = np.zeros((self.bvalues.size, 3))
46+
bvec[:,2] = 1
47+
gtab = gradient_table(self.bvalues, bvec, b0_threshold=0)
48+
49+
self.IAR_algorithm = IvimModelBiExp(gtab)
50+
else:
51+
self.IAR_algorithm = None
52+
53+
54+
def ivim_fit(self, signals, bvalues=None):
55+
"""Perform the IVIM fit
56+
57+
Args:
58+
signals (array-like)
59+
bvalues (array-like, optional): b-values for the signals. If None, self.bvalues will be used. Default is None.
60+
61+
Returns:
62+
_type_: _description_
63+
"""
64+
65+
if self.IAR_algorithm is None:
66+
if bvalues is None:
67+
bvalues = self.bvalues
68+
else:
69+
bvalues = np.asarray(bvalues)
70+
71+
bvec = np.zeros((bvalues.size, 3))
72+
bvec[:,2] = 1
73+
gtab = gradient_table(bvalues, bvec, b0_threshold=0)
74+
75+
self.IAR_algorithm = IvimModelBiExp(gtab)
76+
77+
fit_results = self.IAR_algorithm.fit(signals)
78+
79+
f = fit_results.model_params[1]
80+
Dstar = fit_results.model_params[2]
81+
D = fit_results.model_params[3]
82+
83+
return f, Dstar, D
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import numpy as np
2+
from dipy.core.gradients import gradient_table
3+
from src.wrappers.OsipiBase import OsipiBase
4+
from src.original.IAR_LundUniversity.ivim_fit_method_modified_mix import IvimModelVP
5+
6+
7+
class IAR_LU_modified_mix(OsipiBase):
8+
"""
9+
Bi-exponential fitting algorithm by Ivan A. Rashid, Lund University
10+
"""
11+
12+
# I'm thinking that we define default attributes for each submission like this
13+
# And in __init__, we can call the OsipiBase control functions to check whether
14+
# the user inputs fulfil the requirements
15+
16+
# Some basic stuff that identifies the algorithm
17+
id_author = "Ivan A. Rashid, LU"
18+
id_algorithm_type = "Bi-exponential fit"
19+
id_return_parameters = "f, D*, D"
20+
id_units = "seconds per milli metre squared or milliseconds per micro metre squared"
21+
22+
# Algorithm requirements
23+
required_bvalues = 4
24+
required_thresholds = [0,0] # Interval from "at least" to "at most", in case submissions allow a custom number of thresholds
25+
required_bounds = False
26+
required_bounds_optional = True # Bounds may not be required but are optional
27+
required_initial_guess = False
28+
required_initial_guess_optional = True
29+
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
30+
31+
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None, weighting=None, stats=False):
32+
"""
33+
Everything this algorithm requires should be implemented here.
34+
Number of segmentation thresholds, bounds, etc.
35+
36+
Our OsipiBase object could contain functions that compare the inputs with
37+
the requirements.
38+
"""
39+
super(IAR_LU_modified_mix, self).__init__(bvalues, thresholds, bounds, initial_guess)
40+
41+
# Check the inputs
42+
43+
# Initialize the algorithm
44+
if self.bvalues is not None:
45+
bvec = np.zeros((self.bvalues.size, 3))
46+
bvec[:,2] = 1
47+
gtab = gradient_table(self.bvalues, bvec, b0_threshold=0)
48+
49+
self.IAR_algorithm = IvimModelVP(gtab)
50+
else:
51+
self.IAR_algorithm = None
52+
53+
54+
def ivim_fit(self, signals, bvalues=None):
55+
"""Perform the IVIM fit
56+
57+
Args:
58+
signals (array-like)
59+
bvalues (array-like, optional): b-values for the signals. If None, self.bvalues will be used. Default is None.
60+
61+
Returns:
62+
_type_: _description_
63+
"""
64+
65+
if self.IAR_algorithm is None:
66+
if bvalues is None:
67+
bvalues = self.bvalues
68+
else:
69+
bvalues = np.asarray(bvalues)
70+
71+
bvec = np.zeros((bvalues.size, 3))
72+
bvec[:,2] = 1
73+
gtab = gradient_table(bvalues, bvec, b0_threshold=0)
74+
75+
self.IAR_algorithm = IvimModelVP(gtab, rescale_results_to_mm2_s=True)
76+
77+
fit_results = self.IAR_algorithm.fit(signals)
78+
79+
f = fit_results.model_params[1]
80+
Dstar = fit_results.model_params[2]
81+
D = fit_results.model_params[3]
82+
83+
return f, Dstar, D

0 commit comments

Comments
 (0)