Exemple #1
0
def test_density1_Order():
    Acos, Asin = potential.scf_compute_coeffs(density1, 5,5)
    Acos2, Asin2 = potential.scf_compute_coeffs(density1, 5,5, radial_order=19, costheta_order=19, phi_order=19)
    assert numpy.all(numpy.fabs(Acos - Acos2) < 1e-3), \
    "Increasing the radial, costheta, and phi order fails for Acos from scf_compute_coeffs"
    
    assert numpy.all(numpy.fabs(Asin - Asin) < EPS), \
    "Increasing the radial, costheta, and phi order fails for Asin from scf_compute_coeffs"
Exemple #2
0
def test_density1_Order():
    Acos, Asin = potential.scf_compute_coeffs(density1, 5,5)
    Acos2, Asin2 = potential.scf_compute_coeffs(density1, 5,5, radial_order=19, costheta_order=19, phi_order=19)
    assert numpy.all(numpy.fabs(Acos - Acos2) < 1e-3), \
    "Increasing the radial, costheta, and phi order fails for Acos from scf_compute_coeffs"
    
    assert numpy.all(numpy.fabs(Asin - Asin) < EPS), \
    "Increasing the radial, costheta, and phi order fails for Asin from scf_compute_coeffs"
Exemple #3
0
def test_scf_ZeeuwCoeffs_ReducesToSpherical():
    Aspherical = potential.scf_compute_coeffs_spherical(rho_Zeeuw, 5)
    Aaxi = potential.scf_compute_coeffs(rho_Zeeuw,
                                        5,
                                        5,
                                        radial_order=20,
                                        costheta_order=20)
    reducesto_spherical(Aspherical, Aaxi, "Zeeuw Potential")
Exemple #4
0
def test_scf_compute_nbody_twopowertriaxial():
    N = int(1e5)
    Mh = 11.
    ah = 50. / 8.
    m = Mh / N
    yfactor = 1.5
    zfactor = 2.5
    nsamp = 10
    Norder = 10
    Lorder = 10

    hern = potential.HernquistPotential(amp=2 * Mh, a=ah)
    hern.turn_physical_off()
    hdf = df.isotropicHernquistdf(hern)
    numpy.random.seed(2)
    samp = [hdf.sample(n=N) for i in range(nsamp)]

    positions = numpy.array(
        [[samp[i].x(), samp[i].y() * yfactor, samp[i].z() * zfactor]
         for i in range(nsamp)])

    # This is an triaxial Hernquist profile with the same mass as the above
    tptp = potential.TwoPowerTriaxialPotential(amp=2. * Mh / yfactor / zfactor,
                                               a=ah,
                                               alpha=1.,
                                               beta=4.,
                                               b=yfactor,
                                               c=zfactor)
    tptp.turn_physical_off()

    cc, ss = potential.scf_compute_coeffs(tptp.dens, Norder, Lorder, a=ah)
    c, s = numpy.zeros((2, nsamp, Norder, Lorder, Lorder))
    for i, p in enumerate(positions):
        c[i], s[i] = potential.scf_compute_coeffs_nbody(p,
                                                        Norder,
                                                        Lorder,
                                                        mass=m * numpy.ones(N),
                                                        a=ah)

    # Check that the difference between the coefficients is within two standard deviations
    assert (cc - (numpy.mean(c, axis=0)) <= (2. * numpy.std(c, axis=0))).all()

    # Repeat test for single mass
    c, s = numpy.zeros((2, nsamp, Norder, Lorder, Lorder))
    for i, p in enumerate(positions):
        c[i], s[i] = potential.scf_compute_coeffs_nbody(p,
                                                        Norder,
                                                        Lorder,
                                                        mass=m,
                                                        a=ah)
    assert (cc - (numpy.mean(c, axis=0)) <= (2. * numpy.std(c, axis=0))).all()
    return None
def compute_Acos_Asin(n=9,
                      l=19,
                      a=1. / ro,
                      radial_order=40,
                      costheta_order=40,
                      phi_order=40):

    Acos, Asin = potential.scf_compute_coeffs(
        lambda R, z, p: rho_bar_cyl(R * 8., z * 8., p) /
        (10**9. * bovy_conversion.dens_in_msolpc3(220., 8.)),
        N=n + 1,
        L=l + 1,
        a=a,
        radial_order=radial_order,
        costheta_order=costheta_order,
        phi_order=phi_order)

    return (Acos, Asin)
Exemple #6
0
def compare_dens_nbody():
    N = int(1e5)
    Mh = 11.
    ah = 50. / 8.
    m = Mh / N
    factor = 1.
    nsamp = 10
    Norder = 10
    Lorder = 10

    hern = potential.HernquistPotential(amp=2 * Mh, a=ah)
    hern.turn_physical_off()
    hdf = df.isotropicHernquistdf(hern)
    samp = [hdf.sample(n=N) for i in range(nsamp)]

    positions = numpy.array([[samp[i].x(), samp[i].y(), samp[i].z() * factor]
                             for i in range(nsamp)])

    tptp = potential.TwoPowerTriaxialPotential(amp=2. * Mh,
                                               a=ah,
                                               alpha=1.,
                                               beta=4.,
                                               b=1.,
                                               c=factor)
    tptp.turn_physical_off()

    cc, ss = potential.scf_compute_coeffs(tptp.dens, Norder, Lorder, a=ah)
    c, s = numpy.zeros((2, nsamp, Norder, Lorder, Lorder))
    for i, p in enumerate(positions):
        c[i], s[i] = potential.scf_compute_coeffs_nbody(p,
                                                        m * numpy.ones(N) *
                                                        factor,
                                                        Norder,
                                                        Lorder,
                                                        a=ah)

    # Check that the difference between the coefficients is within two standard deviations
    assert (cc - (numpy.mean(c, axis=0)) <= (2. * numpy.std(c, axis=0))).all()
Exemple #7
0
def test_scf_HernquistCoeffs_ReducesToSpherical():
    Aspherical = potential.scf_compute_coeffs_spherical(
        sphericalHernquistDensity, 5)
    Aaxi = potential.scf_compute_coeffs(sphericalHernquistDensity, 5, 5)
    reducesto_spherical(Aspherical, Aaxi, "Hernquist Potential")
Exemple #8
0
def test_scf_ZeeuwCoeffs_ReducesToSpherical():
    Aspherical = potential.scf_compute_coeffs_spherical(rho_Zeeuw, 5)
    Aaxi = potential.scf_compute_coeffs(rho_Zeeuw, 5,5,radial_order=20,
                                        costheta_order=20)
    reducesto_spherical(Aspherical,Aaxi, "Zeeuw Potential")
Exemple #9
0
def test_scf_HernquistCoeffs_ReducesToSpherical():
    Aspherical = potential.scf_compute_coeffs_spherical(sphericalHernquistDensity, 5)
    Aaxi = potential.scf_compute_coeffs(sphericalHernquistDensity, 5,5)
    reducesto_spherical(Aspherical,Aaxi, "Hernquist Potential")