예제 #1
0
def test_axi_density1_axiOrder():
    Acos, Asin = potential.scf_compute_coeffs_axi(axi_density1, 10, 10)
    Acos2, Asin2 = potential.scf_compute_coeffs_axi(axi_density1,
                                                    10,
                                                    10,
                                                    radial_order=50,
                                                    costheta_order=50)

    assert numpy.all(numpy.fabs(Acos - Acos2) < 1e-10), \
    "Increasing the radial and costheta order fails for scf_compute_coeffs_axi"
예제 #2
0
def make_McMillan2017(ro=8.21, vo=233.1):
    '''
    make_McMillan2017:
    
    Make the McMillan 2017 potential using SCF basis expansion:
    
    No arguments, but could change ro, vo if desired. ro is from the Gravity 
    Collaboration (2018). vo is from Eilers (2018) and Schonrich (2010)
    
    Args:
        None
    '''

    #dicts used in DiskSCFPotential 
    sigmadict = [{'type':'exp','h':Rd_HI,'amp':Sigma0_HI, 'Rhole':Rm_HI},
                 {'type':'exp','h':Rd_H2,'amp':Sigma0_H2, 'Rhole':Rm_H2},
                 {'type':'exp','h':Rd_thin,'amp':Sigma0_thin, 'Rhole':0.},
                 {'type':'exp','h':Rd_thick,'amp':Sigma0_thick, 'Rhole':0.}]

    hzdict = [{'type':'sech2', 'h':zd_HI},
              {'type':'sech2', 'h':zd_H2},
              {'type':'exp', 'h':0.3/ro},
              {'type':'exp', 'h':0.9/ro}]
    McMillan_bulge=\
    mySCFPotential(Acos=potential.scf_compute_coeffs_axi(bulge_dens,20,10,a=0.1)[0],
                    a=0.1,ro=ro,vo=vo)
    McMillan_disk = myDiskSCFPotential(dens=lambda R,z: gas_stellar_dens(R,z),
                                     Sigma=sigmadict, hz=hzdict,
                                     a=2.5, N=30, L=30,ro=ro,vo=vo)
    McMillan_halo = potential.NFWPotential(amp = rho0_halo*(4*np.pi*rh**3),
                                 a = rh,ro=ro,vo=vo)
    McMillan2017 = [McMillan_disk,McMillan_halo,McMillan_bulge]
    
    return McMillan2017
예제 #3
0
def test_scf_compute_axi_density2():
    A = potential.scf_compute_coeffs_axi(axi_density2,
                                         10,
                                         10,
                                         radial_order=30,
                                         costheta_order=12)
    axi_coeffsTest(A[0], A[1])
    analytically_calculated = 2 * numpy.array([
        [1., 7. * 3**(-3 / 2.) / 4., 3 * 11 * 5**(-5. / 2) / 2., 0],
        [0, 0, 0, 0],  ##I never did analytically solve for n=1
        [
            0, 11. / (7 * 5 * 3**(3. / 2) * 2**(3.)),
            (7 * 5**(.5) * 2**3.)**-1., 0
        ]
    ])
    numerically_calculated = A[0][:3, :4, 0]
    shape = numerically_calculated.shape
    for n in range(shape[0]):
        if n == 1: continue
        for l in range(shape[1]):
            assert numpy.fabs(numerically_calculated[n,l] - analytically_calculated[n,l]) < EPS, \
        "Acos(n={0},l={1},0) = {2}, whereas it was analytically calculated to be {3}".format(n,l, numerically_calculated[n,l], analytically_calculated[n,l])

    #Checks that A at l != 0,1,2 are always zero
    assert numpy.all(
        numpy.fabs(A[0][:, 3:, 0]) < 1e-10), "Acos(n,l>2,m=0) = 0 fails."

    #Checks that A = 0 when n = 2,4,..,2*n and l = 0
    assert numpy.all(
        numpy.fabs(A[0][2::2, 0,
                        0]) < 1e-10), "Acos(n > 1,l = 0,m=0) = 0 fails."
예제 #4
0
def test_scf_compute_axi_nbody_twopowertriaxial():
    N = int(1e5)
    Mh = 11.
    ah = 50. / 8.
    m = Mh / N
    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(1)
    samp = [hdf.sample(n=N) for i in range(nsamp)]

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

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

    cc, ss = potential.scf_compute_coeffs_axi(tptp.dens, Norder, Lorder, a=ah)
    c, s = numpy.zeros((2, nsamp, Norder, Lorder, 1))
    for i, p in enumerate(positions):
        c[i], s[i] = potential.scf_compute_coeffs_axi_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, 1))
    for i, p in enumerate(positions):
        c[i], s[i] = potential.scf_compute_coeffs_axi_nbody(p,
                                                            Norder,
                                                            Lorder,
                                                            mass=m,
                                                            a=ah)
    assert (cc - (numpy.mean(c, axis=0)) <= (2. * numpy.std(c, axis=0))).all()
    return None
