How to use the galpy.potential function in galpy

To help you get started, we’ve selected a few galpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GalacticDynamics-Oxford / Agama / pytests / pygama.py View on Github external
def __init__(self,*args,**kwargs):
            """
            Initialize a potential from parameters provided in an INI file
            or as named arguments to the constructor.
            Arguments are the same as for regular agama.Potential (see below);
            an extra keyword "normalize=..." has the same meaning as in Galpy:
            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.

            """
            galpy.potential.Potential.__init__(self,amp=1.)
            normalize=False
            for key, value in kwargs.items():
                if key=="normalize":
                    normalize=value
                    del kwargs[key]
            self._pot = Potential(*args,**kwargs)  # regular Agama potential
            if normalize or \
                    (isinstance(normalize,(int,float)) \
                        and not isinstance(normalize,bool)):
                self.normalize(normalize)
            self.hasC= False
            self.hasC_dxdv=False
        __init__.__doc__ += Potential.__doc__
github GalacticDynamics-Oxford / Agama / pytests / galpy_agama.py View on Github external
#!/usr/bin/python
### This module allows to use potentials from the AGAMA C++ library as regular galpy potentials

import math
import agama, galpy
from galpy.potential import Potential
class CPotential(galpy.potential.Potential):
    """Class that implements an interface to C++ potentials
    """
    def __init__(self,*args,**kwargs):
        """
        NAME:
           __init__
        PURPOSE:
           initialize a potential from parameters provided in an INI file
           or as named arguments to the constructor (see below).
        INPUT:
           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.
        HISTORY:
           2014-12-05 EV
        """
github GalacticDynamics-Oxford / Agama / pytests / pygama.py View on Github external
r=[0.01, 0.0, 0.4, 0.5, 0.3, 0.0, 0.7, 1.0, 1.0, 1.0, 0.9]
    g=[0.01, 0.0, 0.85,1.0, 1.0, 0.9, 1.0, 1.0, 0.85,0.0, 0.9]
    b=[0.01, 1.0, 1.0, 1.0, 0.7, 0.0, 0.0, 0.0, 0.0, 0.0, 0.9]
    matplotlib.pyplot.register_cmap(cmap=matplotlib.colors.LinearSegmentedColormap('sauron', \
        { 'red': zip(f,r,r), 'green': zip(f,g,g), 'blue': zip(f,b,b) } ))
    matplotlib.pyplot.register_cmap(cmap=matplotlib.colors.LinearSegmentedColormap('sauron_r', \
        { 'red': zip(f,r[::-1],r[::-1]), 'green': zip(f,g[::-1],g[::-1]), 'blue': zip(f,b[::-1],b[::-1]) } ))
    del f; del r; del g; del b;  # remove the temporary variables from the module namespace

except ImportError: pass   # no matplotlib - no problem


try:
    # This wrapper class allows to use Agama potentials as regular galpy potentials
    import galpy.potential
    class AgamaPotential(galpy.potential.Potential):
        """
        Class that implements a Galpy interface to Agama potentials
        """
        def __init__(self,*args,**kwargs):
            """
            Initialize a potential from parameters provided in an INI file
            or as named arguments to the constructor.
            Arguments are the same as for regular agama.Potential (see below);
            an extra keyword "normalize=..." has the same meaning as in Galpy:
            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.

            """
            galpy.potential.Potential.__init__(self,amp=1.)
            normalize=False