code: def awf_from_msk(msk, mask=None):
      """
      Computes the axonal water fraction from the mean signal kurtosis
      assuming the 2-compartmental spherical mean technique model [1]_, [2]_
  
      Parameters
      ----------
      msk : ndarray ([X, Y, Z, ...])
          Mean signal kurtosis (msk)
      mask : ndarray, optional
          A boolean array used to mark the coordinates in the data that should be
          analyzed that has the same shape of the msdki parameters
  
      Returns
      -------
      awf : ndarray ([X, Y, Z, ...])
          ndarray containing the axonal volume fraction estimate.
  
      Notes
      -----
      Computes the axonal water fraction from the mean signal kurtosis
      MSK using equation 17 of [1]_
  
      References
      ----------
      .. [1] Neto Henriques R, Jespersen SN, Shemesh N (2019). Microscopic
             anisotropy misestimation in spherical‐mean single diffusion
             encoding MRI. Magnetic Resonance in Medicine (In press).
             doi: 10.1002/mrm.27606
      .. [2] Kaden E, Kelm ND, Carson RP, et al. (2016) Multi‐compartment
             microscopic diffusion imaging. Neuroimage 139:346–359.
      """
      awf = np.zeros(msk.shape)
  
      # Prepare mask
      if mask is None:
          mask = np.ones(msk.shape, dtype=bool)
      else:
          if mask.shape != msk.shape:
              raise ValueError("Mask is not the same shape as data.")
          mask = np.array(mask, dtype=bool, copy=False)
  
      # looping voxels
      index = ndindex(mask.shape)
      for v in index:
          # Skip if out of mask
          if not mask[v]:
              continue
  
          if msk[v] > 2.4:
              awf[v] = 1
          elif msk[v] < 0:
              awf[v] = 0
          else:
              if np.isnan(msk[v]):
                  awf[v] = np.nan
              else:
                  mski = msk[v]
                  fini = (
                      mski / 2.4
                  )  # Initial guess based on linear assumption
                  awf[v] = opt.fsolve(
                      _msk_from_awf_error,
                      fini,
                      args=(mski,),
                      fprime=_diff_msk_from_awf,
                      col_deriv=True,
                  ).item()
  
      return awf
  
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 5 for calling a global function with example usage: awf_from_msk(msk, mask) and returns: awf