def __init__(self,amp=1.,core=_CORE,q=1.,normalize=False):
     """
     NAME:
        __init__
     PURPOSE:
        initialize a Logarithmic Halo potential
     INPUT:
        amp - amplitude to be applied to the potential (default: 1)
        core - core radius at which the logarithm is cut
        q - potential flattening (z/q)**2.
        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.
     OUTPUT:
        (none)
     HISTORY:
        2010-04-02 - Started - Bovy (NYU)
     """
     Potential.__init__(self,amp=amp)
     self.hasC= True
     self._core2= core**2.
     self._q= q
     if normalize:
         self.normalize(normalize)
     return None
 def __init__(self, amp=1.0, alpha=1.0, rc=1.0, normalize=False):
     """
     NAME:
        __init__
     PURPOSE:
        initialize a power-law-density potential
     INPUT:
        amp - amplitude to be applied to the potential (default: 1)
        alpha - inner power
        rc - cut-off radius
        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.
     OUTPUT:
        (none)
     HISTORY:
        2013-06-28 - Written - Bovy (IAS)
     """
     Potential.__init__(self, amp=amp)
     self.alpha = alpha
     self.rc = rc
     self._scale = self.rc
     if normalize or (isinstance(normalize, (int, float)) and not isinstance(normalize, bool)):
         self.normalize(normalize)
     self.hasC = False
Example #3
0
 def __init__(self, amp=1., core=_CORE, q=1., normalize=False):
     """
     NAME:
        __init__
     PURPOSE:
        initialize a Logarithmic Halo potential
     INPUT:
        amp - amplitude to be applied to the potential (default: 1)
        core - core radius at which the logarithm is cut
        q - potential flattening (z/q)**2.
        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.
     OUTPUT:
        (none)
     HISTORY:
        2010-04-02 - Started - Bovy (NYU)
     """
     Potential.__init__(self, amp=amp)
     self.hasC = True
     self._core2 = core**2.
     self._q = q
     if normalize:
         self.normalize(normalize)
     return None
