Exemplo n.º 1
0
def sigmar(Pot,r,dens=None,beta=0.):
    """
    NAME:

       sigmar

    PURPOSE:

       Compute the radial velocity dispersion using the spherical Jeans equation

    INPUT:

       Pot - potential or list of potentials (evaluated at R=r/sqrt(2),z=r/sqrt(2), sphericity not checked)

       r - Galactocentric radius (can be Quantity)

       dens= (None) tracer density profile (function of r); if None, the density is assumed to be that corresponding to the potential

       beta= (0.) anisotropy; can be a constant or a function of r
       
    OUTPUT:

       sigma_r(r)

    HISTORY:

       2018-07-05 - Written - Bovy (UofT)

    """
    Pot= flatten_pot(Pot)
    if dens is None:
        dens= lambda r: evaluateDensities(Pot,r*_INVSQRTTWO,r*_INVSQRTTWO,
                                          use_physical=False)
    if callable(beta):
        intFactor= lambda x: numpy.exp(2.*integrate.quad(lambda y: beta(y)/y,
                                       1.,x)[0])
    else: # assume to be number
        intFactor= lambda x: x**(2.*beta)
    return numpy.sqrt(integrate.quad(lambda x: -intFactor(x)*dens(x)
                                     *evaluaterforces(Pot,
                                                      x*_INVSQRTTWO,
                                                      x*_INVSQRTTWO,
                                                      use_physical=False),
                                     r,numpy.inf)[0]/
                      dens(r)/intFactor(r))
Exemplo n.º 2
0
 def plotEzJz(self, *args, **kwargs):
     """
     NAME:
        plotEzJz
     PURPOSE:
        plot E_z(.)/sqrt(dens(R)) along the orbit
     INPUT:
        pot= Potential instance or list of instances in which the orbit was
              integrated
        d1= - plot Ez vs d1: e.g., 't', 'z', 'R', 'vR', 'vT', 'vz'      
        +bovy_plot.bovy_plot inputs
     OUTPUT:
        figure to output device
     HISTORY:
        2010-08-08 - Written - Bovy (NYU)
     """
     labeldict = {
         't': r'$t$',
         'R': r'$R$',
         'vR': r'$v_R$',
         'vT': r'$v_T$',
         'z': r'$z$',
         'vz': r'$v_z$',
         'phi': r'$\phi$',
         'x': r'$x$',
         'y': r'$y$',
         'vx': r'$v_x$',
         'vy': r'$v_y$'
     }
     if not 'pot' in kwargs:
         try:
             pot = self._pot
         except AttributeError:
             raise AttributeError("Integrate orbit first or specify pot=")
     else:
         pot = kwargs.pop('pot')
     d1 = kwargs.pop('d1', 't')
     self.EzJz= [(evaluatePotentials(pot,self.orbit[ii,0],self.orbit[ii,3],
                                     t=self.t[ii],use_physical=False)-
                  evaluatePotentials(pot,self.orbit[ii,0],0.,
                                     phi= self.orbit[ii,5],t=self.t[ii],
                                     use_physical=False)+
                  self.orbit[ii,4]**2./2.)/\
                     nu.sqrt(evaluateDensities(pot,self.orbit[ii,0],0.,
                                               phi=self.orbit[ii,5],
                                               t=self.t[ii],
                                               use_physical=False))\
                     for ii in range(len(self.t))]
     if not 'xlabel' in kwargs:
         kwargs['xlabel'] = labeldict[d1]
     if not 'ylabel' in kwargs:
         kwargs['ylabel'] = r'$E_z/\sqrt{\rho}$'
     if d1 == 't':
         return plot.bovy_plot(nu.array(self.t),
                               nu.array(self.EzJz) / self.EzJz[0], *args,
                               **kwargs)
     elif d1 == 'z':
         return plot.bovy_plot(self.orbit[:, 3],
                               nu.array(self.EzJz) / self.EzJz[0], *args,
                               **kwargs)
     elif d1 == 'R':
         return plot.bovy_plot(self.orbit[:, 0],
                               nu.array(self.EzJz) / self.EzJz[0], *args,
                               **kwargs)
     elif d1 == 'vR':
         return plot.bovy_plot(self.orbit[:, 1],
                               nu.array(self.EzJz) / self.EzJz[0], *args,
                               **kwargs)
     elif d1 == 'vT':
         return plot.bovy_plot(self.orbit[:, 2],
                               nu.array(self.EzJz) / self.EzJz[0], *args,
                               **kwargs)
     elif d1 == 'vz':
         return plot.bovy_plot(self.orbit[:, 4],
                               nu.array(self.EzJz) / self.EzJz[0], *args,
                               **kwargs)
