docstr: Multi-Shell Multi-Tissue Constrained Spherical Deconvolution
  (MSMT-CSD) [1]_. This method extends the CSD model proposed in [2]_ by
  the estimation of multiple response functions as a function of multiple
  b-values and multiple tissue types.
  
  Spherical deconvolution computes a fiber orientation distribution
  (FOD), also called fiber ODF (fODF) [2]_. The fODF is derived from
  different tissue types and thus overcomes the overestimation of WM in
  GM and CSF areas.
  
  The response function is based on the different tissue types
  and is provided as input to the MultiShellDeconvModel.
  It will be used as deconvolution kernel, as described in [2]_.
  
  Parameters
  ----------
  gtab : GradientTable
  response : ndarray or MultiShellResponse object
      Pre-computed multi-shell fiber response function in the form of a
      MultiShellResponse object, or simple response function as a ndarray.
      The later must be of shape (3, len(bvals)-1, 4), because it will be
      converted into a MultiShellResponse object via the
      `multi_shell_fiber_response` method (important note: the function
      `unique_bvals_tolerance` is used here to select unique bvalues from
      gtab as input). Each column (3,) has two elements. The first is the
      eigen-values as a (3,) ndarray and the second is the signal value
      for the response function without diffusion weighting (S0). Note
      that in order to use more than three compartments, one must create
      a MultiShellResponse object on the side.
  reg_sphere : Sphere (optional)
      sphere used to build the regularization B matrix.
      Default: 'symmetric362'.
  sh_order : int (optional)
      maximal spherical harmonics order. Default: 8
  iso: int (optional)
      Number of tissue compartments for running the MSMT-CSD. Minimum
      number of compartments required is 2.
      Default: 2
  tol : int, optional
      Tolerance gap for b-values clustering.
  
  References
  ----------
  .. [1] Jeurissen, B., et al. NeuroImage 2014. Multi-tissue constrained
         spherical deconvolution for improved analysis of multi-shell
         diffusion MRI data
  .. [2] Tournier, J.D., et al. NeuroImage 2007. Robust determination of
         the fibre orientation distribution in diffusion MRI:
         Non-negativity constrained super-resolved spherical
         deconvolution
  .. [3] Tournier, J.D, et al. Imaging Systems and Technology
         2012. MRtrix: Diffusion Tractography in Crossing Fiber Regions
code: def __init__(
      self,
      gtab,
      response,
      reg_sphere=default_sphere,
      sh_order=8,
      iso=2,
      tol=20,
  ):
      r"""
      Multi-Shell Multi-Tissue Constrained Spherical Deconvolution
      (MSMT-CSD) [1]_. This method extends the CSD model proposed in [2]_ by
      the estimation of multiple response functions as a function of multiple
      b-values and multiple tissue types.
  
      Spherical deconvolution computes a fiber orientation distribution
      (FOD), also called fiber ODF (fODF) [2]_. The fODF is derived from
      different tissue types and thus overcomes the overestimation of WM in
      GM and CSF areas.
  
      The response function is based on the different tissue types
      and is provided as input to the MultiShellDeconvModel.
      It will be used as deconvolution kernel, as described in [2]_.
  
      Parameters
      ----------
      gtab : GradientTable
      response : ndarray or MultiShellResponse object
          Pre-computed multi-shell fiber response function in the form of a
          MultiShellResponse object, or simple response function as a ndarray.
          The later must be of shape (3, len(bvals)-1, 4), because it will be
          converted into a MultiShellResponse object via the
          `multi_shell_fiber_response` method (important note: the function
          `unique_bvals_tolerance` is used here to select unique bvalues from
          gtab as input). Each column (3,) has two elements. The first is the
          eigen-values as a (3,) ndarray and the second is the signal value
          for the response function without diffusion weighting (S0). Note
          that in order to use more than three compartments, one must create
          a MultiShellResponse object on the side.
      reg_sphere : Sphere (optional)
          sphere used to build the regularization B matrix.
          Default: 'symmetric362'.
      sh_order : int (optional)
          maximal spherical harmonics order. Default: 8
      iso: int (optional)
          Number of tissue compartments for running the MSMT-CSD. Minimum
          number of compartments required is 2.
          Default: 2
      tol : int, optional
          Tolerance gap for b-values clustering.
  
      References
      ----------
      .. [1] Jeurissen, B., et al. NeuroImage 2014. Multi-tissue constrained
             spherical deconvolution for improved analysis of multi-shell
             diffusion MRI data
      .. [2] Tournier, J.D., et al. NeuroImage 2007. Robust determination of
             the fibre orientation distribution in diffusion MRI:
             Non-negativity constrained super-resolved spherical
             deconvolution
      .. [3] Tournier, J.D, et al. Imaging Systems and Technology
             2012. MRtrix: Diffusion Tractography in Crossing Fiber Regions
      """
      if not iso >= 2:
          msg = (
              "Multi-tissue CSD requires at least 2 tissue compartments"
          )
          raise ValueError(msg)
  
      super(MultiShellDeconvModel, self).__init__(gtab)
  
      if not isinstance(response, MultiShellResponse):
          bvals = unique_bvals_tolerance(gtab.bvals, tol=tol)
          if iso > 2:
              msg = """Too many compartments for this kind of response
                  input. It must be two tissue compartments."""
              raise ValueError(msg)
          if response.shape != (3, len(bvals) - 1, 4):
              msg = """Response must be of shape (3, len(bvals)-1, 4) or be a
                  MultiShellResponse object."""
              raise ValueError(msg)
          response = multi_shell_fiber_response(
              sh_order,
              bvals=bvals,
              wm_rf=response[0],
              gm_rf=response[1],
              csf_rf=response[2],
          )
  
      B, m, n = multi_tissue_basis(gtab, sh_order, iso)
  
      delta = _basic_delta(
          response.iso, response.m, response.n, 0.0, 0.0
      )
      self.delta = delta
      multiplier_matrix = _inflate_response(response, gtab, n, delta)
  
      r, theta, phi = geo.cart2sphere(*reg_sphere.vertices.T)
      odf_reg, _, _ = shm.real_sh_descoteaux(sh_order, theta, phi)
      reg = np.zeros([i + iso for i in odf_reg.shape])
      reg[:iso, :iso] = np.eye(iso)
      reg[iso:, iso:] = odf_reg
  
      X = B * multiplier_matrix
  
      self.fitter = QpFitter(X, reg)
      self.sh_order = sh_order
      self._X = X
      self.sphere = reg_sphere
      self.gtab = gtab
      self.B_dwi = B
      self.m = m
      self.n = n
      self.response = response
  
imports: from packaging.version import Version
  import numbers
  import warnings
  import numpy
  from dipy.core import geometry
  from dipy.core.gradients import GradientTable, gradient_table, unique_bvals_tolerance, get_bval_indices
  from dipy.data import default_sphere
  from dipy.reconst import shm
  from dipy.reconst.csdeconv import response_from_mask_ssst
  from dipy.reconst.dti import TensorModel, fractional_anisotropy, mean_diffusivity
  from dipy.reconst.multi_voxel import multi_voxel_fit
  from dipy.reconst.utils import _roi_in_volume, _mask_from_roi
  from dipy.sims.voxel import single_tensor
  from dipy.utils.optpkg import optional_package
label_desc: Use image node_id 1 to create a new MultiShellDeconvModel object from inherited base classes: shm with example: obj = MultiShellDeconvModel(gtab, response, reg_sphere, sh_order, iso, tol)