def test_single_voxel_fit(): """ Test the implementation of the fitting for a single voxel. Here, we will use the multi_tensor function to generate a bi-exponential signal. The multi_tensor generates a multi tensor signal and expects eigenvalues of each tensor in mevals. Our basic test requires a scalar signal isotropic signal and hence we set the same eigenvalue in all three directions to generate the required signal. The bvals, f, D_star and D are inspired from the paper by Federau, Christian, et al. We use the function "generate_bvecs" to simulate bvectors corresponding to the bvalues. In the two stage fitting routine, initially we fit the signal values for bvals less than the specified split_b using the TensorModel and get an intial guess for f and D. Then, using these parameters we fit the entire data for all bvalues. """ est_signal = ivim_prediction(ivim_fit_single.model_params, gtab) assert_array_equal(est_signal.shape, data_single.shape) assert_array_almost_equal(ivim_fit_single.model_params, params_LM) assert_array_almost_equal(est_signal, data_single) # Test predict function for single voxel p = ivim_fit_single.predict(gtab) assert_array_equal(p.shape, data_single.shape) assert_array_almost_equal(p, data_single)
def test_single_voxel_fit(): """ Test the implementation of the fitting for a single voxel. Here, we will use the multi_tensor function to generate a bi-exponential signal. The multi_tensor generates a multi tensor signal and expects eigenvalues of each tensor in mevals. Our basic test requires a scalar signal isotropic signal and hence we set the same eigenvalue in all three directions to generate the required signal. The bvals, f, D_star and D are inspired from the paper by Federau, Christian, et al. We use the function "generate_bvecs" to simulate bvectors corresponding to the bvalues. In the two stage fitting routine, initially we fit the signal values for bvals less than the specified split_b using the TensorModel and get an intial guess for f and D. Then, using these parameters we fit the entire data for all bvalues. """ est_signal = ivim_prediction(ivim_fit_single.model_params, gtab) assert_array_equal(est_signal.shape, data_single.shape) assert_array_almost_equal(ivim_fit_single.model_params, params) assert_array_almost_equal(est_signal, data_single) # Test predict function for single voxel p = ivim_fit_single.predict(gtab) assert_array_equal(p.shape, data_single.shape) assert_array_almost_equal(p, data_single)
def test_bounds_x0(): """ Test to check if setting bounds for signal where initial value is higher than subsequent values works. These values are from the IVIM dataset which can be obtained by using the `read_ivim` function from dipy.data.fetcher. These are values from the voxel [160, 98, 33] which can be obtained by : .. code-block:: python from dipy.data.fetcher import read_ivim img, gtab = read_ivim() data = img.get_data() signal = data[160, 98, 33, :] """ test_signal = np.array([4574.34814453, 4745.18164062, 4759.51806641, 4618.24951172, 4665.63623047, 4568.046875, 4525.90478516, 4734.54785156, 4526.41357422, 4299.99414062, 4256.61279297, 4254.50292969, 4098.74707031, 3776.10375977, 3614.0769043, 3440.56445312, 3146.52294922, 3006.94287109, 2879.69580078, 2728.44018555, 2600.09472656]) x0_test = np.array([1., 0.13, 0.001, 0.0001]) test_signal = ivim_prediction(x0_test, gtab) ivim_fit = ivim_model.fit(test_signal) est_signal = ivim_fit.predict(gtab) assert_array_equal(est_signal.shape, test_signal.shape)
def test_bounds_x0(): """ Test to check if setting bounds for signal where initial value is higher than subsequent values works. These values are from the IVIM dataset which can be obtained by using the `read_ivim` function from dipy.data.fetcher. These are values from the voxel [160, 98, 33] which can be obtained by : .. code-block:: python from dipy.data.fetcher import read_ivim img, gtab = read_ivim() data = img.get_data() signal = data[160, 98, 33, :] """ x0_test = np.array([1., 0.13, 0.001, 0.0001]) test_signal = ivim_prediction(x0_test, gtab) ivim_fit = ivim_model_LM.fit(test_signal) est_signal = ivim_fit.predict(gtab) assert_array_equal(est_signal.shape, test_signal.shape)
def test_bounds_x0(): """ Test to check if setting bounds for signal where initial value is higher than subsequent values works. These values are from the IVIM dataset which can be obtained by using the `read_ivim` function from dipy.data.fetcher. These are values from the voxel [160, 98, 33] which can be obtained by : .. code-block:: python from dipy.data.fetcher import read_ivim img, gtab = read_ivim() data = img.get_data() signal = data[160, 98, 33, :] """ x0_test = np.array([1., 0.13, 0.001, 0.0001]) test_signal = ivim_prediction(x0_test, gtab) ivim_fit = ivim_model.fit(test_signal) est_signal = ivim_fit.predict(gtab) assert_array_equal(est_signal.shape, test_signal.shape)