コード例 #1
0
def test_mildnonaxi_meanvr_grid_tlist():
    # Test that for a close to axisymmetric potential, the mean vr is close to zero
    idf = dehnendf(beta=0.)
    pot = [
        LogarithmicHaloPotential(normalize=1.),
        SteadyLogSpiralPotential(A=-0.005, omegas=0.2)
    ]  #very mild non-axi
    edf = evolveddiskdf(idf, pot=pot, to=-10.)
    mvr, grid = edf.meanvR(0.9,
                           t=[0., -2.5, -5., -7.5, -10.],
                           phi=0.2,
                           integrate_method='rk6_c',
                           grid=True,
                           returnGrid=True,
                           gridpoints=_GRIDPOINTS)
    assert numpy.all(
        numpy.fabs(mvr) < 0.003
    ), 'meanvR of evolveddiskdf for axisymmetric potential is not equal to zero for list of times'
    mvr = edf.meanvR(0.9,
                     t=[0., -2.5, -5., -7.5, -10.],
                     phi=0.2,
                     integrate_method='rk6_c',
                     grid=grid)
    assert numpy.all(
        numpy.fabs(mvr) < 0.003
    ), 'meanvR of evolveddiskdf for axisymmetric potential is not equal to zero when calculated with pre-computed grid for list of times'
    return None
コード例 #2
0
def test_mildnonaxi_meanvt_grid_rmEstimates():
    # Test vmomentsurfacemass w/o having the _estimateX functions in the intial DF
    class fakeDehnen(dehnendf):  #class that removes the _estimate functions
        def __init__(self, *args, **kwargs):
            dehnendf.__init__(self, *args, **kwargs)

        _estimatemeanvR = property()
        _estimatemeanvT = property()
        _estimateSigmaR2 = property()
        _estimateSigmaT2 = property()

    idf = fakeDehnen(beta=0.)
    pot = [
        LogarithmicHaloPotential(normalize=1.),
        SteadyLogSpiralPotential(A=-0.005, omegas=0.2)
    ]  #very mild non-axi
    edf = evolveddiskdf(idf, pot=pot, to=-10.)
    mvt, grid = edf.meanvT(0.9,
                           phi=0.2,
                           integrate_method='rk6_c',
                           grid=True,
                           returnGrid=True,
                           gridpoints=_GRIDPOINTS)
    assert numpy.fabs(
        mvt - idf.meanvT(0.9)
    ) < 0.005, 'meanvT of evolveddiskdf for axisymmetric potential is not equal to that of the initial dehnendf'
    return None
コード例 #3
0
def test_mildnonaxi_meanvt_grid_tlist_onet():
    # Test that for a close to axisymmetric potential, the mean vt is close to that of the initial DF, for a list consisting of a single time
    idf = dehnendf(beta=0.)
    pot = [
        LogarithmicHaloPotential(normalize=1.),
        SteadyLogSpiralPotential(A=-0.005, omegas=0.2)
    ]  #very mild non-axi
    edf = evolveddiskdf(idf, pot=pot, to=-10.)
    mvt, grid = edf.meanvT(0.9,
                           t=[0.],
                           phi=0.2,
                           integrate_method='rk6_c',
                           grid=True,
                           returnGrid=True,
                           gridpoints=_GRIDPOINTS)
    assert numpy.fabs(
        mvt - idf.meanvT(0.9)
    ) < 0.005, 'meanvT of evolveddiskdf for axisymmetric potential is not equal to that of the initial dehnendf'
    mvt = edf.meanvT(
        0.9,
        t=[0.],
        phi=0.2,
        integrate_method='rk6_c',
        grid=grid,
        gridpoints=_GRIDPOINTS,
    )
    assert numpy.fabs(
        mvt - idf.meanvT(0.9)
    ) < 0.005, 'meanvT of evolveddiskdf for axisymmetric potential is not equal to that of the initial dehnendf when calculated with pre-computed grid'
    global _maxi_meanvt
    _maxi_meanvt = mvt
    return None
