def test_snapshotKeplerPotential_zforce_naz(): # Set up a snapshot with just one unit mass at the origin s= pynbody.new(star=1) s['mass']= 1. s['eps']= 0. sp= potential.SnapshotRZPotential(s,num_threads=1) spaz= potential.SnapshotRZPotential(s,num_threads=1,nazimuths=12) assert numpy.fabs(sp.zforce(1.,0.)-spaz.zforce(1.,0.)) < 10.**-8., 'SnapshotRZPotential with single unit mass for naz=4 does not agree with naz=12' assert numpy.fabs(sp.zforce(0.5,0.)-spaz.zforce(0.5,0.)) < 10.**-8., 'SnapshotRZPotential with single unit mass for naz=4 does not agree with naz=12' assert numpy.fabs(sp.zforce(1.,0.5)-spaz.zforce(1.,0.5)) < 10.**-8., 'SnapshotRZPotential with single unit mass for naz=4 does not agree with naz=12' assert numpy.fabs(sp.zforce(1.,-0.5)-spaz.zforce(1.,-0.5)) < 10.**-8., 'SnapshotRZPotential with single unit mass for naz=4 does not agree with naz=12' return None
def test_snapshotrzpotential_nopynbody(): # Test that if we cannot load pynbody, we get an ImportError from galpy.potential_src import SnapshotRZPotential SnapshotRZPotential._PYNBODY_LOADED= False try: sp= potential.SnapshotRZPotential(1.) #1. doesn't matter except ImportError: pass else: raise AssertionError("SnapshotRZPotential w/o pynbody should have raised an error, but didn't") return None
def test_snapshotKeplerPotential_hash(): # Test that hashing the previous grid works # Set up a snapshot with just one unit mass at the origin s= pynbody.new(star=1) s['mass']= 1. s['eps']= 0. sp= potential.SnapshotRZPotential(s) kp= potential.KeplerPotential(amp=1.) #should be the same assert numpy.fabs(sp(1.,0.)-kp(1.,0.)) < 10.**-8., 'SnapshotRZPotential with single unit mass does not correspond to KeplerPotential' assert numpy.fabs(sp(1.,0.)-kp(1.,0.)) < 10.**-8., 'SnapshotRZPotential with single unit mass does not correspond to KeplerPotential' return None
def test_snapshotKeplerPotential_zforce_array(): # Test evaluating the snapshotPotential with array input # Set up a snapshot with just one unit mass at the origin s= pynbody.new(star=1) s['mass']= 1. s['eps']= 0. sp= potential.SnapshotRZPotential(s) kp= potential.KeplerPotential(amp=1.) #should be the same rs= numpy.ones(3)*0.5+0.5 zs= (numpy.zeros(3)-1.)/2. assert numpy.all(numpy.fabs(sp.zforce(rs,zs)-kp.zforce(rs,zs)) < 10.**-8.), 'SnapshotRZPotential with single unit mass does not correspond to KeplerPotential' return None
def test_snapshotKeplerPotential_grid(): # Test that evaluating on a grid works # Set up a snapshot with just one unit mass at the origin s= pynbody.new(star=1) s['mass']= 2. s['eps']= 0. sp= potential.SnapshotRZPotential(s) kp= potential.KeplerPotential(amp=2.) #should be the same rs= numpy.arange(3)+1 zs= 0.1 assert numpy.all(numpy.fabs(sp(rs,zs)-kp(rs,zs)) < 10.**-8.), 'SnapshotRZPotential with single unit mass does not correspond to KeplerPotential' return None
def test_snapshotKeplerPotential_eval(): # Set up a snapshot with just one unit mass at the origin s= pynbody.new(star=1) s['mass']= 1. s['eps']= 0. sp= potential.SnapshotRZPotential(s,num_threads=1) kp= potential.KeplerPotential(amp=1.) #should be the same assert numpy.fabs(sp(1.,0.)-kp(1.,0.)) < 10.**-8., 'SnapshotRZPotential with single unit mass does not correspond to KeplerPotential' assert numpy.fabs(sp(0.5,0.)-kp(0.5,0.)) < 10.**-8., 'SnapshotRZPotential with single unit mass does not correspond to KeplerPotential' assert numpy.fabs(sp(1.,0.5)-kp(1.,0.5)) < 10.**-8., 'SnapshotRZPotential with single unit mass does not correspond to KeplerPotential' assert numpy.fabs(sp(1.,-0.5)-kp(1.,-0.5)) < 10.**-8., 'SnapshotRZPotential with single unit mass does not correspond to KeplerPotential' return None