docstr: Diffusion Spectrum Imaging
  
  The theoretical idea underlying this method is that the diffusion
  propagator $P(\mathbf{r})$ (probability density function of the average
  spin displacements) can be estimated by applying 3D FFT to the signal
  values $S(\mathbf{q})$
  
  ..math::
      :nowrap:
          \begin{eqnarray}
              P(\mathbf{r}) & = & S_{0}^{-1}\int S(\mathbf{q})\exp(-i2\pi\mathbf{q}\cdot\mathbf{r})d\mathbf{r}
          \end{eqnarray}
  
  where $\mathbf{r}$ is the displacement vector and $\mathbf{q}$ is the
  wave vector which corresponds to different gradient directions. Method
  used to calculate the ODFs. Here we implement the method proposed by
  Wedeen et al. [1]_.
  
  The main assumption for this model is fast gradient switching and that
  the acquisition gradients will sit on a keyhole Cartesian grid in
  q_space [3]_.
  
  Parameters
  ----------
  gtab : GradientTable,
      Gradient directions and bvalues container class
  qgrid_size : int,
      has to be an odd number. Sets the size of the q_space grid.
      For example if qgrid_size is 17 then the shape of the grid will be
      ``(17, 17, 17)``.
  r_start : float,
      ODF is sampled radially in the PDF. This parameters shows where the
      sampling should start.
  r_end : float,
      Radial endpoint of ODF sampling
  r_step : float,
      Step size of the ODf sampling from r_start to r_end
  filter_width : float,
      Strength of the hanning filter
  
  References
  ----------
  .. [1]  Wedeen V.J et al., "Mapping Complex Tissue Architecture With
  Diffusion Spectrum Magnetic Resonance Imaging", MRM 2005.
  
  .. [2] Canales-Rodriguez E.J et al., "Deconvolution in Diffusion
  Spectrum Imaging", Neuroimage, 2010.
  
  .. [3] Garyfallidis E, "Towards an accurate brain tractography", PhD
  thesis, University of Cambridge, 2012.
  
  Examples
  --------
  In this example where we provide the data, a gradient table
  and a reconstruction sphere, we calculate generalized FA for the first
  voxel in the data with the reconstruction performed using DSI.
  
  >>> import warnings
  >>> from dipy.data import dsi_voxels, default_sphere
  >>> data, gtab = dsi_voxels()
  >>> from dipy.reconst.dsi import DiffusionSpectrumModel
  >>> ds = DiffusionSpectrumModel(gtab)
  >>> dsfit = ds.fit(data)
  >>> from dipy.reconst.odf import gfa
  >>> np.round(gfa(dsfit.odf(default_sphere))[0, 0, 0], 2)
  0.11
  
  Notes
  -----
  A. Have in mind that DSI expects gradients on both hemispheres. If your
  gradients span only one hemisphere you need to duplicate the data and
  project them to the other hemisphere before calling this class. The
  function dipy.reconst.dsi.half_to_full_qspace can be used for this
  purpose.
  
  B. If you increase the size of the grid (parameter qgrid_size) you will
  most likely also need to update the r_* parameters. This is because
  the added zero padding from the increase of gqrid_size also introduces
  a scaling of the PDF.
  
  C. We assume that data only one b0 volume is provided.
  
  See Also
  --------
  dipy.reconst.gqi.GeneralizedQSampling
