class_docstr: Simple Harmonic Oscillator based Reconstruction and Estimation
  (SHORE) [1]_ of the diffusion signal.
  
  The main idea is to model the diffusion signal as a linear combination of
  continuous functions $\phi_i$,
  
  ..math::
      :nowrap:
          \begin{equation}
              S(\mathbf{q})= \sum_{i=0}^I  c_{i} \phi_{i}(\mathbf{q}).
          \end{equation}
  
  where $\mathbf{q}$ is the wave vector which corresponds to different
  gradient directions. Numerous continuous functions $\phi_i$ can be used to
  model $S$. Some are presented in [2,3,4]_.
  
  From the $c_i$ coefficients, there exist analytical formulae to estimate
  the ODF, the return to the origin probability (RTOP), the mean square
  displacement (MSD), amongst others [5]_.
  
  References
  ----------
  .. [1] Ozarslan E. et al., "Simple harmonic oscillator based reconstruction
         and estimation for one-dimensional q-space magnetic resonance
         1D-SHORE)", Proc Intl Soc Mag Reson Med, vol. 16, p. 35., 2008.
  
  .. [2] Merlet S. et al., "Continuous diffusion signal, EAP and ODF
         estimation via Compressive Sensing in diffusion MRI", Medical
         Image Analysis, 2013.
  
  .. [3] Rathi Y. et al., "Sparse multi-shell diffusion imaging", MICCAI,
         2011.
  
  .. [4] Cheng J. et al., "Theoretical Analysis and Practical Insights on
         EAP Estimation via a Unified HARDI Framework", MICCAI workshop on
         Computational Diffusion MRI, 2011.
  
  .. [5] Ozarslan E. et al., "Mean apparent propagator (MAP) MRI: A novel
         diffusion imaging method for mapping tissue microstructure",
         NeuroImage, 2013.
  
  Notes
  -----
  The implementation of SHORE depends on CVXPY (https://www.cvxpy.org/).
class_docstr_tok: ["Simple","Harmonic","Oscillator","based","Reconstruction","and","Estimation","(","SHORE",")","[","1","]","_","of","the","diffusion","signal",".","The","main","idea","is","to","model","the","diffusion","signal","as","a","linear","combination","of","continuous","functions","$","\\phi_i","$",",","..","math",":",":",":","nowrap",":","\\begin","{","equation","}","S","(","\\mathbf","{","q","}",")","=","\\sum_","{","i=0","}","^I","c_","{","i","}","\\phi_","{","i","}","(","\\mathbf","{","q","}",")",".","\\end","{","equation","}","where","$","\\mathbf","{","q","}","$","is","the","wave","vector","which","corresponds","to","different","gradient","directions",".","Numerous","continuous","functions","$","\\phi_i","$","can","be","used","to","model","$","S","$",".","Some","are","presented","in","[","2,3,4","]","_",".","From","the","$","c_i","$","coefficients",",","there","exist","analytical","formulae","to","estimate","the","ODF",",","the","return","to","the","origin","probability","(","RTOP",")",",","the","mean","square","displacement","(","MSD",")",",","amongst","others","[","5","]","_.","References","--","--","--","--","--","..","[","1","]","Ozarslan","E.","et","al.",",","``","Simple","harmonic","oscillator","based","reconstruction","and","estimation","for","one-dimensional","q-space","magnetic","resonance","1D-SHORE",")","''",",","Proc","Intl","Soc","Mag","Reson","Med",",","vol",".","16",",","p.","35.",",","2008",".","..","[","2","]","Merlet","S.","et","al.",",","``","Continuous","diffusion","signal",",","EAP","and","ODF","estimation","via","Compressive","Sensing","in","diffusion","MRI","''",",","Medical","Image","Analysis",",","2013",".","..","[","3","]","Rathi","Y.","et","al.",",","``","Sparse","multi-shell","diffusion","imaging","''",",","MICCAI",",","2011",".","..","[","4","]","Cheng","J.","et","al.",",","``","Theoretical","Analysis","and","Practical","Insights","on","EAP","Estimation","via","a","Unified","HARDI","Framework","''",",","MICCAI","workshop","on","Computational","Diffusion","MRI",",","2011",".","..","[","5","]","Ozarslan","E.","et","al.",",","``","Mean","apparent","propagator","(","MAP",")","MRI",":","A","novel","diffusion","imaging","method","for","mapping","tissue","microstructure","''",",","NeuroImage",",","2013",".","Notes","--","--","-","The","implementation","of","SHORE","depends","on","CVXPY","(","https",":","\/\/www.cvxpy.org\/",")","."]
docstr: Analytical and continuous modeling of the diffusion signal with
  respect to the SHORE basis [1,2]_.
  This implementation is a modification of SHORE presented in [1]_.
  The modification was made to obtain the same ordering of the basis
  presented in [2,3]_.
  
  The main idea is to model the diffusion signal as a linear
  combination of continuous functions $\phi_i$,
  
  ..math::
      :nowrap:
          \begin{equation}
              S(\mathbf{q})= \sum_{i=0}^I  c_{i} \phi_{i}(\mathbf{q}).
          \end{equation}
  
  where $\mathbf{q}$ is the wave vector which corresponds to different
  gradient directions.
  
  From the $c_i$ coefficients, there exists an analytical formula to
  estimate the ODF.
  
  
  Parameters
  ----------
  gtab : GradientTable,
      gradient directions and bvalues container class
  radial_order : unsigned int,
      an even integer that represent the order of the basis
  zeta : unsigned int,
      scale factor
  lambdaN : float,
      radial regularisation constant
  lambdaL : float,
      angular regularisation constant
  tau : float,
      diffusion time. By default the value that makes q equal to the
      square root of the b-value.
  constrain_e0 : bool,
      Constrain the optimization such that E(0) = 1.
  positive_constraint : bool,
      Constrain the propagator to be positive.
  pos_grid : int,
      Grid that define the points of the EAP in which we want to enforce
      positivity.
  pos_radius : float,
      Radius of the grid of the EAP in which enforce positivity in
      millimeters. By default 20e-03 mm.
  cvxpy_solver : str, optional
      cvxpy solver name. Optionally optimize the positivity constraint
      with a particular cvxpy solver. See https://www.cvxpy.org/ for
      details.
      Default: None (cvxpy chooses its own solver)
  
  References
  ----------
  .. [1] Merlet S. et al., "Continuous diffusion signal, EAP and
  ODF estimation via Compressive Sensing in diffusion MRI", Medical
  Image Analysis, 2013.
  
  .. [2] Cheng J. et al., "Theoretical Analysis and Practical Insights
  on EAP Estimation via a Unified HARDI Framework", MICCAI workshop on
  Computational Diffusion MRI, 2011.
  
  .. [3] Ozarslan E. et al., "Mean apparent propagator (MAP) MRI: A novel
     diffusion imaging method for mapping tissue microstructure",
     NeuroImage, 2013.
  
  Examples
  --------
  In this example, where the data, gradient table and sphere tessellation
  used for reconstruction are provided, we model the diffusion signal
  with respect to the SHORE basis and compute the real and analytical
  ODF.
  
  >>> import warnings
  >>> from dipy.data import get_isbi2013_2shell_gtab, default_sphere
  >>> from dipy.sims.voxel import sticks_and_ball
  >>> from dipy.reconst.shm import descoteaux07_legacy_msg
  >>> from dipy.reconst.shore import ShoreModel
  >>> gtab = get_isbi2013_2shell_gtab()
  >>> data, golden_directions = sticks_and_ball(
  ...    gtab, d=0.0015, S0=1., angles=[(0, 0), (90, 0)],
  ...    fractions=[50, 50], snr=None)
  ...
  >>> radial_order = 4
  >>> zeta = 700
  >>> asm = ShoreModel(gtab, radial_order=radial_order, zeta=zeta,
  ...                  lambdaN=1e-8, lambdaL=1e-8)
  >>> with warnings.catch_warnings():
  ...     warnings.filterwarnings(
  ...         "ignore", message=descoteaux07_legacy_msg,
  ...         category=PendingDeprecationWarning)
  ...     asmfit = asm.fit(data)
  ...     odf = asmfit.odf(default_sphere)
docstr_tok: ["Analytical","and","continuous","modeling","of","the","diffusion","signal","with","respect","to","the","SHORE","basis","[","1,2","]","_",".","This","implementation","is","a","modification","of","SHORE","presented","in","[","1","]","_",".","The","modification","was","made","to","obtain","the","same","ordering","of","the","basis","presented","in","[","2,3","]","_",".","The","main","idea","is","to","model","the","diffusion","signal","as","a","linear","combination","of","continuous","functions","$","\\phi_i","$",",","..","math",":",":",":","nowrap",":","\\begin","{","equation","}","S","(","\\mathbf","{","q","}",")","=","\\sum_","{","i=0","}","^I","c_","{","i","}","\\phi_","{","i","}","(","\\mathbf","{","q","}",")",".","\\end","{","equation","}","where","$","\\mathbf","{","q","}","$","is","the","wave","vector","which","corresponds","to","different","gradient","directions",".","From","the","$","c_i","$","coefficients",",","there","exists","an","analytical","formula","to","estimate","the","ODF",".","Parameters","--","--","--","--","--","gtab",":","GradientTable",",","gradient","directions","and","bvalues","container","class","radial_order",":","unsigned","int",",","an","even","integer","that","represent","the","order","of","the","basis","zeta",":","unsigned","int",",","scale","factor","lambdaN",":","float",",","radial","regularisation","constant","lambdaL",":","float",",","angular","regularisation","constant","tau",":","float",",","diffusion","time",".","By","default","the","value","that","makes","q","equal","to","the","square","root","of","the","b-value",".","constrain_e0",":","bool",",","Constrain","the","optimization","such","that","E","(","0",")","=","1.","positive_constraint",":","bool",",","Constrain","the","propagator","to","be","positive",".","pos_grid",":","int",",","Grid","that","define","the","points","of","the","EAP","in","which","we","want","to","enforce","positivity",".","pos_radius",":","float",",","Radius","of","the","grid","of","the","EAP","in","which","enforce","positivity","in","millimeters",".","By","default","20e-03","mm",".","cvxpy_solver",":","str",",","optional","cvxpy","solver","name",".","Optionally","optimize","the","positivity","constraint","with","a","particular","cvxpy","solver",".","See","https",":","\/\/www.cvxpy.org\/","for","details",".","Default",":","None","(","cvxpy","chooses","its","own","solver",")","References","--","--","--","--","--","..","[","1","]","Merlet","S.","et","al.",",","``","Continuous","diffusion","signal",",","EAP","and","ODF","estimation","via","Compressive","Sensing","in","diffusion","MRI","''",",","Medical","Image","Analysis",",","2013",".","..","[","2","]","Cheng","J.","et","al.",",","``","Theoretical","Analysis","and","Practical","Insights","on","EAP","Estimation","via","a","Unified","HARDI","Framework","''",",","MICCAI","workshop","on","Computational","Diffusion","MRI",",","2011",".","..","[","3","]","Ozarslan","E.","et","al.",",","``","Mean","apparent","propagator","(","MAP",")","MRI",":","A","novel","diffusion","imaging","method","for","mapping","tissue","microstructure","''",",","NeuroImage",",","2013",".","Examples","--","--","--","--","In","this","example",",","where","the","data",",","gradient","table","and","sphere","tessellation","used","for","reconstruction","are","provided",",","we","model","the","diffusion","signal","with","respect","to","the","SHORE","basis","and","compute","the","real","and","analytical","ODF",".",">",">",">","import","warnings",">",">",">","from","dipy.data","import","get_isbi2013_2shell_gtab",",","default_sphere",">",">",">","from","dipy.sims.voxel","import","sticks_and_ball",">",">",">","from","dipy.reconst.shm","import","descoteaux07_legacy_msg",">",">",">","from","dipy.reconst.shore","import","ShoreModel",">",">",">","gtab","=","get_isbi2013_2shell_gtab","(",")",">",">",">","data",",","golden_directions","=","sticks_and_ball","(","...","gtab",",","d=0.0015",",","S0=1.",",","angles=","[","(","0",",","0",")",",","(","90",",","0",")","]",",","...","fractions=","[","50",",","50","]",",","snr=None",")","...",">",">",">","radial_order","=","4",">",">",">","zeta","=","700",">",">",">","asm","=","ShoreModel","(","gtab",",","radial_order=radial_order",",","zeta=zeta",",","...","lambdaN=1e-8",",","lambdaL=1e-8",")",">",">",">","with","warnings.catch_warnings","(",")",":","...","warnings.filterwarnings","(","...","``","ignore","''",",","message=descoteaux07_legacy_msg",",","...","category=PendingDeprecationWarning",")","...","asmfit","=","asm.fit","(","data",")","...","odf","=","asmfit.odf","(","default_sphere",")"]
code: def __init__(
      self,
      gtab,
      radial_order=6,
      zeta=700,
      lambdaN=1e-8,
      lambdaL=1e-8,
      tau=1.0 / (4 * np.pi**2),
      constrain_e0=False,
      positive_constraint=False,
      pos_grid=11,
      pos_radius=20e-03,
      cvxpy_solver=None,
  ):
      r"""Analytical and continuous modeling of the diffusion signal with
      respect to the SHORE basis [1,2]_.
      This implementation is a modification of SHORE presented in [1]_.
      The modification was made to obtain the same ordering of the basis
      presented in [2,3]_.
  
      The main idea is to model the diffusion signal as a linear
      combination of continuous functions $\phi_i$,
  
      ..math::
          :nowrap:
              \begin{equation}
                  S(\mathbf{q})= \sum_{i=0}^I  c_{i} \phi_{i}(\mathbf{q}).
              \end{equation}
  
      where $\mathbf{q}$ is the wave vector which corresponds to different
      gradient directions.
  
      From the $c_i$ coefficients, there exists an analytical formula to
      estimate the ODF.
  
  
      Parameters
      ----------
      gtab : GradientTable,
          gradient directions and bvalues container class
      radial_order : unsigned int,
          an even integer that represent the order of the basis
      zeta : unsigned int,
          scale factor
      lambdaN : float,
          radial regularisation constant
      lambdaL : float,
          angular regularisation constant
      tau : float,
          diffusion time. By default the value that makes q equal to the
          square root of the b-value.
      constrain_e0 : bool,
          Constrain the optimization such that E(0) = 1.
      positive_constraint : bool,
          Constrain the propagator to be positive.
      pos_grid : int,
          Grid that define the points of the EAP in which we want to enforce
          positivity.
      pos_radius : float,
          Radius of the grid of the EAP in which enforce positivity in
          millimeters. By default 20e-03 mm.
      cvxpy_solver : str, optional
          cvxpy solver name. Optionally optimize the positivity constraint
          with a particular cvxpy solver. See https://www.cvxpy.org/ for
          details.
          Default: None (cvxpy chooses its own solver)
  
      References
      ----------
      .. [1] Merlet S. et al., "Continuous diffusion signal, EAP and
      ODF estimation via Compressive Sensing in diffusion MRI", Medical
      Image Analysis, 2013.
  
      .. [2] Cheng J. et al., "Theoretical Analysis and Practical Insights
      on EAP Estimation via a Unified HARDI Framework", MICCAI workshop on
      Computational Diffusion MRI, 2011.
  
      .. [3] Ozarslan E. et al., "Mean apparent propagator (MAP) MRI: A novel
         diffusion imaging method for mapping tissue microstructure",
         NeuroImage, 2013.
  
      Examples
      --------
      In this example, where the data, gradient table and sphere tessellation
      used for reconstruction are provided, we model the diffusion signal
      with respect to the SHORE basis and compute the real and analytical
      ODF.
  
      >>> import warnings
      >>> from dipy.data import get_isbi2013_2shell_gtab, default_sphere
      >>> from dipy.sims.voxel import sticks_and_ball
      >>> from dipy.reconst.shm import descoteaux07_legacy_msg
      >>> from dipy.reconst.shore import ShoreModel
      >>> gtab = get_isbi2013_2shell_gtab()
      >>> data, golden_directions = sticks_and_ball(
      ...    gtab, d=0.0015, S0=1., angles=[(0, 0), (90, 0)],
      ...    fractions=[50, 50], snr=None)
      ...
      >>> radial_order = 4
      >>> zeta = 700
      >>> asm = ShoreModel(gtab, radial_order=radial_order, zeta=zeta,
      ...                  lambdaN=1e-8, lambdaL=1e-8)
      >>> with warnings.catch_warnings():
      ...     warnings.filterwarnings(
      ...         "ignore", message=descoteaux07_legacy_msg,
      ...         category=PendingDeprecationWarning)
      ...     asmfit = asm.fit(data)
      ...     odf = asmfit.odf(default_sphere)
      """
  
      self.bvals = gtab.bvals
      self.bvecs = gtab.bvecs
      self.gtab = gtab
      self.constrain_e0 = constrain_e0
      if radial_order > 0 and not (bool(radial_order % 2)):
          self.radial_order = radial_order
      else:
          msg = "radial_order must be a non-zero even positive number."
          raise ValueError(msg)
      self.zeta = zeta
      self.lambdaL = lambdaL
      self.lambdaN = lambdaN
      if (gtab.big_delta is None) or (gtab.small_delta is None):
          self.tau = tau
      else:
          self.tau = gtab.big_delta - gtab.small_delta / 3.0
  
      if positive_constraint and not constrain_e0:
          msg = "Constrain_e0 must be True to enforce positivity."
          raise ValueError(msg)
  
      if positive_constraint or constrain_e0:
          if not have_cvxpy:
              msg = (
                  "cvxpy must be installed for positive_constraint or "
              )
              msg += "constraint_e0."
              raise ImportError(msg)
          if cvxpy_solver is not None:
              if cvxpy_solver not in cvxpy.installed_solvers():
                  msg = (
                      "Input `cvxpy_solver` was set to %s."
                      % cvxpy_solver
                  )
                  msg += " One of %s" % ", ".join(
                      cvxpy.installed_solvers()
                  )
                  msg += " was expected."
                  raise ValueError(msg)
  
      self.cvxpy_solver = cvxpy_solver
      self.positive_constraint = positive_constraint
      self.pos_grid = pos_grid
      self.pos_radius = pos_radius
  
imports: from warnings import warn
  from math import factorial
  import numpy
  from scipy.special import genlaguerre, gamma, hyp2f1
  from dipy.reconst.cache import Cache
  from dipy.reconst.multi_voxel import multi_voxel_fit
  from dipy.reconst.shm import real_sh_descoteaux_from_index
  from dipy.core.geometry import cart2sphere
  from dipy.utils.optpkg import optional_package
label_desc: Use image node_id 1 to create a new ShoreModel object from inherited base classes: Cache with example: obj = ShoreModel(gtab, radial_order, zeta, lambdaN, lambdaL, tau, constrain_e0, positive_constraint, pos_grid, pos_radius, cvxpy_solver)