コード例 #4
0
def test_plot_hierarchgrid():
    idf = dehnendf(beta=0.)
    pot = [
        LogarithmicHaloPotential(normalize=1.),
        SteadyLogSpiralPotential(A=-0.005, omegas=0.2)
    ]  #very mild non-axi
    edf = evolveddiskdf(idf, pot=pot, to=-10.)
    mvr, grid = edf.meanvR(0.9,
                           phi=0.2,
                           integrate_method='rk6_c',
                           grid=True,
                           hierarchgrid=True,
                           returnGrid=True,
                           gridpoints=_GRIDPOINTS)
    grid.plot()
    #w/ list of tiems
    mvr, grid = edf.meanvR(0.9,
                           t=[0., -2.5, -5., -7.5, -10.],
                           phi=0.2,
                           integrate_method='rk6_c',
                           grid=True,
                           hierarchgrid=True,
                           returnGrid=True,
                           gridpoints=_GRIDPOINTS)
    grid.plot(1)
    return None
コード例 #5
0
def test_mildnonaxi_meanvt_hierarchgrid_tlist():
    # Test that for a close to axisymmetric potential, the mean vt is close to that of the initial DF
    idf = dehnendf(beta=0.)
    pot = [
        LogarithmicHaloPotential(normalize=1.),
        SteadyLogSpiralPotential(A=-0.005, omegas=0.2)
    ]  #very mild non-axi
    edf = evolveddiskdf(idf, pot=pot, to=-10.)
    mvt, grid = edf.meanvT(0.9,
                           t=[0., -2.5, -5., -7.5, -10.],
                           phi=0.2,
                           integrate_method='rk6_c',
                           grid=True,
                           hierarchgrid=True,
                           returnGrid=True,
                           gridpoints=_GRIDPOINTS)
    assert numpy.all(
        numpy.fabs(mvt - idf.meanvT(0.9)) < 0.005
    ), 'meanvT of evolveddiskdf for axisymmetric potential is not equal to that of the initial dehnendf when using hierarchgrid and tlist'
    mvt = edf.meanvT(0.9,
                     t=[0., -2.5, -5., -7.5, -10.],
                     phi=0.2,
                     integrate_method='rk6_c',
                     grid=grid,
                     gridpoints=_GRIDPOINTS)
    assert numpy.all(
        numpy.fabs(mvt - idf.meanvT(0.9)) < 0.005
    ), 'meanvT of evolveddiskdf for axisymmetric potential is not equal to that of the initial dehnendf when calculated with pre-computed grid when using hierarchgrid and tlist'
    return None
コード例 #6
0
def test_mildnonaxi_meanvr_grid():
    # Test that for a close to axisymmetric potential, the mean vr is close to zero
    idf= dehnendf(beta=0.)
    pot= [LogarithmicHaloPotential(normalize=1.),
          SteadyLogSpiralPotential(A=-0.005,omegas=0.2)] #very mild non-axi
    edf= evolveddiskdf(idf,pot=pot,to=-10.)
    mvr, grid= edf.meanvR(0.9,phi=0.2,integrate_method='rk6_c',grid=True,
                          returnGrid=True,gridpoints=_GRIDPOINTS)
    assert numpy.fabs(mvr) < 0.001, 'meanvR of evolveddiskdf for axisymmetric potential is not equal to zero'
    mvr= edf.meanvR(0.9,phi=0.2,integrate_method='rk6_c',grid=grid)
    assert numpy.fabs(mvr) < 0.001, 'meanvR of evolveddiskdf for axisymmetric potential is not equal to zero when calculated with pre-computed grid'
    #Pre-compute surfmass and use it, first test that grid is properly returned when given
    smass, ngrid= edf.vmomentsurfacemass(0.9,0,0,phi=0.2,
                                        integrate_method='rk6_c',
                                        grid=grid,gridpoints=_GRIDPOINTS,
                                        returnGrid=True)
    assert ngrid == grid, 'grid returned by vmomentsurfacemass w/ grid input is not the same as the input'
    #Pre-compute surfmass and use it
    nsmass= edf.vmomentsurfacemass(0.9,0,0,phi=0.2,
                                   integrate_method='rk6_c',
                                   grid=True,gridpoints=_GRIDPOINTS)
    assert numpy.fabs(smass-nsmass) < 0.001, 'surfacemass computed w/ and w/o returnGrid are not the same'
    mvr= edf.meanvR(0.9,phi=0.2,integrate_method='rk6_c',grid=grid,
                    surfacemass=smass)
    assert numpy.fabs(mvr) < 0.001, 'meanvR of evolveddiskdf for axisymmetric potential is not equal to zero when calculated with pre-computed grid and surfacemass'
    global _maxi_meanvr
    _maxi_meanvr= mvr
    global _maxi_surfacemass
    _maxi_surfacemass= smass
    return None
