Skip to content

Implement checks for fulfilment of algorithm requirements in the OsipiBase class #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ nosetests.xml
coverage.xml
*.pyc
phantoms/MR_XCAT_qMRI/*.json
phantoms/MR_XCAT_qMRI/*.txt
phantoms/MR_XCAT_qMRI/*.txt

4 changes: 1 addition & 3 deletions src/standardized wip/IAR_LU_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IAR_LU_linear(OsipiBase):
required_bounds_optional = True # Bounds may not be required but are optional
required_initial_guess = False
required_initial_guess_optional = True
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
accepted_dimensions = (1,1) #(min dimension, max dimension)

def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None, weighting=None, stats=False):
"""
Expand All @@ -38,8 +38,6 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
"""
super(IAR_LU_linear, self).__init__(bvalues, thresholds, bounds, initial_guess)

# Check the inputs

# Initialize the algorithm
if self.bvalues is not None:
bvec = np.zeros((self.bvalues.size, 3))
Expand Down
9 changes: 3 additions & 6 deletions src/standardized/ETP_SRI_LinearFitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class ETP_SRI_LinearFitting(OsipiBase):
required_bounds_optional = True # Bounds may not be required but are optional
required_initial_guess = False
required_initial_guess_optional = False
accepted_dimensions = 1
# Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
accepted_dimensions = (1,1) #(min dimension, max dimension)

# Supported inputs in the standardized class
supported_bounds = False
Expand All @@ -41,7 +40,6 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
Our OsipiBase object could contain functions that compare the inputs with
the requirements.
"""

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')
Expand All @@ -52,10 +50,8 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
# defined with initials?
self.ETP_weighting = weighting
self.ETP_stats = stats

# Check the inputs



def ivim_fit(self, signals, bvalues=None, linear_fit_option=False, **kwargs):
"""Perform the IVIM fit

Expand All @@ -67,6 +63,7 @@ def ivim_fit(self, signals, bvalues=None, linear_fit_option=False, **kwargs):
Returns:
_type_: _description_
"""

signals[signals<0.0000001]=0.0000001
if bvalues is None:
bvalues = self.bvalues
Expand Down
7 changes: 3 additions & 4 deletions src/standardized/IAR_LU_biexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IAR_LU_biexp(OsipiBase):
required_bounds_optional = True # Bounds may not be required but are optional
required_initial_guess = False
required_initial_guess_optional = True
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
accepted_dimensions = (1,1) #(min dimension, max dimension)

# Supported inputs in the standardized class
supported_bounds = True
Expand All @@ -46,7 +46,6 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
print('warning, bounds from wrapper are not (yet) used in this algorithm')
self.use_bounds = False
self.use_initial_guess = False
# Check the inputs

# Initialize the algorithm
if self.bvalues is not None:
Expand All @@ -69,7 +68,7 @@ def ivim_fit(self, signals, bvalues, **kwargs):
Returns:
_type_: _description_
"""

if self.IAR_algorithm is None:
if bvalues is None:
bvalues = self.bvalues
Expand Down Expand Up @@ -101,7 +100,7 @@ def ivim_fit_full_volume(self, signals, bvalues, **kwargs):
Returns:
_type_: _description_
"""

if self.IAR_algorithm is None:
if bvalues is None:
bvalues = self.bvalues
Expand Down
5 changes: 2 additions & 3 deletions src/standardized/IAR_LU_modified_mix.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IAR_LU_modified_mix(OsipiBase):
required_bounds_optional = True # Bounds may not be required but are optional
required_initial_guess = False
required_initial_guess_optional = True
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
accepted_dimensions = (1,1) #(min dimension, max dimension)

# Supported inputs in the standardized class
supported_bounds = True
Expand All @@ -46,7 +46,6 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
print('warning, bounds from wrapper are not (yet) used in this algorithm')
self.use_bounds = False
self.use_initial_guess = False
# Check the inputs

# Initialize the algorithm
if self.bvalues is not None:
Expand All @@ -69,7 +68,7 @@ def ivim_fit(self, signals, bvalues, **kwargs):
Returns:
_type_: _description_
"""

if self.IAR_algorithm is None:
if bvalues is None:
bvalues = self.bvalues
Expand Down
3 changes: 1 addition & 2 deletions src/standardized/IAR_LU_modified_topopro.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IAR_LU_modified_topopro(OsipiBase):
required_bounds_optional = True # Bounds may not be required but are optional
required_initial_guess = False
required_initial_guess_optional = True
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
accepted_dimensions = (1,1) #(min dimension, max dimension)

# Supported inputs in the standardized class
supported_bounds = True
Expand All @@ -46,7 +46,6 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
print('warning, bounds from wrapper are not (yet) used in this algorithm')
self.use_bounds = False
self.use_initial_guess = False
# Check the inputs

# Initialize the algorithm
if self.bvalues is not None:
Expand Down
4 changes: 2 additions & 2 deletions src/standardized/IAR_LU_segmented_2step.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IAR_LU_segmented_2step(OsipiBase):
required_bounds_optional = True # Bounds may not be required but are optional
required_initial_guess = False
required_initial_guess_optional = True
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
accepted_dimensions = (1,1) #(min dimension, max dimension)

# Supported inputs in the standardized class
supported_bounds = True
Expand All @@ -46,7 +46,6 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
print('warning, bounds from wrapper are not (yet) used in this algorithm')
self.use_bounds = False
self.use_initial_guess = False
# Check the inputs

# Initialize the algorithm
if self.bvalues is not None:
Expand All @@ -70,6 +69,7 @@ def ivim_fit(self, signals, bvalues, thresholds=None, **kwargs):
_type_: _description_
"""
print(thresholds)


if self.IAR_algorithm is None:
if bvalues is None:
Expand Down
3 changes: 1 addition & 2 deletions src/standardized/IAR_LU_segmented_3step.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IAR_LU_segmented_3step(OsipiBase):
required_bounds_optional = True # Bounds may not be required but are optional
required_initial_guess = False
required_initial_guess_optional = True
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
accepted_dimensions = (1,1) #(min dimension, max dimension)

# Supported inputs in the standardized class
supported_bounds = True
Expand All @@ -46,7 +46,6 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
print('warning, bounds from wrapper are not (yet) used in this algorithm')
self.use_bounds = False
self.use_initial_guess = False
# Check the inputs

# Initialize the algorithm
if self.bvalues is not None:
Expand Down
4 changes: 2 additions & 2 deletions src/standardized/IAR_LU_subtracted.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IAR_LU_subtracted(OsipiBase):
required_bounds_optional = True # Bounds may not be required but are optional
required_initial_guess = False
required_initial_guess_optional = True
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
accepted_dimensions = (1,1) #(min dimension, max dimension)

# Supported inputs in the standardized class
supported_bounds = True
Expand All @@ -46,7 +46,6 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
print('warning, bounds from wrapper are not (yet) used in this algorithm')
self.use_bounds = False
self.use_initial_guess = False
# Check the inputs

# Initialize the algorithm
if self.bvalues is not None:
Expand All @@ -70,6 +69,7 @@ def ivim_fit(self, signals, bvalues, **kwargs):
_type_: _description_
"""


if self.IAR_algorithm is None:
if bvalues is None:
bvalues = self.bvalues
Expand Down
9 changes: 6 additions & 3 deletions src/standardized/OGC_AmsterdamUMC_Bayesian_biexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ class OGC_AmsterdamUMC_Bayesian_biexp(OsipiBase):

# Algorithm requirements
required_bvalues = 4
required_thresholds = [0,
0] # Interval from "at least" to "at most", in case submissions allow a custom number of thresholds
required_thresholds = [0,0] # Interval from "at least" to "at most", in case submissions allow a custom number of thresholds
required_bounds = False
required_bounds_optional = True # Bounds may not be required but are optional
required_initial_guess = False
required_initial_guess_optional = True
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
accepted_dimensions = (1,1) #(min dimension, max dimension)
accepts_priors = True


Expand Down Expand Up @@ -86,6 +85,9 @@ def ivim_fit(self, signals, bvalues, initial_guess=None, **kwargs):
Returns:
_type_: _description_
"""

if initial_guess is not None and len(initial_guess) == 4:
self.initial_guess = initial_guess
bvalues=np.array(bvalues)

epsilon = 0.000001
Expand All @@ -100,5 +102,6 @@ def ivim_fit(self, signals, bvalues, initial_guess=None, **kwargs):
results["D"] = fit_results[0]
results["f"] = fit_results[1]
results["Dp"] = fit_results[2]
results["S0"] = fit_results[3]

return results
6 changes: 3 additions & 3 deletions src/standardized/OGC_AmsterdamUMC_biexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ class OGC_AmsterdamUMC_biexp(OsipiBase):

# Algorithm requirements
required_bvalues = 4
required_thresholds = [0,
0] # Interval from "at least" to "at most", in case submissions allow a custom number of thresholds
required_thresholds = [0,0] # Interval from "at least" to "at most", in case submissions allow a custom number of thresholds
required_bounds = False
required_bounds_optional = True # Bounds may not be required but are optional
required_initial_guess = False
required_initial_guess_optional = True
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
accepted_dimensions = (1,1) #(min dimension, max dimension)


# Supported inputs in the standardized class
Expand Down Expand Up @@ -81,5 +80,6 @@ def ivim_fit(self, signals, bvalues, **kwargs):
results["D"] = fit_results[0]
results["f"] = fit_results[1]
results["Dp"] = fit_results[2]
results["S0"] = fit_results[3]

return results
10 changes: 6 additions & 4 deletions src/standardized/OGC_AmsterdamUMC_biexp_segmented.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ class OGC_AmsterdamUMC_biexp_segmented(OsipiBase):

# Algorithm requirements
required_bvalues = 4
required_thresholds = [1,
1] # Interval from "at least" to "at most", in case submissions allow a custom number of thresholds
required_thresholds = [1,1] # Interval from "at least" to "at most", in case submissions allow a custom number of thresholds
required_bounds = False
required_bounds_optional = True # Bounds may not be required but are optional
required_initial_guess = False
required_initial_guess_optional = True
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
accepted_dimensions = (1,1) #(min dimension, max dimension)


# Supported inputs in the standardized class
Expand Down Expand Up @@ -74,13 +73,16 @@ def ivim_fit(self, signals, bvalues, **kwargs):
Returns:
_type_: _description_
"""


if self.initial_guess is not None and len(self.initial_guess) == 4:
self.initial_guess = self.initial_guess
bvalues=np.array(bvalues)
fit_results = self.OGC_algorithm(bvalues, signals, bounds=self.bounds, cutoff=self.thresholds, p0=self.initial_guess)

results = {}
results["D"] = fit_results[0]
results["f"] = fit_results[1]
results["Dp"] = fit_results[2]
results["S0"] = fit_results[3]

return results
3 changes: 1 addition & 2 deletions src/standardized/OJ_GU_seg.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class OJ_GU_seg(OsipiBase):
required_bounds_optional = False # Bounds may not be required but are optional
required_initial_guess = False
required_initial_guess_optional = False
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
accepted_dimensions = (1,1) #(min dimension, max dimension)

# Supported inputs in the standardized class
supported_bounds = False
Expand All @@ -44,7 +44,6 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
print('warning, bounds from wrapper are not (yet) used in this algorithm')
self.use_bounds = False
self.use_initial_guess = False
# Check the inputs

# Initialize the algorithm

Expand Down
2 changes: 1 addition & 1 deletion src/standardized/PV_MUMC_biexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PV_MUMC_biexp(OsipiBase):
required_bounds_optional = True # Bounds may not be required but are optional
required_initial_guess = False
required_initial_guess_optional = True
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
accepted_dimensions = (1,1) #(min dimension, max dimension)

# Supported inputs in the standardized class
supported_bounds = True
Expand Down
5 changes: 2 additions & 3 deletions src/standardized/PvH_KB_NKI_IVIMfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ class PvH_KB_NKI_IVIMfit(OsipiBase):

# Algorithm requirements
required_bvalues = 4
required_thresholds = [0,
0] # Interval from "at least" to "at most", in case submissions allow a custom number of thresholds
required_thresholds = [0,0] # Interval from "at least" to "at most", in case submissions allow a custom number of thresholds
required_bounds = False
required_bounds_optional = False # Bounds may not be required but are optional
required_initial_guess = False
required_initial_guess_optional =False
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
accepted_dimensions = (1,1) #(min dimension, max dimension)

# Supported inputs in the standardized class
supported_bounds = False
Expand Down
Loading
Loading