code: def test_restore():
      """
      Test the implementation of the RESTORE algorithm
      """
      b0 = 1000.0
      bval, bvecs = read_bvals_bvecs(*get_fnames("55dir_grad"))
      gtab = grad.gradient_table(bval, bvecs)
      B = bval[1]
  
      # Scale the eigenvalues and tensor by the B value so the units match
      D = np.array([1.0, 1.0, 1.0, 0.0, 0.0, 1.0, -np.log(b0) * B]) / B
      evals = np.array([2.0, 1.0, 0.0]) / B
      tensor = from_lower_triangular(D)
  
      # Design Matrix
      X = dti.design_matrix(gtab)
  
      # Signals
      Y = np.exp(np.dot(X, D))
      Y = np.vstack([Y[None, :], Y[None, :]])  # two voxels
      for drop_this in range(1, Y.shape[-1]):
          for jac in [True, False]:
              # RESTORE estimates should be robust to dropping
              this_y = Y.copy()
              this_y[:, drop_this] = 1.0
              for sigma in [
                  67.0,
                  np.array([67.0]),
                  np.ones(this_y.shape[-1]) * 67.0,
                  np.array([66.0, 67.0]).reshape((-1, 1)),
              ]:
                  tensor_model = dti.TensorModel(
                      gtab, fit_method="restore", jac=jac, sigma=sigma
                  )
  
                  tensor_est = tensor_model.fit(this_y)
                  npt.assert_array_almost_equal(
                      tensor_est.evals[0], evals, decimal=3
                  )
                  npt.assert_array_almost_equal(
                      tensor_est.quadratic_form[0], tensor, decimal=3
                  )
  
      # If sigma is very small, it still needs to work:
      tensor_model = dti.TensorModel(
          gtab, fit_method="restore", sigma=0.0001
      )
      tensor_model.fit(Y.copy())
  
      # Test return_S0_hat
      tensor_model = dti.TensorModel(
          gtab, fit_method="restore", sigma=0.0001, return_S0_hat=True
      )
      tmf = tensor_model.fit(Y.copy())
      npt.assert_almost_equal(tmf[0].S0_hat, b0)
  
      # Test warning for failure of NLLS method, resort to OLS result
      # (reason for failure: too few data points for NLLS, due to negative sigma)
      tensor_model = dti.TensorModel(
          gtab, fit_method="restore", sigma=-1.0, return_S0_hat=True
      )
      tmf = npt.assert_warns(UserWarning, tensor_model.fit, Y.copy())
  
      # Test fail_is_nan=True, failed NLLS method gives NaN
      tensor_model = dti.TensorModel(
          gtab,
          fit_method="restore",
          sigma=-1.0,
          return_S0_hat=True,
          fail_is_nan=True,
      )
      tmf = npt.assert_warns(UserWarning, tensor_model.fit, Y.copy())
      npt.assert_equal(tmf[0].S0_hat, np.nan)
  
imports: import warnings
  import numpy
  import numpy.testing
  import scipy.optimize
  import dipy.reconst.dti
  from dipy.io.gradients import read_bvals_bvecs
  from dipy.reconst.dti import ols_resort_msg, axial_diffusivity, color_fa, fractional_anisotropy, from_lower_triangular, geodesic_anisotropy, lower_triangular, mean_diffusivity, radial_diffusivity, TensorModel, trace, linearity, planarity, sphericity, decompose_tensor, _decompose_tensor_nan
  from dipy.io.image import load_nifti_data
  from dipy.data import get_fnames, dsi_voxels, get_sphere
  from dipy.core.subdivide_octahedron import create_unit_sphere
  import dipy.core.gradients
  import dipy.core.sphere
  from dipy.sims.voxel import single_tensor
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 20 for calling a global function with example usage: test_restore() without return types