コード例 #7
0
ファイル: gk_ss_gaussian.py プロジェクト: johnwez1/gdproject
def add_spiral(arms):
    #spiral parameters and defaults then generate a value for it
    sp_m = arms  #4
    sp_spv = (22.5, 7.5)  #20 15-30
    sp_spv = generate_rand(sp_spv[0], sp_spv[1])

    if sp_m == 4:
        sp_i = (-12 * (3.1415 / 180), 2 * (3.1415 / 180)
                )  #12, err = 2      6, err = 1 (2 arms)
        sp_i = generate_rand(sp_i[0], sp_i[1])
    if sp_m == 2:
        sp_i = (-6 * (3.1415 / 180), 1 * (3.1415 / 180)
                )  #12, err = 2      6, err = 1 (2 arms)
        sp_i = generate_rand(sp_i[0], sp_i[1])

    sp_x_0 = (-120 * (3.1415 / 180), 10 * (3.1415 / 180))  #-120 err = 10
    sp_x_0 = generate_rand(sp_x_0[0], sp_x_0[1])

    sp_a = -sp_m / tan(sp_i)
    sp_gamma = sp_x_0 / sp_m
    sp_fr_0 = (0.05, 0.01)
    sp_fr_0 = generate_rand(sp_fr_0[0], sp_fr_0[1])
    #    ro = 8
    #    vo = 220
    sp_A = -(
        1
    ) * sp_fr_0  #*((ro*vo)**2) #not sure on this part but adding these makes it too big so leave them
    sp_component = SteadyLogSpiralPotential(amp=1,
                                            omegas=sp_spv / 220,
                                            A=sp_A,
                                            alpha=sp_a,
                                            gamma=sp_gamma)
    mwp_2D.append(sp_component)
コード例 #8
0
def test_mildnonaxi_meanvt_hierarchgrid():
    # Test that for a close to axisymmetric potential, the mean vt is close to that of the initial DF
    idf= dehnendf(beta=0.)
    pot= [LogarithmicHaloPotential(normalize=1.),
          SteadyLogSpiralPotential(A=-0.005,omegas=0.2)] #very mild non-axi
    edf= evolveddiskdf(idf,pot=pot,to=-10.)
    mvt, grid= edf.meanvT(0.9,phi=0.2,integrate_method='rk6_c',
                          grid=True,hierarchgrid=True,
                          returnGrid=True,gridpoints=_GRIDPOINTS)
    assert numpy.fabs(mvt-idf.meanvT(0.9)) < 0.005, 'meanvT of evolveddiskdf for axisymmetric potential is not equal to that of the initial dehnendf when using hierarchgrid'
    mvt= edf.meanvT(0.9,phi=0.2,integrate_method='rk6_c',grid=grid,
                    gridpoints=_GRIDPOINTS)
    assert numpy.fabs(mvt-idf.meanvT(0.9)) < 0.005, 'meanvT of evolveddiskdf for axisymmetric potential is not equal to that of the initial dehnendf when calculated with pre-computed grid when using hierarchgrid'
    #Also test that the hierarchgrid is properly returned
    smass, ngrid= edf.vmomentsurfacemass(0.9,0,0,phi=0.2,
                                        integrate_method='rk6_c',
                                        grid=grid,gridpoints=_GRIDPOINTS,
                                         returnGrid=True)
    assert ngrid == grid, 'hierarchical grid returned by vmomentsurfacemass w/ grid input is not the same as the input'
    nsmass= edf.vmomentsurfacemass(0.9,0,0,phi=0.2,
                                   integrate_method='rk6_c',
                                   grid=True,hierarchgrid=True,
                                   gridpoints=_GRIDPOINTS)
    assert numpy.fabs(smass-nsmass) < 0.001, 'surfacemass computed w/ and w/o returnGrid are not the same'
    return None
