code: def test_wls_and_ls_fit():
      """
      Tests the WLS and LS fitting functions to see if they returns the correct
      eigenvalues and eigenvectors.
  
      Uses data/55dir_grad as the gradient table and 3by3by56.nii
      as the data.
  
      """
  
      # Defining Test Voxel (avoid nibabel dependency) ###
  
      # Recall: D = [Dxx,Dyy,Dzz,Dxy,Dxz,Dyz,log(S_0)] and D ~ 10^-4 mm^2 /s
      b0 = 1000.0
      bval, bvec = read_bvals_bvecs(*get_fnames("55dir_grad"))
      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
      md = evals.mean()
      tensor = from_lower_triangular(D)
      # Design Matrix
      gtab = grad.gradient_table(bval, bvec)
      X = dti.design_matrix(gtab)
      # Signals
      Y = np.exp(np.dot(X, D))
      npt.assert_almost_equal(Y[0], b0)
      Y.shape = (-1,) + Y.shape
  
      # Testing WLS Fit on single voxel
      # If you do something wonky (passing min_signal<0), you should get an
      # error:
      npt.assert_raises(
          ValueError, TensorModel, gtab, fit_method="WLS", min_signal=-1
      )
  
      # Estimate tensor from test signals
      model = TensorModel(gtab, fit_method="WLS", return_S0_hat=True)
      tensor_est = model.fit(Y)
      npt.assert_equal(tensor_est.shape, Y.shape[:-1])
      npt.assert_array_almost_equal(tensor_est.evals[0], evals)
      npt.assert_array_almost_equal(
          tensor_est.quadratic_form[0],
          tensor,
          err_msg="Calculation of tensor from Y does "
          "not compare to analytical solution",
      )
      npt.assert_almost_equal(tensor_est.md[0], md)
      npt.assert_array_almost_equal(tensor_est.S0_hat[0], b0, decimal=3)
  
      # Test that we can fit a single voxel's worth of data (a 1d array)
      y = Y[0]
      tensor_est = model.fit(y)
      npt.assert_equal(tensor_est.shape, tuple())
      npt.assert_array_almost_equal(tensor_est.evals, evals)
      npt.assert_array_almost_equal(tensor_est.quadratic_form, tensor)
      npt.assert_almost_equal(tensor_est.md, md)
      npt.assert_array_almost_equal(tensor_est.lower_triangular(b0), D)
  
      # Test using fit_method='LS'
      model = TensorModel(gtab, fit_method="LS")
      tensor_est = model.fit(y)
      npt.assert_equal(tensor_est.shape, tuple())
      npt.assert_array_almost_equal(tensor_est.evals, evals)
      npt.assert_array_almost_equal(tensor_est.quadratic_form, tensor)
      npt.assert_almost_equal(tensor_est.md, md)
      npt.assert_array_almost_equal(tensor_est.lower_triangular(b0), D)
      npt.assert_array_almost_equal(
          tensor_est.linearity, linearity(evals)
      )
      npt.assert_array_almost_equal(
          tensor_est.planarity, planarity(evals)
      )
      npt.assert_array_almost_equal(
          tensor_est.sphericity, sphericity(evals)
      )
  
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 10 for calling a global function with example usage: test_wls_and_ls_fit() without return types