def test_isotropic_hernquist_unittransfer(): from galpy.util import conversion ro, vo= 9., 210. pot= potential.HernquistPotential(amp=2.,a=1.3,ro=ro,vo=vo) dfh= isotropicHernquistdf(pot=pot) phys= conversion.get_physical(dfh,include_set=True) assert phys['roSet'], "sphericaldf's ro not set when that of the underlying potential is set" assert phys['voSet'], "sphericaldf's vo not set when that of the underlying potential is set" assert numpy.fabs(phys['ro']-ro) < 1e-8, "Potential's unit system not correctly transfered to sphericaldf's" assert numpy.fabs(phys['vo']-vo) < 1e-8, "Potential's unit system not correctly transfered to sphericaldf's" # Following should not be on pot= potential.HernquistPotential(amp=2.,a=1.3) dfh= isotropicHernquistdf(pot=pot) phys= conversion.get_physical(dfh,include_set=True) assert not phys['roSet'], "sphericaldf's ro set when that of the underlying potential is not set" assert not phys['voSet'], "sphericaldf's vo set when that of the underlying potential is not set" return None
def test_isotropic_hernquist_unitsofsamples(): from galpy.util import conversion ro, vo= 9., 210. pot= potential.HernquistPotential(amp=2.,a=1.3,ro=ro,vo=vo) dfh= isotropicHernquistdf(pot=pot) samp= dfh.sample(n=100) assert conversion.get_physical(samp,include_set=True)['roSet'], 'Orbit samples from spherical DF with units on do not have units on' assert conversion.get_physical(samp,include_set=True)['voSet'], 'Orbit samples from spherical DF with units on do not have units on' assert numpy.fabs(conversion.get_physical(samp,include_set=True)['ro']-ro) < 1e-8, 'Orbit samples from spherical DF with units on do not have correct ro' assert numpy.fabs(conversion.get_physical(samp,include_set=True)['vo']-vo) < 1e-8, 'Orbit samples from spherical DF with units on do not have correct vo' # Also test a case where they should be off pot= potential.HernquistPotential(amp=2.,a=1.3) dfh= isotropicHernquistdf(pot=pot) samp= dfh.sample(n=100) assert not conversion.get_physical(samp,include_set=True)['roSet'], 'Orbit samples from spherical DF with units off do not have units off' assert not conversion.get_physical(samp,include_set=True)['voSet'], 'Orbit samples from spherical DF with units off do not have units off' return None
def test_get_physical(): #Test that the get_physical function returns the right scaling parameters from galpy.util.conversion import get_physical # Potential and variations thereof from galpy.potential import MWPotential2014, DehnenBarPotential dp = DehnenBarPotential assert numpy.fabs( get_physical(MWPotential2014[0]).get('ro') - 8. ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for a Potential' assert numpy.fabs( get_physical(MWPotential2014[0]).get('vo') - 220. ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for a Potential' ro, vo = 9., 230. dp = DehnenBarPotential(ro=ro, vo=vo) assert numpy.fabs( get_physical(dp).get('ro') - ro ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for a Potential' assert numpy.fabs( get_physical(dp).get('vo') - vo ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for a Potential' assert numpy.fabs( get_physical(MWPotential2014).get('ro') - 8. ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for a Potential' assert numpy.fabs( get_physical(MWPotential2014).get('vo') - 220. ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for a Potential' assert numpy.fabs( get_physical(MWPotential2014 + dp).get('ro') - 8. ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for a Potential' assert numpy.fabs( get_physical(MWPotential2014 + dp).get('vo') - 220. ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for a Potential' assert numpy.fabs( get_physical(MWPotential2014 + dp).get('ro') - 8. ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for a Potential' assert numpy.fabs( get_physical(MWPotential2014 + dp).get('vo') - 220. ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for a Potential' # Orbits from galpy.orbit import Orbit ro, vo = 10., 210. o = Orbit(ro=ro, vo=vo) assert numpy.fabs( get_physical(o).get('ro') - ro ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for an Orbit' assert numpy.fabs( get_physical(o).get('vo') - vo ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for an Orbit' # even though one shouldn't do this, let's test a list assert numpy.fabs( get_physical([o, o]).get('ro') - ro ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for an Orbit' assert numpy.fabs( get_physical([o, o]).get('vo') - vo ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for an Orbit' # actionAngle from galpy.actionAngle import actionAngleStaeckel aAS = actionAngleStaeckel(pot=MWPotential2014, delta=0.45) assert numpy.fabs( get_physical(aAS).get('ro') - 8. ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for an actionAngle instance' assert numpy.fabs( get_physical(aAS).get('vo') - 220. ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for an actionAngle instance' # This doesn't make much sense, but let's test... ro, vo = 19., 130. dp = DehnenBarPotential(ro=ro, vo=vo) aAS = actionAngleStaeckel(pot=dp, delta=0.45, ro=ro, vo=vo) assert numpy.fabs( get_physical(aAS).get('ro') - ro ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for an actionAngle instance' assert numpy.fabs( get_physical(aAS).get('vo') - vo ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for an actionAngle instance' # DF from galpy.df import quasiisothermaldf aAS = actionAngleStaeckel(pot=MWPotential2014, delta=0.45) qdf = quasiisothermaldf(1. / 3., 0.2, 0.1, 1., 1., aA=aAS, pot=MWPotential2014) assert numpy.fabs( get_physical(qdf).get('ro') - 8. ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for a DF instance' assert numpy.fabs( get_physical(qdf).get('vo') - 220. ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for a DF instance' # non-standard ro,vo from galpy.potential import MiyamotoNagaiPotential ro, vo = 4., 330. mp = MiyamotoNagaiPotential(a=0.5, b=0.1, ro=ro, vo=vo) aAS = actionAngleStaeckel(pot=mp, delta=0.45, ro=ro, vo=vo) qdf = quasiisothermaldf(1. / 3., 0.2, 0.1, 1., 1., aA=aAS, pot=mp, ro=ro, vo=vo) assert numpy.fabs( get_physical(qdf).get('ro') - ro ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for a DF instance' assert numpy.fabs( get_physical(qdf).get('vo') - vo ) < 1e-10, 'get_physical does not return the correct unit conversion parameter for a DF instance' return None