docstr_tok: ["Diffusion","Spectrum","Imaging","The","theoretical","idea","underlying","this","method","is","that","the","diffusion","propagator","$","P","(","\\mathbf","{","r","}",")","$","(","probability","density","function","of","the","average","spin","displacements",")","can","be","estimated","by","applying","3D","FFT","to","the","signal","values","$","S","(","\\mathbf","{","q","}",")","$","..","math",":",":",":","nowrap",":","\\begin","{","eqnarray","}","P","(","\\mathbf","{","r","}",")","&","=","&","S_","{","0","}","^","{","-1","}","\\int","S","(","\\mathbf","{","q","}",")","\\exp","(","-i2\\pi\\mathbf","{","q","}","\\cdot\\mathbf","{","r","}",")","d\\mathbf","{","r","}","\\end","{","eqnarray","}","where","$","\\mathbf","{","r","}","$","is","the","displacement","vector","and","$","\\mathbf","{","q","}","$","is","the","wave","vector","which","corresponds","to","different","gradient","directions",".","Method","used","to","calculate","the","ODFs",".","Here","we","implement","the","method","proposed","by","Wedeen","et","al",".","[","1","]","_",".","The","main","assumption","for","this","model","is","fast","gradient","switching","and","that","the","acquisition","gradients","will","sit","on","a","keyhole","Cartesian","grid","in","q_space","[","3","]","_.","Parameters","--","--","--","--","--","gtab",":","GradientTable",",","Gradient","directions","and","bvalues","container","class","qgrid_size",":","int",",","has","to","be","an","odd","number",".","Sets","the","size","of","the","q_space","grid",".","For","example","if","qgrid_size","is","17","then","the","shape","of","the","grid","will","be","``","(","17",",","17",",","17",")","``",".","r_start",":","float",",","ODF","is","sampled","radially","in","the","PDF",".","This","parameters","shows","where","the","sampling","should","start",".","r_end",":","float",",","Radial","endpoint","of","ODF","sampling","r_step",":","float",",","Step","size","of","the","ODf","sampling","from","r_start","to","r_end","filter_width",":","float",",","Strength","of","the","hanning","filter","References","--","--","--","--","--","..","[","1","]","Wedeen","V.J","et","al.",",","``","Mapping","Complex","Tissue","Architecture","With","Diffusion","Spectrum","Magnetic","Resonance","Imaging","''",",","MRM","2005",".","..","[","2","]","Canales-Rodriguez","E.J","et","al.",",","``","Deconvolution","in","Diffusion","Spectrum","Imaging","''",",","Neuroimage",",","2010",".","..","[","3","]","Garyfallidis","E",",","``","Towards","an","accurate","brain","tractography","''",",","PhD","thesis",",","University","of","Cambridge",",","2012",".","Examples","--","--","--","--","In","this","example","where","we","provide","the","data",",","a","gradient","table","and","a","reconstruction","sphere",",","we","calculate","generalized","FA","for","the","first","voxel","in","the","data","with","the","reconstruction","performed","using","DSI",".",">",">",">","import","warnings",">",">",">","from","dipy.data","import","dsi_voxels",",","default_sphere",">",">",">","data",",","gtab","=","dsi_voxels","(",")",">",">",">","from","dipy.reconst.dsi","import","DiffusionSpectrumModel",">",">",">","ds","=","DiffusionSpectrumModel","(","gtab",")",">",">",">","dsfit","=","ds.fit","(","data",")",">",">",">","from","dipy.reconst.odf","import","gfa",">",">",">","np.round","(","gfa","(","dsfit.odf","(","default_sphere",")",")","[","0",",","0",",","0","]",",","2",")","0.11","Notes","--","--","-","A",".","Have","in","mind","that","DSI","expects","gradients","on","both","hemispheres",".","If","your","gradients","span","only","one","hemisphere","you","need","to","duplicate","the","data","and","project","them","to","the","other","hemisphere","before","calling","this","class",".","The","function","dipy.reconst.dsi.half_to_full_qspace","can","be","used","for","this","purpose",".","B",".","If","you","increase","the","size","of","the","grid","(","parameter","qgrid_size",")","you","will","most","likely","also","need","to","update","the","r_","*","parameters",".","This","is","because","the","added","zero","padding","from","the","increase","of","gqrid_size","also","introduces","a","scaling","of","the","PDF",".","C.","We","assume","that","data","only","one","b0","volume","is","provided",".","See","Also","--","--","--","--","dipy.reconst.gqi.GeneralizedQSampling"]
code: def __init__(
      self,
      gtab,
      qgrid_size=17,
      r_start=2.1,
      r_end=6.0,
      r_step=0.2,
      filter_width=32,
      normalize_peaks=False,
  ):
      r"""Diffusion Spectrum Imaging
  
      The theoretical idea underlying this method is that the diffusion
      propagator $P(\mathbf{r})$ (probability density function of the average
      spin displacements) can be estimated by applying 3D FFT to the signal
      values $S(\mathbf{q})$
  
      ..math::
          :nowrap:
              \begin{eqnarray}
                  P(\mathbf{r}) & = & S_{0}^{-1}\int S(\mathbf{q})\exp(-i2\pi\mathbf{q}\cdot\mathbf{r})d\mathbf{r}
              \end{eqnarray}
  
      where $\mathbf{r}$ is the displacement vector and $\mathbf{q}$ is the
      wave vector which corresponds to different gradient directions. Method
      used to calculate the ODFs. Here we implement the method proposed by
      Wedeen et al. [1]_.
  
      The main assumption for this model is fast gradient switching and that
      the acquisition gradients will sit on a keyhole Cartesian grid in
      q_space [3]_.
  
      Parameters
      ----------
      gtab : GradientTable,
          Gradient directions and bvalues container class
      qgrid_size : int,
          has to be an odd number. Sets the size of the q_space grid.
          For example if qgrid_size is 17 then the shape of the grid will be
          ``(17, 17, 17)``.
      r_start : float,
          ODF is sampled radially in the PDF. This parameters shows where the
          sampling should start.
      r_end : float,
          Radial endpoint of ODF sampling
      r_step : float,
          Step size of the ODf sampling from r_start to r_end
      filter_width : float,
          Strength of the hanning filter
  
      References
      ----------
      .. [1]  Wedeen V.J et al., "Mapping Complex Tissue Architecture With
      Diffusion Spectrum Magnetic Resonance Imaging", MRM 2005.
  
      .. [2] Canales-Rodriguez E.J et al., "Deconvolution in Diffusion
      Spectrum Imaging", Neuroimage, 2010.
  
      .. [3] Garyfallidis E, "Towards an accurate brain tractography", PhD
      thesis, University of Cambridge, 2012.
  
      Examples
      --------
      In this example where we provide the data, a gradient table
      and a reconstruction sphere, we calculate generalized FA for the first
      voxel in the data with the reconstruction performed using DSI.
  
      >>> import warnings
      >>> from dipy.data import dsi_voxels, default_sphere
      >>> data, gtab = dsi_voxels()
      >>> from dipy.reconst.dsi import DiffusionSpectrumModel
      >>> ds = DiffusionSpectrumModel(gtab)
      >>> dsfit = ds.fit(data)
      >>> from dipy.reconst.odf import gfa
      >>> np.round(gfa(dsfit.odf(default_sphere))[0, 0, 0], 2)
      0.11
  
      Notes
      -----
      A. Have in mind that DSI expects gradients on both hemispheres. If your
      gradients span only one hemisphere you need to duplicate the data and
      project them to the other hemisphere before calling this class. The
      function dipy.reconst.dsi.half_to_full_qspace can be used for this
      purpose.
  
      B. If you increase the size of the grid (parameter qgrid_size) you will
      most likely also need to update the r_* parameters. This is because
      the added zero padding from the increase of gqrid_size also introduces
      a scaling of the PDF.
  
      C. We assume that data only one b0 volume is provided.
  
      See Also
      --------
      dipy.reconst.gqi.GeneralizedQSampling
  
      """
  
      self.bvals = gtab.bvals
      self.bvecs = gtab.bvecs
      self.normalize_peaks = normalize_peaks
      # 3d volume for Sq
      if qgrid_size % 2 == 0:
          raise ValueError("qgrid_size needs to be an odd integer")
      self.qgrid_size = qgrid_size
      # necessary shifting for centering
      self.origin = self.qgrid_size // 2
  
      # hanning filter width
      self.filter = hanning_filter(gtab, filter_width, self.origin)
      # odf sampling radius
      self.qradius = np.arange(r_start, r_end, r_step)
      self.qradiusn = len(self.qradius)
      # create qspace grid
      self.qgrid = create_qspace(gtab, self.origin)
      b0 = np.min(self.bvals)
      self.dn = (self.bvals > b0).sum()
      self.gtab = gtab
  
imports: import numpy
  from scipy.ndimage import map_coordinates
  from scipy.fftpack import fftn, fftshift, ifftshift
  from dipy.reconst.odf import OdfModel, OdfFit
  from dipy.reconst.cache import Cache
  from dipy.reconst.multi_voxel import multi_voxel_fit
label_desc: Use image node_id 1 to create a new DiffusionSpectrumModel object from inherited base classes: OdfModel, Cache with example: obj = DiffusionSpectrumModel(gtab, qgrid_size, r_start, r_end, r_step, filter_width, normalize_peaks)