code: def apparent_kurtosis_coef(
      dki_params, sphere, min_diffusivity=0, min_kurtosis=-3.0 / 7
  ):
      r"""Calculate the apparent kurtosis coefficient (AKC) in each direction
      of a sphere [1]_
  
      Parameters
      ----------
      dki_params : ndarray (x, y, z, 27) or (n, 27)
      All parameters estimated from the diffusion kurtosis model.
      Parameters are ordered as follows:
          1) Three diffusion tensor's eigenvalues
          2) Three lines of the eigenvector matrix each containing the first,
              second and third coordinates of the eigenvectors respectively
          3) Fifteen elements of the kurtosis tensor
      sphere : a Sphere class instance
          The AKC will be calculated for each of the vertices in the sphere
      min_diffusivity : float (optional)
          Because negative eigenvalues are not physical and small eigenvalues
          cause quite a lot of noise in diffusion-based metrics, diffusivity
          values smaller than `min_diffusivity` are replaced with
          `min_diffusivity`. Default = 0
      min_kurtosis : float (optional)
          Because high-amplitude negative values of kurtosis are not physically
          and biologicaly pluasible, and these cause artefacts in
          kurtosis-based measures, directional kurtosis values smaller than
          `min_kurtosis` are replaced with `min_kurtosis`. Default = -3./7
          (theoretical kurtosis limit for regions that consist of water confined
          to spherical pores [2]_)
  
      Returns
      -------
      akc : ndarray (x, y, z, g) or (n, g)
          Apparent kurtosis coefficient (AKC) for all g directions of a sphere.
  
      Notes
      -----
      For each sphere direction with coordinates $(n_{1}, n_{2}, n_{3})$, the
      calculation of AKC is done using formula [1]_:
  
      .. math ::
  
          AKC(n)=\frac{MD^{2}}{ADC(n)^{2}}\sum_{i=1}^{3}\sum_{j=1}^{3}
          \sum_{k=1}^{3}\sum_{l=1}^{3}n_{i}n_{j}n_{k}n_{l}W_{ijkl}
  
      where $W_{ijkl}$ are the elements of the kurtosis tensor, MD the mean
      diffusivity and ADC the apparent diffusion coefficient computed as:
  
      .. math ::
  
          ADC(n)=\sum_{i=1}^{3}\sum_{j=1}^{3}n_{i}n_{j}D_{ij}
  
      where $D_{ij}$ are the elements of the diffusion tensor.
  
      References
      ----------
      .. [1] Neto Henriques R, Correia MM, Nunes RG, Ferreira HA (2015).
             Exploring the 3D geometry of the diffusion kurtosis tensor -
             Impact on the development of robust tractography procedures and
             novel biomarkers, NeuroImage 111: 85-99
      .. [2] Barmpoutis, A., & Zhuo, J., 2011. Diffusion kurtosis imaging:
             Robust estimation from DW-MRI using homogeneous polynomials.
             Proceedings of the 8th {IEEE} International Symposium on
             Biomedical Imaging: From Nano to Macro, ISBI 2011, 262-265.
             doi: 10.1109/ISBI.2011.5872402
  
      """
      # Flat parameters
      outshape = dki_params.shape[:-1]
      dki_params = dki_params.reshape((-1, dki_params.shape[-1]))
  
      # Split data
      evals, evecs, kt = split_dki_param(dki_params)
  
      # Initialize AKC matrix
      V = sphere.vertices
      akc = np.zeros((len(kt), len(V)))
  
      # select relevant voxels to process
      rel_i = _positive_evals(
          evals[..., 0], evals[..., 1], evals[..., 2]
      )
      kt = kt[rel_i]
      evecs = evecs[rel_i]
      evals = evals[rel_i]
      akci = akc[rel_i]
  
      # Compute MD and DT
      md = mean_diffusivity(evals)
      dt = lower_triangular(vec_val_vect(evecs, evals))
  
      # loop over all relevant voxels
      for vox in range(len(kt)):
          akci[vox] = directional_kurtosis(
              dt[vox],
              md[vox],
              kt[vox],
              V,
              min_diffusivity=min_diffusivity,
              min_kurtosis=min_kurtosis,
          )
  
      # reshape data according to input data
      akc[rel_i] = akci
  
      return akc.reshape((outshape + (len(V),)))
  
imports: import numpy
  import warnings
  import scipy.optimize
  import dipy.core.sphere
  from dipy.reconst.multi_voxel import multi_voxel_fit
  from dipy.reconst.dti import TensorFit, mean_diffusivity, from_lower_triangular, lower_triangular, decompose_tensor, MIN_POSITIVE_SIGNAL, nlls_fit_tensor, restore_fit_tensor
  from dipy.reconst.utils import dki_design_matrix
  from dipy.reconst.recspeed import local_maxima
  from dipy.reconst.base import ReconstModel
  from dipy.core.ndindex import ndindex
  from dipy.core.geometry import sphere2cart, cart2sphere, perpendicular_directions
  from dipy.core.optimize import PositiveDefiniteLeastSquares
  from dipy.data import get_sphere, get_fnames, load_sdp_constraints
  from dipy.reconst.vec_val_sum import vec_val_vect
  from dipy.core.gradients import check_multi_b
label_desc: Use image node_id 9 for calling a global function with example usage: apparent_kurtosis_coef(dki_params, sphere, min_diffusivity, min_kurtosis) and returns: akc