コード例 #9
0
def add_spiral(arms):
    #spiral parameters and defaults then generate a value for it
    sp_m = arms  #4
    sp_spv = (22.5, 7.5)  #20 15-30
    sp_spv = generate_rand(sp_spv[0], sp_spv[1])

    if sp_m == 4:
        sp_i = (-12 * (3.1415 / 180), 2 * (3.1415 / 180)
                )  #12, err = 2      6, err = 1 (2 arms)
        sp_i = generate_rand(sp_i[0], sp_i[1])
    if sp_m == 2:
        sp_i = (-6 * (3.1415 / 180), 1 * (3.1415 / 180)
                )  #12, err = 2      6, err = 1 (2 arms)
        sp_i = generate_rand(sp_i[0], sp_i[1])

    sp_x_0 = (-120 * (3.1415 / 180), 10 * (3.1415 / 180))  #-120 err = 10
    sp_x_0 = generate_rand(sp_x_0[0], sp_x_0[1])

    sp_a = -sp_m / tan(sp_i)
    sp_gamma = sp_x_0 / sp_m
    sp_fr_0 = (0.05, 0.01)
    sp_fr_0 = generate_rand(sp_fr_0[0], sp_fr_0[1])
    #    ro = 8
    #    vo = 220
    sp_A = -sp_fr_0  #to get from ramirez to galpy divide by 220 below so its in natural units
    sp_component = SteadyLogSpiralPotential(amp=1,
                                            omegas=sp_spv / 220,
                                            A=sp_A,
                                            alpha=sp_a,
                                            gamma=sp_gamma)
    mwp_2D.append(sp_component)  # not yet
コード例 #10
0
def plot_2d(sp=False):
    mwp_2D = [i.toPlanar() for i in mwp]
    sun_2D = sun.toPlanar()
    sun_2D.integrate(ts, mwp_2D, method='odeint')
    #spiral parameters and defaults
    if sp == True:
        sp_m = 4  #4    #2
        sp_spv = 25  #20   #
        sp_i = -5 * (3.1415 / 180)  #-12    #-5
        sp_x_0 = -120 * (3.1415 / 180)  #-120    #
        sp_a = -sp_m / tan(sp_i)
        sp_gamma = sp_x_0 / sp_m
        sp_fr_0 = 0.05  #0.05    #
        ro = 8
        vo = 220
        sp_A = -(
            sp_fr_0
        )  #divide by row to normalise?? #*((vo)**2) #not sure on this part but adding these makes it too big so leave them

        sp_component = SteadyLogSpiralPotential(amp=1,
                                                omegas=sp_spv / 220,
                                                A=sp_A,
                                                alpha=sp_a,
                                                gamma=sp_gamma)
        mwp_2D.append(sp_component)  # not yet
    for o in orbits:
        o_2D = o.toPlanar()
        o_2D.integrate(ts, mwp_2D, method='odeint')
        delta_x = o_2D.x(ts) - sun_2D.x(ts)
        delta_y = o_2D.y(ts) - sun_2D.y(ts)
        delta = (delta_x**2 + delta_y**2)**0.5
        plt.semilogy(sun_2D.time(ts), delta * 1000)
コード例 #11
0
def test_mildnonaxi_vertexdev_grid():
    # Test that for a close to axisymmetric potential, the vertex deviation is close to zero
    idf= dehnendf(beta=0.)
    pot= [LogarithmicHaloPotential(normalize=1.),
          SteadyLogSpiralPotential(A=-0.005,omegas=0.2)] #very mild non-axi
    edf= evolveddiskdf(idf,pot=pot,to=-10.)
    vdev, grid= edf.vertexdev(0.9,phi=0.2,integrate_method='rk6_c',grid=True,
                              returnGrid=True,gridpoints=_GRIDPOINTS)
    assert numpy.fabs(vdev) < 2., 'vertexdev of evolveddiskdf for axisymmetric potential is not close to zero' #2 is pretty big, but the weak spiral creates that
    vdev= edf.vertexdev(0.9,phi=0.2,integrate_method='rk6_c',grid=grid,
                        gridpoints=_GRIDPOINTS)
    assert numpy.fabs(vdev) < 2., 'vertexdev of evolveddiskdf for axisymmetric potential is not equal zero when calculated with pre-computed grid'
    vdev= edf.vertexdev(0.9,phi=0.2,integrate_method='rk6_c',grid=grid,
                        sigmaR2=_maxi_sigmar2,sigmaT2=_maxi_sigmat2,
                        sigmaRT=_maxi_sigmart,gridpoints=_GRIDPOINTS)
    assert numpy.fabs(vdev) < 2., 'sigmart of evolveddiskdf for axisymmetric potential is not equal to zero when calculated with pre-computed sigmaR2,sigmaT2,sigmaRT'
    return None