예제 #5
0
def test_scf_compute_axi_density1():
    A = potential.scf_compute_coeffs_axi(axi_density1, 10,10)
    axi_coeffsTest(A[0], A[1])
    analytically_calculated = numpy.array([[4./3, 7.* 3**(-5/2.), 2*11*5**(-5./2), 0],
                                            [0, 0,0,0],
                                            [0,11. / (3.**(5./2) * 5 * 7. * 2), 1. / (2*3.*5**.5*7.), 0]])
    numerically_calculated = A[0][:3,:4,0]
    shape = numerically_calculated.shape
    for n in range(shape[0]):
        for l in range(shape[1]):
            assert numpy.fabs(numerically_calculated[n,l] - analytically_calculated[n,l]) < EPS, \
        "Acos(n={0},l={1},0) = {2}, whereas it was analytically calculated to be {3}".format(n,l, numerically_calculated[n,l], analytically_calculated[n,l])  
    #Checks that A at l != 0,1,2 are always zero    
    assert numpy.all(numpy.fabs(A[0][:,3:,0]) < 1e-10), "Acos(n,l>2,m=0) = 0 fails."
    
    #Checks that A at n odd is always zero    
    assert numpy.all(numpy.fabs(A[0][1::2,:,0]) < 1e-10), "Acos(n odd,l,m=0) = 0 fails."
    
    #Checks that A = 0 when n != 0 and l = 0  
    assert numpy.all(numpy.fabs(A[0][1:,0,0]) < 1e-10), "Acos(n > 1,l=0,m=0) = 0 fails."
예제 #6
0
def test_scf_compute_axi_density2():
    A = potential.scf_compute_coeffs_axi(axi_density2, 10,10,
                                         radial_order=30,costheta_order=12)
    axi_coeffsTest(A[0], A[1])
    analytically_calculated = 2*numpy.array([[1., 7.* 3**(-3/2.) /4., 3*11*5**(-5./2)/2., 0],
                                            [0,0,0,0], ##I never did analytically solve for n=1
                                            [0, 11./(7*5*3**(3./2)*2**(3.)), (7 * 5**(.5)*2**3.)**-1., 0]])
    numerically_calculated = A[0][:3,:4,0]
    shape = numerically_calculated.shape
    for n in range(shape[0]):
        if n ==1: continue 
        for l in range(shape[1]):
            assert numpy.fabs(numerically_calculated[n,l] - analytically_calculated[n,l]) < EPS, \
        "Acos(n={0},l={1},0) = {2}, whereas it was analytically calculated to be {3}".format(n,l, numerically_calculated[n,l], analytically_calculated[n,l])
    
    #Checks that A at l != 0,1,2 are always zero    
    assert numpy.all(numpy.fabs(A[0][:,3:,0]) < 1e-10), "Acos(n,l>2,m=0) = 0 fails."
    
    #Checks that A = 0 when n = 2,4,..,2*n and l = 0  
    assert numpy.all(numpy.fabs(A[0][2::2,0,0]) < 1e-10), "Acos(n > 1,l = 0,m=0) = 0 fails."
예제 #7
0
def test_scf_compute_axi_density1():
    A = potential.scf_compute_coeffs_axi(axi_density1, 10,10)
    axi_coeffsTest(A[0], A[1])
    analytically_calculated = numpy.array([[4./3, 7.* 3**(-5/2.), 2*11*5**(-5./2), 0],
                                            [0, 0,0,0],
                                            [0,11. / (3.**(5./2) * 5 * 7. * 2), 1. / (2*3.*5**.5*7.), 0]])
    numerically_calculated = A[0][:3,:4,0]
    shape = numerically_calculated.shape
    for n in range(shape[0]):
        for l in range(shape[1]):
            assert numpy.fabs(numerically_calculated[n,l] - analytically_calculated[n,l]) < EPS, \
        "Acos(n={0},l={1},0) = {2}, whereas it was analytically calculated to be {3}".format(n,l, numerically_calculated[n,l], analytically_calculated[n,l])  
    #Checks that A at l != 0,1,2 are always zero    
    assert numpy.all(numpy.fabs(A[0][:,3:,0]) < 1e-10), "Acos(n,l>2,m=0) = 0 fails."
    
    #Checks that A at n odd is always zero    
    assert numpy.all(numpy.fabs(A[0][1::2,:,0]) < 1e-10), "Acos(n odd,l,m=0) = 0 fails."
    
    #Checks that A = 0 when n != 0 and l = 0  
    assert numpy.all(numpy.fabs(A[0][1:,0,0]) < 1e-10), "Acos(n > 1,l=0,m=0) = 0 fails."
