# Tests of the galpy.df.jeans module: Jeans equations
import numpy
from galpy.df import jeans

# Test sigmar: radial velocity dispersion from the spherical Jeans equation
# For log halo, constant beta: sigma(r) = vc/sqrt(2.-2*beta)
def test_sigmar_wlog_constbeta():
    from galpy.potential import LogarithmicHaloPotential
    lp= LogarithmicHaloPotential(normalize=1.,q=1.)
    rs= numpy.linspace(0.001,5.,101)
    # beta = 0 --> sigma = vc/sqrt(2)
    assert numpy.all(numpy.fabs(numpy.array([jeans.sigmar(lp,r) for r in rs])-1./numpy.sqrt(2.)) < 1e-10), 'Radial sigma computed w/ spherical Jeans equation incorrect for LogarithmicHaloPotential and beta=0'
    # general beta --> sigma = vc/sqrt(2-2beta)
    beta= 0.5
    assert numpy.all(numpy.fabs(numpy.array([jeans.sigmar(lp,r,beta=beta) for r in rs])-1./numpy.sqrt(2.-2.*beta)) < 1e-10), 'Radial sigma computed w/ spherical Jeans equation incorrect for LogarithmicHaloPotential and beta=0'
    beta= -0.5
    assert numpy.all(numpy.fabs(numpy.array([jeans.sigmar(lp,r,beta=beta) for r in rs])-1./numpy.sqrt(2.-2.*beta)) < 1e-10), 'Radial sigma computed w/ spherical Jeans equation incorrect for LogarithmicHaloPotential and beta=0'
    return None

@@ -935,24 +935,26 @@
 l and beta=0
+.5
 '%0A    beta= 
@@ -1178,24 +1178,1360 @@
 al and beta=
+-0.5'%0A    return None%0A%0A# Test sigmar: radial velocity dispersion from the spherical Jeans equation%0A# For log halo, constant beta: sigma(r) = vc/sqrt(2.-2*beta)%0Adef test_sigmar_wlog_constbeta_diffdens_powerlaw():%0A    from galpy.potential import LogarithmicHaloPotential%0A    lp= LogarithmicHaloPotential(normalize=1.,q=1.)%0A    rs= numpy.linspace(0.001,5.,101)%0A    # general beta and r%5E-gamma --%3E sigma = vc/sqrt(gamma-2beta)%0A    gamma, beta= 1.,0.%0A    assert numpy.all(numpy.fabs(numpy.array(%5Bjeans.sigmar(lp,r,beta=beta,dens=lambda r: r**-gamma) for r in rs%5D)-1./numpy.sqrt(gamma-2.*beta)) %3C 1e-10), 'Radial sigma computed w/ spherical Jeans equation incorrect for LogarithmicHaloPotential, beta=0, and power-law density r%5E-1'%0A    gamma, beta= 3.,0.5%0A    assert numpy.all(numpy.fabs(numpy.array(%5Bjeans.sigmar(lp,r,beta=beta,dens=lambda r: r**-gamma) for r in rs%5D)-1./numpy.sqrt(gamma-2.*beta)) %3C 1e-10), 'Radial sigma computed w/ spherical Jeans equation incorrect for LogarithmicHaloPotential, beta=0.5, and power-law density r%5E-3'%0A    gamma, beta= 0.,-0.5%0A    assert numpy.all(numpy.fabs(numpy.array(%5Bjeans.sigmar(lp,r,beta=beta,dens=lambda r: r**-gamma) for r in rs%5D)-1./numpy.sqrt(gamma-2.*beta)) %3C 1e-10), 'Radial sigma computed w/ spherical Jeans equation incorrect for LogarithmicHaloPotential, beta=-0.5, and power-law density r%5E
 0'%0A    retur

Add test of jeans sigmar with density different from potential