Пример #1
0
def plot_Sn_timesamples(PSP):
    """ Plots Fig. 5 from Sanders & Binney (2014) """
    TT = pot.stackel_triax()
    f, a = plt.subplots(2, 1, figsize=[3.32, 3.6])
    plt.subplots_adjust(hspace=0.0, top=0.8)

    LowestPeriod = 2.0 * np.pi / 38.86564386
    Times = np.array([2.0, 4.0, 8.0, 12.0])
    Sr = np.arange(2, 14, 2)

    # Loop over length of integration window
    for i, P, C in zip(Times, [".", "s", "D", "^"], ["k", "r", "b", "g"]):
        diffact = np.zeros((len(Sr), 3))
        difffreq = np.zeros((len(Sr), 3))
        MAXGAPS = np.array([])
        # Loop over N_max
        for k, j in enumerate(Sr):
            NT = choose_NT(j)
            timeseries = np.linspace(0.0, i * LowestPeriod, NT)
            results = odeint(pot.orbit_derivs2, PSP, timeseries, args=(TT,), rtol=1e-13, atol=1e-13)
            act, ang, n_vec, toy_aa, pars = find_actions(results, timeseries, N_matrix=j, ifprint=False, use_box=True)
            # Check all modes
            checks, maxgap = ced(n_vec, ua(toy_aa.T[3:].T, np.ones(3)))
            if len(maxgap) > 0:
                maxgap = np.max(maxgap)
            else:
                maxgap = 0
            diffact[k] = act[:3] / TT.action(results[0])
            print i, j, print_max_average(n_vec, toy_aa.T[3:].T, act[3:]), str(ang[3:6] - TT.freq(results[0])).replace(
                "[", ""
            ).replace("]", ""), str(np.abs(act[:3] - TT.action(results[0]))).replace("[", "").replace("]", ""), len(
                checks
            ), maxgap
            MAXGAPS = np.append(MAXGAPS, maxgap)
            difffreq[k] = ang[3:6] / TT.freq(results[0])
        size = 15
        if P == ".":
            size = 30
        LW = np.array(map(lambda i: 0.5 + i * 0.5, MAXGAPS))
        a[0].scatter(
            Sr,
            np.log10(np.abs(diffact.T[2] - 1)),
            marker=P,
            s=size,
            color=C,
            facecolors="none",
            lw=LW,
            label=r"$T =\,$" + str(i) + r"$\,T_F$",
        )
        a[1].scatter(Sr, np.log10(np.abs(difffreq.T[2] - 1)), marker=P, s=size, color=C, facecolors="none", lw=LW)
    a[1].get_yticklabels()[-1].set_visible(False)
    a[0].set_xticklabels([])
    a[0].set_xlim(1, 13)
    a[0].set_ylabel(r"$\log_{10}|J_3^\prime/J_{3, \rm true}-1|$")
    leg = a[0].legend(loc="upper center", bbox_to_anchor=(0.5, 1.4), ncol=2, scatterpoints=1)
    leg.draw_frame(False)
    a[1].set_xlim(1, 13)
    a[1].set_xlabel(r"$N_{\rm max}$")
    a[1].set_ylabel(r"$\log_{10}|\Omega_3^\prime/\Omega_{3,\rm true}-1|$")
    plt.savefig("Sn_T_box.pdf", bbox_inches="tight")
