Skip to content

Commit 4093e32

Browse files
author
IvanARashid
committed
Adapted my submissions to OsipiBase
1 parent 892be98 commit 4093e32

File tree

7 files changed

+500
-3
lines changed

7 files changed

+500
-3
lines changed

src/original/IAR_LundUniversity/ivim_fit_method_modified_topopro.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ def __init__(self, gtab, bounds=[[0,1], [0.005, 0.1], [1e-5, 0.004]], \
8080
# Bounds expressed as (lower bound, upper bound) for [f, D*, D].
8181
self.bounds = np.array([(0, 1), (5, 100), (0, 4)])
8282
elif (bounds[0][1] <= 1) or rescale_units: # Realistically, if mm2/s units are used, D* bound is <= 1
83-
self.bounds = np.array([(bounds[0][0], bounds[1][0]), \
84-
(bounds[0][1]*1000, bounds[1][1]*1000), \
85-
(bounds[0][2]*1000, bounds[1][2]*1000)])
83+
self.bounds = np.array([(bounds[0][0], bounds[0][1]), \
84+
(bounds[1][0]*1000, bounds[1][1]*1000), \
85+
(bounds[2][0]*1000, bounds[2][1]*1000)])
8686
else: # Finally, if units if µm2/ms are already used
8787
self.bounds = np.array([(bounds[0][0], bounds[1][0], \
8888
(bounds[0][1], bounds[1][1]), \

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
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
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_topopro import IvimModelTopoPro
5+
6+
7+
class IAR_LU_modified_topopro(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_topopro, 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 = IvimModelTopoPro(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 = IvimModelTopoPro(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
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_segmented_2step import IvimModelSegmented2Step
5+
6+
7+
class IAR_LU_segmented_2step(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 = "Segmented 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_segmented_2step, 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 = IvimModelSegmented2Step(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 = IvimModelSegmented2Step(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

0 commit comments

Comments
 (0)