@@ -75,29 +75,44 @@ def data_ivim_fit_saved():
75
75
for name , data in all_data .items ():
76
76
for algorithm in algorithms :
77
77
algorithm_dict = algorithm_information .get (algorithm , {})
78
- xfail = name in algorithm_dict .get ("xfail_names" , [])
78
+ xfail = {"xfail" : name in algorithm_dict .get ("xfail_names" , {}),
79
+ "strict" : algorithm_dict .get ("xfail_names" , {}).get (name , True )}
79
80
kwargs = algorithm_dict .get ("options" , {})
80
- tolerances = algorithm_dict .get ("tolerances" , None )
81
+ tolerances = algorithm_dict .get ("tolerances" , {} )
81
82
yield name , bvals , data , algorithm , xfail , kwargs , tolerances
82
83
83
84
84
85
@pytest .mark .parametrize ("name, bvals, data, algorithm, xfail, kwargs, tolerances" , data_ivim_fit_saved ())
85
86
def test_ivim_fit_saved (name , bvals , data , algorithm , xfail , kwargs , tolerances , request ):
86
- if xfail :
87
- mark = pytest .mark .xfail (reason = "xfail" , strict = True )
87
+ if xfail [ "xfail" ] :
88
+ mark = pytest .mark .xfail (reason = "xfail" , strict = xfail [ "strict" ] )
88
89
request .node .add_marker (mark )
89
90
fit = OsipiBase (algorithm = algorithm , ** kwargs )
90
91
signal = np .asarray (data ['data' ])
91
92
signal = np .abs (signal )
92
93
signal /= signal [0 ]
94
+ ratio = 1 / signal [0 ]
93
95
# has_negatives = np.any(signal<0)
94
- if tolerances is None :
95
- # signal = np.abs(signal)
96
- # ratio = 1 / signal[0]
97
- # signal /= signal[0]
98
- # tolerance = 1e-2 + 25 * data['noise'] * ratio # totally empirical
99
- # tolerance = 1
100
- tolerances = {"f" : 5 , "D" : 5 , "Dp" : 25 }
96
+ if "dynamic_rtol" in tolerances :
97
+ dyn_rtol = tolerances ["dynamic_rtol" ]
98
+ scale = dyn_rtol ["offset" ] + dyn_rtol ["ratio" ]* ratio + dyn_rtol ["noise" ]* data ["noise" ] + dyn_rtol ["noiseCrossRatio" ]* ratio * data ["noise" ]
99
+ tolerances ["rtol" ] = {"f" : scale * dyn_rtol ["f" ], "D" : scale * dyn_rtol ["D" ], "Dp" : scale * dyn_rtol ["Dp" ]}
100
+ else :
101
+ tolerances ["rtol" ] = tolerances .get ("rtol" , {"f" : 5 , "D" : 5 , "Dp" : 25 })
102
+ if "dynamic_atol" in tolerances :
103
+ dyn_atol = tolerances ["dynamic_atol" ]
104
+ scale = dyn_atol ["offset" ] + dyn_atol ["ratio" ]* ratio + dyn_atol ["noise" ]* data ["noise" ] + dyn_atol ["noiseCrossRatio" ]* ratio * data ["noise" ]
105
+ tolerances ["atol" ] = {"f" : scale * dyn_atol ["f" ], "D" : scale * dyn_atol ["D" ], "Dp" : scale * dyn_atol ["Dp" ]}
106
+ else :
107
+ tolerances ["atol" ] = tolerances .get ("atol" , {"f" : 1e-2 , "D" : 1e-2 , "Dp" : 1e-1 })
108
+ # if tolerances:
109
+ # # signal = np.abs(signal)
110
+ # # ratio = 1 / signal[0]
111
+ # # signal /= signal[0]
112
+ # # tolerance = 1e-2 + 25 * data['noise'] * ratio # totally empirical
113
+ # # tolerance = 1
114
+ # tolerances = {"rtol": {"f": 5, "D": 5, "Dp": 25},
115
+ # "atol": {"f": 1e-2, "D": 1e-2, "Dp": 1e-1}}
101
116
#if has_negatives: # this fitting doesn't do well with negatives
102
117
# tolerance += 1
103
118
#if data['f'] == 1.0:
@@ -108,6 +123,6 @@ def test_ivim_fit_saved(name, bvals, data, algorithm, xfail, kwargs, tolerances,
108
123
#npt.assert_allclose([data['f'], data['D']], [f_fit, D_fit], atol=tolerance)
109
124
#npt.assert_allclose(data['Dp'], Dp_fit, atol=1e-1) # go easy on the perfusion as it's a linear fake
110
125
[f_fit , Dp_fit , D_fit ] = fit .ivim_fit (signal , bvals )
111
- npt .assert_allclose (data ['f' ], f_fit , rtol = tolerances ["f" ])
112
- npt .assert_allclose (data ['D' ], D_fit , rtol = tolerances ["D" ])
113
- npt .assert_allclose (data ['Dp' ], Dp_fit , rtol = tolerances ["Dp" ]) # go easy on the perfusion as it's a linear fake
126
+ npt .assert_allclose (data ['f' ], f_fit , rtol = tolerances ["rtol" ][ "f" ], atol = tolerances [ "atol" ][ " f" ])
127
+ npt .assert_allclose (data ['D' ], D_fit , rtol = tolerances ["rtol" ][ "D" ], atol = tolerances [ "atol" ][ " D" ])
128
+ npt .assert_allclose (data ['Dp' ], Dp_fit , rtol = tolerances ["rtol" ][ " Dp" ], atol = tolerances [ "atol" ][ "Dp" ])
0 commit comments