Ejemplo n.º 1
0
def test_dens_in_criticaldens():
    #Test the scaling, as a 2nd derivative of the potential / G, should scale as velocity^2/position^2
    vofid, rofid = 200., 8.
    assert numpy.fabs(
        4. * bovy_conversion.dens_in_criticaldens(vofid, rofid) /
        bovy_conversion.dens_in_criticaldens(2. * vofid, rofid) -
        1.) < 10.**-10., 'dens_in_criticaldens did not work as expected'
    assert numpy.fabs(
        .25 * bovy_conversion.dens_in_criticaldens(vofid, rofid) /
        bovy_conversion.dens_in_criticaldens(vofid, 2 * rofid) -
        1.) < 10.**-10., 'dens_in_critical did not work as expected'
    return None
Ejemplo n.º 2
0
    def rvir(self,
             H=70.,
             Om=0.3,
             t=0.,
             overdens=200.,
             wrtcrit=False,
             ro=None,
             vo=None,
             use_physical=False
             ):  # use_physical necessary bc of pop=False, does nothing inside
        """
        NAME:

           rvir

        PURPOSE:

           calculate the virial radius for this density distribution

        INPUT:

           H= (default: 70) Hubble constant in km/s/Mpc
           
           Om= (default: 0.3) Omega matter
       
           overdens= (200) overdensity which defines the virial radius

           wrtcrit= (False) if True, the overdensity is wrt the critical density rather than the mean matter density

           ro= distance scale in kpc or as Quantity (default: object-wide, which if not set is 8 kpc))

           vo= velocity scale in km/s or as Quantity (default: object-wide, which if not set is 220 km/s))

        OUTPUT:
        
           virial radius
        
        HISTORY:

           2014-01-29 - Written - Bovy (IAS)

        """
        if ro is None: ro = self._ro
        if vo is None: vo = self._vo
        if wrtcrit:
            od = overdens / bovy_conversion.dens_in_criticaldens(vo, ro, H=H)
        else:
            od = overdens / bovy_conversion.dens_in_meanmatterdens(
                vo, ro, H=H, Om=Om)
        dc = 12. * self.dens(self.a, 0., t=t, use_physical=False) / od
        x = optimize.brentq(
            lambda y: (numpy.log(1. + y) - y / (1. + y)) / y**3. - 1. / dc,
            0.01, 100.)
        return x * self.a
Ejemplo n.º 3
0
    def rvir(self,H=70.,Om=0.3,overdens=200.,wrtcrit=False,ro=None,vo=None,
             use_physical=False): # use_physical necessary bc of pop=False, does nothing inside
        """
        NAME:

           rvir

        PURPOSE:

           calculate the virial radius for this density distribution

        INPUT:

           H= (default: 70) Hubble constant in km/s/Mpc
           
           Om= (default: 0.3) Omega matter
       
           overdens= (200) overdensity which defines the virial radius

           wrtcrit= (False) if True, the overdensity is wrt the critical density rather than the mean matter density

           ro= distance scale in kpc or as Quantity (default: object-wide, which if not set is 8 kpc))

           vo= velocity scale in km/s or as Quantity (default: object-wide, which if not set is 220 km/s))

        OUTPUT:
        
           virial radius
        
        HISTORY:

           2014-01-29 - Written - Bovy (IAS)

        """
        if ro is None: ro= self._ro
        if vo is None: vo= self._vo
        if wrtcrit:
            od= overdens/bovy_conversion.dens_in_criticaldens(vo,ro,H=H)
        else:
            od= overdens/bovy_conversion.dens_in_meanmatterdens(vo,ro,
                                                                H=H,Om=Om)
        dc= 12.*self.dens(self.a,0.,use_physical=False)/od
        x= optimize.brentq(lambda y: (numpy.log(1.+y)-y/(1.+y))/y**3.-1./dc,
                           0.01,100.)
        return x*self.a
    def rvir(self, vo, ro, H=70., Om=0.3, overdens=200., wrtcrit=False):
        """
        NAME:

           rvir

        PURPOSE:

           calculate the virial radius for this density distribution

        INPUT:

           vo - velocity unit in km/s

           ro - length unit in kpc

           H= (default: 70) Hubble constant in km/s/Mpc
           
           Om= (default: 0.3) Omega matter
       
           overdens= (200) overdensity which defines the virial radius

           wrtcrit= (False) if True, the overdensity is wrt the critical density rather than the mean matter density
           
        OUTPUT:
        
           virial radius in natural units
        
        HISTORY:

           2014-01-29 - Written - Bovy (IAS)

        """
        if wrtcrit:
            od = overdens / bovy_conversion.dens_in_criticaldens(vo, ro, H=H)
        else:
            od = overdens / bovy_conversion.dens_in_meanmatterdens(
                vo, ro, H=H, Om=Om)
        dc = 12. * self.dens(self.a, 0.) / od
        x = optimize.brentq(
            lambda y: (numpy.log(1. + y) - y / (1. + y)) / y**3. - 1. / dc,
            0.01, 100.)
        return x * self.a
