def test_overview(): from galpy.potential import NFWPotential np= NFWPotential(normalize=1.) from galpy.orbit import Orbit o= Orbit(vxvv=[1.,0.1,1.1,0.1,0.02,0.]) from galpy.actionAngle import actionAngleSpherical aA= actionAngleSpherical(pot=np) js= aA(o) assert numpy.fabs((js[0]-0.00980542)/js[0]) < 10.**-3., 'Action calculation in the overview section has changed' assert numpy.fabs((js[1]-1.1)/js[0]) < 10.**-3., 'Action calculation in the overview section has changed' assert numpy.fabs((js[2]-0.00553155)/js[0]) < 10.**-3., 'Action calculation in the overview section has changed' from galpy.df import quasiisothermaldf qdf= quasiisothermaldf(1./3.,0.2,0.1,1.,1., pot=np,aA=aA) assert numpy.fabs((qdf(o)-61.57476085)/61.57476085) < 10.**-3., 'qdf calculation in the overview section has changed' return None
def plot_aaspher_conservation(plotfilename1,plotfilename2): #Setup orbit E, Lz= -1.25, 0.6 o= Orbit([0.8,0.3,Lz/0.8,0.,numpy.sqrt(2.*(E-evalPot(0.8,0.,MWPotential2014)-(Lz/0.8)**2./2.-0.3**2./2.)),0.]) #Integrate the orbit to estimate an equivalent b nt= 1001 ts= numpy.linspace(0.,20.,nt) o.integrate(ts,MWPotential2014,method='symplec4_c') b= estimateBIsochrone(o.R(ts),o.z(ts),pot=MWPotential2014) print b b= 0.3 #Now integrate the orbit in the isochronePotential ip= IsochronePotential(normalize=1.,b=b) aAI= actionAngleIsochrone(ip=ip) orbt= 2.*numpy.pi/aAI.actionsFreqs(o)[4] norb= 200. nt= 20001 ts= numpy.linspace(0.,norb*orbt,nt) o.integrate(ts,ip,method='symplec4_c') #Calculate actions, frequencies, and angles jfa= aAI.actionsFreqsAngles(o.R(ts),o.vR(ts),o.vT(ts), o.z(ts),o.vz(ts),o.phi(ts)) dJs= numpy.fabs((jfa[0]-numpy.mean(jfa[0]))/numpy.mean(jfa[0])) dOrs= numpy.fabs((jfa[3]-numpy.mean(jfa[3]))/numpy.mean(jfa[3])) dOzs= numpy.fabs((jfa[5]-numpy.mean(jfa[5]))/numpy.mean(jfa[5])) print "frequencies", numpy.mean(dOrs), numpy.mean(dOzs) ar= dePeriod(numpy.reshape(jfa[6],(1,len(ts)))).flatten() az= dePeriod(numpy.reshape(jfa[8],(1,len(ts)))).flatten() danglers= numpy.fabs(ar-numpy.mean(jfa[3])*ts-jfa[6][0])/2./numpy.pi danglezs= numpy.fabs(az-numpy.mean(jfa[5])*ts-jfa[8][0])/2./numpy.pi #Break up breakt= 50. pts= parse_break(ts,ts < breakt) pdJs= parse_break(dJs,ts < breakt) pdanglers= parse_break(danglers,ts < breakt) pdanglezs= parse_break(danglezs,ts < breakt) #dAngles bovy_plot.bovy_print() pyplot.subplot(2,1,1) bovy_plot.bovy_plot(pts/orbt, pdJs, color='k',loglog=True,gcf=True, xrange=[0.5,norb], yrange=[10.**-12.,1.]) bovy_plot.bovy_text(r'$\texttt{actionAngleIsochrone}$', top_left=True,size=14.) ax= pyplot.gca() ax.yaxis.set_ticks([10.**-12.,10.**-8.,10.**-4.,1.]) nullfmt = NullFormatter() # no labels ax.xaxis.set_major_formatter(nullfmt) #Same for actionAngleSpherical aAS= actionAngleSpherical(pot=ip) tts= ts[::1] jfa= aAS.actionsFreqsAngles(o.R(tts),o.vR(tts),o.vT(tts), o.z(tts),o.vz(tts),o.phi(tts), fixed_quad=True) #dJr dJs= numpy.fabs((jfa[0]-numpy.mean(jfa[0]))/numpy.mean(jfa[0])) dOrs= numpy.fabs((jfa[3]-numpy.mean(jfa[3]))/numpy.mean(jfa[3])) dOzs= numpy.fabs((jfa[5]-numpy.mean(jfa[5]))/numpy.mean(jfa[5])) print "frequencies", numpy.mean(dOrs), numpy.mean(dOzs) #dAngles ar= dePeriod(numpy.reshape(jfa[6],(1,len(tts)))).flatten() az= dePeriod(numpy.reshape(jfa[8],(1,len(tts)))).flatten() danglers= numpy.fabs(ar-numpy.mean(jfa[3])*tts-jfa[6][0])/2./numpy.pi danglezs= numpy.fabs(az-numpy.mean(jfa[5])*tts-jfa[8][0])/2./numpy.pi print numpy.mean(danglers) print numpy.mean(danglezs) ptts= parse_break(tts,tts < breakt) pdJs= parse_break(dJs,tts < breakt) pyplot.subplot(2,1,2) bovy_plot.bovy_plot(ptts/orbt, pdJs, color='k',loglog=True,gcf=True, xrange=[0.5,norb], yrange=[10.**-12.,1.], xlabel=r'$\mathrm{Number\ of\ orbital\ periods}$') bovy_plot.bovy_text(r'$\texttt{actionAngleSpherical}$', top_left=True,size=14.) bovy_plot.bovy_text(0.175,10.**2.,r'$\left|\Delta J_R / J_R\right|$', fontsize=16., rotation='vertical') ax= pyplot.gca() ax.xaxis.set_major_formatter(ticker.FormatStrFormatter(r'$%0.f$')) ax.yaxis.set_ticks([10.**-12.,10.**-8.,10.**-4.,1.]) bovy_plot.bovy_end_print(plotfilename1) #Now plot the deviations in the angles bovy_plot.bovy_print() pyplot.subplot(2,1,1) liner= bovy_plot.bovy_plot(pts/orbt, pdanglers, color='k',ls='-',loglog=True,gcf=True, xrange=[0.5,norb], yrange=[10.**-12.,1.]) linez= bovy_plot.bovy_plot(pts/orbt, pdanglezs, color='k',ls='--',overplot=True) legend1= pyplot.legend((liner[0],linez[0]), (r'$\theta_R$', r'$\theta_z$'), loc='lower right',#bbox_to_anchor=(.91,.375), numpoints=2, prop={'size':14}, frameon=False) bovy_plot.bovy_text(r'$\texttt{actionAngleIsochrone}$', top_left=True,size=14.) ax= pyplot.gca() ax.yaxis.set_ticks([10.**-12.,10.**-8.,10.**-4.,1.]) nullfmt = NullFormatter() # no labels ax.xaxis.set_major_formatter(nullfmt) #Same for Spherical pdanglers= parse_break(danglers,tts < breakt) pdanglezs= parse_break(danglezs,tts < breakt) pyplot.subplot(2,1,2) bovy_plot.bovy_plot(ptts/orbt, pdanglers, color='k',ls='-',loglog=True,gcf=True, xrange=[0.5,norb], yrange=[10.**-12.,1.], xlabel=r'$\mathrm{Number\ of\ orbital\ periods}$') bovy_plot.bovy_plot(ptts/orbt, pdanglezs, color='k',ls='--',overplot=True) bovy_plot.bovy_text(r'$\texttt{actionAngleSpherical}$', top_left=True,size=14.) bovy_plot.bovy_text(0.175,10.**4.,r'$\left|\Delta \theta_{R,z} / 2\,\pi\right|$', fontsize=16., rotation='vertical') ax= pyplot.gca() ax.xaxis.set_major_formatter(ticker.FormatStrFormatter(r'$%0.f$')) ax.yaxis.set_ticks([10.**-12.,10.**-8.,10.**-4.,1.]) bovy_plot.bovy_end_print(plotfilename2) return None
def test_physical_compatible_combos(): # Test that physical_compatible acts as expected for combinations of # different types of objects from galpy.util.bovy_conversion import physical_compatible from galpy.potential import HernquistPotential from galpy.orbit import Orbit from galpy.actionAngle import actionAngleSpherical from galpy.df import quasiisothermaldf # Set up different objects for possible cases # Potentials pot_default_phys = HernquistPotential(amp=0.55, a=2., ro=8., vo=220.) pot_nonstandardro = HernquistPotential(amp=0.55, a=2., ro=9., vo=220.) pot_nonstandardvo = HernquistPotential(amp=0.55, a=2., ro=8., vo=230.) pot_nonstandardrovo = HernquistPotential(amp=0.55, a=2., ro=9., vo=230.) pot_nophys = HernquistPotential(amp=0.55) pot_default_noro = HernquistPotential(amp=0.55, vo=220.) pot_default_novo = HernquistPotential(amp=0.55, ro=8.) pot_nonstandardro_novo = HernquistPotential(amp=0.55, ro=9.) pot_nonstandardvo_noro = HernquistPotential(amp=0.55, vo=230.) pot_nonstandardvo_noro = HernquistPotential(amp=0.55, vo=230.) # Orbits orb_default_phys = Orbit([1., 0.1, 1.1, 0.1, 0.3, -0.9], ro=8., vo=220.) orb_nonstandardro = Orbit([1., 0.1, 1.1, 0.1, 0.3, -0.9], ro=9., vo=220.) orb_nonstandardvo = Orbit([1., 0.1, 1.1, 0.1, 0.3, -0.9], ro=8., vo=230.) orb_nonstandardrovo = Orbit([1., 0.1, 1.1, 0.1, 0.3, -0.9], ro=9., vo=230.) orb_nophys = Orbit([1., 0.1, 1.1, 0.1, 0.3, -0.9]) orb_default_noro = Orbit([1., 0.1, 1.1, 0.1, 0.3, -0.9], vo=220.) orb_nonstandardvo_noro = Orbit([1., 0.1, 1.1, 0.1, 0.3, -0.9], vo=230.) # aAs aA_default_phys = actionAngleSpherical(pot=pot_default_phys, ro=8., vo=220.) aA_nonstandardro = actionAngleSpherical(pot=pot_nonstandardro, ro=9., vo=220.) aA_nonstandardvo = actionAngleSpherical(pot=pot_nonstandardvo, ro=8., vo=230.) aA_nonstandardrovo = actionAngleSpherical(pot=pot_nonstandardrovo, ro=9., vo=230.) aA_nophys = actionAngleSpherical(pot=pot_nophys) aA_default_novo = actionAngleSpherical(pot=pot_default_novo, ro=8.) aA_nonstandardvo_noro = actionAngleSpherical(pot=pot_nonstandardvo_noro, vo=230.) # DFs qdf_default_phys = quasiisothermaldf(1. / 3., 0.2, 0.1, 1., 1., pot=pot_default_phys, aA=aA_default_phys, ro=8., vo=220.) qdf_nonstandardro = quasiisothermaldf(1. / 3., 0.2, 0.1, 1., 1., pot=pot_nonstandardro, aA=aA_nonstandardro, ro=9., vo=220.) qdf_nonstandardvo = quasiisothermaldf(1. / 3., 0.2, 0.1, 1., 1., pot=pot_nonstandardvo, aA=aA_nonstandardvo, ro=8., vo=230.) qdf_nonstandardrovo = quasiisothermaldf(1. / 3., 0.2, 0.1, 1., 1., pot=pot_nonstandardrovo, aA=aA_nonstandardrovo, ro=9., vo=230.) qdf_nophys = quasiisothermaldf(1. / 3., 0.2, 0.1, 1., 1., pot=pot_nophys, aA=aA_nophys) # Now do some tests! assert physical_compatible(pot_default_phys,orb_default_phys), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(pot_default_phys,aA_default_phys), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(pot_default_phys,qdf_default_phys), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(pot_nonstandardro,orb_nonstandardro), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(pot_nonstandardro,aA_nonstandardro), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(pot_nonstandardro,qdf_nonstandardro), \ "pot_default_phys does not behave as expected for combinations of different objects" assert not physical_compatible(pot_default_phys,orb_nonstandardro), \ "pot_default_phys does not behave as expected for combinations of different objects" assert not physical_compatible(pot_default_phys,aA_nonstandardro), \ "pot_default_phys does not behave as expected for combinations of different objects" assert not physical_compatible(pot_default_phys,qdf_nonstandardro), \ "pot_default_phys does not behave as expected for combinations of different objects" assert not physical_compatible(pot_default_phys,orb_nonstandardvo), \ "pot_default_phys does not behave as expected for combinations of different objects" assert not physical_compatible(pot_default_phys,aA_nonstandardvo), \ "pot_default_phys does not behave as expected for combinations of different objects" assert not physical_compatible(pot_default_phys,qdf_nonstandardvo), \ "pot_default_phys does not behave as expected for combinations of different objects" assert not physical_compatible(pot_default_phys,orb_nonstandardrovo), \ "pot_default_phys does not behave as expected for combinations of different objects" assert not physical_compatible(pot_default_phys,aA_nonstandardrovo), \ "pot_default_phys does not behave as expected for combinations of different objects" assert not physical_compatible(pot_default_phys,qdf_nonstandardrovo), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible([pot_nophys,pot_nophys],orb_nonstandardrovo), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(pot_nophys,aA_nonstandardrovo), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(pot_nophys,qdf_nonstandardrovo), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(pot_nophys,orb_default_phys), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(pot_nophys,aA_default_phys), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(pot_nophys,qdf_default_phys), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(pot_nophys,orb_nophys), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(pot_nophys,orb_nophys), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(pot_nophys,qdf_nophys), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(pot_default_noro,qdf_nonstandardro), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(pot_nonstandardro_novo,orb_default_noro), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(aA_nonstandardvo_noro,orb_nonstandardvo_noro), \ "pot_default_phys does not behave as expected for combinations of different objects" assert not physical_compatible(aA_default_novo,qdf_nonstandardrovo), \ "pot_default_phys does not behave as expected for combinations of different objects" # Also test agained None! assert physical_compatible(None,pot_default_phys), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(None,orb_default_phys), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(None,aA_default_phys), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(None,qdf_default_phys), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(pot_default_phys,None), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(orb_default_phys,None), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(aA_default_phys,None), \ "pot_default_phys does not behave as expected for combinations of different objects" assert physical_compatible(qdf_default_phys,None), \ "pot_default_phys does not behave as expected for combinations of different objects" return None