Skip to content

Commit

Permalink
Further tests of actionAngleInverse units handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jobovy committed Nov 17, 2017
1 parent dc792ce commit 88a8fac
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
22 changes: 22 additions & 0 deletions tests/test_actionAngle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,28 @@ def test_actionAngleIsochroneInverseTorus_orbit():
'Integrated orbit does not agree with torus orbit in phi'
return None

# Test physical output for actionAngleIsochroneInverse
def test_physical_actionAngleIsochroneInverse():
from galpy.potential import IsochronePotential
from galpy.actionAngle import actionAngleIsochroneInverse
from galpy.util import bovy_conversion
ro,vo= 7., 230.
ip= IsochronePotential(normalize=1.01,b=1.02)
aAII= actionAngleIsochroneInverse(ip=ip,ro=ro,vo=vo)
aAIInu= actionAngleIsochroneInverse(ip=ip)
correct_fac= [ro,vo,vo,ro,vo,1.]
for ii in range(6):
assert numpy.fabs(aAII(0.1,1.1,0.1,0.1,0.2,0.)[ii]-aAIInu(0.1,1.1,0.1,0.1,0.2,0.)[ii]*correct_fac[ii]) < 10.**-8., 'actionAngleInverse function __call__ does not return Quantity with the right value'
correct_fac= [ro,vo,vo,ro,vo,1.,
bovy_conversion.freq_in_Gyr(vo,ro),
bovy_conversion.freq_in_Gyr(vo,ro),
bovy_conversion.freq_in_Gyr(vo,ro)]
for ii in range(9):
assert numpy.fabs(aAII.xvFreqs(0.1,1.1,0.1,0.1,0.2,0.)[ii]-aAIInu.xvFreqs(0.1,1.1,0.1,0.1,0.2,0.)[ii]*correct_fac[ii]) < 10.**-8., 'actionAngleInverse function xvFreqs does not return Quantity with the right value'
for ii in range(3):
assert numpy.fabs(aAII.Freqs(0.1,1.1,0.1)[ii]-aAIInu.Freqs(0.1,1.1,0.1)[ii]*bovy_conversion.freq_in_Gyr(vo,ro)) < 10.**-8., 'actionAngleInverse function Freqs does not return Quantity with the right value'
return None

def check_actionAngleIsochroneInverse_wrtIsochrone(pot,aAI,aAII,obs,
tol,ntimes=1001):
times= numpy.linspace(0.,30.,ntimes)
Expand Down
30 changes: 27 additions & 3 deletions tests/test_quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2975,7 +2975,8 @@ def test_actionAngle_method_value():
for ii in range(6,9):
assert numpy.fabs(aA.actionsFreqsAngles(1.1,0.1,1.1,0.1,0.2,0.)[ii].to(units.rad).value-aAnu.actionsFreqsAngles(1.1,0.1,1.1,0.1,0.2,0.)[ii]) < 10.**-8., 'actionAngle function actionsFreqsAngles does not return Quantity with the right value'
# actionAngleIsochroneInverse
aA= actionAngleIsochroneInverse(b=0.8,ro=ro,vo=vo)
aA= actionAngleIsochroneInverse(b=0.8,
ro=ro*units.kpc,vo=vo*units.km/units.s)
aAnu= actionAngleIsochroneInverse(b=0.8)
correct_unit= [units.kpc,units.km/units.s,units.km/units.s,
units.kpc,units.km/units.s,units.rad]
Expand Down Expand Up @@ -3165,7 +3166,7 @@ def test_actionAngleIsochrone_setup_b_units():
assert numpy.fabs(aA.b-aAu.b) < 10.**-10., 'b with units in actionAngleIsochrone setup does not work as expected'
return None

def test_actionAngleIsochroneApprix_setup_b_units():
def test_actionAngleIsochroneApprox_setup_b_units():
from galpy.actionAngle import actionAngleIsochroneApprox
from galpy.potential import MWPotential
ro= 9.
Expand All @@ -3174,6 +3175,15 @@ def test_actionAngleIsochroneApprix_setup_b_units():
assert numpy.fabs(aA._aAI.b-aAu._aAI.b) < 10.**-10., 'b with units in actionAngleIsochroneApprox setup does not work as expected'
return None

def test_actionAngleIsochroneInverse_setup_b_units():
from galpy.actionAngle import actionAngleIsochroneInverse
from galpy.potential import MWPotential
ro= 9.
aA= actionAngleIsochroneInverse(pot=MWPotential,b=0.7*ro*units.kpc,ro=ro)
aAu= actionAngleIsochroneInverse(pot=MWPotential,b=0.7)
assert numpy.fabs(aA.b-aAu.b) < 10.**-10., 'b with units in actionAngleIsochroneInverse setup does not work as expected'
return None

def test_actionAngleIsochroneApprix_setup_tintJ_units():
from galpy.actionAngle import actionAngleIsochroneApprox
from galpy.potential import MWPotential
Expand Down Expand Up @@ -3423,7 +3433,21 @@ def test_actionAngle_input_wrongunits():
0.2*units.km/units.s,0.1*units.rad)
return None


def test_actionAngleInverse_input_wrongunits():
from galpy.actionAngle import actionAngleIsochroneInverse
from galpy.potential import IsochronePotential
ip= IsochronePotential(normalize=1.,b=0.7)
aAII= actionAngleIsochroneInverse(ip=ip,ro=8.,vo=220.)
with pytest.raises(units.UnitConversionError) as excinfo:
aAII(1.*units.Gyr,0.1*units.kpc*units.km/units.s,
1.1*units.kpc*units.km/units.s,0.1*units.rad,
0.2*units.rad,0.1*units.rad)
with pytest.raises(units.UnitConversionError) as excinfo:
aAII(1.*units.Gyr,0.1*units.kpc*units.km/units.s,
1.1*units.kpc*units.km/units.s,0.1*units.km,
0.2*units.rad,0.1*units.rad)
return None

def test_estimateDeltaStaeckel_method_returntype():
from galpy.potential import MiyamotoNagaiPotential
from galpy.actionAngle import estimateDeltaStaeckel
Expand Down

0 comments on commit 88a8fac

Please sign in to comment.