Пример #2
0
def plot3D_stacktriax(initial,final_t,N_MAT,file_output):
    """ For producing plots from paper """

    # Setup Stackel potential
    TT = pot.stackel_triax()
    times = choose_NT(N_MAT)
    timeseries=np.linspace(0.,final_t,times)
    # Integrate orbit
    results = odeint(pot.orbit_derivs2,initial,timeseries,args=(TT,),rtol=1e-13,atol=1e-13)
    # Find actions, angles and frequencies
    (act,ang,n_vec,toy_aa, pars),loop = find_actions(results, timeseries,N_matrix=N_MAT,ifloop=True)

    toy_pot = 0
    if(loop[2]>0.5 or loop[0]>0.5):
        toy_pot = pot.isochrone(par=np.append(pars,0.))
    else:
        toy_pot = pot.harmonic_oscillator(omega=pars[:3])
    # Integrate initial condition in toy potential
    timeseries_2=np.linspace(0.,2.*final_t,3500)
    results_toy = odeint(pot.orbit_derivs2,initial,timeseries_2,args=(toy_pot,))

    print "True actions: ", TT.action(results[0])
    print "Found actions: ", act[:3]
    print "True frequencies: ",TT.freq(results[0])
    print "Found frequencies: ",ang[3:6]


    # and plot
    f,a = plt.subplots(2,3,figsize=[3.32,5.5])
    a[0,0] = plt.subplot2grid((3,2), (0, 0))
    a[1,0] = plt.subplot2grid((3,2), (0, 1))
    a[0,1] = plt.subplot2grid((3,2), (1, 0))
    a[1,1] = plt.subplot2grid((3,2), (1, 1))
    a[0,2] = plt.subplot2grid((3,2), (2, 0),colspan=2)
    plt.subplots_adjust(wspace=0.5,hspace=0.45)

    # xy orbit
    a[0,0].plot(results.T[0],results.T[1],'k')
    a[0,0].set_xlabel(r'$x/{\rm kpc}$')
    a[0,0].set_ylabel(r'$y/{\rm kpc}$')
    a[0,0].xaxis.set_major_locator(MaxNLocator(5))
    # xz orbit
    a[1,0].plot(results.T[0],results.T[2],'k')
    a[1,0].set_xlabel(r'$x/{\rm kpc}$')
    a[1,0].set_ylabel(r'$z/{\rm kpc}$')
    a[1,0].xaxis.set_major_locator(MaxNLocator(5))
    # toy orbits
    a[0,0].plot(results_toy.T[0],results_toy.T[1],'r',alpha=0.2,linewidth=0.3)
    a[1,0].plot(results_toy.T[0],results_toy.T[2],'r',alpha=0.2,linewidth=0.3)

    # Toy actions
    a[0,2].plot(Conv*timeseries,toy_aa.T[0],'k:',label='Toy action')
    a[0,2].plot(Conv*timeseries,toy_aa.T[1],'r:')
    a[0,2].plot(Conv*timeseries,toy_aa.T[2],'b:')
    # Arrows to show approx. actions
    arrow_end = a[0,2].get_xlim()[1]
    arrowd = 0.08*(arrow_end-a[0,2].get_xlim()[0])
    a[0,2].annotate('',(arrow_end+arrowd,act[0]),(arrow_end,act[0]),arrowprops=dict(arrowstyle='<-',color='k'),annotation_clip=False)
    a[0,2].annotate('',(arrow_end+arrowd,act[1]),(arrow_end,act[1]),arrowprops=dict(arrowstyle='<-',color='r'),annotation_clip=False)
    a[0,2].annotate('',(arrow_end+arrowd,act[2]),(arrow_end,act[2]),arrowprops=dict(arrowstyle='<-',color='b'),annotation_clip=False)
    # True actions
    a[0,2].plot(Conv*timeseries,TT.action(results[0])[0]*np.ones(len(timeseries)),'k',label='True action')
    a[0,2].plot(Conv*timeseries,TT.action(results[0])[1]*np.ones(len(timeseries)),'k')
    a[0,2].plot(Conv*timeseries,TT.action(results[0])[2]*np.ones(len(timeseries)),'k')
    a[0,2].set_xlabel(r'$t/{\rm Gyr}$')
    a[0,2].set_ylabel(r'$J/{\rm kpc\,km\,s}^{-1}$')
    leg = a[0,2].legend(loc='upper center',bbox_to_anchor=(0.5,1.2),ncol=3, numpoints = 1)
    leg.draw_frame(False)

    # Toy angle coverage
    a[0,1].plot(toy_aa.T[3]/(np.pi),toy_aa.T[4]/(np.pi),'k.',markersize=0.4)
    a[0,1].set_xlabel(r'$\theta_1/\pi$')
    a[0,1].set_ylabel(r'$\theta_2/\pi$')
    a[1,1].plot(toy_aa.T[3]/(np.pi),toy_aa.T[5]/(np.pi),'k.',markersize=0.4)
    a[1,1].set_xlabel(r'$\theta_1/\pi$')
    a[1,1].set_ylabel(r'$\theta_3/\pi$')

    plt.savefig(file_output,bbox_inches='tight')
    return act
