docstr: Spherical Deconvolution Transform (SDT) [1]_.
  
  The SDT computes a fiber orientation distribution (FOD) as opposed to a
  diffusion ODF as the QballModel or the CsaOdfModel. This results in a
  sharper angular profile with better angular resolution. The Constrained
  SDTModel is similar to the Constrained CSDModel but mathematically it
  deconvolves the q-ball ODF as oppposed to the HARDI signal (see [1]_
  for a comparison and a through discussion).
  
  A sharp fODF is obtained because a single fiber *response* function is
  injected as *a priori* knowledge. In the SDTModel, this response is a
  single fiber q-ball ODF as opposed to a single fiber signal function
  for the CSDModel. The response function will be used as deconvolution
  kernel.
  
  Parameters
  ----------
  gtab : GradientTable
  ratio : float
      ratio of the smallest vs the largest eigenvalue of the single
      prolate tensor response function
  reg_sphere : Sphere
      sphere used to build the regularization B matrix
  sh_order : int
      maximal spherical harmonics order
  lambda_ : float
      weight given to the constrained-positivity regularization part of
      the deconvolution equation
  tau : float
      threshold (tau *mean(fODF)) controlling the amplitude below
      which the corresponding fODF is assumed to be zero.
  
  References
  ----------
  .. [1] Descoteaux, M., et al. IEEE TMI 2009. Deterministic and
         Probabilistic Tractography Based on Complex Fibre Orientation
         Distributions.
