Esempio n. 1
0
    def __init__(self,discpot,zlim,vlim,times=np.linspace(0,1,1001)*u.Gyr,zpt=31,vpt=31,zarray=False,varray=False):

        """
        NAME:
           __init__
        PURPOSE:
           Initialize a vertical disc in equilibrium
        INPUT:
           pot (galpy potential) - should be a 1-dimensional potential
           zlim (float) - maximum height of the galactic disc in kpc
           vlim (float) - maximum velocity of the galactic disc in km/s
        OPTIONAL INPUTS:
           times (array) - time array over which to integrate the disc orbits.
                    Otherwise, it defaults to 1001 timesteps over 5 Gyr.
           zpt (int) - number of phase-space points along the z-axis
           vpt (int) - number of phase-space points along the vz-axis
           zarray (boolean) - if True, zlim is an array specifying the points along the z-axis at which to calculte the perturbation
           varray (boolean) - if True, vlim is an array specifying the points along the vz-axis at which to calculte the perturbation
        OUTPUT:
           instance
        """

        turn_physical_off(discpot) #1-dimensional potential object from Galpy
        self.pot= discpot
        self.InternalUnits= get_physical(self.pot)
        if zarray:
            self.zmax=np.max(np.abs(zlim))
            self.znpt= len(zlim)
            self.z= zlim
        else:
            self.zmax= zlim/self.InternalUnits['ro']
            self.znpt= zpt
            self.z= np.linspace(-self.zmax,self.zmax,self.znpt) # in galpy internal units
        if varray:
            self.vmax=np.max(np.abs(vlim))
            self.vnpt= len(vlim)
            self.v= vlim
        else:
            self.vmax= vlim/self.InternalUnits['vo']
            self.vnpt= vpt
            self.v= np.linspace(-self.vmax,self.vmax,self.vnpt) # in galpy internal units

        self.tt= times

        self.Jz,self.Oz= self.calc_JO()
        self.integOrbits(self.tt)
Esempio n. 2
0
    def _coordinate_system(zmin_max, vmin_max, N, galactic_potential):
        """

        :param zmin_max:
        :param vmin_max:
        :param N:
        :param galactic_potential:
        :return:
        """
        _z = np.linspace(-zmin_max, zmin_max, N)
        _v = np.linspace(-vmin_max, vmin_max, N)

        turn_physical_off(galactic_potential)
        units = get_physical(galactic_potential)

        z_units_internal = _z / units['ro']
        v_units_internal = _v / units['vo']

        return z_units_internal, v_units_internal, galactic_potential, units
Esempio n. 3
0
def test_get_physical():
    #Test that the get_physical function returns the right scaling parameters
    from galpy.util.bovy_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