Ejemplo n.º 5
0
    def _rvir(self,vo,ro,H=70.,Om=0.3,overdens=200.,wrtcrit=False):
        """
        NAME:

           _rvir

        PURPOSE:

           calculate the virial radius for this density distribution

        INPUT:

           vo - velocity unit in km/s

           ro - length unit in kpc

           H= (default: 70) Hubble constant in km/s/Mpc
           
           Om= (default: 0.3) Omega matter
       
           overdens= (200) overdensity which defines the virial radius

           wrtcrit= (False) if True, the overdensity is wrt the critical density rather than the mean matter density
           
        OUTPUT:
        
           virial radius in natural units
        
        HISTORY:

           2014-01-29 - Written - Bovy (IAS)

        """
        if wrtcrit:
            od= overdens/bovy_conversion.dens_in_criticaldens(vo,ro,H=H)
        else:
            od= overdens/bovy_conversion.dens_in_meanmatterdens(vo,ro,H=H,Om=Om)
        dc= 12.*self.dens(self.a,0.)/od
        x= optimize.brentq(lambda y: (numpy.log(1.+y)-y/(1.+y))/y**3.-1./dc,
                           0.01,100.)
        return x*self.a
Ejemplo n.º 6
0
    def __init__(self,amp=1.,a=1.,normalize=False,
                 conc=None,mvir=None,
                 vo=None,ro=None,
                 H=70.,Om=0.3,overdens=200.,wrtcrit=False):
        """
        NAME:

           __init__

        PURPOSE:

           Initialize a NFW potential

        INPUT:

           amp - amplitude to be applied to the potential (default: 1); can be a Quantity with units of mass or Gxmass

           a - scale radius (can be Quantity)

           normalize - if True, normalize such that vc(1.,0.)=1., or, if given as a number, such that the force is this fraction of the force necessary to make vc(1.,0.)=1.


           Alternatively, NFW potentials can be initialized using 

              conc= concentration

              mvir= virial mass in 10^12 Msolar

           in which case you also need to supply the following keywords
           
              H= (default: 70) Hubble constant in km/s/Mpc
           
              Om= (default: 0.3) Omega matter
       
              overdens= (200) overdensity which defines the virial radius

              wrtcrit= (False) if True, the overdensity is wrt the critical density rather than the mean matter density
           
           ro=, vo= distance and velocity scales for translation into internal units (default from configuration file)

        OUTPUT:

           (none)

        HISTORY:

           2010-07-09 - Written - Bovy (NYU)

           2014-04-03 - Initialization w/ concentration and mass - Bovy (IAS)

        """
        Potential.__init__(self,amp=amp,ro=ro,vo=vo,amp_units='mass')
        if _APY_LOADED and isinstance(a,units.Quantity):
            a= a.to(units.kpc).value/self._ro
        if conc is None:
            self.a= a
            self.alpha= 1
            self.beta= 3
            if normalize or \
                    (isinstance(normalize,(int,float)) \
                         and not isinstance(normalize,bool)):
                self.normalize(normalize)
        else:
            if wrtcrit:
                od= overdens/bovy_conversion.dens_in_criticaldens(self._vo,
                                                                  self._ro,H=H)
            else:
                od= overdens/bovy_conversion.dens_in_meanmatterdens(self._vo,
                                                                    self._ro,
                                                                    H=H,Om=Om)
            mvirNatural= mvir*100./bovy_conversion.mass_in_1010msol(self._vo,
                                                                    self._ro)
            rvir= (3.*mvirNatural/od/4./numpy.pi)**(1./3.)
            self.a= rvir/conc
            self._amp= mvirNatural/(numpy.log(1.+conc)-conc/(1.+conc))
        self._scale= self.a
        self.hasC= True
        self.hasC_dxdv= True
        self._nemo_accname= 'NFW'
        return None