コード例 #12
0
def test_mildnonaxi_sigmart_grid():
    # Test that for a close to axisymmetric potential, the sigmaR2 is close to zero
    idf= dehnendf(beta=0.)
    pot= [LogarithmicHaloPotential(normalize=1.),
          SteadyLogSpiralPotential(A=-0.005,omegas=0.2)] #very mild non-axi
    edf= evolveddiskdf(idf,pot=pot,to=-10.)
    srt, grid= edf.sigmaRT(0.9,phi=0.2,integrate_method='rk6_c',grid=True,
                           returnGrid=True,gridpoints=_GRIDPOINTS)
    assert numpy.fabs(srt) < 0.01, 'sigmart of evolveddiskdf for axisymmetric potential is not equal to zero'
    srt= edf.sigmaRT(0.9,phi=0.2,integrate_method='rk6_c',grid=grid,
                     gridpoints=_GRIDPOINTS)
    assert numpy.fabs(srt) < 0.01, 'sigmart of evolveddiskdf for axisymmetric potential is not equal zero when calculated with pre-computed grid'
    srt= edf.sigmaRT(0.9,phi=0.2,integrate_method='rk6_c',grid=grid,
                     meanvR=_maxi_meanvr,
                     meanvT=_maxi_meanvt,surfacemass=_maxi_surfacemass,
                     gridpoints=_GRIDPOINTS)
    assert numpy.fabs(srt) < 0.01, 'sigmart of evolveddiskdf for axisymmetric potential is not equal to zero when calculated with pre-computed grid and meanvR,surfacemass'
    global _maxi_sigmart
    _maxi_sigmart= srt
    return None
コード例 #13
0
def test_mildnonaxi_sigmat2_grid():
    # Test that for a close to axisymmetric potential, the sigmaR2 is close to the value of the initial DF
    idf= dehnendf(beta=0.)
    pot= [LogarithmicHaloPotential(normalize=1.),
          SteadyLogSpiralPotential(A=-0.005,omegas=0.2)] #very mild non-axi
    edf= evolveddiskdf(idf,pot=pot,to=-10.)
    st2, grid= edf.sigmaT2(0.9,phi=0.2,integrate_method='rk6_c',grid=True,
                           returnGrid=True,gridpoints=_GRIDPOINTS)
    ist2= idf.sigmaT2(0.9)
    assert numpy.fabs(numpy.log(st2)-numpy.log(ist2)) < 0.025, 'sigmat2 of evolveddiskdf for axisymmetric potential is not equal to that of initial DF'
    st2= edf.sigmaT2(0.9,phi=0.2,integrate_method='rk6_c',grid=grid,
                     gridpoints=_GRIDPOINTS)
    assert numpy.fabs(numpy.log(st2)-numpy.log(ist2)) < 0.025, 'sigmat2 of evolveddiskdf for axisymmetric potential is not equal to that of initial DF when calculated with pre-computed grid'
    st2= edf.sigmaT2(0.9,phi=0.2,integrate_method='rk6_c',grid=grid,
                     meanvT=_maxi_meanvt,surfacemass=_maxi_surfacemass,
                     gridpoints=_GRIDPOINTS)
    assert numpy.fabs(numpy.log(st2)-numpy.log(ist2)) < 0.025, 'sigmat2 of evolveddiskdf for axisymmetric potential is not equal to that of initial DF when calculated with pre-computed grid and meanvR,surfacemass'
    global _maxi_sigmat2
    _maxi_sigmat2= st2
    return None
コード例 #14
0
ファイル: apo_ss_2D.py プロジェクト: johnwez1/gdproject
sp_a = -sp_m / tan(sp_i)
sp_gamma = sp_x_0 / sp_m
sp_fr_0 = 0.05  #0.05
ro = 8
vo = 220
sp_A = -(
    1
) * sp_fr_0  #*((ro*vo)**2) #not sure on this part but adding these makes it too big so leave them
#galpy natural units takes care of this stuff - so just leave it
#there was a lot of jumbling to get it to look the same as literature
#just believe it!!!

sp_component = SteadyLogSpiralPotential(amp=1,
                                        omegas=sp_spv,
                                        A=sp_A,
                                        alpha=sp_a,
                                        gamma=sp_gamma,
                                        ro=8,
                                        vo=220)
mwp_2D.append(sp_component)  # not yet

print("finally calculating distance from sun...")
for o in orbits_2D[2:]:
    o_2D = o.toPlanar()
    o_2D.integrate(ts, mwp_2D, method='odeint')
    delta_x = o_2D.x(ts) - sun_2D.x(ts)
    delta_y = o_2D.y(ts) - sun_2D.y(ts)
    delta = (delta_x**2 + delta_y**2)**0.5
    plt.semilogy(sun_2D.time(ts), delta * 1000)

plt.title("Solar Sibling Proximity")