예제 #8
0
def test_densMatches_axi_density2():
    Acos, Asin = potential.scf_compute_coeffs_axi(axi_density2, 50, 3)
    scf = SCFPotential(amp=1, Acos=Acos, Asin=Asin)
    assertmsg = "Comparing axi_density2 with SCF fails at R={0}, Z={1}, phi={2}"
    compareFunctions(axi_density2, scf.dens, assertmsg, eps=1e-3)
예제 #9
0
def test_scf_axiZeeuwCoeffs_ReducesToSpherical():
    Aspherical = potential.scf_compute_coeffs_spherical(rho_Zeeuw, 10)
    Aaxi = potential.scf_compute_coeffs_axi(rho_Zeeuw, 10, 10)
    axi_reducesto_spherical(Aspherical, Aaxi, "Zeeuw Potential")
예제 #10
0
def test_scf_axiHernquistCoeffs_ReducesToSpherical():
    Aspherical = potential.scf_compute_coeffs_spherical(
        sphericalHernquistDensity, 10)
    Aaxi = potential.scf_compute_coeffs_axi(sphericalHernquistDensity, 10, 10)
    axi_reducesto_spherical(Aspherical, Aaxi, "Hernquist Potential")
예제 #11
0
def test_densMatches_axi_density2():
    Acos, Asin = potential.scf_compute_coeffs_axi(axi_density2,50,3)
    scf = SCFPotential(amp=1, Acos=Acos, Asin=Asin)
    assertmsg = "Comparing axi_density2 with SCF fails at R={0}, Z={1}, phi={2}"
    compareFunctions(axi_density2,scf.dens, assertmsg, eps=1e-3) 
예제 #12
0
def test_scf_axiZeeuwCoeffs_ReducesToSpherical():
    Aspherical = potential.scf_compute_coeffs_spherical(rho_Zeeuw, 10)
    Aaxi = potential.scf_compute_coeffs_axi(rho_Zeeuw, 10,10)
    axi_reducesto_spherical(Aspherical,Aaxi, "Zeeuw Potential")
예제 #13
0
def test_scf_axiHernquistCoeffs_ReducesToSpherical():
    Aspherical = potential.scf_compute_coeffs_spherical(sphericalHernquistDensity, 10)
    Aaxi = potential.scf_compute_coeffs_axi(sphericalHernquistDensity, 10,10)
    axi_reducesto_spherical(Aspherical,Aaxi, "Hernquist Potential")
예제 #14
0
def test_axi_density1_axiOrder():
    Acos, Asin = potential.scf_compute_coeffs_axi(axi_density1, 10,10)
    Acos2, Asin2 = potential.scf_compute_coeffs_axi(axi_density1, 10, 10, radial_order=50, costheta_order=50)
     
    assert numpy.all(numpy.fabs(Acos - Acos2) < 1e-10), \
    "Increasing the radial and costheta order fails for scf_compute_coeffs_axi"
예제 #15
0
    return gas_dens(R,z)+stellar_dens(R,z)+bulge_dens(R,z)+NFW_dens(R,z)

def sech(x):
    return 1./np.cosh(x)


#dicts used in DiskSCFPotential 
sigmadict = [{'type':'exp','h':Rd_HI,'amp':Sigma0_HI, 'Rhole':Rm_HI},
             {'type':'exp','h':Rd_H2,'amp':Sigma0_H2, 'Rhole':Rm_H2},
             {'type':'exp','h':Rd_thin,'amp':Sigma0_thin, 'Rhole':0.},
             {'type':'exp','h':Rd_thick,'amp':Sigma0_thick, 'Rhole':0.}]

hzdict = [{'type':'sech2', 'h':zd_HI},
          {'type':'sech2', 'h':zd_H2},
          {'type':'exp', 'h':0.3/ro},
          {'type':'exp', 'h':0.9/ro}]

#generate separate disk and halo potential - and combined potential
McMillan_bulge=\
    mySCFPotential(Acos=scf_compute_coeffs_axi(bulge_dens,20,10,a=0.1)[0],
                 a=0.1,ro=ro,vo=vo)
McMillan_disk = myDiskSCFPotential(dens=lambda R,z: gas_stellar_dens(R,z),
                                 Sigma=sigmadict, hz=hzdict,
                                 a=2.5, N=30, L=30,ro=ro,vo=vo)
McMillan_halo = NFWPotential(amp = rho0_halo*(4*np.pi*rh**3),
                             a = rh,ro=ro,vo=vo)
McMillan2017 = [McMillan_disk,McMillan_halo,McMillan_bulge]