Exemplo n.º 3
0
 def plotEzJz(self,*args,**kwargs):
     """
     NAME:
        plotEzJz
     PURPOSE:
        plot E_z(.)/sqrt(dens(R)) along the orbit
     INPUT:
        pot= Potential instance or list of instances in which the orbit was
              integrated
        d1= - plot Ez vs d1: e.g., 't', 'z', 'R', 'vR', 'vT', 'vz'      
        +bovy_plot.bovy_plot inputs
     OUTPUT:
        figure to output device
     HISTORY:
        2010-08-08 - Written - Bovy (NYU)
     """
     labeldict= {'t':r'$t$','R':r'$R$','vR':r'$v_R$','vT':r'$v_T$',
                 'z':r'$z$','vz':r'$v_z$','phi':r'$\phi$',
                 'x':r'$x$','y':r'$y$','vx':r'$v_x$','vy':r'$v_y$'}
     if not 'pot' in kwargs:
         try:
             pot= self._pot
         except AttributeError:
             raise AttributeError("Integrate orbit first or specify pot=")
     else:
         pot= kwargs.pop('pot')
     d1= kwargs.pop('d1','t')
     self.EzJz= [(evaluatePotentials(pot,self.orbit[ii,0],self.orbit[ii,3],
                                     t=self.t[ii],use_physical=False)-
                  evaluatePotentials(pot,self.orbit[ii,0],0.,t=self.t[ii],
                                     use_physical=False)+
                  self.orbit[ii,4]**2./2.)/\
                     nu.sqrt(evaluateDensities(pot,self.orbit[ii,0],0.,
                                               t=self.t[ii],
                                               use_physical=False))\
                     for ii in range(len(self.t))]
     if not 'xlabel' in kwargs:
         kwargs['xlabel']= labeldict[d1]
     if not 'ylabel' in kwargs:
         kwargs['ylabel']= r'$E_z/\sqrt{\rho}$'
     if d1 == 't':
         return plot.bovy_plot(nu.array(self.t),
                               nu.array(self.EzJz)/self.EzJz[0],
                               *args,**kwargs)
     elif d1 == 'z':
         return plot.bovy_plot(self.orbit[:,3],
                               nu.array(self.EzJz)/self.EzJz[0],
                               *args,**kwargs)
     elif d1 == 'R':
         return plot.bovy_plot(self.orbit[:,0],
                               nu.array(self.EzJz)/self.EzJz[0],
                               *args,**kwargs)
     elif d1 == 'vR':
         return plot.bovy_plot(self.orbit[:,1],
                               nu.array(self.EzJz)/self.EzJz[0],
                               *args,**kwargs)
     elif d1 == 'vT':
         return plot.bovy_plot(self.orbit[:,2],
                               nu.array(self.EzJz)/self.EzJz[0],
                               *args,**kwargs)
     elif d1 == 'vz':
         return plot.bovy_plot(self.orbit[:,4],
                               nu.array(self.EzJz)/self.EzJz[0],
                               *args,**kwargs)
Exemplo n.º 4
0
def sigmalos(Pot,R,dens=None,surfdens=None,beta=0.,sigma_r=None):
    """
    NAME:

       sigmalos

    PURPOSE:

       Compute the line-of-sight velocity dispersion using the spherical Jeans equation

    INPUT:

       Pot - potential or list of potentials (evaluated at R=r/sqrt(2),z=r/sqrt(2), sphericity not checked)

       R - Galactocentric projected radius (can be Quantity)

       dens= (None) tracer density profile (function of r); if None, the density is assumed to be that corresponding to the potential

       surfdens= (None) tracer surface density profile (value at R or function of R); if None, the surface density is assumed to be that corresponding to the density

       beta= (0.) anisotropy; can be a constant or a function of r

       sigma_r= (None) if given, the solution of the spherical Jeans equation sigma_r(r) (used instead of solving the Jeans equation as part of this routine)
       
    OUTPUT:

       sigma_los(R)

    HISTORY:

       2018-08-27 - Written - Bovy (UofT)

    """
    Pot= flatten_pot(Pot)
    if dens is None:
        densPot= True
        dens= lambda r: evaluateDensities(Pot,r*_INVSQRTTWO,r*_INVSQRTTWO,
                                          use_physical=False)
    else:
        densPot= False
    if callable(surfdens):
        called_surfdens= surfdens(R)
    elif surfdens is None:
        if densPot:
            called_surfdens= evaluateSurfaceDensities(Pot,R,numpy.inf,
                                                    use_physical=False)
        if not densPot or numpy.isnan(called_surfdens):
            called_surfdens=\
                    2.*integrate.quad(lambda x: dens(numpy.sqrt(R**2.+x**2.)),
                                      0.,numpy.inf)[0]
    else:
        called_surfdens= surfdens
    if callable(beta):
        call_beta= beta
    else:
        call_beta= lambda x: beta
    if sigma_r is None:
        call_sigma_r= lambda r: sigmar(Pot,r,dens=dens,beta=beta)
    elif not callable(sigma_r):
        call_sigma_r= lambda x: sigma_r
    else:
        call_sigma_r= sigma_r
    return numpy.sqrt(2.*integrate.quad(\
            lambda x: (1.-call_beta(x)*R**2./x**2.)*x*dens(x)\
                *call_sigma_r(x)**2./numpy.sqrt(x**2.-R**2.),R,numpy.inf)[0]\
                          /called_surfdens)