Пример #3
0
def plot3D_stacktriax(initial, final_t, N_MAT, file_output):
    """ For producing plots from paper """

    # Setup Stackel potential
    TT = pot.stackel_triax()
    times = choose_NT(N_MAT)
    timeseries = np.linspace(0., final_t, times)
    # Integrate orbit
    results = odeint(pot.orbit_derivs2,
                     initial,
                     timeseries,
                     args=(TT, ),
                     rtol=1e-13,
                     atol=1e-13)
    # Find actions, angles and frequencies
    (act, ang, n_vec, toy_aa, pars), loop = find_actions(results,
                                                         timeseries,
                                                         N_matrix=N_MAT,
                                                         ifloop=True)

    toy_pot = 0
    if (loop[2] > 0.5 or loop[0] > 0.5):
        toy_pot = pot.isochrone(par=np.append(pars, 0.))
    else:
        toy_pot = pot.harmonic_oscillator(omega=pars[:3])
    # Integrate initial condition in toy potential
    timeseries_2 = np.linspace(0., 2. * final_t, 3500)
    results_toy = odeint(pot.orbit_derivs2,
                         initial,
                         timeseries_2,
                         args=(toy_pot, ))

    print "True actions: ", TT.action(results[0])
    print "Found actions: ", act[:3]
    print "True frequencies: ", TT.freq(results[0]) / Conv
    print "Found frequencies: ", ang[3:6] / Conv

    # and plot
    f, a = plt.subplots(2, 3, figsize=[3.32, 5.5])
    a[0, 0] = plt.subplot2grid((3, 2), (0, 0))
    a[1, 0] = plt.subplot2grid((3, 2), (0, 1))
    a[0, 1] = plt.subplot2grid((3, 2), (1, 0))
    a[1, 1] = plt.subplot2grid((3, 2), (1, 1))
    a[0, 2] = plt.subplot2grid((3, 2), (2, 0), colspan=2)
    plt.subplots_adjust(wspace=0.5, hspace=0.45)

    # xy orbit
    a[0, 0].plot(results.T[0], results.T[1], 'k')
    a[0, 0].set_xlabel(r'$x/{\rm kpc}$')
    a[0, 0].set_ylabel(r'$y/{\rm kpc}$')
    a[0, 0].xaxis.set_major_locator(MaxNLocator(5))
    # xz orbit
    a[1, 0].plot(results.T[0], results.T[2], 'k')
    a[1, 0].set_xlabel(r'$x/{\rm kpc}$')
    a[1, 0].set_ylabel(r'$z/{\rm kpc}$')
    a[1, 0].xaxis.set_major_locator(MaxNLocator(5))
    # toy orbits
    a[0, 0].plot(results_toy.T[0],
                 results_toy.T[1],
                 'r',
                 alpha=0.2,
                 linewidth=0.3)
    a[1, 0].plot(results_toy.T[0],
                 results_toy.T[2],
                 'r',
                 alpha=0.2,
                 linewidth=0.3)

    # Toy actions
    a[0, 2].plot(Conv * timeseries, toy_aa.T[0], 'k:', label='Toy action')
    a[0, 2].plot(Conv * timeseries, toy_aa.T[1], 'r:')
    a[0, 2].plot(Conv * timeseries, toy_aa.T[2], 'b:')
    # Arrows to show approx. actions
    arrow_end = a[0, 2].get_xlim()[1]
    arrowd = 0.08 * (arrow_end - a[0, 2].get_xlim()[0])
    a[0, 2].annotate('', (arrow_end + arrowd, act[0]), (arrow_end, act[0]),
                     arrowprops=dict(arrowstyle='<-', color='k'),
                     annotation_clip=False)
    a[0, 2].annotate('', (arrow_end + arrowd, act[1]), (arrow_end, act[1]),
                     arrowprops=dict(arrowstyle='<-', color='b'),
                     annotation_clip=False)
    a[0, 2].annotate('', (arrow_end + arrowd, act[2]), (arrow_end, act[2]),
                     arrowprops=dict(arrowstyle='<-', color='r'),
                     annotation_clip=False)
    # True actions
    a[0, 2].plot(Conv * timeseries,
                 TT.action(results[0])[0] * np.ones(len(timeseries)),
                 'k',
                 label='True action')
    a[0, 2].plot(Conv * timeseries,
                 TT.action(results[0])[1] * np.ones(len(timeseries)), 'k')
    a[0, 2].plot(Conv * timeseries,
                 TT.action(results[0])[2] * np.ones(len(timeseries)), 'k')
    a[0, 2].set_xlabel(r'$t/{\rm Gyr}$')
    a[0, 2].set_ylabel(r'$J/{\rm kpc\,km\,s}^{-1}$')
    leg = a[0, 2].legend(loc='upper center',
                         bbox_to_anchor=(0.5, 1.2),
                         ncol=3,
                         numpoints=1)
    leg.draw_frame(False)

    # Toy angle coverage
    a[0, 1].plot(toy_aa.T[3] / (np.pi),
                 toy_aa.T[4] / (np.pi),
                 'k.',
                 markersize=0.4)
    a[0, 1].set_xlabel(r'$\theta_1/\pi$')
    a[0, 1].set_ylabel(r'$\theta_2/\pi$')
    a[1, 1].plot(toy_aa.T[3] / (np.pi),
                 toy_aa.T[5] / (np.pi),
                 'k.',
                 markersize=0.4)
    a[1, 1].set_xlabel(r'$\theta_1/\pi$')
    a[1, 1].set_ylabel(r'$\theta_3/\pi$')

    plt.savefig(file_output, bbox_inches='tight')
    return act
