code: def mean_kurtosis(
      dki_params, min_kurtosis=-3.0 / 7, max_kurtosis=3, analytical=True
  ):
      r""" Compute mean kurtosis (MK) from the kurtosis tensor
  
      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 eigenvector
          3) Fifteen elements of the kurtosis tensor
      min_kurtosis : float (optional)
          To keep kurtosis values within a plausible biophysical range, mean
          kurtosis values that are 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 [4]_)
      max_kurtosis : float (optional)
          To keep kurtosis values within a plausible biophysical range, mean
          kurtosis values that are larger than `max_kurtosis` are replaced with
          `max_kurtosis`. Default = 10
      analytical : bool (optional)
          If True, MK is calculated using its analytical solution, otherwise an
          exact numerical estimator is used (see Notes). Default is set to True
  
      Returns
      -------
      mk : array
          Calculated MK.
  
      Notes
      -----
      The MK is defined as the average of directional kurtosis coefficients
      across all spatial directions, which can be formulated by the following
      surface integral[1]_:
  
      .. math::
  
           MK \equiv \frac{1}{4\pi} \int d\Omega_\mathbf{n} K(\mathbf{n})
  
      This integral can be numerically solved by averaging directional
      kurtosis values sampled for directions of a spherical t-design [2]_.
  
      Alternatively, MK can be solved from the analytical solution derived by
      Tabesh et al. [3]_. This solution is given by:
  
      .. math::
  
          MK=F_1(\lambda_1,\lambda_2,\lambda_3)\hat{W}_{1111}+
             F_1(\lambda_2,\lambda_1,\lambda_3)\hat{W}_{2222}+
             F_1(\lambda_3,\lambda_2,\lambda_1)\hat{W}_{3333}+ \\
             F_2(\lambda_1,\lambda_2,\lambda_3)\hat{W}_{2233}+
             F_2(\lambda_2,\lambda_1,\lambda_3)\hat{W}_{1133}+
             F_2(\lambda_3,\lambda_2,\lambda_1)\hat{W}_{1122}
  
      where $\hat{W}_{ijkl}$ are the components of the $W$ tensor in the
      coordinates system defined by the eigenvectors of the diffusion tensor
      $\mathbf{D}$ and
  
      .. math::
  
          F_1(\lambda_1,\lambda_2,\lambda_3)=
          \frac{(\lambda_1+\lambda_2+\lambda_3)^2}
          {18(\lambda_1-\lambda_2)(\lambda_1-\lambda_3)}
          [\frac{\sqrt{\lambda_2\lambda_3}}{\lambda_1}
          R_F(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)+\\
          \frac{3\lambda_1^2-\lambda_1\lambda_2-\lambda_2\lambda_3-
          \lambda_1\lambda_3}
          {3\lambda_1 \sqrt{\lambda_2 \lambda_3}}
          R_D(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)-1 ]
  
          F_2(\lambda_1,\lambda_2,\lambda_3)=
          \frac{(\lambda_1+\lambda_2+\lambda_3)^2}
          {3(\lambda_2-\lambda_3)^2}
          [\frac{\lambda_2+\lambda_3}{\sqrt{\lambda_2\lambda_3}}
          R_F(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)+\\
          \frac{2\lambda_1-\lambda_2-\lambda_3}{3\sqrt{\lambda_2 \lambda_3}}
          R_D(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)-2]
  
      where $R_f$ and $R_d$ are the Carlson's elliptic integrals.
  
      References
      ----------
      .. [1] Jensen, J.H., Helpern, J.A., 2010. MRI quantification of
             non-Gaussian water diffusion by kurtosis analysis. NMR in
             Biomedicine 23(7): 698-710
      .. [2] Hardin, R.H., Sloane, N.J.A., 1996. McLaren's Improved Snub Cube and
             Other New Spherical Designs in Three Dimensions. Discrete and
             Computational Geometry 15, 429-441.
      .. [3] Tabesh, A., Jensen, J.H., Ardekani, B.A., Helpern, J.A., 2011.
             Estimation of tensors and tensor-derived measures in diffusional
             kurtosis imaging. Magn Reson Med. 65(3), 823-836
      .. [4] 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. For numpy versions more recent than 1.6.0, this step
      # isn't required
      outshape = dki_params.shape[:-1]
      dki_params = dki_params.reshape((-1, dki_params.shape[-1]))
  
      if analytical:
          # Split the model parameters to three variable containing the evals,
          # evecs, and kurtosis elements
          evals, evecs, kt = split_dki_param(dki_params)
  
          # Rotate the kurtosis tensor from the standard Cartesian coordinate
          # system to another coordinate system in which the 3 orthonormal
          # eigenvectors of DT are the base coordinate
          Wxxxx = Wrotate_element(kt, 0, 0, 0, 0, evecs)
          Wyyyy = Wrotate_element(kt, 1, 1, 1, 1, evecs)
          Wzzzz = Wrotate_element(kt, 2, 2, 2, 2, evecs)
          Wxxyy = Wrotate_element(kt, 0, 0, 1, 1, evecs)
          Wxxzz = Wrotate_element(kt, 0, 0, 2, 2, evecs)
          Wyyzz = Wrotate_element(kt, 1, 1, 2, 2, evecs)
  
          # Compute MK
          MK = (
              _F1m(evals[..., 0], evals[..., 1], evals[..., 2]) * Wxxxx
              + _F1m(evals[..., 1], evals[..., 0], evals[..., 2])
              * Wyyyy
              + _F1m(evals[..., 2], evals[..., 1], evals[..., 0])
              * Wzzzz
              + _F2m(evals[..., 0], evals[..., 1], evals[..., 2])
              * Wyyzz
              + _F2m(evals[..., 1], evals[..., 0], evals[..., 2])
              * Wxxzz
              + _F2m(evals[..., 2], evals[..., 1], evals[..., 0])
              * Wxxyy
          )
  
      else:
          # Numerical Solution using t-design of 45 directions
          V = np.loadtxt(get_fnames("t-design"))
          sph = dps.Sphere(xyz=V)
          KV = apparent_kurtosis_coef(
              dki_params, sph, min_kurtosis=min_kurtosis
          )
          MK = np.mean(KV, axis=-1)
  
      if min_kurtosis is not None:
          MK = MK.clip(min=min_kurtosis)
  
      if max_kurtosis is not None:
          MK = MK.clip(max=max_kurtosis)
  
      return MK.reshape(outshape)
  
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 10 for calling a global function with example usage: mean_kurtosis(dki_params, min_kurtosis, max_kurtosis, analytical) and returns: MK