docstr_tok: ["Spherical","Deconvolution","Transform","(","SDT",")","[","1","]","_",".","The","SDT","computes","a","fiber","orientation","distribution","(","FOD",")","as","opposed","to","a","diffusion","ODF","as","the","QballModel","or","the","CsaOdfModel",".","This","results","in","a","sharper","angular","profile","with","better","angular","resolution",".","The","Constrained","SDTModel","is","similar","to","the","Constrained","CSDModel","but","mathematically","it","deconvolves","the","q-ball","ODF","as","oppposed","to","the","HARDI","signal","(","see","[","1","]","_","for","a","comparison","and","a","through","discussion",")",".","A","sharp","fODF","is","obtained","because","a","single","fiber","*","response","*","function","is","injected","as","*","a","priori","*","knowledge",".","In","the","SDTModel",",","this","response","is","a","single","fiber","q-ball","ODF","as","opposed","to","a","single","fiber","signal","function","for","the","CSDModel",".","The","response","function","will","be","used","as","deconvolution","kernel",".","Parameters","--","--","--","--","--","gtab",":","GradientTable","ratio",":","float","ratio","of","the","smallest","vs","the","largest","eigenvalue","of","the","single","prolate","tensor","response","function","reg_sphere",":","Sphere","sphere","used","to","build","the","regularization","B","matrix","sh_order",":","int","maximal","spherical","harmonics","order","lambda_",":","float","weight","given","to","the","constrained-positivity","regularization","part","of","the","deconvolution","equation","tau",":","float","threshold","(","tau","*","mean","(","fODF",")",")","controlling","the","amplitude","below","which","the","corresponding","fODF","is","assumed","to","be","zero",".","References","--","--","--","--","--","..","[","1","]","Descoteaux",",","M.",",","et","al",".","IEEE","TMI","2009",".","Deterministic","and","Probabilistic","Tractography","Based","on","Complex","Fibre","Orientation","Distributions","."]
code: def __init__(
      self,
      gtab,
      ratio,
      reg_sphere=None,
      sh_order=8,
      lambda_=1.0,
      tau=0.1,
  ):
      r"""Spherical Deconvolution Transform (SDT) [1]_.
  
      The SDT computes a fiber orientation distribution (FOD) as opposed to a
      diffusion ODF as the QballModel or the CsaOdfModel. This results in a
      sharper angular profile with better angular resolution. The Constrained
      SDTModel is similar to the Constrained CSDModel but mathematically it
      deconvolves the q-ball ODF as oppposed to the HARDI signal (see [1]_
      for a comparison and a through discussion).
  
      A sharp fODF is obtained because a single fiber *response* function is
      injected as *a priori* knowledge. In the SDTModel, this response is a
      single fiber q-ball ODF as opposed to a single fiber signal function
      for the CSDModel. The response function will be used as deconvolution
      kernel.
  
      Parameters
      ----------
      gtab : GradientTable
      ratio : float
          ratio of the smallest vs the largest eigenvalue of the single
          prolate tensor response function
      reg_sphere : Sphere
          sphere used to build the regularization B matrix
      sh_order : int
          maximal spherical harmonics order
      lambda_ : float
          weight given to the constrained-positivity regularization part of
          the deconvolution equation
      tau : float
          threshold (tau *mean(fODF)) controlling the amplitude below
          which the corresponding fODF is assumed to be zero.
  
      References
      ----------
      .. [1] Descoteaux, M., et al. IEEE TMI 2009. Deterministic and
             Probabilistic Tractography Based on Complex Fibre Orientation
             Distributions.
  
      """
      SphHarmModel.__init__(self, gtab)
      m, n = sph_harm_ind_list(sh_order)
      self.m, self.n = m, n
      self._where_b0s = lazy_index(gtab.b0s_mask)
      self._where_dwi = lazy_index(~gtab.b0s_mask)
  
      no_params = ((sh_order + 1) * (sh_order + 2)) / 2
  
      if no_params > np.sum(~gtab.b0s_mask):
          msg = "Number of parameters required for the fit are more "
          msg += "than the actual data points"
          warnings.warn(msg, UserWarning)
  
      x, y, z = gtab.gradients[self._where_dwi].T
      r, theta, phi = cart2sphere(x, y, z)
      # for the gradient sphere
      self.B_dwi = real_sh_descoteaux_from_index(
          m, n, theta[:, None], phi[:, None]
      )
  
      # for the odf sphere
      if reg_sphere is None:
          self.sphere = get_sphere("symmetric362")
      else:
          self.sphere = reg_sphere
  
      r, theta, phi = cart2sphere(
          self.sphere.x, self.sphere.y, self.sphere.z
      )
      self.B_reg = real_sh_descoteaux_from_index(
          m, n, theta[:, None], phi[:, None]
      )
  
      self.R, self.P = forward_sdt_deconv_mat(ratio, n)
  
      # scale lambda_ to account for differences in the number of
      # SH coefficients and number of mapped directions
      self.lambda_ = (
          lambda_ * self.R.shape[0] * self.R[0, 0] / self.B_reg.shape[0]
      )
      self.tau = tau
      self.sh_order = sh_order
  
imports: import warnings
  import numpy
  import numbers
  from scipy.integrate import quad
  from scipy.special import lpn, gamma
  import scipy.linalg
  import scipy.linalg.lapack
  from dipy.data import small_sphere, get_sphere, default_sphere
  from dipy.core.geometry import cart2sphere
  from dipy.core.ndindex import ndindex
  from dipy.sims.voxel import single_tensor
  from dipy.reconst.multi_voxel import multi_voxel_fit
  from dipy.reconst.dti import TensorModel, fractional_anisotropy
  from dipy.reconst.shm import sph_harm_ind_list, real_sh_descoteaux_from_index, sph_harm_lookup, lazy_index, SphHarmFit, real_sh_descoteaux, sh_to_rh, forward_sdeconv_mat, SphHarmModel
  from dipy.reconst.utils import _roi_in_volume, _mask_from_roi
  from dipy.direction.peaks import peaks_from_model
  from dipy.core.geometry import vec2vec_rotmat
  from dipy.utils.deprecator import deprecate_with_version, deprecated_params
label_desc: Use image node_id 1 to create a new ConstrainedSDTModel object from inherited base classes: SphHarmModel with example: obj = ConstrainedSDTModel(gtab, ratio, reg_sphere, sh_order, lambda_, tau)