code: def wls_fit_msdki(
      design_matrix,
      msignal,
      ng,
      mask=None,
      min_signal=MIN_POSITIVE_SIGNAL,
      return_S0_hat=False,
  ):
      r"""
      Fits the mean signal diffusion kurtosis imaging based on a weighted
      least square solution [1]_.
  
      Parameters
      ----------
      design_matrix : array (nub, 3)
          Design matrix holding the covariants used to solve for the regression
          coefficients of the mean signal diffusion kurtosis model. Note that
          nub is the number of unique b-values
      msignal : ndarray ([X, Y, Z, ..., nub])
          Mean signal along all gradient directions for each unique b-value
          Note that the last dimension should contain the signal means and nub
          is the number of unique b-values.
      ng : ndarray(nub)
          Number of gradient directions used to compute the mean signal for
          all unique b-values
      mask : array
          A boolean array used to mark the coordinates in the data that
          should be analyzed that has the shape data.shape[:-1]
      min_signal : float, optional
          Voxel with mean signal intensities lower than the min positive signal
          are not processed. Default: 0.0001
      return_S0_hat : bool
          If True, also return S0 values for the fit.
  
      Returns
      -------
      params : array (..., 2)
          Containing the mean signal diffusivity and mean signal kurtosis
  
      References
      ----------
      .. [1] Henriques, R.N., 2018. Advanced Methods for Diffusion MRI Data
             Analysis and their Application to the Healthy Ageing Brain
             (Doctoral thesis). Downing College, University of Cambridge.
             https://doi.org/10.17863/CAM.29356
      """
      params = np.zeros(msignal.shape[:-1] + (3,))
  
      # Prepare mask
      if mask is None:
          mask = np.ones(msignal.shape[:-1], dtype=bool)
      else:
          if mask.shape != msignal.shape[:-1]:
              raise ValueError("Mask is not the same shape as data.")
          mask = np.array(mask, dtype=bool, copy=False)
  
      index = ndindex(mask.shape)
      for v in index:
          # Skip if out of mask
          if not mask[v]:
              continue
          # Skip if no signal is present
          if np.mean(msignal[v]) <= min_signal:
              continue
          # Define weights as diag(ng * yn**2)
          W = np.diag(ng * msignal[v] ** 2)
  
          # WLS fitting
          BTW = np.dot(design_matrix.T, W)
          inv_BT_W_B = np.linalg.pinv(np.dot(BTW, design_matrix))
          p = np.linalg.multi_dot([inv_BT_W_B, BTW, np.log(msignal[v])])
  
          # Process parameters
          p[1] = p[1] / (p[0] ** 2)
          p[2] = np.exp(p[2])
          params[v] = p
  
      if return_S0_hat:
          return params[..., :2], params[..., 2]
      else:
          return params[..., :2]
  
imports: import numpy
  import scipy.optimize
  from dipy.core.gradients import check_multi_b, unique_bvals_magnitude, round_bvals
  from dipy.reconst.base import ReconstModel
  from dipy.reconst.dti import MIN_POSITIVE_SIGNAL
  from dipy.core.ndindex import ndindex
  from dipy.core.onetime import auto_attr
label_desc: Use image node_id 7 for calling a global function with example usage: wls_fit_msdki(design_matrix, msignal, ng, mask, min_signal, return_S0_hat) and returns: params,  params, params