@@ -33,7 +33,7 @@ class ASD_MemorialSloanKettering_QAMPER_IVIM(OsipiBase):
33
33
supported_initial_guess = True
34
34
supported_thresholds = False
35
35
36
- def __init__ (self , bvalues = None , thresholds = None , bounds = None , initial_guess = None ):
36
+ def __init__ (self , bvalues = None , thresholds = None , bounds = None , initial_guess = None , eng = None ):
37
37
"""
38
38
Everything this algorithm requires should be implemented here.
39
39
Number of segmentation thresholds, bounds, etc.
@@ -44,7 +44,14 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
44
44
#super(OGC_AmsterdamUMC_biexp, self).__init__(bvalues, bounds, initial_guess, fitS0)
45
45
super (ASD_MemorialSloanKettering_QAMPER_IVIM , self ).__init__ (bvalues = bvalues , bounds = bounds , initial_guess = initial_guess )
46
46
self .initialize (bounds , initial_guess )
47
- self .eng = matlab .engine .start_matlab ()
47
+ if eng is None :
48
+ print ('initiating matlab; this may take some time. For repeated testing one could use the optional input eng as an already initiated matlab engine' )
49
+ self .eng = matlab .engine .start_matlab ()
50
+ self .keep_alive = False
51
+ else :
52
+ self .eng = eng
53
+ self .keep_alive = True
54
+
48
55
49
56
50
57
def algorithm (self ,dwi_arr , bval_arr , LB0 , UB0 , x0in ):
@@ -61,12 +68,12 @@ def algorithm(self,dwi_arr, bval_arr, LB0, UB0, x0in):
61
68
def initialize (self , bounds , initial_guess ):
62
69
if bounds is None :
63
70
print ('warning, no bounds were defined, so algorithm-specific default bounds are used' )
64
- self .bounds = ([1e-6 , 0 , 1e-6 , 0 ],[0.003 , 1.0 , 5e- 2 , 5 ])
71
+ self .bounds = ([1e-6 , 0 , 0.004 , 0 ],[0.003 , 1.0 , 0. 2 , 5 ])
65
72
else :
66
73
self .bounds = bounds
67
74
if initial_guess is None :
68
75
print ('warning, no initial guesses were defined, so algorithm-specific default initial guess is used' )
69
- self .initial_guess = [0.001 , 0.001 , 0.2 , 1 ]
76
+ self .initial_guess = [0.001 , 0.2 , 0.01 , 1 ]
70
77
else :
71
78
self .initial_guess = initial_guess
72
79
self .use_initial_guess = True
@@ -85,10 +92,10 @@ def ivim_fit(self, signals, bvalues, **kwargs):
85
92
"""
86
93
87
94
bvalues = np .array (bvalues )
88
- LB = np .array (self .bounds [0 ])
89
- UB = np .array (self .bounds [1 ])
95
+ LB = np .array (self .bounds [0 ])[[ 1 , 0 , 2 , 3 ]]
96
+ UB = np .array (self .bounds [1 ])[[ 1 , 0 , 2 , 3 ]]
90
97
91
- fit_results = self .algorithm (np .array (signals )[:,np .newaxis ], bvalues , LB , UB , np .array (self .initial_guess ))
98
+ fit_results = self .algorithm (np .array (signals )[:,np .newaxis ], bvalues , LB , UB , np .array (self .initial_guess )[[ 1 , 0 , 2 , 3 ]] )
92
99
93
100
results = {}
94
101
results ["D" ] = fit_results [0 ]
@@ -99,20 +106,22 @@ def ivim_fit(self, signals, bvalues, **kwargs):
99
106
100
107
101
108
def __del__ (self ):
102
- if hasattr (self , "eng" ) and self .eng :
103
- try :
104
- self .eng .quit ()
105
- except Exception as e :
106
- print (f"Warning: Failed to quit MATLAB engine cleanly: { e } " )
109
+ if not self .keep_alive :
110
+ if hasattr (self , "eng" ) and self .eng :
111
+ try :
112
+ self .eng .quit ()
113
+ except Exception as e :
114
+ print (f"Warning: Failed to quit MATLAB engine cleanly: { e } " )
107
115
108
116
109
117
def __enter__ (self ):
110
118
return self
111
119
112
120
113
121
def __exit__ (self , exc_type , exc_val , exc_tb ):
114
- if hasattr (self , "eng" ) and self .eng :
115
- try :
116
- self .eng .quit ()
117
- except Exception as e :
118
- print (f"Warning: Failed to quit MATLAB engine cleanly: { e } " )
122
+ if not self .keep_alive :
123
+ if hasattr (self , "eng" ) and self .eng :
124
+ try :
125
+ self .eng .quit ()
126
+ except Exception as e :
127
+ print (f"Warning: Failed to quit MATLAB engine cleanly: { e } " )
0 commit comments