code: def test_cti_fits():
      ctiM = cti.CorrelationTensorModel(gtab1, gtab2)
      CTI_data = np.zeros((2, 2, 1, len(gtab1.bvals)))
      for i, DTD in enumerate(DTDs):
          D = np.mean(DTD, axis=0)
          evals, evecs = decompose_tensor(D)
          C = qti.dtd_covariance(DTD)
          C = qti.from_6x6_to_21x1(C)
          ccti = from_qte_to_cti(C)
          MD = mean_diffusivity(evals)
          K = multi_gaussian_k_from_c(ccti, MD)
          cti_params = construct_cti_params(evals, evecs, K, ccti)
          cti_pred_signals = ctiM.predict(cti_params, S0=S0)
          evals, evecs, kt, ct = split_cti_params(cti_params)
  
          # Testing the model with correct min_signal value
          ctiM = cti.CorrelationTensorModel(gtab1, gtab2, min_signal=1)
          cti_pred_signals = ctiM.predict(cti_params, S0=S0)
          ctiF = ctiM.fit(cti_pred_signals)
          evals, evecs, kt, ct = cti.split_cti_params(ctiF.model_params)
          assert_array_almost_equal(evals, ctiF.evals)
          assert_array_almost_equal(evecs, ctiF.evecs)
          assert np.allclose(
              kt, ctiF.kt
          ), "kt doesn't match in test_split_cti_param "
          assert np.allclose(
              ct, ctiF.ct
          ), "ct doesn't match in test_split_cti_param"
  
          # Testing Multi-Voxel Fit
          CTI_data[0, 0, 0] = cti_pred_signals
          CTI_data[0, 1, 0] = cti_pred_signals
          CTI_data[1, 0, 0] = cti_pred_signals
          CTI_data[1, 1, 0] = cti_pred_signals
          multi_params = np.zeros((2, 2, 1, 48))
          multi_params[0, 0, 0] = multi_params[0, 1, 0] = cti_params
          multi_params[1, 0, 0] = multi_params[1, 1, 0] = cti_params
          ctiF_multi = ctiM.fit(CTI_data)
  
          multi_evals, _, multi_kt, multi_ct = split_cti_params(
              ctiF_multi.model_params
          )
          assert np.allclose(evals, multi_evals), "Evals don't match"
          assert np.allclose(kt, multi_kt), "K doesn't match"
          assert np.allclose(ct, multi_ct), "C doesn't match"
  
          # Check that it works with more than one voxel, and with a different S0
          # in each voxel:
          cti_multi_pred_signals = ctiM.predict(
              multi_params, S0=100 * np.ones(ctiF_multi.shape[:3])
          )
          CTI_data = cti_multi_pred_signals
          ctiF_multi_pred_signals = ctiM.fit(CTI_data)
          multi_evals, _, multi_kt, multi_ct = split_cti_params(
              ctiF_multi_pred_signals.model_params
          )
          assert np.allclose(evals, multi_evals), "Evals don't match"
          assert np.allclose(kt, multi_kt), "K doesn't match"
          assert np.allclose(ct, multi_ct), "C doesn't match"
  
          # Testing ls_fit_cti
          inverse_design_matrix = np.linalg.pinv(
              design_matrix(gtab1, gtab2)
          )
          cti_return = ls_fit_cti(
              design_matrix(gtab1, gtab2),
              cti_pred_signals,
              inverse_design_matrix,
          )
          evals_return, _, kt_return, ct_return = split_cti_params(
              cti_return
          )
          assert np.allclose(evals, evals_return), "evals do not match!"
          assert np.allclose(kt, kt_return), "K do not match!"
          assert np.allclose(ct, ct_return), "C do not match!"
  
          # OLS fitting
          ctiM = cti.CorrelationTensorModel(
              gtab1, gtab2, fit_method="OLS"
          )
          ctiF = ctiM.fit(cti_pred_signals)
          ols_evals, _, ols_kt, ols_ct = split_cti_params(
              ctiF.model_params
          )
          assert np.allclose(evals, ols_evals), "evals do not match!"
          assert np.allclose(kt, ols_kt), "K do not match!"
          assert np.allclose(ct, ols_ct), "C do not match!"
  
          # WLS fitting
          cti_wlsM = cti.CorrelationTensorModel(
              gtab1, gtab2, fit_method="WLS"
          )
          cti_wlsF = cti_wlsM.fit(cti_pred_signals)
          wls_evals, _, wls_kt, wls_ct = split_cti_params(
              cti_wlsF.model_params
          )
          assert np.allclose(evals, wls_evals), "evals do not match!"
          assert np.allclose(kt, wls_kt), "K do not match!"
          assert np.allclose(ct, wls_ct), "C do not match!"
  
          # checking Mean Kurtosis Values
          mk_result = ctiF.mk(
              min_kurtosis=-3.0 / 7, max_kurtosis=10, analytical=True
          )
          mean_kurtosis_result = mean_kurtosis(
              cti_params,
              min_kurtosis=-3.0 / 7,
              max_kurtosis=10,
              analytical=True,
          )
          assert np.allclose(mk_result, mean_kurtosis_result), (
              "The results of the mk function from CorrelationTensorFit and the "
              "mean_kurtosis function from dki.py are not equal."
          )
          # checking Axial Kurtosis Values
          ak_result = ctiF.ak(
              min_kurtosis=-3.0 / 7, max_kurtosis=10, analytical=True
          )
          axial_kurtosis_result = axial_kurtosis(
              cti_params,
              min_kurtosis=-3.0 / 7,
              max_kurtosis=10,
              analytical=True,
          )
  
          assert np.allclose(ak_result, axial_kurtosis_result), (
              "The results of the ak function from CorrelationTensorFit and the "
              "axial_kurtosis function from dki.py are not equal."
          )
          # checking Radial kurtosis values
          rk_result = ctiF.rk(
              min_kurtosis=-3.0 / 7, max_kurtosis=10, analytical=True
          )
          radial_kurtosis_result = radial_kurtosis(
              cti_params,
              min_kurtosis=-3.0 / 7,
              max_kurtosis=10,
              analytical=True,
          )
  
          assert np.allclose(rk_result, radial_kurtosis_result), (
              "The results of the rk function from CorrelationTensorFit and the "
              "radial_kurtosis function from DKI.py are not equal."
          )
          # checking Anisotropic values.
          kfa_result = ctiF.kfa
          kurtosis_fractional_anisotropy_result = (
              kurtosis_fractional_anisotropy(cti_params)
          )
          assert np.allclose(
              kfa_result, kurtosis_fractional_anisotropy_result
          ), (
              "The results of the kfa function from CorrelationTensorFit and the"
              "kurtosis_fractional_anisotropy function from dki.py are not equal"
          )
          # checking mean Kurtosis tensor
          mkt_result = ctiF.mkt(min_kurtosis=-3.0 / 7, max_kurtosis=10)
          mean_kurtosis_result = mean_kurtosis_tensor(
              cti_params, min_kurtosis=-3.0 / 7, max_kurtosis=10
          )
          assert np.allclose(mkt_result, mean_kurtosis_result), (
              "The results of the mkt function from CorrelationTensorFit and the"
              "mean_kurtosis_tensor function from dki.py are not equal."
          )
          # checking anisotropic source of kurtosis.
          K_aniso = ctiF.K_aniso
          variance_of_eigenvalues = []
          for tensor in DTD:
              evals_tensor, _ = decompose_tensor(tensor)
              variance_of_eigenvalues.append(np.var(evals_tensor))
          mean_variance_of_eigenvalues = np.mean(
              variance_of_eigenvalues
          )
          mean_D = np.trace(np.mean(DTD, axis=0)) / 3
  
          ground_truth_K_aniso = (6 / 5) * (
              mean_variance_of_eigenvalues / (mean_D**2)
          )
          error_msg = (
              f"Calculated K_iso {K_aniso} for isotropicDTD does not match the "
              f"ground truth {ground_truth_K_aniso}"
          )
          assert np.isclose(K_aniso, ground_truth_K_aniso), error_msg
  
          # checking isotropic source of kurtosis.
          K_iso = ctiF.K_iso
  
          mean_diffusivities = []
  
          for tensor in DTD:
              evals_tensor, _ = decompose_tensor(tensor)
              mean_diffusivities.append(np.mean(evals_tensor))
          variance_of_mean_diffusivities = np.var(mean_diffusivities)
          mean_D = np.mean(mean_diffusivities)
          ground_truth_K_iso = (
              3 * variance_of_mean_diffusivities / (mean_D**2)
          )
  
          error_msg = (
              f"Calculated K_iso {K_iso} for anisotropicDTD does not match the "
              f"ground truth {ground_truth_K_iso}"
          )
          assert np.isclose(K_iso, ground_truth_K_iso), error_msg
  
          # checking microscopic source of kurtosis
          ground_truth_K_micro = 0
          K_micro = ctiF.K_micro
          assert np.allclose(
              K_micro, ground_truth_K_micro
          ), "K_micro values don't match ground truth values"
  
imports: import numpy
  import math
  from dipy.core.sphere import disperse_charges, HemiSphere
  from dipy.reconst.utils import cti_design_matrix
  from numpy.testing import assert_array_almost_equal, assert_raises
  from dipy.reconst.tests.test_qti import _anisotropic_DTD, _isotropic_DTD
  from dipy.core.gradients import gradient_table
  import dipy.reconst.qti
  import dipy.reconst.cti
  from dipy.reconst.dti import decompose_tensor, mean_diffusivity
  from dipy.reconst.cti import split_cti_params, ls_fit_cti, multi_gaussian_k_from_c, from_qte_to_cti
  from dipy.reconst.dki import mean_kurtosis, axial_kurtosis, radial_kurtosis, mean_kurtosis_tensor, kurtosis_fractional_anisotropy
label_desc: Use image node_id 7 for calling a global function with example usage: test_cti_fits() without return types