Пример #4
0
def plot_Sn_timesamples(PSP):
    """ Plots Fig. 5 from Sanders & Binney (2014) """
    TT = pot.stackel_triax()
    f, a = plt.subplots(2, 1, figsize=[3.32, 3.6])
    plt.subplots_adjust(hspace=0., top=0.8)

    LowestPeriod = 2. * np.pi / 38.86564386
    Times = np.array([2., 4., 8., 12.])
    Sr = np.arange(2, 14, 2)

    # Loop over length of integration window
    for i, P, C in zip(Times, ['.', 's', 'D', '^'], ['k', 'r', 'b', 'g']):
        diffact = np.zeros((len(Sr), 3))
        difffreq = np.zeros((len(Sr), 3))
        MAXGAPS = np.array([])
        # Loop over N_max
        for k, j in enumerate(Sr):
            NT = choose_NT(j)
            timeseries = np.linspace(0., i * LowestPeriod, NT)
            results = odeint(pot.orbit_derivs2,
                             PSP,
                             timeseries,
                             args=(TT, ),
                             rtol=1e-13,
                             atol=1e-13)
            act, ang, n_vec, toy_aa, pars = find_actions(results,
                                                         timeseries,
                                                         N_matrix=j,
                                                         ifprint=False,
                                                         use_box=True)
            # Check all modes
            checks, maxgap = ced(n_vec, ua(toy_aa.T[3:].T, np.ones(3)))
            if len(maxgap) > 0:
                maxgap = np.max(maxgap)
            else:
                maxgap = 0
            diffact[k] = act[:3] / TT.action(results[0])
            print i, j, print_max_average(
                n_vec, toy_aa.T[3:].T,
                act[3:]), str(ang[3:6] - TT.freq(results[0])).replace(
                    '[', '').replace(']', ''), str(
                        np.abs(act[:3] - TT.action(results[0]))).replace(
                            '[', '').replace(']', ''), len(checks), maxgap
            MAXGAPS = np.append(MAXGAPS, maxgap)
            difffreq[k] = ang[3:6] / TT.freq(results[0])
        size = 15
        if (P == '.'):
            size = 30
        LW = np.array(map(lambda i: 0.5 + i * 0.5, MAXGAPS))
        a[0].scatter(Sr,
                     np.log10(np.abs(diffact.T[2] - 1)),
                     marker=P,
                     s=size,
                     color=C,
                     facecolors="none",
                     lw=LW,
                     label=r'$T =\,$' + str(i) + r'$\,T_F$')
        a[1].scatter(Sr,
                     np.log10(np.abs(difffreq.T[2] - 1)),
                     marker=P,
                     s=size,
                     color=C,
                     facecolors="none",
                     lw=LW)
    a[1].get_yticklabels()[-1].set_visible(False)
    a[0].set_xticklabels([])
    a[0].set_xlim(1, 13)
    a[0].set_ylabel(r"$\log_{10}|J_3^\prime/J_{3, \rm true}-1|$")
    leg = a[0].legend(loc='upper center',
                      bbox_to_anchor=(0.5, 1.4),
                      ncol=2,
                      scatterpoints=1)
    leg.draw_frame(False)
    a[1].set_xlim(1, 13)
    a[1].set_xlabel(r'$N_{\rm max}$')
    a[1].set_ylabel(r"$\log_{10}|\Omega_3^\prime/\Omega_{3,\rm true}-1|$")
    plt.savefig('Sn_T_box.pdf', bbox_inches='tight')