コード例 #1
0
ファイル: helpers.py プロジェクト: abonaca/gary
def sanders_act_ang_freq(t, w, N_max=6):
    w2 = w.copy()
    loop = classify_orbit(w)

    if np.any(loop):
        w2[:, 3:] = (w2[:, 3:] * u.kpc / u.Myr).to(u.km / u.s).value
        (act, ang, n_vec, toy_aa,
         pars), loop2 = genfunc_3d.find_actions(w2,
                                                t / 1000.,
                                                N_matrix=N_max,
                                                ifloop=True)
    else:
        (act, ang, n_vec, toy_aa,
         pars), loop2 = genfunc_3d.find_actions(w2,
                                                t,
                                                N_matrix=N_max,
                                                ifloop=True)

    actions = act[:3]
    angles = ang[:3]
    freqs = ang[3:6]

    if np.any(loop):
        toy_potential = IsochronePotential(m=pars[0] * 1E11,
                                           b=pars[1],
                                           units=galactic)
        actions = (actions * u.kpc * u.km / u.s).to(u.kpc**2 / u.Myr).value
        freqs = (freqs / u.Gyr).to(1 / u.Myr).value
    else:
        toy_potential = HarmonicOscillatorPotential(omega=np.array(pars))

    return actions, angles, freqs, toy_potential
コード例 #2
0
ファイル: binney_tremaine.py プロジェクト: jobovy/tact
def print_freqs():
	log = logarithmic()
	timeseries = np.linspace(0.,500.,2048)
	ntheta,nphi = 30,30
	for i in np.arange(4.,ntheta+1)/(ntheta+1):
		for j in .5*np.pi*np.arange(15.,nphi+1)/(nphi+1):
			# if(i>0.9 and j>np.pi*0.45):
			# if(j>np.pi/4.):
			# if(i>0.59 and j>np.pi/2.*0.9):
			print np.arccos(i),j
			st,ct = np.sin(np.arccos(i)),i
			sp,cp = np.sin(j),np.cos(j)
			combo = cp*cp*st*st+sp*sp*st*st/log.qy2+ct*ct/log.qz2
			r = np.sqrt((np.exp(1.)-0.1)/combo)
			initial = np.array([r*cp*st,r*sp*st,r*ct,0.0001,0.0001,0.0001])
			# initial = np.array([0.111937987197,0.0104758765442,1.12993449025,0.0001,0.0001,0.0001])
			results = odeint(pot.orbit_derivs2,initial,timeseries,args=(log,),rtol=1e-5,atol=1e-5)
			# print(log.H(initial),log.H(results[-1]))
			plots(timeseries,results)
			# freq = find_freqs(timeseries,results)
			L = find_actions(results, timeseries, N_matrix = 4, ifloop=True,ifprint = False)
			# if(L==None):
				# break
			(act,ang,n_vec,toy_aa,para),loop = L
			E = eval_mean_error_functions(act,ang,n_vec,toy_aa,timeseries,withplot=False)/np.std(timeseries)
			# ctas(ang,n_vec,toy_aa,timeseries)
			# print freq[0],freq[1],freq[2]
			print ang[3],ang[4],ang[5],initial[0],initial[1],initial[2],act[0],act[1],act[2] #,E[0],E[1],E[2],E[3],E[4],E[5] #,freq[0],freq[1],freq[2]
			exit()
コード例 #3
0
ファイル: helpers.py プロジェクト: abonaca/gary
def sanders_act_ang_freq(t, w, N_max=6):
    w2 = w.copy()
    loop = classify_orbit(w)

    if np.any(loop):
        w2[:,3:] = (w2[:,3:]*u.kpc/u.Myr).to(u.km/u.s).value
        (act,ang,n_vec,toy_aa,pars),loop2 = genfunc_3d.find_actions(w2, t/1000.,
                                                                    N_matrix=N_max, ifloop=True)
    else:
        (act,ang,n_vec,toy_aa,pars),loop2 = genfunc_3d.find_actions(w2, t,
                                                                    N_matrix=N_max, ifloop=True)

    actions = act[:3]
    angles = ang[:3]
    freqs = ang[3:6]

    if np.any(loop):
        toy_potential = IsochronePotential(m=pars[0]*1E11, b=pars[1], units=galactic)
        actions = (actions*u.kpc*u.km/u.s).to(u.kpc**2/u.Myr).value
        freqs = (freqs/u.Gyr).to(1/u.Myr).value
    else:
        toy_potential = HarmonicOscillatorPotential(omega=np.array(pars))

    return actions,angles,freqs,toy_potential
