Beispiel #1
0
def test_anisotropic_hernquist_energyoutofbounds():
    pot= potential.HernquistPotential(amp=2.3,a=1.3)
    betas= [-0.7,-0.5,-0.4,0.,0.3,0.5]
    for beta in betas:
        dfh= constantbetaHernquistdf(pot=pot,beta=beta)
        assert numpy.all(numpy.fabs(dfh((numpy.arange(0.1,10.,0.1),1.1))) < 1e-8), 'Evaluating the isotropic Hernquist DF at E > 0 does not give zero'
        assert numpy.all(numpy.fabs(dfh((pot(0,0)-1e-4,1.1))) < 1e-8), 'Evaluating the isotropic Hernquist DF at E < -GM/a does not give zero'
    return None
Beispiel #2
0
def test_anisotropic_hernquist_meanvr_directint():
    pot= potential.HernquistPotential(amp=2.3,a=1.3)
    betas= [-0.7,-0.5,-0.4,0.,0.3,0.5]
    for beta in betas:
        dfh= constantbetaHernquistdf(pot=pot,beta=beta)
        tol= 1e-8
        check_meanvr_directint(dfh,pot,tol,beta=beta,rmin=pot._scale/10.,
                               rmax=pot._scale*10.,bins=31)
    return None
Beispiel #3
0
def test_anisotropic_hernquist_dens_directint():
    pot= potential.HernquistPotential(amp=2.3,a=1.3)
    betas= [-0.7,-0.5,-0.4,0.,0.3,0.5]
    for beta in betas:
        dfh= constantbetaHernquistdf(pot=pot,beta=beta)
        tol= 1e-7
        check_dens_directint(dfh,pot,tol,
                             lambda r: pot.dens(r,0)/(2.3/2.), # need to divide by mass
                             rmin=pot._scale/10.,
                             rmax=pot._scale*10.,bins=31)
    return None
Beispiel #4
0
def test_anisotropic_hernquist_beta():
    pot= potential.HernquistPotential(amp=2.3,a=1.3)
    betas= [-0.7,-0.5,-0.4,0.,0.3,0.5]
    for beta in betas:
        dfh= constantbetaHernquistdf(pot=pot,beta=beta)
        numpy.random.seed(10)
        samp= dfh.sample(n=1000000)
        tol= 8*1e-2 * (beta > -0.7) + 0.12 * (beta == -0.7)
        check_beta(samp,pot,tol,beta=beta,
                   rmin=pot._scale/10.,rmax=pot._scale*10.,bins=31)
    return None
Beispiel #5
0
def test_anisotropic_hernquist_negdf():
    pot= potential.HernquistPotential(amp=2.3,a=1.3)
    # beta > 0.5 has negative DF parts
    dfh= constantbetaHernquistdf(pot=pot,beta=0.7)
    with pytest.warns(None) as record:
        samp= dfh.sample(n=100)
    raisedWarning= False
    for rec in record:
        # check that the message matches
        raisedWarning+= (str(rec.message.args[0]) == "The DF appears to have negative regions; we'll try to ignore these for sampling the DF, but this may adversely affect the generated samples. Proceed with care!")
    assert raisedWarning, "Using an anisotropic Hernquist DF that has negative parts should have raised a warning, but didn't"
Beispiel #6
0
def test_anisotropic_hernquist_sigmar():
    pot= potential.HernquistPotential(amp=2.3,a=1.3)
    betas= [-0.7,-0.5,-0.4,0.,0.3,0.5]
    for beta in betas:
        dfh= constantbetaHernquistdf(pot=pot,beta=beta)
        numpy.random.seed(10)
        samp= dfh.sample(n=100000)
        tol= 0.05
        check_sigmar_against_jeans(samp,pot,tol,beta=beta,
                                   rmin=pot._scale/10.,rmax=pot._scale*10.,
                                   bins=31)
    return None
Beispiel #7
0
def test_anisotropic_hernquist_dens_massprofile():
    pot= potential.HernquistPotential(amp=2.3,a=1.3)
    betas= [-0.7,-0.5,-0.4,0.,0.3,0.5]
    for beta in betas:
        dfh= constantbetaHernquistdf(pot=pot,beta=beta)
        numpy.random.seed(10)
        samp= dfh.sample(n=100000)
        tol= 5*1e-3
        check_spherical_massprofile(samp,lambda r: pot.mass(r)\
                                    /pot.mass(numpy.amax(samp.r())),
                                    tol,skip=1000)
    return None
Beispiel #8
0
def test_anisotropic_hernquist_diffcalls():
    from galpy.orbit import Orbit
    pot= potential.HernquistPotential(amp=2.3,a=1.3)
    betas= [-0.7,-0.5,-0.4,0.,0.3,0.5]
    for beta in betas:
        dfh= constantbetaHernquistdf(pot=pot,beta=beta)
        # R,vR... vs. E
        R,vR,vT,z,vz,phi= 1.1,0.3,0.2,0.9,-0.2,2.4
        # Calculate E directly and L from Orbit
        assert numpy.fabs(dfh(R,vR,vT,z,vz,phi)-dfh((pot(R,z)+0.5*(vR**2.+vT**2.+vz**2.),numpy.sqrt(numpy.sum(Orbit([R,vR,vT,z,vz,phi]).L()**2.))))) < 1e-8, 'Calling the isotropic Hernquist DF with R,vR,... or E[R,vR,...] does not give the same answer'
        # Also as orbit
        assert numpy.fabs(dfh(R,vR,vT,z,vz,phi)-dfh(Orbit([R,vR,vT,z,vz,phi]))) < 1e-8, 'Calling the isotropic Hernquist DF with R,vR,... or E[R,vR,...] does not give the same answer'   
    return None
Beispiel #9
0
def test_anisotropic_hernquist_dens_spherically_symmetric():
    pot= potential.HernquistPotential(amp=2.3,a=1.3)
    betas= [-0.7,-0.5,-0.4,0.,0.3,0.5]
    for beta in betas:
        dfh= constantbetaHernquistdf(pot=pot,beta=beta)
        numpy.random.seed(10)
        samp= dfh.sample(n=100000)
        # Check spherical symmetry for different harmonics l,m
        tol= 1e-2
        check_spherical_symmetry(samp,0,0,tol)
        check_spherical_symmetry(samp,1,0,tol)
        check_spherical_symmetry(samp,1,-1,tol)
        check_spherical_symmetry(samp,1,1,tol)
        check_spherical_symmetry(samp,2,0,tol)
        check_spherical_symmetry(samp,2,-1,tol)
        check_spherical_symmetry(samp,2,-2,tol)
        check_spherical_symmetry(samp,2,1,tol)
        check_spherical_symmetry(samp,2,2,tol)
        # and some higher order ones
        check_spherical_symmetry(samp,3,1,tol)
        check_spherical_symmetry(samp,9,-6,tol)
    return None
Beispiel #10
0
def test_anisotropic_hernquist_wrongpot():
    pot= potential.JaffePotential(amp=2.,a=1.3)   
    with pytest.raises(AssertionError)  as excinfo:
        dfh= constantbetaHernquistdf(pot=pot)
    assert str(excinfo.value) == 'pot= must be potential.HernquistPotential', 'Error message when not supplying the potential is incorrect'
    return None