Example #4
0
 def __init__(self,amp=1.,b=1.,normalize=False):
     """
     NAME:
        __init__
     PURPOSE:
        initialize an isochrone potential
     INPUT:
        amp= amplitude to be applied to the potential (default: 1)
        b= scale radius of the isochrone potential
        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.
     OUTPUT:
        (none)
     HISTORY:
        2013-09-08 - Written - Bovy (IAS)
     """
     Potential.__init__(self,amp=amp)
     self.b= b
     self._scale= self.b
     self.b2= self.b**2.
     if normalize or \
             (isinstance(normalize,(int,float)) \
                  and not isinstance(normalize,bool)):
         self.normalize(normalize)
     self.hasC= True
 def __init__(self, amp=1., a=1., normalize=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.
     OUTPUT:
        (none)
     HISTORY:
        2010-07-09 - Written - Bovy (NYU)
     """
     Potential.__init__(self, amp=amp)
     self.a = a
     self.alpha = 1
     self.beta = 3
     if normalize:
         self.normalize(normalize)
     self.hasC = True
     return None
Example #6
0
    def __init__(self,amp=1.,alpha=1.,normalize=False):
        """
        NAME:

           __init__

        PURPOSE:

           initialize a power-law-density potential

        INPUT:

           amp - amplitude to be applied to the potential (default: 1)

           alpha - inner power

           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.

        OUTPUT:

           (none)

        HISTORY:

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

        """
        Potential.__init__(self,amp=amp)
        self.alpha= alpha
        if normalize or \
                (isinstance(normalize,(int,float)) \
                     and not isinstance(normalize,bool)):
            self.normalize(normalize)
        self.hasC= True
        self.hasC_dxdv= True
Example #7
0
 def __init__(self,amp=1.,a=1.,normalize=False):
     """
     NAME:
        __init__
     PURPOSE:
        initialize a Burkert-density potential
     INPUT:
        amp - amplitude to be applied to the potential (default: 1)
        a = scale radius
        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.
     OUTPUT:
        (none)
     HISTORY:
        2013-04-10 - Written - Bovy (IAS)
     """
     Potential.__init__(self,amp=amp)
     self.a=a
     self._scale= self.a
     if normalize or \
             (isinstance(normalize,(int,float)) \
                  and not isinstance(normalize,bool)):
         self.normalize(normalize)
     self.hasC= False
Example #8
0
 def __init__(self,amp=1.,ro=1.,hr=1./3.,hz=1./16.,
              maxiter=_MAXITER,tol=0.001,normalize=False):
     """
     NAME:
        __init__
     PURPOSE:
        initialize a double-exponential disk potential
     INPUT:
        amp - amplitude to be applied to the potential (default: 1)
        hr - disk scale-length in terms of ro
        hz - scale-height
        tol - relative accuracy of potential-evaluations
        maxiter - scipy.integrate keyword
        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.
     OUTPUT:
        DoubleExponentialDiskPotential object
     HISTORY:
        2010-04-16 - Written - Bovy (NYU)
     """
     Potential.__init__(self,amp=amp)
     self._ro= ro
     self._hr= hr
     self._hz= hz
     self._alpha= 1./self._hr
     self._beta= 1./self._hz
     self._gamma= self._alpha/self._beta
     self._maxiter= maxiter
     self._tol= tol
     self._zforceNotSetUp= True #We have not calculated a typical Kz yet
     if normalize:
         self.normalize(normalize)
 def __init__(self,amp=1.,a=1.,normalize=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.
     OUTPUT:
        (none)
     HISTORY:
        2010-07-09 - Written - Bovy (NYU)
     """
     Potential.__init__(self,amp=amp)
     self.a= a
     self.alpha= 1
     self.beta= 3
     if normalize:
         self.normalize(normalize)
     self.hasC= True
     return None
 def __init__(self,amp=1.,a=1.,alpha=1.,beta=3.,normalize=False):
     """
     NAME:
        __init__
     PURPOSE:
        initialize a two-power-density potential
     INPUT:
        amp - amplitude to be applied to the potential (default: 1)
        a - "scale" (in terms of Ro)
        alpha - inner power
        beta - outer power
        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.
     OUTPUT:
        (none)
     HISTORY:
        2010-07-09 - Started - Bovy (NYU)
     """
     self.a= a
     self.alpha= alpha
     self.beta= beta
     if alpha == round(alpha) and beta == round(beta):
         integerSelf= TwoPowerIntegerSphericalPotential(amp=amp,a=a,
                                                        alpha=int(alpha),
                                                        beta=int(beta),
                                                        normalize=normalize)
         self.integerSelf= integerSelf
     else:
         Potential.__init__(self,amp=amp)
         self.integerSelf= None
         if normalize:
             self.normalize(normalize)
     return None
Example #11
0
    def __init__(self,
                 orbit,
                 amp=1.,
                 GM=.06,
                 normalize=False,
                 softening=None,
                 softening_model='plummer',
                 softening_length=0.01):
        """
        NAME:

           __init__

        PURPOSE:

           initialize a MovingObjectPotential

        INPUT:

           orbit - the Orbit of the object (Orbit object)

           amp= - amplitude to be applied to the potential (default: 1)

           GM - 'mass' of the object (degenerate with amp)

           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. (at t=0)

           Softening: either provide

              a) softening= with a ForceSoftening-type object

              b) softening_model=  type of softening to use ('plummer')

                 softening_length= (optional)

        OUTPUT:

           (none)

        HISTORY:

           2011-04-10 - Started - Bovy (NYU)

        """
        Potential.__init__(self, amp=amp)
        self._gm = GM
        self._orb = orbit
        if softening is None:
            if softening_model.lower() == 'plummer':
                self._softening = PlummerSoftening(
                    softening_length=softening_length)
        else:
            self._softening = softening
        if normalize:
            self.normalize(normalize)
Example #12
0
    def __init__(self,orbit,amp=1.,GM=.06,normalize=False,
                 softening=None,
                 softening_model='plummer',softening_length=0.01):
        """
        NAME:

           __init__

        PURPOSE:

           initialize a MovingObjectPotential

        INPUT:

           orbit - the Orbit of the object (Orbit object)

           amp= - amplitude to be applied to the potential (default: 1)

           GM - 'mass' of the object (degenerate with amp)

           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. (at t=0)

           Softening: either provide

              a) softening= with a ForceSoftening-type object

              b) softening_model=  type of softening to use ('plummer')

                 softening_length= (optional)

        OUTPUT:

           (none)

        HISTORY:

           2011-04-10 - Started - Bovy (NYU)

        """
        Potential.__init__(self,amp=amp)
        self._gm= GM
        self._orb= orbit
        if softening is None:
            if softening_model.lower() == 'plummer':
                self._softening= PlummerSoftening(softening_length=softening_length)
        else:
            self._softening= softening
        if normalize or \
                (isinstance(normalize,(int,float)) \
                     and not isinstance(normalize,bool)):
            self.normalize(normalize)
        return None
Example #13
0
 def __init__(self,
              RZPot,
              rgrid=(0.01, 2., 101),
              zgrid=(-0.2, 0.2, 101),
              logR=False):
     """
     NAME:
        __init__
     PURPOSE:
        Initialize an interpRZPotential instance
     INPUT:
        RZPot - RZPotential to be interpolated
        rgrid - R grid to be given to linspace
        zgrid - z grid to be given to linspace
        logR - if True, rgrid is in the log of R
     OUTPUT:
        instance
     HISTORY:
        2010-07-21 - Written - Bovy (NYU)
     """
     Potential.__init__(self, amp=1.)
     self._origPot = RZPot
     self._rgrid = nu.linspace(*rgrid)
     if logR:
         self._rgrid = nu.exp(self._rgrid)
     self._zgrid = nu.linspace(*zgrid)
     R = nu.zeros(len(self._rgrid) * len(self._zgrid))
     z = nu.zeros(len(self._rgrid) * len(self._zgrid))
     Rforce = nu.zeros(len(self._rgrid) * len(self._zgrid))
     zforce = nu.zeros(len(self._rgrid) * len(self._zgrid))
     if _DEBUG:
         print "Computing forces on grid ..."
     for ii in range(len(self._rgrid)):
         for jj in range(len(self._zgrid)):
             Rforce[ii * len(self._zgrid) + jj] = RZPot.Rforce(
                 self._rgrid[ii], self._zgrid[jj])
             zforce[ii * len(self._zgrid) + jj] = RZPot.zforce(
                 self._rgrid[ii], self._zgrid[jj])
             R[ii * len(self._zgrid) + jj] = self._rgrid[ii]
             z[ii * len(self._zgrid) + jj] = self._zgrid[jj]
     if _DEBUG:
         print "Interpolating ..."
     self._interpRforce = interpolate.interp2d(R,
                                               z,
                                               Rforce,
                                               bounds_error=True)
     self._interpzforce = interpolate.interp2d(R,
                                               z,
                                               zforce,
                                               bounds_error=True)
Example #14
0
    def __init__(self,orbit,amp=1.,GM=.06,
                 softening=None,
                 softening_model='plummer',softening_length=0.01):
        """
        NAME:

           __init__

        PURPOSE:

           initialize a MovingObjectPotential

        INPUT:

           orbit - the Orbit of the object (Orbit object)

           amp= - amplitude to be applied to the potential (default: 1)

           GM - 'mass' of the object (degenerate with amp)

           Softening: either provide

              a) softening= with a ForceSoftening-type object

              b) softening_model=  type of softening to use ('plummer')

                 softening_length= (optional)

        OUTPUT:

           (none)

        HISTORY:

           2011-04-10 - Started - Bovy (NYU)

        """
        Potential.__init__(self,amp=amp)
        self._gm= GM
        self._orb= orbit
        if softening is None:
            if softening_model.lower() == 'plummer':
                self._softening= PlummerSoftening(softening_length=softening_length)
        else:
            self._softening= softening
        self.isNonAxi= True
        return None
    def __init__(self,amp=1.,ro=1.,hr=1./3.,
                 maxiter=_MAXITER,tol=0.001,normalize=False,
                 new=True,glorder=100):
        """
        NAME:

           __init__

        PURPOSE:

           initialize a razor-thin-exponential disk potential

        INPUT:

           amp - amplitude to be applied to the potential (default: 1)

           hr - disk scale-length in terms of ro

           tol - relative accuracy of potential-evaluations

           maxiter - scipy.integrate keyword

           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.

        OUTPUT:

           RazorThinExponentialDiskPotential object

        HISTORY:

           2012-12-27 - Written - Bovy (IAS)

        """
        Potential.__init__(self,amp=amp)
        self._new= new
        self._glorder= glorder
        self._ro= ro
        self._hr= hr
        self._scale= self._hr
        self._alpha= 1./self._hr
        self._maxiter= maxiter
        self._tol= tol
        self._glx, self._glw= nu.polynomial.legendre.leggauss(self._glorder)
        if normalize or \
                (isinstance(normalize,(int,float)) \
                     and not isinstance(normalize,bool)): #pragma: no cover
            self.normalize(normalize)
 def __init__(self,amp=1.,a=1.,alpha=1,beta=3,normalize=False):
     """
     NAME:
        __init__
     PURPOSE:
        initialize a two-power-density potential for integer powers
     INPUT:
        amp - amplitude to be applied to the potential (default: 1)
        a - "scale" (in terms of Ro)
        alpha - inner power (default: NFW)
        beta - outer power (default: NFW)
        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.
     OUTPUT:
        (none)
     HISTORY:
        2010-07-09 - Started - Bovy (NYU)
     """
     if alpha == 1 and beta == 4:
         HernquistSelf= HernquistPotential(amp=amp,a=a,normalize=normalize)
         self.HernquistSelf= HernquistSelf
         self.JaffeSelf= None
         self.NFWSelf= None
     elif alpha == 2 and beta == 4:
         JaffeSelf= JaffePotential(amp=amp,a=a,normalize=normalize)
         self.HernquistSelf= None
         self.JaffeSelf= JaffeSelf
         self.NFWSelf= None
     elif alpha == 1 and beta == 3:
         NFWSelf= NFWPotential(amp=amp,a=a,normalize=normalize)
         self.HernquistSelf= None
         self.JaffeSelf= None
         self.NFWSelf= NFWSelf
     else:
         Potential.__init__(self,amp=amp)
         self.HernquistSelf= None
         self.JaffeSelf= None
         self.NFWSelf= None
         if normalize or \
                 (isinstance(normalize,(int,float)) \
                      and not isinstance(normalize,bool)):
             self.normalize(normalize)
     return None
 def __init__(self, amp=1., a=1., alpha=1, beta=3, normalize=False):
     """
     NAME:
        __init__
     PURPOSE:
        initialize a two-power-density potential for integer powers
     INPUT:
        amp - amplitude to be applied to the potential (default: 1)
        a - "scale" (in terms of Ro)
        alpha - inner power (default: NFW)
        beta - outer power (default: NFW)
        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.
     OUTPUT:
        (none)
     HISTORY:
        2010-07-09 - Started - Bovy (NYU)
     """
     if alpha == 1 and beta == 4:
         HernquistSelf = HernquistPotential(amp=amp,
                                            a=a,
                                            normalize=normalize)
         self.HernquistSelf = HernquistSelf
         self.JaffeSelf = None
         self.NFWSelf = None
     elif alpha == 2 and beta == 4:
         JaffeSelf = JaffePotential(amp=amp, a=a, normalize=normalize)
         self.HernquistSelf = None
         self.JaffeSelf = JaffeSelf
         self.NFWSelf = None
     elif alpha == 1 and beta == 3:
         NFWSelf = NFWPotential(amp=amp, a=a, normalize=normalize)
         self.HernquistSelf = None
         self.JaffeSelf = None
         self.NFWSelf = NFWSelf
     else:
         Potential.__init__(self, amp=amp)
         self.HernquistSelf = None
         self.JaffeSelf = None
         self.NFWSelf = None
         if normalize:
             self.normalize(normalize)
     return None
Example #18
0
 def __init__(self,RZPot,rgrid=(0.01,2.,101),zgrid=(-0.2,0.2,101),
              logR=False):
     """
     NAME:
        __init__
     PURPOSE:
        Initialize an interpRZPotential instance
     INPUT:
        RZPot - RZPotential to be interpolated
        rgrid - R grid to be given to linspace
        zgrid - z grid to be given to linspace
        logR - if True, rgrid is in the log of R
     OUTPUT:
        instance
     HISTORY:
        2010-07-21 - Written - Bovy (NYU)
     """
     Potential.__init__(self,amp=1.)
     self._origPot= RZPot
     self._rgrid= nu.linspace(*rgrid)
     if logR:
         self._rgrid= nu.exp(self._rgrid)
     self._zgrid= nu.linspace(*zgrid)
     R= nu.zeros(len(self._rgrid)*len(self._zgrid))
     z= nu.zeros(len(self._rgrid)*len(self._zgrid))
     Rforce= nu.zeros(len(self._rgrid)*len(self._zgrid))
     zforce= nu.zeros(len(self._rgrid)*len(self._zgrid))
     if _DEBUG:
         print "Computing forces on grid ..."
     for ii in range(len(self._rgrid)):
         for jj in range(len(self._zgrid)):
             Rforce[ii*len(self._zgrid)+jj]= RZPot.Rforce(self._rgrid[ii],
                                                          self._zgrid[jj])
             zforce[ii*len(self._zgrid)+jj]= RZPot.zforce(self._rgrid[ii],
                                                          self._zgrid[jj])
             R[ii*len(self._zgrid)+jj]= self._rgrid[ii]
             z[ii*len(self._zgrid)+jj]= self._zgrid[jj]
     if _DEBUG:
         print "Interpolating ..."
     self._interpRforce= interpolate.interp2d(R,z,Rforce,bounds_error=True)
     self._interpzforce= interpolate.interp2d(R,z,zforce,bounds_error=True)
Example #19
0
    def __init__(self,amp=1.,alpha=0.5,q=0.9,core=_CORE,normalize=False):
        """
        NAME:

           __init__

        PURPOSE:

           initialize a flattened power-law potential

        INPUT:

           amp - amplitude to be applied to the potential (default: 1)

           alpha - power

           q - flattening

           core - core radius

           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.

        OUTPUT:

           (none)

        HISTORY:

           2013-01-09 - Written - Bovy (IAS)

        """
        Potential.__init__(self,amp=amp)
        self.alpha= alpha
        self.q2= q**2.
        self.core2= core**2.
        if normalize or \
                (isinstance(normalize,(int,float)) \
                     and not isinstance(normalize,bool)): #pragma: no cover
            self.normalize(normalize)
        self.hasC= True
        self.hasC_dxdv= True
    def __init__(self,amp=1.,a=1.,normalize=False):
        """
        NAME:

           __init__

        PURPOSE:

           Initialize a Jaffe 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.

        OUTPUT:

           (none)

        HISTORY:

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

        """
        Potential.__init__(self,amp=amp)
        self.a= a
        self._scale= self.a
        self.alpha= 2
        self.beta= 4
        if normalize or \
                (isinstance(normalize,(int,float)) \
                     and not isinstance(normalize,bool)): #pragma: no cover
            self.normalize(normalize)
        self.hasC= True
        self.hasC_dxdv= True
        return None
Example #21
0
    def __init__(self,amp=1.,a=1.,b=0.1,normalize=False):
        """
        NAME:

           __init__

        PURPOSE:

           initialize a Miyamoto-Nagai potential

        INPUT:

           amp - amplitude to be applied to the potential (default: 1)

           a - "disk scale" (in terms of Ro)

           b - "disk height" (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.

        OUTPUT:

           (none)

        HISTORY:

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

        """
        Potential.__init__(self,amp=amp)
        self._a= a
        self._scale= self._a
        self._b= b
        self._b2= self._b**2.
        if normalize or \
                (isinstance(normalize,(int,float)) \
                     and not isinstance(normalize,bool)):
            self.normalize(normalize)
        self.hasC= True
Example #22
0
 def __init__(self,amp=1.,alpha=1.,normalize=False):
     """
     NAME:
        __init__
     PURPOSE:
        initialize a power-law-density potential
     INPUT:
        amp - amplitude to be applied to the potential (default: 1)
        alpha - inner power
        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.
     OUTPUT:
        (none)
     HISTORY:
        2010-07-10 - Written - Bovy (NYU)
     """
     Potential.__init__(self,amp=amp)
     self.alpha= alpha
     if normalize:
         self.normalize(normalize)
     self.hasC= True
Example #23
0
    def __init__(self, amp=1., a=0., b=0., normalize=False):
        """
        NAME:

           __init__

        PURPOSE:

           initialize a Miyamoto-Nagai potential

        INPUT:

           amp - amplitude to be applied to the potential (default: 1)

           a - "disk scale" (in terms of Ro)

           b - "disk height" (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.

        OUTPUT:

           (none)

        HISTORY:

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

        """
        Potential.__init__(self, amp=amp)
        self._a = a
        self._b = b
        self._b2 = self._b**2.
        if normalize:
            self.normalize(normalize)
        self.hasC = True
 def __init__(self, amp=1., a=1., alpha=1., beta=3., normalize=False):
     """
     NAME:
        __init__
     PURPOSE:
        initialize a two-power-density potential
     INPUT:
        amp - amplitude to be applied to the potential (default: 1)
        a - "scale" (in terms of Ro)
        alpha - inner power
        beta - outer power
        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.
     OUTPUT:
        (none)
     HISTORY:
        2010-07-09 - Started - Bovy (NYU)
     """
     self.a = a
     self.alpha = alpha
     self.beta = beta
     if alpha == round(alpha) and beta == round(beta):
         integerSelf = TwoPowerIntegerSphericalPotential(
             amp=amp,
             a=a,
             alpha=int(alpha),
             beta=int(beta),
             normalize=normalize)
         self.integerSelf = integerSelf
     else:
         Potential.__init__(self, amp=amp)
         self.integerSelf = None
         if normalize:
             self.normalize(normalize)
     return None
Example #25
0
 def __init__(self, formula, w=1):
     Potential.__init__(self, symmetric=False)
     self.formula = formula
     self.w = w
Example #26
0
    def __init__(self, s, 
                 rgrid=(0.01,2.,101), zgrid=(0.,0.2,101), 
                 interpepifreq = False, interpverticalfreq = False, interpPot = True,
                 enable_c = True, logR = False, zsym = True, 
                 numcores=pynbody.config['number_of_threads'], use_pkdgrav = False) : 
        
        # inititalize using the base class
        Potential.__init__(self,amp=1.0)

        # other properties
        self._numcores = numcores
        self._s = s 

        # the interpRZPotential class sets these flags
        self._enable_c = enable_c
        self.hasC = True
                
        # set up the flags for interpolated quantities
        # since the potential and force are always calculated together, 
        # set the force interpolations to true if potential is true and 
        # vice versa
        self._interpPot = interpPot or interpRforce or interpzforce
        self._interpRforce = self._interpPot
        self._interpzforce = self._interpPot
        self._interpvcirc = self._interpPot
        
        # these require additional calculations so set them seperately
        self._interpepifreq = interpepifreq
        self._interpverticalfreq = interpverticalfreq

        # make the potential accessible at points beyond the grid
        self._origPot = SnapshotPotential(s, numcores)

        # setup the grid
        self._zsym = zsym
        self._logR = logR
        
        self._rgrid = np.linspace(*rgrid)
        if logR : 
            self._rgrid = np.exp(self._rgrid)
            self._logrgrid = np.log(self._rgrid)
            rs = self._logrgrid
        else : 
            rs = self._rgrid

        self._zgrid = np.linspace(*zgrid)

        # calculate the grids
        self._setup_potential(self._rgrid,self._zgrid,use_pkdgrav=use_pkdgrav)

        if enable_c and interpPot: 
            self._potGrid_splinecoeffs    = interpRZPotential.calc_2dsplinecoeffs_c(self._potGrid)
            self._rforceGrid_splinecoeffs = interpRZPotential.calc_2dsplinecoeffs_c(self._rforceGrid)
            self._zforceGrid_splinecoeffs = interpRZPotential.calc_2dsplinecoeffs_c(self._zforceGrid)

        else :
            self._potInterp= interpolate.RectBivariateSpline(rs,
                                                             self._zgrid,
                                                             self._potGrid,
                                                             kx=3,ky=3,s=0.)
            self._rforceInterp= interpolate.RectBivariateSpline(rs,
                                                                self._zgrid,
                                                                self._rforceGrid,
                                                                kx=3,ky=3,s=0.)
            self._zforceInterp= interpolate.RectBivariateSpline(rs,
                                                                self._zgrid,
                                                                self._zforceGrid,
                                                                kx=3,ky=3,s=0.)
        if interpepifreq:
            self._R2interp = interpolate.RectBivariateSpline(rs,
                                                             self._zgrid,
                                                             self._R2derivGrid,
                                                             kx=3,ky=3,s=0.)
            
        if interpverticalfreq: 
            self._z2interp = interpolate.RectBivariateSpline(rs,
                                                             self._zgrid,
                                                             self._z2derivGrid,
                                                             kx=3,ky=3,s=0.)
         
        # setup the derived quantities
        if interpPot: 
            self._vcircGrid = np.sqrt(self._rgrid*(-self._rforceGrid[:,0]))
            self._vcircInterp = interpolate.InterpolatedUnivariateSpline(rs, self._vcircGrid, k=3)
        
        if interpepifreq: 
            self._epifreqGrid = np.sqrt(self._R2derivGrid[:,0] - 3./self._rgrid*self._rforceGrid[:,0])
            self._epifreqInterp = interpolate.InterpolatedUnivariateSpline(rs, self._epifreqGrid, k=3)
            
        if interpverticalfreq:
            self._verticalfreqGrid = np.sqrt(np.abs(self._z2derivGrid[:,0]))
            self._verticalfreqInterp = interpolate.InterpolatedUnivariateSpline(rs, self._verticalfreqGrid, k=3)
Example #27
0
    def __init__(self, s, num_threads=pynbody.config['number_of_threads']) : 
        Potential.__init__(self,amp=1.0)

        self._s = s
        self._point_hash = {}
        self._num_threads = num_threads
    def __init__(self,amp=1.,ro=1.,hr=1./3.,hz=1./16.,
                 maxiter=_MAXITER,tol=0.001,normalize=False,
                 new=True,kmaxFac=2.,glorder=10):
        """
        NAME:

           __init__

        PURPOSE:

           initialize a double-exponential disk potential

        INPUT:

           amp - amplitude to be applied to the potential (default: 1)

           hr - disk scale-length in terms of ro

           hz - scale-height

           tol - relative accuracy of potential-evaluations

           maxiter - scipy.integrate keyword

           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.

        OUTPUT:

           DoubleExponentialDiskPotential object

        HISTORY:

           2010-04-16 - Written - Bovy (NYU)

           2013-01-01 - Re-implemented using faster integration techniques - Bovy (IAS)

        """
        Potential.__init__(self,amp=amp)
        self.hasC= True
        self._new= new
        self._kmaxFac= kmaxFac
        self._glorder= glorder
        self._ro= ro
        self._hr= hr
        self._scale= self._hr
        self._hz= hz
        self._alpha= 1./self._hr
        self._beta= 1./self._hz
        self._gamma= self._alpha/self._beta
        self._maxiter= maxiter
        self._tol= tol
        self._zforceNotSetUp= True #We have not calculated a typical Kz yet
        #Setup j0 zeros etc.
        self._glx, self._glw= nu.polynomial.legendre.leggauss(self._glorder)
        self._nzeros=100
        #j0 for potential and z
        self._j0zeros= nu.zeros(self._nzeros+1)
        self._j0zeros[1:self._nzeros+1]= special.jn_zeros(0,self._nzeros)
        self._dj0zeros= self._j0zeros-nu.roll(self._j0zeros,1)
        self._dj0zeros[0]= self._j0zeros[0]
        #j1 for R
        self._j1zeros= nu.zeros(self._nzeros+1)
        self._j1zeros[1:self._nzeros+1]= special.jn_zeros(1,self._nzeros)
        self._dj1zeros= self._j1zeros-nu.roll(self._j1zeros,1)
        self._dj1zeros[0]= self._j1zeros[0]
        #j2 for R2deriv
        self._j2zeros= nu.zeros(self._nzeros+1)
        self._j2zeros[1:self._nzeros+1]= special.jn_zeros(2,self._nzeros)
        self._dj2zeros= self._j2zeros-nu.roll(self._j2zeros,1)
        self._dj2zeros[0]= self._j2zeros[0]
        if normalize or \
                (isinstance(normalize,(int,float)) \
                     and not isinstance(normalize,bool)):
            self.normalize(normalize)
        #Load Kepler potential for large R
        self._kp= KeplerPotential(normalize=4.*nu.pi/self._alpha**2./self._beta)
    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
Example #30
0
__author__ = 'Jullan'
# -*- coding: utf-8 -*-
#Made by Jullan
from Potential import Potential
import pot_functions as V0
import numpy as np

if (__name__ == "__main__"):
    pot1 = Potential(V0.sine_func, 0.0004, 2, label="Sinusoidal-potential")
    pot2 = Potential(V0.const, 0.0004, 226, label="Constant-potential")
    pot3 = Potential(V0.linear_func, 0.0004, 226, label="Linear-potential")
    pot4 = Potential(V0.quadratic_func,
                     0.0004,
                     226,
                     label="Quadratic-potential")
    #pot5 = Potential(V0.exp_func, 0.0004, 226, label="Exponential-potential")
    pot6 = Potential(V0.heaviside, 0.0004, 226, label="Heaviside-potential")
    pot7 = Potential(V0.quartic_func, 0.0004, 226, label="Quartic-potential")

    pots = [pot1, pot2, pot3, pot4, pot6, pot7]
    print(
        "Calculating V(x,y) (with the help of threading) based on the following V_0(x) functions:"
    )
    for pot in pots:
        print("\t" + pot.label)
        pot.start()

    for pot in pots:
        pot.join()

    print("Calculation of V(x,y) potentials done!")
Example #31
0
 def __init__(self,
              RZPot=None,rgrid=(0.01,2.,101),zgrid=(0.,0.2,101),logR=False,
              interpPot=False,interpRforce=False,interpzforce=False,
              interpDens=False,
              interpvcirc=False,
              interpdvcircdr=False,
              interpepifreq=False,interpverticalfreq=False,
              use_c=False,enable_c=False,zsym=True,
              numcores=None):
     """
     NAME:
        __init__
     PURPOSE:
        Initialize an interpRZPotential instance
     INPUT:
        RZPot - RZPotential to be interpolated
        rgrid - R grid to be given to linspace
        zgrid - z grid to be given to linspace
        logR - if True, rgrid is in the log of R
        interpPot, interpRfoce, interpzforce, interpDens,interpvcirc, interpeopifreq, interpverticalfreq, interpdvcircdr= if True, interpolate these functions
        use_c= use C to speed up the calculation
        enable_c= enable use of C for interpolations
        zsym= if True (default), the potential is assumed to be symmetric around z=0 (so you can use, e.g.,  zgrid=(0.,1.,101)).
        numcores= if set to an integer, use this many cores (only used for vcirc, dvcircdR, epifreq, and verticalfreq; NOT NECESSARILY FASTER, TIME TO MAKE SURE)
     OUTPUT:
        instance
     HISTORY:
        2010-07-21 - Written - Bovy (NYU)
        2013-01-24 - Started with new implementation - Bovy (IAS)
     """
     Potential.__init__(self,amp=1.)
     self.hasC= True
     self._origPot= RZPot
     self._rgrid= numpy.linspace(*rgrid)
     self._logR= logR
     if self._logR:
         self._rgrid= numpy.exp(self._rgrid)
         self._logrgrid= numpy.log(self._rgrid)
     self._zgrid= numpy.linspace(*zgrid)
     self._interpPot= interpPot
     self._interpRforce= interpRforce
     self._interpzforce= interpzforce
     self._interpDens= interpDens
     self._interpvcirc= interpvcirc
     self._interpdvcircdr= interpdvcircdr
     self._interpepifreq= interpepifreq
     self._interpverticalfreq= interpverticalfreq
     self._enable_c= enable_c*ext_loaded
     self._zsym= zsym
     if interpPot:
         if use_c*ext_loaded:
             self._potGrid, err= calc_potential_c(self._origPot,self._rgrid,self._zgrid)
         else:
             from galpy.potential import evaluatePotentials
             potGrid= numpy.zeros((len(self._rgrid),len(self._zgrid)))
             for ii in range(len(self._rgrid)):
                 for jj in range(len(self._zgrid)):
                     potGrid[ii,jj]= evaluatePotentials(self._rgrid[ii],self._zgrid[jj],self._origPot)
             self._potGrid= potGrid
         if self._logR:
             self._potInterp= interpolate.RectBivariateSpline(self._logrgrid,
                                                              self._zgrid,
                                                              self._potGrid,
                                                              kx=3,ky=3,s=0.)
         else:
             self._potInterp= interpolate.RectBivariateSpline(self._rgrid,
                                                              self._zgrid,
                                                              self._potGrid,
                                                              kx=3,ky=3,s=0.)
         if enable_c*ext_loaded:
             self._potGrid_splinecoeffs= calc_2dsplinecoeffs_c(self._potGrid)
     if interpRforce:
         if use_c*ext_loaded:
             self._rforceGrid, err= calc_potential_c(self._origPot,self._rgrid,self._zgrid,rforce=True)
         else:
             from galpy.potential import evaluateRforces
             rforceGrid= numpy.zeros((len(self._rgrid),len(self._zgrid)))
             for ii in range(len(self._rgrid)):
                 for jj in range(len(self._zgrid)):
                     rforceGrid[ii,jj]= evaluateRforces(self._rgrid[ii],self._zgrid[jj],self._origPot)
             self._rforceGrid= rforceGrid
         if self._logR:
             self._rforceInterp= interpolate.RectBivariateSpline(self._logrgrid,
                                                                 self._zgrid,
                                                                 self._rforceGrid,
                                                                 kx=3,ky=3,s=0.)
         else:
             self._rforceInterp= interpolate.RectBivariateSpline(self._rgrid,
                                                                 self._zgrid,
                                                                 self._rforceGrid,
                                                                 kx=3,ky=3,s=0.)
         if enable_c*ext_loaded:
             self._rforceGrid_splinecoeffs= calc_2dsplinecoeffs_c(self._rforceGrid)
     if interpzforce:
         if use_c*ext_loaded:
             self._zforceGrid, err= calc_potential_c(self._origPot,self._rgrid,self._zgrid,zforce=True)
         else:
             from galpy.potential import evaluatezforces
             zforceGrid= numpy.zeros((len(self._rgrid),len(self._zgrid)))
             for ii in range(len(self._rgrid)):
                 for jj in range(len(self._zgrid)):
                     zforceGrid[ii,jj]= evaluatezforces(self._rgrid[ii],self._zgrid[jj],self._origPot)
             self._zforceGrid= zforceGrid
         if self._logR:
             self._zforceInterp= interpolate.RectBivariateSpline(self._logrgrid,
                                                                 self._zgrid,
                                                                 self._zforceGrid,
                                                                 kx=3,ky=3,s=0.)
         else:
             self._zforceInterp= interpolate.RectBivariateSpline(self._rgrid,
                                                                 self._zgrid,
                                                                 self._zforceGrid,
                                                                 kx=3,ky=3,s=0.)
         if enable_c*ext_loaded:
             self._zforceGrid_splinecoeffs= calc_2dsplinecoeffs_c(self._zforceGrid)
     if interpDens:
         if False:
             raise NotImplementedError("Using C to calculate an interpolation grid for the density is not supported currently")
             self._densGrid, err= calc_dens_c(self._origPot,self._rgrid,self._zgrid)
         else:
             from galpy.potential import evaluateDensities
             densGrid= numpy.zeros((len(self._rgrid),len(self._zgrid)))
             for ii in range(len(self._rgrid)):
                 for jj in range(len(self._zgrid)):
                     densGrid[ii,jj]= evaluateDensities(self._rgrid[ii],self._zgrid[jj],self._origPot)
             self._densGrid= densGrid
         if self._logR:
             self._densInterp= interpolate.RectBivariateSpline(self._logrgrid,
                                                               self._zgrid,
                                                               numpy.log(self._densGrid+10.**-10.),
                                                               kx=3,ky=3,s=0.)
         else:
             self._densInterp= interpolate.RectBivariateSpline(self._rgrid,
                                                               self._zgrid,
                                                               numpy.log(self._densGrid+10.**-10.),
                                                               kx=3,ky=3,s=0.)
         if False:
             self._densGrid_splinecoeffs= calc_2dsplinecoeffs_c(self._densGrid)
     if interpvcirc:
         from galpy.potential import vcirc
         if not numcores is None:
             self._vcircGrid= multi.parallel_map((lambda x: vcirc(self._origPot,self._rgrid[x])),
                                                 range(len(self._rgrid)),numcores=numcores)
         else:
             self._vcircGrid= numpy.array([vcirc(self._origPot,r) for r in self._rgrid])
         if self._logR:
             self._vcircInterp= interpolate.InterpolatedUnivariateSpline(self._logrgrid,self._vcircGrid,k=3)
         else:
             self._vcircInterp= interpolate.InterpolatedUnivariateSpline(self._rgrid,self._vcircGrid,k=3)
     if interpdvcircdr:
         from galpy.potential import dvcircdR
         if not numcores is None:
             self._dvcircdrGrid= multi.parallel_map((lambda x: dvcircdR(self._origPot,self._rgrid[x])),
                                                    range(len(self._rgrid)),numcores=numcores)
         else:
             self._dvcircdrGrid= numpy.array([dvcircdR(self._origPot,r) for r in self._rgrid])
         if self._logR:
             self._dvcircdrInterp= interpolate.InterpolatedUnivariateSpline(self._logrgrid,self._dvcircdrGrid,k=3)
         else:
             self._dvcircdrInterp= interpolate.InterpolatedUnivariateSpline(self._rgrid,self._dvcircdrGrid,k=3)
     if interpepifreq:
         from galpy.potential import epifreq
         if not numcores is None:
             self._epifreqGrid= multi.parallel_map((lambda x: epifreq(self._origPot,self._rgrid[x])),
                                                   range(len(self._rgrid)),numcores=numcores)
         else:
             self._epifreqGrid= numpy.array([epifreq(self._origPot,r) for r in self._rgrid])
         indx= True-numpy.isnan(self._epifreqGrid)
         if numpy.sum(indx) < 4:
             if self._logR:
                 self._epifreqInterp= interpolate.InterpolatedUnivariateSpline(self._logrgrid[indx],self._epifreqGrid[indx],k=1)
             else:
                 self._epifreqInterp= interpolate.InterpolatedUnivariateSpline(self._rgrid[indx],self._epifreqGrid[indx],k=1)
         else:
             if self._logR:
                 self._epifreqInterp= interpolate.InterpolatedUnivariateSpline(self._logrgrid[indx],self._epifreqGrid[indx],k=3)
             else:
                 self._epifreqInterp= interpolate.InterpolatedUnivariateSpline(self._rgrid[indx],self._epifreqGrid[indx],k=3)
     if interpverticalfreq:
         from galpy.potential import verticalfreq
         if not numcores is None:
             self._verticalfreqGrid= multi.parallel_map((lambda x: verticalfreq(self._origPot,self._rgrid[x])),
                                                    range(len(self._rgrid)),numcores=numcores)
         else:
             self._verticalfreqGrid= numpy.array([verticalfreq(self._origPot,r) for r in self._rgrid])
         if self._logR:
             self._verticalfreqInterp= interpolate.InterpolatedUnivariateSpline(self._logrgrid,self._verticalfreqGrid,k=3)
         else:
             self._verticalfreqInterp= interpolate.InterpolatedUnivariateSpline(self._rgrid,self._verticalfreqGrid,k=3)
     return None
Example #32
0
 def __init__(self):
     Potential.__init__(self, symmetric=False)