Exemplo n.º 1
0
def test_diskdf():
    from galpy.df import dehnendf
    # Init. dehnendf w/ flat rot., hr=1/3, hs=1, and sr(1)=0.2
    df = dehnendf(beta=0., profileParams=(1. / 3., 1.0, 0.2))
    # Same, w/ correction factors to scale profiles
    dfc = dehnendf(beta=0.,
                   profileParams=(1. / 3., 1.0, 0.2),
                   correct=True,
                   niter=20)
    if True:
        # Log. diff. between scale and DF surf. dens.
        numpy.log(df.surfacemass(0.5) / df.targetSurfacemass(0.5))
        assert numpy.fabs(
            numpy.log(df.surfacemass(0.5) / df.targetSurfacemass(0.5)) +
            0.056954077791649592
        ) < 10.**-4., 'diskdf does not behave as expected'
        # Same for corrected DF
        numpy.log(dfc.surfacemass(0.5) / dfc.targetSurfacemass(0.5))
        assert numpy.fabs(
            numpy.log(dfc.surfacemass(0.5) / dfc.targetSurfacemass(0.5)) +
            4.1440377205802041e-06
        ) < 10.**-4., 'diskdf does not behave as expected'
        # Log. diff between scale and DF sr
        numpy.log(df.sigmaR2(0.5) / df.targetSigma2(0.5))
        assert numpy.fabs(
            numpy.log(df.sigmaR2(0.5) / df.targetSigma2(0.5)) +
            0.12786083001363127
        ) < 10.**-4., 'diskdf does not behave as expected'
        # Same for corrected DF
        numpy.log(dfc.sigmaR2(0.5) / dfc.targetSigma2(0.5))
        assert numpy.fabs(
            numpy.log(dfc.sigmaR2(0.5) / dfc.targetSigma2(0.5)) +
            6.8065001252214986e-06
        ) < 10.**-4., 'diskdf does not behave as expected'
        # Evaluate DF w/ R,vR,vT
        df(numpy.array([0.9, 0.1, 0.8]))
        assert numpy.fabs(
            df(numpy.array([0.9, 0.1, 0.8])) - numpy.array(0.1740247246180417)
        ) < 10.**-4., 'diskdf does not behave as expected'
        # Evaluate corrected DF w/ Orbit instance
        from galpy.orbit import Orbit
        dfc(Orbit([0.9, 0.1, 0.8]))
        assert numpy.fabs(
            dfc(Orbit([0.9, 0.1, 0.8])) - numpy.array(0.16834863725552207)
        ) < 10.**-4., 'diskdf does not behave as expected'
        # Calculate the mean velocities
        df.meanvR(0.9), df.meanvT(0.9)
        assert numpy.fabs(
            df.meanvR(0.9)) < 10.**-4., 'diskdf does not behave as expected'
        assert numpy.fabs(df.meanvT(0.9) - 0.91144428051168291
                          ) < 10.**-4., 'diskdf does not behave as expected'
        # Calculate the velocity dispersions
        numpy.sqrt(dfc.sigmaR2(0.9)), numpy.sqrt(dfc.sigmaT2(0.9))
        assert numpy.fabs(numpy.sqrt(dfc.sigmaR2(0.9)) - 0.22103383792719539
                          ) < 10.**-4., 'diskdf does not behave as expected'
        assert numpy.fabs(numpy.sqrt(dfc.sigmaT2(0.9)) - 0.17613725303902811
                          ) < 10.**-4., 'diskdf does not behave as expected'
        # Calculate the skew of the velocity distribution
        df.skewvR(0.9), df.skewvT(0.9)
        assert numpy.fabs(
            df.skewvR(0.9)) < 10.**-4., 'diskdf does not behave as expected'
        assert numpy.fabs(df.skewvT(0.9) + 0.47331638366025863
                          ) < 10.**-4., 'diskdf does not behave as expected'
        # Calculate the kurtosis of the velocity distribution
        df.kurtosisvR(0.9), df.kurtosisvT(0.9)
        assert numpy.fabs(df.kurtosisvR(0.9) + 0.13561300880237059
                          ) < 10.**-4., 'diskdf does not behave as expected'
        assert numpy.fabs(df.kurtosisvT(0.9) - 0.12612702099300721
                          ) < 10.**-4., 'diskdf does not behave as expected'
        # Calculate a higher-order moment of the velocity DF
        df.vmomentsurfacemass(1., 6., 2.) / df.surfacemass(1.)
        assert numpy.fabs(
            df.vmomentsurfacemass(1., 6., 2.) / df.surfacemass(1.) -
            0.00048953492205559054
        ) < 10.**-4., 'diskdf does not behave as expected'
        # Calculate the Oort functions
        dfc.oortA(1.), dfc.oortB(1.), dfc.oortC(1.), dfc.oortK(1.)
        assert numpy.fabs(dfc.oortA(1.) - 0.40958989067012197
                          ) < 10.**-4., 'diskdf does not behave as expected'
        assert numpy.fabs(dfc.oortB(1.) + 0.49396172114486514
                          ) < 10.**-4., 'diskdf does not behave as expected'
        assert numpy.fabs(
            dfc.oortC(1.)) < 10.**-4., 'diskdf does not behave as expected'
        assert numpy.fabs(
            dfc.oortK(1.)) < 10.**-4., 'diskdf does not behave as expected'
    # Sample Orbits from the DF, returns list of Orbits
    numpy.random.seed(1)
    os = dfc.sample(n=100, returnOrbit=True, nphi=1)
    # check that these have the right mean radius = 2hr=2/3
    rs = numpy.array([o.R() for o in os])
    assert numpy.fabs(numpy.mean(rs) - 2. / 3.) < 0.1
    # Sample vR and vT at given R, check their mean
    vrvt = dfc.sampleVRVT(0.7, n=500, target=True)
    vt = vrvt[:, 1]
    assert numpy.fabs(numpy.mean(vrvt[:, 0])) < 0.05
    assert numpy.fabs(numpy.mean(vt) - dfc.meanvT(0.7)) < 0.01
    # Sample Orbits along a given line-of-sight
    os = dfc.sampleLOS(45., n=1000)
    return None