Ejemplo n.º 7
0
    def __init__(self,amp=1.,a=1.,normalize=False,
                 conc=None,mvir=None,
                 vo=220.,ro=8.,
                 H=70.,Om=0.3,overdens=200.,wrtcrit=False):
        """
        NAME:

           __init__

        PURPOSE:

           Initialize a NFW potential

        INPUT:

           amp - amplitude to be applied to the potential

           a - "scale" (in terms of Ro)

           normalize - if True, normalize such that vc(1.,0.)=1., or, if given as a number, such that the force is this fraction of the force necessary to make vc(1.,0.)=1.


           Alternatively, NFW potentials can be initialized using 

              conc= concentration

              mvir= virial mass in 10^12 Msolar

           in which case you also need to supply the following keywords
           
              vo= (220.) velocity unit in km/s

              ro= (8.) length unit in kpc

              H= (default: 70) Hubble constant in km/s/Mpc
           
              Om= (default: 0.3) Omega matter
       
              overdens= (200) overdensity which defines the virial radius

              wrtcrit= (False) if True, the overdensity is wrt the critical density rather than the mean matter density
           
        OUTPUT:

           (none)

        HISTORY:

           2010-07-09 - Written - Bovy (NYU)

           2014-04-03 - Initialization w/ concentration and mass - Bovy (IAS)

        """
        Potential.__init__(self,amp=amp)
        if conc is None:
            self.a= a
            self.alpha= 1
            self.beta= 3
            if normalize or \
                    (isinstance(normalize,(int,float)) \
                         and not isinstance(normalize,bool)):
                self.normalize(normalize)
        else:
            if wrtcrit:
                od= overdens/bovy_conversion.dens_in_criticaldens(vo,ro,H=H)
            else:
                od= overdens/bovy_conversion.dens_in_meanmatterdens(vo,ro,H=H,Om=Om)
            mvirNatural= mvir*100./bovy_conversion.mass_in_1010msol(vo,ro)
            rvir= (3.*mvirNatural/od/4./numpy.pi)**(1./3.)
            self.a= rvir/conc
            self._amp= mvirNatural/(numpy.log(1.+conc)-conc/(1.+conc))
        self._scale= self.a
        self.hasC= True
        return None
