Skip to content

Commit d65aa4d

Browse files
author
IvanARashid
committed
Changed how args and kwargs are passed through osipi_fit
1 parent a7e1da3 commit d65aa4d

File tree

6 files changed

+26
-79
lines changed

6 files changed

+26
-79
lines changed

src/standardized/IAR_LU_biexp.py

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

5353

54-
def ivim_fit(self, signals, bvalues=None):
54+
def ivim_fit(self, signals, bvalues):
5555
"""Perform the IVIM fit
5656
5757
Args:

src/standardized/IAR_LU_segmented_2step.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class IAR_LU_segmented_2step(OsipiBase):
2828
required_initial_guess_optional = True
2929
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
3030

31-
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None, weighting=None, stats=False):
31+
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None):
3232
"""
3333
Everything this algorithm requires should be implemented here.
3434
Number of segmentation thresholds, bounds, etc.
@@ -51,7 +51,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
5151
self.IAR_algorithm = None
5252

5353

54-
def ivim_fit(self, signals, bvalues=None):
54+
def ivim_fit(self, signals, bvalues, thresholds=None):
5555
"""Perform the IVIM fit
5656
5757
Args:
@@ -61,6 +61,7 @@ def ivim_fit(self, signals, bvalues=None):
6161
Returns:
6262
_type_: _description_
6363
"""
64+
print(thresholds)
6465

6566
if self.IAR_algorithm is None:
6667
if bvalues is None:

src/standardized/IAR_LU_subtracted.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class IAR_LU_subtracted(OsipiBase):
2828
required_initial_guess_optional = True
2929
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
3030

31-
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None, weighting=None, stats=False):
31+
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None):
3232
"""
3333
Everything this algorithm requires should be implemented here.
3434
Number of segmentation thresholds, bounds, etc.
@@ -51,7 +51,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
5151
self.IAR_algorithm = None
5252

5353

54-
def ivim_fit(self, signals, bvalues=None):
54+
def ivim_fit(self, signals, bvalues):
5555
"""Perform the IVIM fit
5656
5757
Args:

src/standardized/PV_MUMC_biexp.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/wrappers/OsipiBase.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,32 @@ def osipi_initiate_algorithm(self, algorithm, **kwargs):
4242
self.__class__ = getattr(importlib.import_module(import_path), algorithm)
4343
self.__init__(**kwargs)
4444

45-
def osipi_fit(self, data=None, bvalues=None, thresholds=None, bounds=None, initial_guess=None, **kwargs):
45+
#def osipi_fit(self, data=None, bvalues=None, thresholds=None, bounds=None, initial_guess=None, **kwargs):
46+
def osipi_fit(self, data, bvalues, **kwargs):
4647
"""Fits the data with the bvalues
4748
Returns [S0, f, Dstar, D]
4849
"""
4950

5051
# We should first check whether the attributes in the __init__ are not None
5152
# Then check if they are input here, if they are, these should overwrite the attributes
5253
use_bvalues = bvalues if bvalues is not None else self.bvalues
53-
use_thresholds = thresholds if self.bvalues is None else self.thresholds
54-
use_bounds = bounds if self.bounds is None else self.bounds
55-
use_initial_guess = initial_guess if self.initial_guess is None else self.initial_guess
54+
#use_thresholds = thresholds if self.thresholds is None else self.thresholds
55+
#use_bounds = bounds if self.bounds is None else self.bounds
56+
#use_initial_guess = initial_guess if self.initial_guess is None else self.initial_guess
5657

5758
# Make sure we don't make arrays of None's
5859
if use_bvalues is not None: use_bvalues = np.asarray(use_bvalues)
59-
if use_thresholds is not None: use_thresholds = np.asarray(use_thresholds)
60-
if use_bounds is not None: use_bounds = np.asarray(use_bounds)
61-
if use_initial_guess is not None: use_initial_guess = np.asarray(use_initial_guess)
62-
kwargs["bvalues"] = use_bvalues
60+
#if use_thresholds is not None: use_thresholds = np.asarray(use_thresholds)
61+
#if use_bounds is not None: use_bounds = np.asarray(use_bounds)
62+
#if use_initial_guess is not None: use_initial_guess = np.asarray(use_initial_guess)
63+
#kwargs["bvalues"] = use_bvalues
6364

6465
#args = [data, use_bvalues, use_thresholds]
65-
args = [data, use_thresholds]
66-
if self.required_bounds or self.required_bounds_optional:
67-
args.append(use_bounds)
68-
if self.required_initial_guess or self.required_initial_guess_optional:
69-
args.append(use_initial_guess)
66+
args = [data, use_bvalues]
67+
#if self.required_bounds or self.required_bounds_optional:
68+
#args.append(use_bounds)
69+
#if self.required_initial_guess or self.required_initial_guess_optional:
70+
#args.append(use_initial_guess)
7071

7172
# Run a check_requirements method that makes sure that these inputs fulfil the requirements
7273

@@ -76,7 +77,7 @@ def osipi_fit(self, data=None, bvalues=None, thresholds=None, bounds=None, initi
7677
# Then we pass everything into the ivim_fit method which performs the fit according to the algorithm
7778

7879
#args = [data, use_bvalues, use_initial_guess, use_bounds, use_thresholds]
79-
args = [arg for arg in args if arg is not None]
80+
#args = [arg for arg in args if arg is not None]
8081
results = self.ivim_fit(*args, **kwargs)
8182

8283
#self.parameter_estimates = self.ivim_fit(data, bvalues)

tests/IVIMmodels/unit_tests/simple_test_run_of_algorithm.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import os
33
from pathlib import Path
44
#from src.standardized.ETP_SRI_LinearFitting import ETP_SRI_LinearFitting
5-
#from src.standardized.IAR_LU_biexp import IAR_LU_biexp
6-
from src.standardized.PV_MUMC_biexp import PV_MUMC_biexp
5+
from src.standardized.IAR_LU_biexp import IAR_LU_biexp
6+
from src.standardized.IAR_LU_segmented_2step import IAR_LU_segmented_2step
7+
#from src.standardized.PV_MUMC_biexp import PV_MUMC_biexp
78

89
## Simple test code...
910
# Used to just do a test run of an algorithm during development
@@ -25,7 +26,7 @@ def ivim_model(b, S0=1, f=0.1, Dstar=0.01, D=0.001):
2526

2627
#model1 = ETP_SRI_LinearFitting(thresholds=[200])
2728
#model2 = IAR_LU_biexp()
28-
model2 = PV_MUMC_biexp()
29+
model2 = IAR_LU_segmented_2step()
2930

3031
#dev_test_run(model1, linear_fit_option=True)
31-
dev_test_run(model2)
32+
dev_test_run(model2, thresholds="Arbitrary kwarg for ivim_fit")

0 commit comments

Comments
 (0)