Exemplo n.º 2
0
def test_diskdf():
    from galpy.df import dehnendf
    # Init. dehnendf w/ flat rot., hr=1/3, hs=1, and sr(1)=0.2
    df= dehnendf(beta=0.,profileParams=(1./3.,1.0,0.2))
    # Same, w/ correction factors to scale profiles
    dfc= dehnendf(beta=0.,profileParams=(1./3.,1.0,0.2),
                  correct=True,niter=20)
    if True:
        # Log. diff. between scale and DF surf. dens.
        numpy.log(df.surfacemass(0.5)/df.targetSurfacemass(0.5))
        assert numpy.fabs(numpy.log(df.surfacemass(0.5)/df.targetSurfacemass(0.5))+0.056954077791649592) < 10.**-4., 'diskdf does not behave as expected'
    # Same for corrected DF
        numpy.log(dfc.surfacemass(0.5)/dfc.targetSurfacemass(0.5))
        assert numpy.fabs(numpy.log(dfc.surfacemass(0.5)/dfc.targetSurfacemass(0.5))+4.1440377205802041e-06) < 10.**-4., 'diskdf does not behave as expected'
    # Log. diff between scale and DF sr
        numpy.log(df.sigmaR2(0.5)/df.targetSigma2(0.5))
        assert numpy.fabs(numpy.log(df.sigmaR2(0.5)/df.targetSigma2(0.5))+0.12786083001363127) < 10.**-4., 'diskdf does not behave as expected'
    # Same for corrected DF
        numpy.log(dfc.sigmaR2(0.5)/dfc.targetSigma2(0.5))
        assert numpy.fabs(numpy.log(dfc.sigmaR2(0.5)/dfc.targetSigma2(0.5))+6.8065001252214986e-06) < 10.**-4., 'diskdf does not behave as expected'
    # Evaluate DF w/ R,vR,vT
        df(numpy.array([0.9,0.1,0.8]))
        assert numpy.fabs(df(numpy.array([0.9,0.1,0.8]))-numpy.array(0.1740247246180417)) < 10.**-4., 'diskdf does not behave as expected'
    # Evaluate corrected DF w/ Orbit instance
        from galpy.orbit import Orbit
        dfc(Orbit([0.9,0.1,0.8]))   
        assert numpy.fabs(dfc(Orbit([0.9,0.1,0.8]))-numpy.array(0.16834863725552207)) < 10.**-4., 'diskdf does not behave as expected'
    # Calculate the mean velocities
        df.meanvR(0.9), df.meanvT(0.9)
        assert numpy.fabs(df.meanvR(0.9))  < 10.**-4., 'diskdf does not behave as expected'
        assert numpy.fabs(df.meanvT(0.9)-0.91144428051168291) < 10.**-4., 'diskdf does not behave as expected'
        # Calculate the velocity dispersions
        numpy.sqrt(dfc.sigmaR2(0.9)), numpy.sqrt(dfc.sigmaT2(0.9))
        assert numpy.fabs(numpy.sqrt(dfc.sigmaR2(0.9))-0.22103383792719539) < 10.**-4., 'diskdf does not behave as expected'
        assert numpy.fabs(numpy.sqrt(dfc.sigmaT2(0.9))-0.17613725303902811) < 10.**-4., 'diskdf does not behave as expected'
        # Calculate the skew of the velocity distribution
        df.skewvR(0.9), df.skewvT(0.9)
        assert numpy.fabs(df.skewvR(0.9)) < 10.**-4., 'diskdf does not behave as expected'
        assert numpy.fabs(df.skewvT(0.9)+0.47331638366025863) < 10.**-4., 'diskdf does not behave as expected'
        # Calculate the kurtosis of the velocity distribution
        df.kurtosisvR(0.9), df.kurtosisvT(0.9)
        assert numpy.fabs(df.kurtosisvR(0.9)+0.13561300880237059) < 10.**-4., 'diskdf does not behave as expected'
        assert numpy.fabs(df.kurtosisvT(0.9)-0.12612702099300721) < 10.**-4., 'diskdf does not behave as expected'
        # Calculate a higher-order moment of the velocity DF
        df.vmomentsurfacemass(1.,6.,2.)/df.surfacemass(1.)
        assert numpy.fabs(df.vmomentsurfacemass(1.,6.,2.)/df.surfacemass(1.)-0.00048953492205559054) < 10.**-4., 'diskdf does not behave as expected'
        # Calculate the Oort functions
        dfc.oortA(1.), dfc.oortB(1.), dfc.oortC(1.), dfc.oortK(1.)
        assert numpy.fabs(dfc.oortA(1.)-0.40958989067012197) < 10.**-4., 'diskdf does not behave as expected'
        assert numpy.fabs(dfc.oortB(1.)+0.49396172114486514) < 10.**-4., 'diskdf does not behave as expected'
        assert numpy.fabs(dfc.oortC(1.))  < 10.**-4., 'diskdf does not behave as expected'
        assert numpy.fabs(dfc.oortK(1.)) < 10.**-4., 'diskdf does not behave as expected'
    # Sample Orbits from the DF, returns list of Orbits
    numpy.random.seed(1)
    os= dfc.sample(n=100,returnOrbit=True,nphi=1)
    # check that these have the right mean radius = 2hr=2/3
    rs= numpy.array([o.R() for o in os])
    assert numpy.fabs(numpy.mean(rs)-2./3.) < 0.1
    # Sample vR and vT at given R, check their mean
    vrvt= dfc.sampleVRVT(0.7,n=500,target=True); vt= vrvt[:,1]
    assert numpy.fabs(numpy.mean(vrvt[:,0])) < 0.05
    assert numpy.fabs(numpy.mean(vt)-dfc.meanvT(0.7)) < 0.01
    # Sample Orbits along a given line-of-sight
    os= dfc.sampleLOS(45.,n=1000)
    return None