code: def test_kurtosis_maximum():
      # TEST 1
      # simulate a crossing fibers intersecting at 70 degrees. The first fiber
      # is aligned to the x-axis while the second fiber is aligned to the x-z
      # plane with an angular deviation of 70 degrees from the first one.
      # According to Neto Henriques et al, 2015 (NeuroImage 111: 85-99), the
      # kurtosis tensor of this simulation will have a maxima aligned to axis y
      angles = [(90, 0), (90, 0), (20, 0), (20, 0)]
      signal_70, dt_70, kt_70 = multi_tensor_dki(
          gtab_2s,
          mevals_cross,
          S0=100,
          angles=angles,
          fractions=frac_cross,
          snr=None,
      )
      # prepare inputs
      dkiM = dki.DiffusionKurtosisModel(gtab_2s, fit_method="WLS")
      dkiF = dkiM.fit(signal_70)
      MD = dkiF.md
      kt = dkiF.kt
      R = dkiF.evecs
      evals = dkiF.evals
      dt = lower_triangular(np.dot(np.dot(R, np.diag(evals)), R.T))
      sphere = default_sphere
  
      # compute maxima
      k_max_cross, max_dir = dki._voxel_kurtosis_maximum(
          dt, MD, kt, sphere, gtol=1e-5
      )
  
      yaxis = np.array([0.0, 1.0, 0.0])
      cos_angle = np.abs(np.dot(max_dir[0], yaxis))
      assert_almost_equal(cos_angle, 1.0)
  
      # TEST 2
      # test the function on cases of well aligned fibers oriented in a random
      # defined direction. According to Neto Henriques et al, 2015 (NeuroImage
      # 111: 85-99), the maxima of kurtosis is any direction perpendicular to the
      # fiber direction. Moreover, according to multicompartmetal simulations,
      # kurtosis in this direction has to be equal to:
      fie = 0.49
      ADi = 0.00099
      ADe = 0.00226
      RDi = 0
      RDe = 0.00087
      RD = fie * RDi + (1 - fie) * RDe
      RK = 3 * fie * (1 - fie) * ((RDi - RDe) / RD) ** 2
  
      # prepare simulation:
      theta = random.uniform(0, 180)
      phi = random.uniform(0, 320)
      angles = [(theta, phi), (theta, phi)]
      mevals = np.array([[ADi, RDi, RDi], [ADe, RDe, RDe]])
      frac = [fie * 100, (1 - fie) * 100]
      signal, dt, kt = multi_tensor_dki(
          gtab_2s, mevals, angles=angles, fractions=frac, snr=None
      )
  
      # prepare inputs
      dkiM = dki.DiffusionKurtosisModel(gtab_2s, fit_method="WLS")
      dkiF = dkiM.fit(signal)
      MD = dkiF.md
      kt = dkiF.kt
      R = dkiF.evecs
      evals = dkiF.evals
      dt = lower_triangular(np.dot(np.dot(R, np.diag(evals)), R.T))
  
      # compute maxima
      k_max, max_dir = dki._voxel_kurtosis_maximum(
          dt, MD, kt, sphere, gtol=1e-5
      )
  
      # check if max direction is perpendicular to fiber direction
      fdir = np.array(
          [sphere2cart(1.0, np.deg2rad(theta), np.deg2rad(phi))]
      )
      cos_angle = np.abs(np.dot(max_dir[0], fdir[0]))
      assert_almost_equal(cos_angle, 0.0, decimal=5)
  
      # check if max direction is equal to expected value
      assert_almost_equal(k_max, RK)
  
      # According to Neto Henriques et al., 2015 (NeuroImage 111: 85-99),
      # e.g. see figure 1 of this article, kurtosis maxima for the first test is
      # also equal to the maxima kurtosis value of well-aligned fibers, since
      # simulations parameters (apart from fiber directions) are equal
      assert_almost_equal(k_max_cross, RK)
  
      # Test 3 - Test performance when kurtosis is spherical - this case, can be
      # problematic since a spherical kurtosis does not have an maximum
      k_max, max_dir = dki._voxel_kurtosis_maximum(
          dt_sph, np.mean(evals_sph), kt_sph, sphere, gtol=1e-2
      )
      assert_almost_equal(k_max, Kref_sphere)
  
      # Test 4 - Test performance when kt have all elements zero - this case, can
      # be problematic this case does not have an maximum
      k_max, max_dir = dki._voxel_kurtosis_maximum(
          dt_sph, np.mean(evals_sph), np.zeros(15), sphere, gtol=1e-2
      )
      assert_almost_equal(k_max, 0.0)
  
imports: import numpy
  import random
  import dipy.reconst.dki
  import dipy.reconst.dti
  from numpy.testing import assert_array_almost_equal, assert_array_equal, assert_almost_equal, assert_raises
  from dipy.sims.voxel import multi_tensor_dki
  from dipy.io.gradients import read_bvals_bvecs
  from dipy.core.gradients import gradient_table
  from dipy.data import get_fnames
  from dipy.reconst.dti import from_lower_triangular, decompose_tensor
  from dipy.reconst.dki import mean_kurtosis, carlson_rf, carlson_rd, axial_kurtosis, radial_kurtosis, mean_kurtosis_tensor, _positive_evals, lower_triangular, kurtosis_fractional_anisotropy
  from dipy.core.sphere import Sphere
  from dipy.data import default_sphere
  from dipy.core.geometry import sphere2cart
  from dipy.utils.optpkg import optional_package
  from dipy.utils.tripwire import TripWireError
label_desc: Use image node_id 19 for calling a global function with example usage: test_kurtosis_maximum() without return types