Ejemplo n.º 8
0
    def __init__(self,
                 amp=1.,
                 a=1.,
                 normalize=False,
                 conc=None,
                 mvir=None,
                 vo=None,
                 ro=None,
                 H=70.,
                 Om=0.3,
                 overdens=200.,
                 wrtcrit=False):
        """
        NAME:

           __init__

        PURPOSE:

           Initialize a NFW potential

        INPUT:

           amp - amplitude to be applied to the potential (default: 1); can be a Quantity with units of mass or Gxmass

           a - scale radius (can be Quantity)

           normalize - if True, normalize such that vc(1.,0.)=1., or, if given as a number, such that the force is this fraction of the force necessary to make vc(1.,0.)=1.


           Alternatively, NFW potentials can be initialized using 

              conc= concentration

              mvir= virial mass in 10^12 Msolar

           in which case you also need to supply the following keywords
           
              H= (default: 70) Hubble constant in km/s/Mpc
           
              Om= (default: 0.3) Omega matter
       
              overdens= (200) overdensity which defines the virial radius

              wrtcrit= (False) if True, the overdensity is wrt the critical density rather than the mean matter density
           
           ro=, vo= distance and velocity scales for translation into internal units (default from configuration file)

        OUTPUT:

           (none)

        HISTORY:

           2010-07-09 - Written - Bovy (NYU)

           2014-04-03 - Initialization w/ concentration and mass - Bovy (IAS)

        """
        Potential.__init__(self, amp=amp, ro=ro, vo=vo, amp_units='mass')
        if _APY_LOADED and isinstance(a, units.Quantity):
            a = a.to(units.kpc).value / self._ro
        if conc is None:
            self.a = a
            self.alpha = 1
            self.beta = 3
            if normalize or \
                    (isinstance(normalize,(int,float)) \
                         and not isinstance(normalize,bool)):
                self.normalize(normalize)
        else:
            if wrtcrit:
                od = overdens / bovy_conversion.dens_in_criticaldens(
                    self._vo, self._ro, H=H)
            else:
                od = overdens / bovy_conversion.dens_in_meanmatterdens(
                    self._vo, self._ro, H=H, Om=Om)
            mvirNatural = mvir * 100. / bovy_conversion.mass_in_1010msol(
                self._vo, self._ro)
            rvir = (3. * mvirNatural / od / 4. / numpy.pi)**(1. / 3.)
            self.a = rvir / conc
            self._amp = mvirNatural / (numpy.log(1. + conc) - conc /
                                       (1. + conc))
        self._scale = self.a
        self.hasC = True
        self.hasC_dxdv = True
        self._nemo_accname = 'NFW'
        return None
    def __init__(self,
                 amp=1.,
                 a=1.,
                 normalize=False,
                 conc=None,
                 mvir=None,
                 vo=220.,
                 ro=8.,
                 H=70.,
                 Om=0.3,
                 overdens=200.,
                 wrtcrit=False):
        """
        NAME:

           __init__

        PURPOSE:

           Initialize a NFW potential

        INPUT:

           amp - amplitude to be applied to the potential

           a - "scale" (in terms of Ro)

           normalize - if True, normalize such that vc(1.,0.)=1., or, if given as a number, such that the force is this fraction of the force necessary to make vc(1.,0.)=1.


           Alternatively, NFW potentials can be initialized using 

              conc= concentration

              mvir= virial mass in 10^12 Msolar

           in which case you also need to supply the following keywords
           
              vo= (220.) velocity unit in km/s

              ro= (8.) length unit in kpc

              H= (default: 70) Hubble constant in km/s/Mpc
           
              Om= (default: 0.3) Omega matter
       
              overdens= (200) overdensity which defines the virial radius

              wrtcrit= (False) if True, the overdensity is wrt the critical density rather than the mean matter density
           
        OUTPUT:

           (none)

        HISTORY:

           2010-07-09 - Written - Bovy (NYU)

           2014-04-03 - Initialization w/ concentration and mass - Bovy (IAS)

        """
        Potential.__init__(self, amp=amp)
        if conc is None:
            self.a = a
            self.alpha = 1
            self.beta = 3
            if normalize or \
                    (isinstance(normalize,(int,float)) \
                         and not isinstance(normalize,bool)):
                self.normalize(normalize)
        else:
            if wrtcrit:
                od = overdens / bovy_conversion.dens_in_criticaldens(
                    vo, ro, H=H)
            else:
                od = overdens / bovy_conversion.dens_in_meanmatterdens(
                    vo, ro, H=H, Om=Om)
            mvirNatural = mvir * 100. / bovy_conversion.mass_in_1010msol(
                vo, ro)
            rvir = (3. * mvirNatural / od / 4. / numpy.pi)**(1. / 3.)
            self.a = rvir / conc
            self._amp = mvirNatural / (numpy.log(1. + conc) - conc /
                                       (1. + conc))
        self._scale = self.a
        self.hasC = True
        self.hasC_dxdv = True
        self._nemo_accname = 'NFW'
        return None
Ejemplo n.º 10
0
def test_dens_in_criticaldens():
    #Test the scaling, as a 2nd derivative of the potential / G, should scale as velocity^2/position^2
    vofid, rofid= 200., 8.
    assert numpy.fabs(4.*bovy_conversion.dens_in_criticaldens(vofid,rofid)/bovy_conversion.dens_in_criticaldens(2.*vofid,rofid)-1.) < 10.**-10., 'dens_in_criticaldens did not work as expected'
    assert numpy.fabs(.25*bovy_conversion.dens_in_criticaldens(vofid,rofid)/bovy_conversion.dens_in_criticaldens(vofid,2*rofid)-1.) < 10.**-10., 'dens_in_critical did not work as expected'
    return None