コード例 #4
0
def print_freqs():
    log = logarithmic()
    timeseries = np.linspace(0., 500., 2048)
    ntheta, nphi = 30, 30
    for i in np.arange(4., ntheta + 1) / (ntheta + 1):
        for j in .5 * np.pi * np.arange(15., nphi + 1) / (nphi + 1):
            # if(i>0.9 and j>np.pi*0.45):
            # if(j>np.pi/4.):
            # if(i>0.59 and j>np.pi/2.*0.9):
            print np.arccos(i), j
            st, ct = np.sin(np.arccos(i)), i
            sp, cp = np.sin(j), np.cos(j)
            combo = cp * cp * st * st + sp * sp * st * st / log.qy2 + ct * ct / log.qz2
            r = np.sqrt((np.exp(1.) - 0.1) / combo)
            initial = np.array(
                [r * cp * st, r * sp * st, r * ct, 0.0001, 0.0001, 0.0001])
            # initial = np.array([0.111937987197,0.0104758765442,1.12993449025,0.0001,0.0001,0.0001])
            results = odeint(pot.orbit_derivs2,
                             initial,
                             timeseries,
                             args=(log, ),
                             rtol=1e-5,
                             atol=1e-5)
            # print(log.H(initial),log.H(results[-1]))
            plots(timeseries, results)
            # freq = find_freqs(timeseries,results)
            L = find_actions(results,
                             timeseries,
                             N_matrix=4,
                             ifloop=True,
                             ifprint=False)
            # if(L==None):
            # break
            (act, ang, n_vec, toy_aa, para), loop = L
            E = eval_mean_error_functions(
                act, ang, n_vec, toy_aa, timeseries,
                withplot=False) / np.std(timeseries)
            # ctas(ang,n_vec,toy_aa,timeseries)
            # print freq[0],freq[1],freq[2]
            print ang[3], ang[4], ang[5], initial[0], initial[1], initial[
                2], act[0], act[1], act[
                    2]  #,E[0],E[1],E[2],E[3],E[4],E[5] #,freq[0],freq[1],freq[2]
            exit()
コード例 #5
0
ファイル: lm_check.py プロジェクト: jobovy/tact
a[1,0].set_ylabel(r'$z/{\rm kpc}$')
a[0,1].set_xlabel(r'$t/{\rm Gyr}$')
a[0,1].set_ylabel(r"$(J_1'-\langle J_1'\rangle )/{\rm kpc\,km\,s}^{-1}$")
a[1,1].set_xlabel(r'$t/{\rm Gyr}$')
a[1,1].set_ylabel(r"$(\Omega_1'-\langle\Omega_1'\rangle )/1000\,{\rm Gyr}^{-1}$")
a[0,2].set_xlabel(r'$\theta_1/\pi$')
a[0,2].set_ylabel(r'$\theta_2/\pi$')
a[1,2].set_xlabel(r'$\theta_1/\pi$')
a[1,2].set_ylabel(r'$\theta_3/\pi$')

times = np.array([])
angles = np.array([])
toyangles = np.array([])
actions = np.array([])
freqs= np.array([])
(act,ang,n_vec,toy_aa,para),loop = find_actions(results, timeseries, N_matrix = 6, ifloop=True,ifprint = False)
size = len(ang[6:])/3
AA = [np.array([np.sum(ang[6+i*size:6+(i+1)*size]*np.sin(np.sum(n_vec*K,axis=1))) for K in toy_aa.T[3:].T]) for i in range(3)]
# a[0,2].plot((toy_aa.T[3]+2.*AA[0]) % (2.*np.pi) / np.pi,(toy_aa.T[4]+2.*AA[1]) % (2.*np.pi)/ np.pi,'.',markersize=3)
# a[1,2].plot((toy_aa.T[3]+2.*AA[0]) % (2.*np.pi) / np.pi,(toy_aa.T[5]+2.*AA[2]) % (2.*np.pi) / np.pi,'.',markersize=3)
# plt.savefig('LM_test.pdf',bbox_inches='tight')

# exit(0)
toyangles = toy_aa.T[3:6].T/np.pi
MaxRoll = 0.5*Roll
from solver import check_each_direction as ced
from solver import unroll_angles as ua

for i in np.arange(0,MaxRoll,Roll/100.):
	(act,ang,n_vec,toy_aa,para),loop = find_actions(results[i:i+Roll], timeseries[:Roll], N_matrix = 6, ifloop=True,ifprint = False)
	checks,maxgap = ced(n_vec,ua(toy_aa.T[3:].T,np.ones(3)))
コード例 #6
0
ファイル: lm_check.py プロジェクト: jobovy/tact
a[1, 1].set_xlabel(r'$t/{\rm Gyr}$')
a[1,
  1].set_ylabel(r"$(\Omega_1'-\langle\Omega_1'\rangle )/1000\,{\rm Gyr}^{-1}$")
a[0, 2].set_xlabel(r'$\theta_1/\pi$')
a[0, 2].set_ylabel(r'$\theta_2/\pi$')
a[1, 2].set_xlabel(r'$\theta_1/\pi$')
a[1, 2].set_ylabel(r'$\theta_3/\pi$')

times = np.array([])
angles = np.array([])
toyangles = np.array([])
actions = np.array([])
freqs = np.array([])
(act, ang, n_vec, toy_aa, para), loop = find_actions(results,
                                                     timeseries,
                                                     N_matrix=6,
                                                     ifloop=True,
                                                     ifprint=False)
size = len(ang[6:]) / 3
AA = [
    np.array([
        np.sum(ang[6 + i * size:6 + (i + 1) * size] *
               np.sin(np.sum(n_vec * K, axis=1))) for K in toy_aa.T[3:].T
    ]) for i in range(3)
]
# a[0,2].plot((toy_aa.T[3]+2.*AA[0]) % (2.*np.pi) / np.pi,(toy_aa.T[4]+2.*AA[1]) % (2.*np.pi)/ np.pi,'.',markersize=3)
# a[1,2].plot((toy_aa.T[3]+2.*AA[0]) % (2.*np.pi) / np.pi,(toy_aa.T[5]+2.*AA[2]) % (2.*np.pi) / np.pi,'.',markersize=3)
# plt.savefig('LM_test.pdf',bbox_inches='tight')

# exit(0)
toyangles = toy_aa.T[3:6].T / np.pi
コード例 #7
0
ファイル: sag.py プロジェクト: jobovy/tact
def rotate_coords(X):
	xy = LM.invcoordrot(X[0],X[1])
	vxvy = LM.invcoordrot(X[3],X[4])
	return np.array([xy[0],xy[1],X[2],vxvy[0],vxvy[1],X[5]])


def unrotate_coords(X):
	xy = LM.coordrot(X[0],X[1])
	vxvy = LM.coordrot(X[3],X[4])
	return np.array([xy[0],xy[1],X[2],vxvy[0],vxvy[1],X[5]])


for i in datae:
	results = np.array([rotate_coords(p) for p in odeint(pot.orbit_derivs2,i,timeseries,args=(LM,),rtol=1e-10,atol=1e-10)])
	L = find_actions(results,timeseries,N_matrix=6,ifprint=False)
	(act,ang,n_vec,toy_aa,para) = L
	checks,maxgap = ced(n_vec,ua(toy_aa.T[3:].T,np.ones(3)))
	TMAX = 1000
	counter = 0
	while(len(checks)>0 and counter<10):
		# print(checks)
		if(np.any(maxgap<0.)):
			TMAX=TMAX*2.
			results = np.array([rotate_coords(p) for p in odeint(pot.orbit_derivs2,initial,np.linspace(0.,10.,TMAX),args=(LM,),rtol=1e-10,atol=1e-10)])
			L = find_actions(results, np.linspace(0.,10.,TMAX), N_matrix = 6, ifprint = False)
		else:
			results2 = np.array([rotate_coords(p) for p in odeint(pot.orbit_derivs2,unrotate_coords(results[-1]),timeseries,args=(LM,),rtol=1e-10,atol=1e-10)])
			results = np.vstack((results,results2))
			L = find_actions(results, np.linspace(0.,len(results)/100.,len(results)), N_matrix = 6, ifprint = False)
		(act,ang,n_vec,toy_aa,para) = L
コード例 #8
0
        initial = np.array([xy[0], xy[1], zlittle, pxpy[0], pxpy[1], pz])
        results = np.array([
            rotate_coords(p) for p in odeint(pot.orbit_derivs2,
                                             initial,
                                             timeseries,
                                             args=(LM, ),
                                             rtol=1e-10,
                                             atol=1e-10)
        ])
        # results_long = np.array([rotate_coords(p) for p in odeint(pot.orbit_derivs2,initial,timeseries_long,args=(LM,),rtol=1e-5,atol=1e-5)])
        # loop = assess_angmom(results_long)
        # LL = np.any(loop>0)
        # BOX = not LL
        L = find_actions(results,
                         timeseries,
                         N_matrix=6,
                         ifloop=True,
                         ifprint=False)

        if (L == None):
            print LM.H(initial), i, px, pz, loop
            continue

        (act, ang, n_vec, toy_aa, para), loop = L
        # print(eval_mean_error_functions(act,ang,n_vec,toy_aa,timeseries,withplot=True))
        checks, maxgap = ced(n_vec, ua(toy_aa.T[3:].T, np.ones(3)))
        TMAX = 1000
        counter = 0
        while (len(checks) > 0 and counter < 10):
            # print(checks)
            if (np.any(maxgap < 0.)):