        Animate a previously calculated orbit in 3D (with reasonable defaults).

        Parameters
        ----------
        d1 : str
            First dimension to plot ('x', 'y', 'R', 'vR', 'vT', 'z', 'vz', ...), can only be a single entry.
        d2 : str
            Second dimension to plot. Same format as d1.
        d3 : str
            Third dimension to plot. Same format as d1.
        width : int, optional
            Width of output div in px, by default 800.
        height : int, optional
            Height of output div in px, by default 600.
        mw_plane_bg : bool, optional
            Whether to add a Milky Way plane when plotting x, y, z, by default False.
        xlabel : str or list, optional
            Label for the first dimension; should only have to be specified when using a function as d1.
        ylabel : str or list, optional
            Label for the second dimension; should only have to be specified when using a function as d2.
        zlabel : str or list, optional
            Label for the third dimension; should only have to be specified when using a function as d3.
        json_filename : str, optional
            If set, save the data necessary for the figure in this filename (e.g.,  json_filename= 'orbit_data/orbit.json'); this path is also used in the output HTML, so needs to be accessible, by default None.
        ro : float or Quantity, optional
            Physical scale in kpc for distances to use to convert, Default is the object-wide default.
        vo : float or Quantity, optional
            Physical scale for velocities in km/s to use to convert, by default None. Default is the object-wide default.
        use_physical : bool, optional
            Use to override object-wide default for using a physical scale for output.

        Returns
        -------
        IPython.display.HTML
            Object with code to animate the orbit; can be directly shown in jupyter notebook or embedded in HTML pages; get a text version of the HTML using the _repr_html_() function.

        Notes
        -----
        - 2022-12-09 - Written - Henry Leung (UofT)


    Query Simbad for the phase-space coordinates of one object.

    Parameters
    ----------
    name : str
        Name of the object.
    obs : numpy.ndarray, optional
        Array of [ro, vo, zo, solarmotion] that can be altered.

    Returns
    -------
    list
        A list of [ra, dec, dist, pmra, pmdec, vlos].

    Notes
    -----
    - 2018-07-15 - Written - Mathew Bub (UofT)
    - 2019-06-16 - Added named_objects - Bovy (UofT)


Fit an orbit to data in a given potential


The log likelihood for fitting an orbit


Function to check whether ro is set, because it's required for funcName


Function to check whether vo is set, because it's required for funcName


Calculate heliocentric rectangular coordinates


Calculate l,b, and d


Calculate pmra and pmdec


Check that the stepsize in t is an integer x dt


parse the integrator method to pass to C


Parse the tolerance keywords


    Integrate an ode for a planarOrbit.

    Parameters
    ----------
    pot : Potential or list of such instances
    yo : numpy.ndarray
        Initial condition [q,p], can be [N,4] or [4].
    t : numpy.ndarray
        Set of times at which one wants the result.
    int_method : str
        Integration method. Options are 'leapfrog_c', 'rk4_c', 'rk6_c', 'symplec4_c', ...
    rtol : float, optional
        Relative tolerance.
    atol : float, optional
        Absolute tolerance.
    progressbar : bool, optional
        If True, display a tqdm progress bar when integrating multiple orbits (requires tqdm to be installed!).
    dt : float, optional
        Force integrator to use this stepsize (default is to automatically determine one).

    Returns
    -------
    tuple
        (y,err)
        y : array, shape (len(y0),len(t),4)
            Array containing the value of y for each desired time in t, with the initial value y0 in the first row.
        err : int
            Error message, if not zero: 1 means maximum step reduction happened for adaptive integrators.

    Notes
    -----
    - 2011-10-03 - Written - Bovy (IAS)
    - 2018-12-20 - Adapted to allow multiple objects - Bovy (UofT)
    - 2022-04-12 - Add progressbar - Bovy (UofT)


    Integrate an ode for a planarOrbit+phase space volume dxdv

    Parameters
    ----------
    pot : Potential or list of such instances
    yo : numpy.ndarray
        Initial condition [q,p]
    dyo : numpy.ndarray
        Initial condition [dq,dp]
    t : numpy.ndarray
        Set of times at which one wants the result
    int_method : str
        Integration method. One of 'leapfrog_c', 'rk4_c', 'rk6_c', 'symplec4_c'
    rtol : float, optional
        Relative tolerance. Default is None
    atol : float, optional
        Absolute tolerance. Default is None
    dt : float, optional
        Force integrator to use this stepsize (default is to automatically determine one)

    Returns
    -------
    tuple
        (y,err)
        y,dy : array, shape (len(y0),len(t),8)
        Array containing the value of y for each desired time in t, \
        with the initial value y0 in the first row.
        err: error message if not zero, 1: maximum step reduction happened for adaptive integrators

    Notes
    -----
    - 2011-10-19 - Written - Bovy (IAS)


    Integrate an ode for a planarOrbit

    Parameters
    ----------
    pot : Potential or list of such instances
    yo : numpy.ndarray
        Initial condition [q,p], shape [N,3] or [N,4]
    t : numpy.ndarray
        Set of times at which one wants the result
    int_method : str
        Integration method. One of 'leapfrog', 'odeint', 'dop853'
    rtol : float, optional
        Relative tolerance. Default is None
    atol : float, optional
        Absolute tolerance. Default is None
    numcores : int, optional
        Number of cores to use for multi-processing
    progressbar : bool, optional
        If True, display a tqdm progress bar when integrating multiple orbits (requires tqdm to be installed!).
    dt : float, optional
        Force integrator to use this stepsize (default is to automatically determine one)

    Returns
    -------
    tuple
        (y,err)
        y : array, shape (N,len(t),3/4)
        Array containing the value of y for each desired time in t, \
        with the initial value y0 in the first row.
        err: error message, always zero for now

    Notes
    -----
    - 2010-07-20 - Written - Bovy (NYU)
    - 2019-04-09 - Adapted to allow multiple objects and parallel mapping - Bovy (UofT)
    - 2022-04-12 - Add progressbar - Bovy (UofT)


    Integrate an ode for a planarOrbit+phase space volume dxdv

    Parameters
    ----------
    pot : Potential or list of such instances
    yo : numpy.ndarray
        Initial condition [q,p], shape [N,4]
    dyo : numpy.ndarray
        Initial condition [dq,dp], shape [N,4]
    t : numpy.ndarray
        Set of times at which one wants the result
    int_method : str
        Integration method. One of 'leapfrog', 'odeint', 'dop853'
    rectIn : bool
        If True, input dyo is in rectangular coordinates
    rectOut : bool
        If True, output dyo is in rectangular coordinates
    rtol : float, optional
        Relative tolerance. Default is None
    atol : float, optional
        Absolute tolerance. Default is None
    progressbar : bool, optional
        If True, display a tqdm progress bar when integrating multiple orbits (requires tqdm to be installed!).
    dt : float, optional
        Force integrator to use this stepsize (default is to automatically determine one)
    numcores : int, optional
        Number of cores to use for multi-processing

    Returns
    -------
    tuple
        (y,err)
        y,dy : array, shape (N,len(t),8)
        Array containing the value of y for each desired time in t, \
        with the initial value y0 in the first row.
        err: error message if not zero, 1: maximum step reduction happened for adaptive integrators

    Notes
    -----
    - 2011-10-17 - Written - Bovy (IAS)
    - 2019-05-21 - Adapted to allow multiple objects and parallel mapping - Bovy (UofT)
    - 2022-04-12 - Add progressbar - Bovy (UofT)


    Integrate an ode for a PlanarOrbit for integrate_sos in C

    Parameters
    ----------
    pot : Potential or list of such instances
    yo : numpy.ndarray
        Initial condition [q,p], shape [N,5] or [N,6]
    psi : numpy.ndarray
        Set of increment angles at which one wants the result [increments wrt initial angle]
    t0 : float or numpy.ndarray
        Initial time
    int_method : str
        'rk4_c', 'rk6_c', 'dopr54_c', or 'dop853_c'
    surface : str, optional
        Surface to use ('x' for finding x=0, vx>0; 'y' for finding y=0, vy>0), by default "x"
    rtol : float, optional
        Relative tolerance, by default None
    atol : float, optional
        Absolute tolerance, by default None
    progressbar : bool, optional
        If True, display a tqdm progress bar when integrating multiple orbits (requires tqdm to be installed!), by default True
    dpsi : float, optional
        Force integrator to use this stepsize (default is to automatically determine one; only for C-based integrators), by default None

    Returns
    -------
    tuple
        (y,err)
        y : array, shape (N,len(psi),5) where the last of the last dimension is the time
            Array containing the value of y for each desired angle in psi, with the initial value y0 in the first row.
        err : int
            Error message, always zero for now

    Notes
    -----
    - 2023-03-17 - Written based on integrateFullOrbit_sos_c - Bovy (UofT)


    Integrate an ode for a PlanarOrbit for integrate_sos

    Parameters
    ----------
    pot : Potential or list of such instances
    yo : numpy.ndarray
        Initial condition [q,p], shape [N,5] or [N,6]
    psi : numpy.ndarray
        Set of increment angles at which one wants the result [increments wrt initial angle]
    t0 : float or numpy.ndarray
        Initial time
    surface : str, optional
        Surface to use ('x' for finding x=0, vx>0; 'y' for finding y=0, vy>0), by default "x"
    int_method : str
        Integration method to use. One of 'leapfrog', 'odeint', or 'dop853'
    rtol : float, optional
        Relative tolerance, by default None
    atol : float, optional
        Absolute tolerance, by default None
    numcores : int, optional
        Number of cores to use for multi-processing, by default 1
    progressbar : bool, optional
        If True, display a tqdm progress bar when integrating multiple orbits (requires tqdm to be installed!), by default True
    dpsi : float, optional
        Force integrator to use this stepsize (default is to automatically determine one; only for C-based integrators), by default None

    Returns
    -------
    tuple
        (y,err)
        y : array, shape (N,len(psi),4/5) where the last of the last dimension is the time
            Array containing the value of y for each desired angle in psi, with the initial value y0 in the first row.
        err : int
            Error message, always zero for now

    Notes
    -----
    - 2023-03-24 - Written based on integrateFullOrbi_sos - Bovy (UofT)


    Implements the EOM, i.e., the right-hand side of the differential
    equation, for integrating a planar Orbit assuming angular momentum
    conservation.

    Parameters
    ----------
    y : numpy.ndarray
        Current phase-space position.
    t : float
        Current time.
    pot : list of Potential instance(s)
        Potential instance(s).
    l2 : float
        Angular momentum squared.

    Returns
    -------
    numpy.ndarray
        dy/dt.

    Notes
    -----
    - 2010-07-20 - Written - Bovy (NYU)


    Implements the EOM, i.e., the right-hand side of the differential equation, for integrating a general planar Orbit

    Parameters
    ----------
    y : numpy.ndarray
        Current phase-space position
    t : float
        Current time
    pot : (list of) Potential instance(s)

    Returns
    -------
    numpy.ndarray
        dy/dt

    Notes
    -----
    - 2010-07-20 - Written - Bovy (NYU)


    Implements the EOM, i.e., the right-hand side of the differential
    equation, for integrating phase space differences, rectangular

    Parameters
    ----------
    x : numpy.ndarray
        Current phase-space position
    t : float
        Current time
    pot : (list of) Potential instance(s)

    Returns
    -------
    numpy.ndarray
        dy/dt

    Notes
    -----
    - 2011-10-18 - Written - Bovy (IAS)


    Implements the EOM, i.e., the right-hand side of the differential
    equation, for integrating a general planar Orbit in the SOS style

    Parameters
    ----------
    y : numpy.ndarray
        Current phase-space position
    psi : float
        Current angle
    pot : (list of) Potential instance(s)

    Returns
    -------
    numpy.ndarray
        dy/dt

    Notes
    -----
    - 2023-03-24 - Written - Bovy (UofT)


    Implements the EOM, i.e., the right-hand side of the differential
    equation, for integrating a general planar Orbit in the SOS style

    Parameters
    ----------
    y : numpy.ndarray
        Current phase-space position
    psi : float
        Current angle
    pot : list of Potential instance(s)
        Potential instance(s)

    Returns
    -------
    numpy.ndarray
        dy/dt

    Notes
    -----
    - 2023-03-24 - Written - Bovy (UofT)


    Returns the planar force in the rectangular frame.

    Parameters
    ----------
    x : numpy.ndarray
        Current position.
    t : float, optional
        Current time (default is 0.0).
    pot : list or Potential instance(s)
        Potential instance(s).
    vx : numpy.ndarray, optional
        If set, use this [vx,vy] when evaluating dissipative forces (default is None).

    Returns
    -------
    numpy.ndarray
        Force.

    Notes
    -----
    - 2011-02-02 - Written - Bovy (NYU)


        Return the wavenumber at radius R (d f(R)/ d R in Phi_a(R) = F(R) e^[i f(R)]; see Binney & Tremaine 2008)

        Parameters
        ----------
        R : float
            Cylindrical radius

        Returns
        -------
        float
            wavenumber at R

        Notes
        -----
        - 2014-08-23 - Written - Bovy (IAS)


        Return the number of arms.

        Returns
        -------
        int
            Number of arms.

        Notes
        -----
        - 2014-08-23 - Written - Bovy (IAS)


        Return formation time of the bar.

        Returns
        -------
        tform : float
            Formation time of the bar in normalized units.

        Notes
        -----
        - 2011-03-08 - Written - Bovy (NYU)


Derivative of the density as a function of m


Evaluation of the potential as a function of (x,y,z) in the
        aligned coordinate frame


Evaluation of the i-th force component as a function of (x,y,z)


General 2nd derivative of the potential as a function of (x,y,z)
        in the aligned coordinate frame


Integral that gives the force in x,y,z


Integral that gives the 2nd derivative of the potential in x,y,z


Potential as a function of r and time


        Evaluate the radial density derivative x r^(2beta) for this potential.

        Parameters
        ----------
        r : float
            Spherical radius.
        beta : float, optional
            Power of r in the density derivative. Default is 0.

        Returns
        -------
        float
            The derivative of the density times r^(2beta).

        Notes
        -----
        - 2021-02-14 - Written - Bovy (UofT)


        Return the accpars potential parameters for use of this potential with NEMO.

        Parameters
        ----------
        vo : float
            Velocity unit in km/s.
        ro : float
            Length unit in kpc.

        Returns
        -------
        str
            accpars string.

        Notes
        -----
        - 2018-09-14 - Written - Bovy (UofT)


        Calculate the virial radius for this density distribution.

        Parameters
        ----------
        H : float, optional
            Hubble constant in km/s/Mpc. Default is 70.0.
        Om : float, optional
            Omega matter. Default is 0.3.
        t : float, optional
            Time. Default is 0.0.
        overdens : float, optional
            Overdensity which defines the virial radius. Default is 200.0.
        wrtcrit : bool, optional
            If True, the overdensity is wrt the critical density rather than the mean matter density. Default is False.
        ro : float or Quantity, optional
            Distance scale for translation into internal units (default is the object-wide value).
        vo : float or Quantity, optional
            Velocity scale for translation into internal units (default is the object-wide value).

        Returns
        -------
        float
            Virial radius.

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


        Calculate the radius at which the rotation curve peaks.

        Returns
        -------
        float
            Radius at which the rotation curve peaks.

        Notes
        -----
        - 2020-02-05 - Written - Bovy (UofT)


        Calculate the maximum rotation curve velocity.

        Returns
        -------
        float
            Peak velocity in the rotation curve.

        Notes
        -----
        - 2020-02-05 - Written - Bovy (UofT)


        Return the accpars potential parameters for use of this potential with NEMO

        Parameters
        ----------
        vo : float
            Velocity unit in km/s
        ro : float
            Length unit in kpc

        Returns
        -------
        str
            accpars string

        Notes
        -----
        - 2014-12-18 - Written - Bovy (IAS)


        Turn off automatic returning of outputs in physical units.

        Returns
        -------
        None

        Notes
        -----
        - 2016-01-30 - Written - Bovy (UofT)


        Turn on automatic returning of outputs in physical units.

        Parameters
        ----------
        ro : float or Quantity, optional
            Reference distance (kpc).
        vo : float or Quantity, optional
            Reference velocity (km/s).

        Returns
        -------
        None

        Notes
        -----
        - 2016-01-30 - Written - Bovy (UofT)
        - 2020-04-22 - Don't turn on a parameter when it is False - Bovy (UofT)


        Evaluate the force.

        Parameters
        ----------
        x : float or Quantity
            Position.
        t : float or Quantity, optional
            Time (default: 0.0).

        Returns
        -------
        float or Quantity
            Force at position x and time t.

        Notes
        -----
        - 2010-07-12 - Written - Bovy (NYU)


        Plot the potential

        Parameters
        ----------
        t : float or Quantity, optional
            The time at which to evaluate the forces. Default is 0.0.
        min : float, optional
            Minimum x.
        max : float, optional
            Maximum x.
        ns : int, optional
            Grid in x.
        savefilename : str, optional
            Save to or restore from this savefile (pickle).

        Returns
        -------
        plot to output device

        Notes
        -----
        - 2010-07-13 - Written - Bovy (NYU)


    Evaluate the sum of a list of potentials.

    Parameters
    ----------
    Pot : list of linearPotential instance(s)
        The list of potentials to evaluate.
    x : float or Quantity
        The position at which to evaluate the potentials.
    t : float or Quantity, optional
        The time at which to evaluate the potentials. Default is 0.0.

    Returns
    -------
    float or Quantity
        The value of the potential at the given position and time.

    Notes
    -----
    - 2010-07-13 - Written - Bovy (NYU)


Raw, undecorated function for internal use


    Evaluate the forces due to a list of potentials.

    Parameters
    ----------
    Pot : list of linearPotential instance(s)
        The list of potentials to evaluate.
    x : float or Quantity
        The position at which to evaluate the forces.
    t : float or Quantity, optional
        The time at which to evaluate the forces. Default is 0.0.

    Returns
    -------
    float or Quantity
        The value of the forces at the given position and time.

    Notes
    -----
    - 2010-07-13 - Written - Bovy (NYU)


    Plot a combination of potentials

    Parameters
    ----------
    Pot : list of linearPotential instance(s)
        The list of potentials to evaluate.
    t : float or Quantity, optional
        The time at which to evaluate the forces. Default is 0.0.
    min : float, optional
        Minimum x.
    max : float, optional
        Maximum x.
    ns : int, optional
        Grid in x.
    savefilename : str, optional
        Save to or restore from this savefile (pickle).

    Returns
    -------
    plot to output device

    Notes
    -----
    - 2010-07-13 - Written - Bovy (NYU)


        Evaluate cylindrical radial force F_R  (R,z).

        Parameters
        ----------
        R : float or Quantity
            Cylindrical Galactocentric radius.
        z : float or Quantity
            Vertical height.
        phi : float or Quantity, optional
            Azimuth. Default is 0.0.
        t : float or Quantity, optional
            Time. Default is 0.0.
        v : numpy.ndarray, optional
            3D velocity. Default is None.

        Returns
        -------
        float or Quantity
            Cylindrical radial force F_R (R,z,phi,t,v).

        Notes
        -----
        - 2018-03-18 - Written - Bovy (UofT)


        Evaluate the vertical force F_z  (R,z,t).

        Parameters
        ----------
        R : float or Quantity
            Cylindrical Galactocentric radius.
        z : float or Quantity
            Vertical height.
        phi : float or Quantity, optional
            Azimuth. Default is 0.0.
        t : float or Quantity, optional
            Time. Default is 0.0.
        v : numpy.ndarray, optional
            3D velocity. Default is None.

        Returns
        -------
        float or Quantity
            Vertical force F_z (R,z,phi,t,v).

        Notes
        -----
        - 2018-03-16 - Written - Bovy (UofT)


        Evaluate the azimuthal torque F_phi  (R,z,phi,t,v).

        Parameters
        ----------
        R : float or Quantity
            Cylindrical Galactocentric radius.
        z : float or Quantity
            Vertical height.
        phi : float or Quantity, optional
            Azimuth. Default is 0.0.
        t : float or Quantity, optional
            Time. Default is 0.0.
        v : numpy.ndarray, optional
            3D velocity. Default is None.

        Returns
        -------
        float or Quantity
            Azimuthal torque F_phi (R,z,phi,t,v).

        Notes
        -----
        - 2018-03-16 - Written - Bovy (UofT)


    Determine whether this combination of potentials and forces is Dissipative

    Parameters
    ----------
    obj : Potential/DissipativeForce instance or list of such instances

    Returns
    -------
    bool
        True or False depending on whether the object is dissipative

    Notes
    -----
    - 2018-03-16 - Written - Bovy (UofT)
    - 2023-05-29 - Adjusted to also take planarDissipativeForces into account - Bovy (UofT)


Evaluation of the x force as a function of (x,y,z) in the aligned
        coordinate frame


Evaluation of the y force as a function of (x,y,z) in the aligned
        coordinate frame


Evaluation of the z force as a function of (x,y,z) in the aligned
        coordinate frame


r"""General 2nd derivative of the potential as a function of (x,y,z)
        in the aligned coordinate frame, d^2\Phi/dx_i/dx_j


2D Rotation matrix for non-zero pa or pattern speed
        to goto the aligned coordinates


Integral involved in the potential at (x,y,z)
    integrates 1/A B^(n+1) where
    A = sqrt((tau+a)(tau+b)(tau+c)) and B = (1-x^2/(tau+a)-y^2/(tau+b)-z^2/(tau+c))
    from lambda to infty with respect to tau.
    The lower limit lambda is given by lowerlim function.


Integral involved in the force at (x,y,z)
    integrates 1/A B^n (x_i/(tau+a_i)) where
    A = sqrt((tau+a)(tau+b)(tau+c)) and B = (1-x^2/(tau+a)-y^2/(tau+b)-z^2/(tau+c))
    from lambda to infty with respect to tau.
    The lower limit lambda is given by lowerlim function.


r"""Integral involved in second derivatives d^\Phi/(dx_i dx_j)
    integrate
        1/A B^(n-1) (-2 x_i/(tau+a_i)) (-2 x_j/(tau+a_j))
    when i /= j or
        1/A [ B^(n-1) 4n x_i^2 / (a_i+t)^2 + B^n -(-2/(a_i+t)) ]
    when i == j where
    A = sqrt((tau+a)(tau+b)(tau+c)) and B = (1-x^2/(tau+a)-y^2/(tau+b)-z^2/(tau+c))
    from lambda to infty with respect to tau
    The lower limit lambda is given by lowerlim function.
    This is a second derivative of _potInt.


Returns the real positive root of
      x/(a+t) + y/(b+t) + z/(c+t) = 1
    when x/a + y/b + z/c > 1 else zero


        Turn on automatic returning of outputs in physical units.

        Parameters
        ----------
        ro : float or Quantity, optional
            Reference distance in kpc. Default is None.
        vo : float or Quantity, optional
            Reference velocity in km/s. Default is None.

        Returns
        -------
        None

        Notes
        -----
        - 2016-01-30 - Written - Bovy (UofT)
        - 2020-04-22 - Don't turn on a parameter when it is False - Bovy (UofT)


        Evaluate the spherical radial force F_r (R,z).

        Parameters
        ----------
        R : float or Quantity
            Cylindrical Galactocentric radius.
        z : float or Quantity
            Vertical height.
        phi : float or Quantity, optional
            Azimuth. Default is None.
        t : float or Quantity, optional
            Time. Default is 0.0.
        v : float or Quantity, optional
            Current velocity in cylindrical coordinates. Required when including dissipative forces. Default is None.

        Returns
        -------
        F_r : float or Quantity
            The spherical radial force F_r (R,z).

        Notes
        -----
        - 2016-06-20 - Written - Bovy (UofT)


        Convert a 3D potential into a planar potential in the mid-plane.

        Returns
        -------
        planarPotential, planarAxiPotential, or planarDissipativeForce instance


        Return formation time of the bar.

        Returns
        -------
        tform : float
            Formation time of the bar in normalized units.

        Other Parameters
        ----------------
        none

        Notes
        -----
        - 2011-03-08 - Written - Bovy (NYU)


        Return the pattern speed.

        Returns
        -------
        float
            The pattern speed.

        Notes
        -----
        - 2011-10-10 - Written - Bovy (IAS)


The density corresponding to phi_ME


        Initialize an SCF Potential from a given density.

        Parameters
        ----------
        dens : function
            Density function that takes parameters R, z and phi; z and phi are optional for spherical profiles, phi is optional for axisymmetric profiles. The density function must take input positions in internal units (R/ro, z/ro), but can return densities in physical units. You can use the member dens of Potential instances or the density from evaluateDensities.
        N : int
            Number of radial basis functions.
        L : int, optional
            Number of costheta basis functions; for non-axisymmetric profiles also sets the number of azimuthal (phi) basis functions to M = 2L+1).
        a : float or Quantity, optional
            Expansion scale length.
        symmetry : {'spherical','axisymmetry',None}, optional
            Symmetry of the profile to assume. None is the general, non-axisymmetric case.
        radial_order : int, optional
            Number of sample points for the radial integral. If None, radial_order=max(20, N + 3/2L + 1).
        costheta_order : int, optional
            Number of sample points of the costheta integral. If None, If costheta_order=max(20, L + 1).
        phi_order : int, optional
            Number of sample points of the phi integral. If None, If costheta_order=max(20, L + 1).
        ro : float or Quantity, optional
            Distance scale for translation into internal units (default from configuration file).
        vo : float or Quantity, optional
            Velocity scale for translation into internal units (default from configuration file).

        Returns
        -------
        SCFPotential object

        Notes
        -----
        - Written - Jo Bovy (UofT) - 2022-06-20


        Evaluate the square root of equation (3.15) with the (2 - del_m,0) term outside the square root.

        Parameters
        ----------
        L : int
            Evaluate Nroot for 0 <= l <= L.
        M : int
            Evaluate Nroot for 0 <= m <= M.

        Returns
        -------
        numpy.ndarray
            The square root of equation (3.15) with the (2 - del_m,0) outside.

        Notes
        -----
        - Written on 2016-05-16 by Aladdin Seaifan (UofT).


        Calculate xi given r.

        Parameters
        ----------
        r : float
            Evaluate at radius r.

        Returns
        -------
        xi : float
            The calculated xi.

        Notes
        -----
        - 2016-05-18 - Written - Aladdin Seaifan (UofT)


        Evaluate rho_tilde as defined in equation 3.9 and 2.24 for 0 <= n < N and 0 <= l < L

        Parameters
        ----------
        r : float
            Evaluate at radius r
        N : int
            size of the N dimension
        L : int
            size of the L dimension

        Returns
        -------
        numpy.ndarray
            The value of rho tilde

        Notes
        -----
         - Written on 2016-05-17 by Aladdin Seaifan (UofT)


        Evaluate phi_tilde as defined in equation 3.10 and 2.25 for 0 <= n < N and 0 <= l < L

        Parameters
        ----------
        r : float
            Evaluate at radius r
        N : int
            size of the N dimension
        L : int
            size of the L dimension

        Returns
        -------
        numpy.ndarray
            phi tilde

        Notes
        -----
        - Written on 2016-05-17 by Aladdin Seaifan (UofT)


        Evaluate the NxLxM density or potential

        Parameters
        ----------
        funcTilde : function
            Must be _rhoTilde or _phiTilde
        R : float
            Cylindrical Galactocentric radius
        z : float
            vertical height
        phi : float
            azimuth

        Returns
        -------
        numpy.ndarray
            An NxLxM density or potential at (R,z, phi)

        Notes
        -----
        - Written on 2016-05-18 by Aladdin Seaifan (UofT)


        Evaluate the density or potential for a given array of coordinates.

        Parameters
        ----------
        funcTilde : function
            Must be _rhoTilde or _phiTilde.
        R : numpy.ndarray
            Cylindrical Galactocentric radius.
        z : numpy.ndarray
            Vertical height.
        phi : numpy.ndarray
            Azimuth.

        Returns
        -------
        numpy.ndarray
            Density or potential evaluated at (R,z, phi).

        Notes
        -----
        - 2016-06-02 - Written - Aladdin Seaifan (UofT)


        Evaluate the forces in the x direction for a given array of coordinates.

        Parameters
        ----------
        dr_dx : numpy.ndarray
            The derivative of r with respect to the chosen variable x.
        dtheta_dx : numpy.ndarray
            The derivative of theta with respect to the chosen variable x.
        dphi_dx : numpy.ndarray
            The derivative of phi with respect to the chosen variable x.
        R : numpy.ndarray
            Cylindrical Galactocentric radius.
        z : numpy.ndarray
            Vertical height.
        phi : numpy.ndarray
            Azimuth.

        Returns
        -------
        numpy.ndarray
            The forces in the x direction.

        Notes
        -----
        - 2016-06-02 - Written - Aladdin Seaifan (UofT)


    Evaluate the Gegenbauer polynomial for 0 <= l < L and 0<= n < N

    Parameters
    ----------
    xi : float
        Radial transformed variable
    N : int
        Size of the N dimension
    L : int
        Size of the L dimension
    alpha : function, optional
        A lambda function of l. Default alpha = 2l + 3/2
    singleL : bool, optional
        If True only compute the L-th polynomial (default: False)

    Returns
    -------
    numpy.ndarray
        An LxN Gegenbauer Polynomial

    Notes
    -----
    - 2016-05-16 - Written - Aladdin Seaifan (UofT)
    - 2021-02-22 - Upgraded to array xi - Bovy (UofT)
    - 2021-02-22 - Added singleL for use in compute...nbody - Bovy (UofT)


    Numerically compute the expansion coefficients for a spherical expansion for a given $N$-body set of points

    Parameters
    ----------
    pos : numpy.ndarray
        Positions of particles in rectangular coordinates with shape [3,n]
    N : int
        Size of the Nth dimension of the expansion coefficients
    mass : float or numpy.ndarray, optional
        Mass of particles (scalar or array with size n), by default 1.0
    a : float, optional
        Parameter used to scale the radius, by default 1.0

    Returns
    -------
    tuple
        Expansion coefficients for density dens that can be given to SCFPotential.__init__

    Notes
    -----
    - 2020-11-18 - Written - Morgan Bennett (UofT)
    - 2021-02-22 - Sped-up - Bovy (UofT)


    Numerically compute the expansion coefficients for a given spherical density

    Parameters
    ----------
    dens : function
        A density function that takes a parameter R
    N : int
        Size of expansion coefficients
    a : float, optional
        Parameter used to scale the radius (default is 1.0)
    radial_order : int, optional
        Number of sample points of the radial integral. If None, radial_order=max(20, N + 1) (default is None)

    Returns
    -------
    tuple
        (Acos,Asin) - Expansion coefficients for density dens that can be given to SCFPotential.__init__

    Notes
    -----
    - 2016-05-18 - Written - Aladdin Seaifan (UofT)


    Numerically compute the expansion coefficients for a given $N$-body set of points assuming that the density is axisymmetric

    Parameters
    ----------
    pos : numpy.ndarray
        Positions of particles in rectangular coordinates with shape [3,n]
    N : int
        Size of the Nth dimension of the expansion coefficients
    L : int
        Size of the Lth dimension of the expansion coefficients
    mass : float or numpy.ndarray, optional
        Mass of particles (scalar or array with size n), by default 1.0
    a : float, optional
        Parameter used to scale the radius, by default 1.0

    Returns
    -------
    tuple
        Expansion coefficients for density dens that can be given to SCFPotential.__init__

    Notes
    -----
    - 2021-02-22 - Written based on general code - Bovy (UofT)


    Numerically compute the expansion coefficients for a given axi-symmetric density

    Parameters
    ----------
    dens : function
        A density function that takes parameters R and z
    N : int
        Size of the Nth dimension of the expansion coefficients
    L : int
        Size of the Lth dimension of the expansion coefficients
    a : float, optional
        Parameter used to shift the basis functions (default is 1.0)
    radial_order : int, optional
        Number of sample points of the radial integral. If None, radial_order=max(20, N + 3/2L + 1) (default is None)
    costheta_order : int, optional
        Number of sample points of the costheta integral. If None, If costheta_order=max(20, L + 1) (default is None)

    Returns
    -------
    tuple
        (Acos,Asin) - Expansion coefficients for density dens that can be given to SCFPotential.__init__

    Notes
    -----
    - 2016-05-20 - Written - Aladdin Seaifan (UofT)


    Numerically compute the expansion coefficients for a given $N$-body set of points

    Parameters
    ----------
    pos : numpy.ndarray
        Positions of particles in rectangular coordinates with shape [3,n]
    N : int
        Size of the Nth dimension of the expansion coefficients
    L : int
        Size of the Lth and Mth dimension of the expansion coefficients
    mass : float or numpy.ndarray, optional
        Mass of particles (scalar or array with size n), by default 1.0
    a : float, optional
        Parameter used to scale the radius, by default 1.0

    Returns
    -------
    tuple
        Expansion coefficients for density dens that can be given to SCFPotential.__init__

    Notes
    -----
    - 2020-11-18 - Written - Morgan Bennett (UofT)


    Numerically compute the expansion coefficients for a given triaxial density

    Parameters
    ----------
    dens : function
        A density function that takes parameters R, z and phi
    N : int
        Size of the Nth dimension of the expansion coefficients
    L : int
        Size of the Lth and Mth dimension of the expansion coefficients
    a : float, optional
        Parameter used to shift the basis functions (default is 1.0)
    radial_order : int, optional
        Number of sample points of the radial integral. If None, radial_order=max(20, N + 3/2L + 1) (default is None)
    costheta_order : int, optional
        Number of sample points of the costheta integral. If None, If costheta_order=max(20, L + 1) (default is None)
    phi_order : int, optional
        Number of sample points of the phi integral. If None, If costheta_order=max(20, L + 1) (default is None)

    Returns
    -------
    tuple
        (Acos,Asin) - Expansion coefficients for density dens that can be given to SCFPotential.__init__

    Notes
    -----
    - 2016-05-27 - Written - Aladdin Seaifan (UofT)


    Generate a cartesian product of input arrays.

    Parameters
    ----------
    arraySizes : list
        list of size of arrays
    out : numpy.ndarray, optional
        Array to place the cartesian product in.

    Returns
    -------
    numpy.ndarray
        2-D array of shape (product(arraySizes), len(arraySizes)) containing cartesian products

    Notes
    -----
    -  2016-06-02 - Obtained from http://stackoverflow.com/questions/1208118/using-numpy-to-build-an-array-of-all-combinations-of-two-arrays


    Numerically take n integrals over a function that returns a float or an array

    Parameters
    ----------
    integrand : function
        The function you're integrating over.
    bounds : list
        The bounds of the integral in the form of [[a_0, b_0], [a_1, b_1], ... , [a_n, b_n]] where a_i is the lower bound and b_i is the upper bound
    Ksample : list, optional
        Number of sample points in the form of [K_0, K_1, ..., K_n] where K_i is the sample point of the ith integral. (default is [20])
    roundoff : float, optional
        if the integral is less than this value, round it to 0. (default is 0)

    Returns
    -------
    numpy.ndarray
        The integral of the function integrand

    Notes
    -----
    - 2016-05-24 - Written - Aladdin Seaifan (UofT)


        Calculates the potential and force grids for the snapshot for
        use with other galpy functions.

        **Input**:

        *R*: R grid coordinates (numpy array)

        *z*: z grid coordinates (numpy array)

        **Optional Keywords**:

        *use_pkdgrav*: (False) whether to use pkdgrav for the gravity
         calculation

        *dr*: (0.01) offset to use for the gradient calculation - the
         points are positioned at +/- dr from the central point


        Normalize all positions by R0 and velocities by Vc(R0).

        If :class:`~scipy.interpolate.RectBivariateSpline` or
        :class:`~scipy.interpolate.InterpolatedUnivariateSpline` are
        used, redefine them for use with the rescaled coordinates.

        To undo the normalization, call
        :func:`~galpy.potential.SnapshotPotential.InterpSnapshotPotential.denormalize`.


Undo the normalization.


        Evaluate the dimensionless kr parameter kr = mrv / hbar.

        Parameters
        ----------
        r : float
            Spherical radius (natural units).
        v : float
            Current velocity in cylindrical coordinates (natural units).
        Returns
        -------
        kr : float
            Dimensionless kr parameter.


Evaluate the classical Mach number M_sigma = v / sigma(r).


        Evolve time parameters to t_end.

        Parameters
        ----------
        time : float
            End time for the potential evolution.

        Returns
        -------
        None

        Notes
        -----
        - 2019-08-12 - Written - Webb (UofT)


        Get mass density at a given location in the potential

        Parameters
        ----------
        eps : AMUSE Quantity
            Softening length (necessary for AMUSE, but not used by galpy potential)
        x,y,z : AMUSE Quantity
            Position in the potential

        Returns
        -------
        AMUSE Quantity
            The density

        Notes
        -----
        - 2019-08-12 - Written - Webb (UofT)
        - 2019-11-06 - added physical compatibility - Starkman (UofT)


        Get circular velocity at a given radius in the potential

        Parameters
        ----------
        r : AMUSE Quantity
            Radius in the potential

        Returns
        -------
        AMUSE Quantity
            The circular velocity

        Notes
        -----
        - 2019-08-12 - Written - Webb (UofT)
        - 2019-11-06 - added physical compatibility - Starkman (UofT)


        Get mass enclosed within a given radius in the potential

        Parameters
        ----------
        r : AMUSE Quantity
            Radius in the potential

        Returns
        -------
        AMUSE Quantity
            The mass enclosed

        Notes
        -----
        - 2019-08-12 - Written - Webb (UofT)
        - 2019-11-06 - added physical compatibility - Starkman (UofT)


        Stop the potential model (necessary function for AMUSE)

        Notes
        -----
        - 2019-08-12 - Written - Webb (UofT)


        Return formation time of the perturbation.

        Returns
        -------
        float
            Formation time of the perturbation in normalized units.

        Notes
        -----
        - 2011-10-19 - Written - Bovy (IAS)


        Evaluate the potential.

        Parameters
        ----------
        z : float
            Height above the midplane.
        t : float, optional
            Time at which to evaluate the potential. Default is 0.0.

        Returns
        -------
        float
            The potential at (R, z, phi, t) - phi(R, 0., phi, t0).

        Notes
        -----
        - 2010-07-13 - Written - Bovy (NYU)
        - 2018-10-07 - Added support for non-axi potentials - Bovy (UofT)
        - 2019-08-19 - Added support for time-dependent potentials - Bovy (UofT)


        Evaluate the force.

        Parameters
        ----------
        z : float
            Height above the midplane.
        t : float, optional
            Time at which to evaluate the force. Default is 0.0.

        Returns
        -------
        float
            The vertical force at (R, z, phi, t).

        Notes
        -----
        - 2010-07-13 - Written - Bovy (NYU)
        - 2018-10-07 - Added support for non-axi potentials - Bovy (UofT)
        - 2019-08-19 - Added support for time-dependent potentials - Bovy (UofT)


    Convert a 3D azisymmetric potential to a vertical potential at a given R.

    Parameters
    ----------
    Pot : Potential instance
        The 3D potential to convert.
    R : float or Quantity
        Galactocentric radius at which to evaluate the vertical potential.

    Returns
    -------
    verticalPotential instance
        The vertical potential at (R, z, phi, t).

    Notes
    -----
    - 2010-07-21 - Written - Bovy (NYU)


    Convert a 3D azisymmetric potential to a vertical potential at a given R.

    Parameters
    ----------
    Pot : Potential instance
        The 3D potential to convert.
    R : float or Quantity
        Galactocentric radius at which to evaluate the vertical potential.
    phi : float, optional
        Azimuth at which to evaluate the vertical potential. Default is None.
    t0 : float, optional
        Time at which to evaluate the vertical potential. Default is 0.0.

    Returns
    -------
    verticalPotential instance
        The vertical potential at (R, z, phi, t).

    Notes
    -----
    - 2010-07-21 - Written - Bovy (NYU)


    Plot the escape velocity curve for this potential (in the z=0 plane for non-spherical potentials).

    Parameters
    ----------
    Pot : Potential or list of Potential instances
        Potential(s) for which to plot the escape velocity curve.
    Rrange : numpy.ndarray or Quantity, optional
        Range in R to consider (can be Quantity).
    grid : int, optional
        Grid in R.
    savefilename : str, optional
        Save to or restore from this savefile (pickle).
    *args, **kwargs : dict
        Arguments and keyword arguments for `galpy.util.plot.plot`.

    Returns
    -------
    matplotlib.AxesSubplot
        Plot to output device.

    Notes
    -----
    - 2010-08-08 - Written by Bovy (NYU).


    Calculate the escape velocity curve for this potential (in the z=0 plane for non-spherical potentials).

    Parameters
    ----------
    Pot : Potential or list of Potential instances
        Potential or list of Potential instances.
    Rs : numpy.ndarray or Quantity
        Radius(i).
    t : float, optional
        Instantaneous time (default is 0.0).

    Returns
    -------
    numpy.ndarray or Quantity
        Array of v_esc.

    Raises
    ------
    AttributeError
        Escape velocity curve plotting for non-axisymmetric potentials is not currently supported.

    Notes
    -----
    - 2011-04-16 - Written - Bovy (NYU)


    Calculate the escape velocity at R for potential Pot.

    Parameters
    ----------
    Pot : Potential or list of Potential instances
        Potential or list of Potential instances.
    R : numpy.ndarray or Quantity
        Galactocentric radius.
    t : float, optional
        Time (default is 0.0).

    Returns
    -------
    numpy.ndarray or Quantity
        Escape velocity.

    Notes
    -----
    - 2011-10-09 - Written - Bovy (IAS)


        Evaluate the derivative w.r.t. lambda for this potential.

        Parameters
        ----------
        l : float
            Prolate spheroidal coordinate lambda.
        n : float
            Prolate spheroidal coordinate nu.

        Returns
        -------
        float
            Derivative w.r.t. lambda.

        Notes
        -----
        - 2015-02-15 - Written - Trick (MPIA)


        Evaluate the derivative w.r.t. nu for this potential.

        Parameters
        ----------
        l : float
            Prolate spheroidal coordinate lambda.
        n : float
            Prolate spheroidal coordinate nu.

        Returns
        -------
        float
            Derivative w.r.t. nu.

        Notes
        -----
        - 2015-02-15 - Written - Trick (MPIA)


        Evaluate the second derivative w.r.t. lambda for this potential.

        Parameters
        ----------
        l : float
            Prolate spheroidal coordinate lambda.
        n : float
            Prolate spheroidal coordinate nu.

        Returns
        -------
        float
            Second derivative w.r.t. lambda.

        Notes
        -----
        - 2015-02-15 - Written - Trick (MPIA)


        Evaluate the second derivative w.r.t. nu for this potential.

        Parameters
        ----------
        l : float
            Prolate spheroidal coordinate lambda.
        n : float
            Prolate spheroidal coordinate nu.

        Returns
        -------
        float
            Second derivative w.r.t. nu.

        Notes
        -----
        - 2015-02-15 - Written - Trick (MPIA)


        Evaluate the mixed derivative w.r.t. lambda and nu for this potential.

        Parameters
        ----------
        l : float
            Prolate spheroidal coordinate lambda.
        n : float
            Prolate spheroidal coordinate nu.

        Returns
        -------
        float
            Mixed derivative w.r.t. lambda and nu.

        Notes
        -----
        - 2015-02-13 - Written - Trick (MPIA)


The potential as a function of r


The force as a function of r


The second radial derivative as a function of r


The density as a function of r


    Decorator to check inputs and throw TypeError if any of the inputs are arrays for Potentials that do not support array evaluation.

    Parameters
    ----------
    func : function
        Function to be decorated.

    Returns
    -------
    function
        Decorated function.

    Notes
    -----
    - 2017-summer - Written for SpiralArmsPotential - Jack Hong (UBC)
    - 2019-05-23 - Moved to Potential for more general use - Bovy (UofT)


        Evaluate the cylindrical radial force F_R.

        Parameters
        ----------
        R : float or Quantity
            Cylindrical Galactocentric radius.
        z : float or Quantity
            Vertical height.
        phi : float or Quantity, optional
            Azimuth (default: 0.0).
        t : float or Quantity, optional
            Time (default: 0.0).

        Returns
        -------
        float or Quantity
            F_R (R,z,phi,t).

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


        Evaluate the vertical force F_z.

        Parameters
        ----------
        R : float or Quantity
            Cylindrical Galactocentric radius.
        z : float or Quantity
            Vertical height.
        phi : float or Quantity, optional
            Azimuth (default: 0.0).
        t : float or Quantity, optional
            Time (default: 0.0).

        Returns
        -------
        float or Quantity
            F_z (R,z,phi,t).

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


        Evaluate the second spherical radial derivative.

        Parameters
        ----------
        R : float or Quantity
            Cylindrical Galactocentric radius.
        z : float or Quantity
            Vertical height.
        phi : float or Quantity, optional
            Azimuth (default: 0.0).
        t : float or Quantity, optional
            Time (default: 0.0).

        Returns
        -------
        float or Quantity
            d2phi/dr2.

        Notes
        -----
        - 2018-03-21 - Written - Webb (UofT)


        Evaluate the density rho(R,z,t).

        Parameters
        ----------
        R : float or Quantity
            Cylindrical Galactocentric radius.
        z : float or Quantity
            Vertical height.
        phi : float or Quantity, optional
            Azimuth (default: 0.0).
        t : float or Quantity, optional
            Time (default: 0.0).
        forcepoisson : bool, optional
            If True, calculate the density through the Poisson equation, even if an explicit expression for the density exists (default: False).

        Returns
        -------
        float or Quantity
            rho (R,z,phi,t).

        Notes
        -----
        - 2010-08-08 - Written - Bovy (NYU)
        - 2018-03-21 - Modified - Webb (UofT)


        Evaluate the surface density Sigma(R,z,phi,t) = int_{-z}^{+z} dz' rho(R,z',phi,t).

        Parameters
        ----------
        R : float or Quantity
            Cylindrical Galactocentric radius.
        z : float or Quantity
            Vertical height.
        phi : float or Quantity, optional
            Azimuth (default: 0.0).
        t : float or Quantity, optional
            Time (default: 0.0).
        forcepoisson : bool, optional
            If True, calculate the surface density through the Poisson equation, even if an explicit expression for the surface density exists (default: False).

        Returns
        -------
        float or Quantity
            Sigma(R,z,phi,t).

        Notes
        -----
        - 2018-08-19 - Written - Bovy (UofT)
        - 2021-04-19 - Adjusted for non-z-symmetric densities - Bovy (UofT)


        Evaluate the surface density for this potential.

        Parameters
        ----------
        R : float or Quantity
            Cylindrical Galactocentric radius.
        z : float or Quantity
            Vertical height.
        phi : float or Quantity, optional
            Azimuth (default: 0.0).
        t : float or Quantity, optional
            Time (default: 0.0).

        Returns
        -------
        float or Quantity
            The surface density.

        Notes
        -----
        - 2018-08-19 - Written - Bovy (UofT).
        - 2021-04-19 - Adjusted for non-z-symmetric densities by Bovy (UofT).


        Evaluate the mass enclosed.

        Parameters
        ----------
        R : float or Quantity
            Cylindrical Galactocentric radius.
        z : float or Quantity, optional
            Vertical height up to which to integrate (default: None).
        t : float or Quantity, optional
            Time (default: 0.0).
        forceint : bool, optional
            If True, calculate the mass through integration of the density, even if an explicit expression for the mass exists (default: False).

        Returns
        -------
        float or Quantity
            Mass enclosed within the spherical shell with radius R if z is None else mass in the slab <R and between -z and z; except: potentials inheriting from EllipsoidalPotential, which if z is None return the mass within the ellipsoidal shell with semi-major axis R.

        Notes
        -----
        - 2014-01-29 - Written - Bovy (IAS)
        - 2019-08-15 - Added spherical warning - Bovy (UofT)
        - 2021-03-15 - Changed to integrate to spherical shell for z is None slab otherwise - Bovy (UofT)
        - 2021-03-18 - Switched to using Gauss' theorem - Bovy (UofT)


        Calculate the half-mass radius, the radius of the spherical shell that contains half the total mass.

        Parameters
        ----------
        t : float or Quantity, optional
            Time (default: 0.0).
        INF : float or Quantity, optional
            Radius at which the total mass is calculated (default: numpy.inf).

        Returns
        -------
        float or Quantity
            Half-mass radius.

        Notes
        -----
        - 2021-03-18 - Written - Bovy (UofT)


        Calculate the dynamical time from tdyn^2 = 3pi/[G<rho>]

        Parameters
        ----------
        R : float or Quantity
            Galactocentric radius.
        t : float or Quantity, optional
            Time (default: 0.0).

        Returns
        -------
        float or Quantity
            Dynamical time.

        Notes
        -----
        - 2021-03-18 - Written - Bovy (UofT)


        Calculate the virial mass.

        Parameters
        ----------
        H : float, optional
            Hubble constant in km/s/Mpc (default: 70).
        Om : float, optional
            Omega matter (default: 0.3).
        overdens : float, optional
            Overdensity which defines the virial radius (default: 200).
        wrtcrit : bool, optional
            If True, the overdensity is wrt the critical density rather than the mean matter density (default: False).
        ro : float or Quantity, optional
            Distance scale in kpc (default: object-wide, which if not set is 8 kpc).
        vo : float or Quantity, optional
            Velocity scale in km/s (default: object-wide, which if not set is 220 km/s).
        forceint : bool, optional
            If True, calculate the mass through integration of the density, even if an explicit expression for the mass exists.

        Returns
        -------
        float or Quantity
            M(<rvir).

        Notes
        -----
        - 2014-09-12 - Written - Bovy (IAS)


        Evaluate the second radial derivative.

        Parameters
        ----------
        R : float or Quantity
            Galactocentric radius.
        z : float or Quantity
            Vertical height.
        phi : float or Quantity, optional
            Galactocentric azimuth (default: 0.0).
        t : float or Quantity, optional
            Time (default: 0.0).

        Returns
        -------
        float or Quantity
            d2phi/dR2.

        Notes
        -----
        - 2011-10-09 - Written - Bovy (IAS)


        Evaluate the second vertical derivative.

        Parameters
        ----------
        R : float or Quantity
            Galactocentric radius.
        z : float or Quantity
            Vertical height.
        phi : float or Quantity, optional
            Galactocentric azimuth (default: 0.0).
        t : float or Quantity, optional
            Time (default: 0.0).

        Returns
        -------
        float or Quantity
            d2phi/dz2.

        Notes
        -----
        - 2012-07-25 - Written - Bovy (IAS@MPIA)


        Evaluate the mixed R,z derivative.

        Parameters
        ----------
        R : float or Quantity
            Galactocentric radius.
        z : float or Quantity
            Vertical height.
        phi : float or Quantity, optional
            Galactocentric azimuth (default: 0.0).
        t : float or Quantity, optional
            Time (default: 0.0).

        Returns
        -------
        float or Quantity
            d2phi/dz/dR.

        Notes
        -----
        - 2013-08-26 - Written - Bovy (IAS)


        Normalize a potential in such a way that vc(R=1,z=0)=1., or a fraction of this.

        Parameters
        ----------
        norm : float
            Normalize such that Rforce(R=1,z=0) is such that it is 'norm' of the force necessary to make vc(R=1,z=0)=1 (if True, norm=1).

        Returns
        -------
        None

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


        Evaluate the azimuthal torque.

        Parameters
        ----------
        R : float or Quantity
            Cylindrical Galactocentric radius.
        z : float or Quantity
            Vertical height.
        phi : float or Quantity, optional
            Azimuth (default: 0.0).
        t : float or Quantity, optional
            Time (default: 0.0).

        Returns
        -------
        float or Quantity
            tau_phi(R, z, phi, t).

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


        Evaluate the second azimuthal derivative.

        Parameters
        ----------
        R : float or Quantity
            Cylindrical Galactocentric radius.
        z : float or Quantity
            Vertical height.
        phi : float or Quantity, optional
            Azimuth (default: 0.0).
        t : float or Quantity, optional
            Time (default: 0.0).

        Returns
        -------
        float or Quantity
            d2Phi/dphi2.

        Notes
        -----
        - 2013-09-24 - Written - Bovy (IAS)


        Evaluate the mixed radial, azimuthal derivative.

        Parameters
        ----------
        R : float or Quantity
            Cylindrical Galactocentric radius.
        z : float or Quantity
            Vertical height.
        phi : float or Quantity, optional
            Azimuth (default: 0.0).
        t : float or Quantity, optional
            Time (default: 0.0).

        Returns
        -------
        float or Quantity
            d2Phi/dphidR.

        Notes
        -----
        - 2014-06-30 - Written - Bovy (IAS)


        Evaluate the mixed azimuthal, vertical derivative.

        Parameters
        ----------
        R : float or Quantity
            Cylindrical Galactocentric radius.
        z : float or Quantity
            Vertical height.
        phi : float or Quantity, optional
            Azimuth (default: 0.0).
        t : float or Quantity, optional
            Time (default: 0.0).

        Returns
        -------
        float or Quantity
            d2Phi/dphidz.

        Notes
        -----
        - 2021-04-30 - Written - Bovy (UofT)


        Convert a 3D potential into a planar potential in the mid-plane.

        Returns
        -------
        planarPotential


        Convert a 3D potential into a linear (vertical) potential at R.

        Parameters
        ----------
        R : float or Quantity
            Galactocentric radius at which to create the vertical potential.
        phi : float or Quantity, optional
            Galactocentric azimuth at which to create the vertical potential; required for non-axisymmetric potential.
        t0 : float or Quantity, optional
            Time at which to create the vertical potential (default: 0.0)

        Returns
        -------
        linear (vertical) potential : function
            Phi(z,phi,t) = Phi(R,z,phi,t)-Phi(R,0.,phi0,t0) where phi0 and t0 are the phi and t inputs.


        Plot the potential.

        Parameters
        ----------
        t : float, optional
            Time to plot potential at. Default is 0.0.
        rmin : float or Quantity, optional
            Minimum R. Default is 0.0.
        rmax : float or Quantity, optional
            Maximum R. Default is 1.5.
        nrs : int, optional
            Grid in R. Default is 21.
        zmin : float or Quantity, optional
            Minimum z. Default is -0.5.
        zmax : float or Quantity, optional
            Maximum z. Default is 0.5.
        nzs : int, optional
            Grid in z. Default is 21.
        phi : float or Quantity, optional
            Azimuth to use for non-axisymmetric potentials. Default is None.
        xy : bool, optional
            If True, plot the potential in X-Y. Default is False.
        effective : bool, optional
            If True, plot the effective potential Phi + Lz^2/2/R^2. Default is False.
        Lz : float or Quantity, optional
            Angular momentum to use for the effective potential when effective=True. Default is None.
        justcontours : bool, optional
            If True, just plot contours. Default is False.
        savefilename : str, optional
            Save to or restore from this savefile (pickle). Default is None.
        xrange : list, optional
            Can be specified independently from rmin, zmin, etc. Default is None.
        yrange : list, optional
            Can be specified independently from rmin, zmin, etc. Default is None.
        levels : list, optional
            Contours to plot. Default is None.
        cntrcolors : str or list, optional
            Colors of the contours (single color or array with length ncontours). Default is None.
        ncontours : int, optional
            Number of contours when levels is None. Default is 21.
        **kwargs : dict, optional
            Any additional keyword arguments are passed to `galpy.util.plot.dens2d`.

        Returns
        -------
        galpy.util.plot.dens2d return value

        Notes
        -----
        - 2010-07-09 - Written - Bovy (NYU)
        - 2014-04-08 - Added effective= - Bovy (IAS)
        - 2024-07-09 - Propagate other plotting keywords - Bovy (UofT)


        Plot the density of this potential.

        Parameters
        ----------
        t : float, optional
            Time to plot potential at.
        rmin : float or Quantity, optional
            Minimum R. If `xy` is True, this is `xmin`.
        rmax : float or Quantity, optional
            Maximum R. If `xy` is True, this is `ymax`.
        nrs : int, optional
            Grid in R.
        zmin : float or Quantity, optional
            Minimum z. If `xy` is True, this is `ymin`.
        zmax : float or Quantity, optional
            Maximum z. If `xy` is True, this is `ymax`.
        nzs : int, optional
            Grid in z.
        phi : float, optional
            Azimuth to use for non-axisymmetric potentials.
        xy : bool, optional
            If True, plot the density in X-Y.
        ncontours : int, optional
            Number of contours.
        justcontours : bool, optional
            If True, just plot contours.
        savefilename : str, optional
            Save to or restore from this savefile (pickle).
        log : bool, optional
            If True, plot the log density.

        Returns
        -------
        None

        Notes
        -----
        - 2014-01-05 - Written - Bovy (IAS)


        Plot the surface density of this potential.

        Parameters
        ----------
        t : float, optional
            Time to plot potential at.
        z : float or Quantity, optional
            Height between which to integrate the density (from -z to z).
        xmin : float or Quantity, optional
            Minimum x.
        xmax : float or Quantity, optional
            Maximum x.
        nxs : int, optional
            Grid in x.
        ymin : float or Quantity, optional
            Minimum y.
        ymax : float or Quantity, optional
            Maximum y.
        nys : int, optional
            Grid in y.
        ncontours : int, optional
            Number of contours.
        justcontours : bool, optional
            If True, just plot contours.
        savefilename : str, optional
            Save to or restore from this savefile (pickle).
        log : bool, optional
            If True, plot the log density.
        **kwargs : dict, optional
            Any additional keyword arguments are passed to `galpy.util.plot.dens2d`.

        Returns
        -------
        None

        Notes
        -----
        - 2020-08-19 - Written - Bovy (UofT)


        Calculate the circular velocity at R in this potential.

        Parameters
        ----------
        R : float or Quantity
            Galactocentric radius.
        phi : float, optional
            Azimuth to use for non-axisymmetric potentials.
        t : float or Quantity, optional
            Time.

        Returns
        -------
        float or Quantity
            Circular rotation velocity.

        Notes
        -----
        - 2011-10-09 - Written - Bovy (IAS)
        - 2016-06-15 - Added phi= keyword for non-axisymmetric potential - Bovy (UofT)


        Calculate the derivative of the circular velocity at R with respect to R in this potential.

        Parameters
        ----------
        R : float or Quantity
            Galactocentric radius.
        phi : float, optional
            Azimuth to use for non-axisymmetric potentials.
        t : float or Quantity, optional
            Time. Default: 0.0

        Returns
        -------
        float or Quantity
            Derivative of the circular rotation velocity with respect to R.

        Notes
        -----
        - 2013-01-08 - Written - Bovy (IAS)
        - 2016-06-28 - Added phi= keyword for non-axisymmetric potential - Bovy (UofT)


        Calculate the circular angular speed at R in this potential.

        Parameters
        ----------
        R : float or Quantity
            Galactocentric radius.
        t : float or Quantity, optional
            Time. Default: 0.0

        Returns
        -------
        float or Quantity
            Circular angular speed.

        Notes
        -----
        - 2011-10-09 - Written - Bovy (IAS)


        Calculate the epicycle frequency at R in this potential.

        Parameters
        ----------
        R : float or Quantity
            Galactocentric radius.
        t : float or Quantity, optional
            Time. Default: 0.0

        Returns
        -------
        float or Quantity
            Epicycle frequency.

        Notes
        -----
        - 2011-10-09 - Written - Bovy (IAS)


        Calculate the vertical frequency at R in this potential.

        Parameters
        ----------
        R : float or Quantity
            Galactocentric radius.
        t : float or Quantity, optional
            Time. Default: 0.0

        Returns
        -------
        float or Quantity
            Vertical frequency.

        Notes
        -----
        - 2012-07-25 - Written - Bovy (IAS@MPIA)


        Calculate the radius of a Lindblad resonance.

        Parameters
        ----------
        OmegaP : float or Quantity
            Pattern speed.
        m : int or str, optional
            Order of the resonance (as in m(O-Op)=kappa (negative m for outer)).
            Use m='corotation' for corotation.
            Default: 2.
        t : float or Quantity, optional
            Time. Default: 0.0.
        **kwargs: dict, optional
            Additional parameters passed to scipy.optimize.brentq.

        Returns
        -------
        float or Quantity or None
            Radius of Lindblad resonance. None if there is no resonance.

        Notes
        -----
        - 2011-10-09 - Written - Bovy (IAS)


        Calculate the escape velocity at R for this potential.

        Parameters
        ----------
        R : float or Quantity
            Galactocentric radius.
        t : float or Quantity, optional
            Time. Default: 0.0.

        Returns
        -------
        float or Quantity
            Escape velocity.

        Notes
        -----
        - 2011-10-09 - Written - Bovy (IAS)


        Calculate the radius of a circular orbit of Lz.

        Parameters
        ----------
        lz : float or Quantity
            Angular momentum.
        t : float or Quantity, optional
            Time. Default: 0.0.

        Returns
        -------
        float or Quantity
            Radius.

        Notes
        -----
        - 2012-07-30 - Written - Bovy (IAS@MPIA)
        - An efficient way to call this function on many objects is provided as the Orbit method rguiding.

        See Also
        --------
        galpy.orbit.Orbit.rguiding


        Calculate the radius of a circular orbit with energy E.

        Parameters
        ----------
        E : float or Quantity
            Energy.
        t : float or Quantity, optional
            Time. Default: 0.0.

        Returns
        -------
        float or Quantity
            Radius.

        Notes
        -----
        - 2022-04-06 - Written - Bovy (UofT)
        - An efficient way to call this function on many objects is provided as the Orbit method rE.

        See Also
        --------
        galpy.orbit.Orbit.rE


        Calculate the angular momentum of a circular orbit with energy E.

        Parameters
        ----------
        E : float or Quantity
            Energy.
        t : float or Quantity, optional
            Time. Default: 0.0.

        Returns
        -------
        float or Quantity
            Lc(E).

        Notes
        -----
        - 2022-04-06 - Written - Bovy (UofT).


        Calculate the potential flattening, defined as sqrt(fabs(z/R F_R/F_z))

        Parameters
        ----------
        R : float or Quantity
            Galactocentric radius.
        z : float or Quantity
            Height.
        t : float or Quantity, optional
            Time. Default: 0.0.

        Returns
        -------
        float or Quantity
            Flattening.

        Notes
        -----
        - 2012-09-13 - Written - Bovy (IAS)


        Calculate the terminal velocity at l in this potential.

        Parameters
        ----------
        l : float or Quantity
            Galactic longitude [deg/rad; can be Quantity).
        t : float or Quantity, optional
            Time. Default: 0.0.
        deg : bool, optional
            If True (default), l in deg.

        Returns
        -------
        float or Quantity
            Terminal velocity.

        Notes
        -----
        - 2013-05-31 - Written - Bovy (IAS).


        Plot the rotation curve for this potential (in the z=0 plane for non-spherical potentials).

        Parameters
        ----------
        Rrange : float or Quantity, optional
            Range to plot. Default: [0.01, 2.] * ro.
        grid : int, optional
            Number of points to plot. Default: 1001.
        savefilename : str, optional
            Save to or restore from this savefile (pickle).
        *args, **kwargs :
            Arguments and keyword arguments for galpy.util.plot.plot.

        Returns
        -------
        matplotlib.pyplot.axis
            Plot to output device.

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


        Plot the escape velocity curve for this potential (in the z=0 plane for non-spherical potentials).

        Parameters
        ----------
        Rrange : float or Quantity, optional
            Range to plot. Default: [0.01, 2.] * ro.
        grid : int, optional
            Number of points to plot. Default: 1001.
        savefilename : str, optional
            Save to or restore from this savefile (pickle).
        *args, **kwargs :
            Arguments and keyword arguments for galpy.util.plot.plot.

        Returns
        -------
        matplotlib.pyplot.axis
            Plot to output device.

        Notes
        -----
        - 2010-08-08 - Written - Bovy (NYU).


        Return the concentration.

        Parameters
        ----------
        H : float, optional
            Hubble constant in km/s/Mpc. Default: 70.0.
        Om : float, optional
            Omega matter. Default: 0.3.
        t : float or Quantity, optional
            Time. Default: 0.0.
        overdens : float, optional
            Overdensity which defines the virial radius. Default: 200.0.
        wrtcrit : bool, optional
            If True, the overdensity is wrt the critical density rather than the mean matter density. Default: False.
        ro : float or Quantity, optional
            Distance scale in kpc. Default: object-wide, which if not set is 8 kpc.
        vo : float or Quantity, optional
            Velocity scale in km/s. Default: object-wide, which if not set is 220 km/s.

        Returns
        -------
        float
            Concentration (scale/rvir).

        Notes
        -----
        - 2014-04-03 - Written - Bovy (IAS)


        Return the accname potential name for use of this potential with NEMO.

        Returns
        -------
        str
            Acceleration name.

        Notes
        -----
        - 2014-12-18 - Written - Bovy (IAS)


        Return the accpars potential parameters for use of this potential with NEMO.

        Parameters
        ----------
        vo : float
            Velocity unit in km/s.
        ro : float
            Length unit in kpc.

        Returns
        -------
        str
            Accpars string.

        Notes
        -----
        - 2014-12-18 - Written - Bovy (IAS)


        Calculate the tidal radius for object of mass M assuming a circular orbit

        Parameters
        ----------
        R : float or Quantity
            Galactocentric radius
        z : float or Quantity
            height
        phi : float or Quantity, optional
            azimuth (default: 0.0)
        t : float or Quantity, optional
            time (default: 0.0)
        M : float or Quantity
            mass of the object

        Returns
        -------
        float or Quantity
            Tidal radius

        Notes
        -----
        - 2018-03-21 - Written - Webb (UofT)
        - The tidal radius is computed as

           .. math::

               r_t^3 = \\frac{GM_s}{\\Omega^2-\\mathrm{d}^2\\Phi/\\mathrm{d}r^2}

          where :math:`M_s` is the cluster mass, :math:`\\Omega` is the circular frequency, and :math:`\\Phi` is the gravitational potential. For non-spherical potentials, we evaluate :math:`\\Omega^2 = (1/r)(\\mathrm{d}\\Phi/\\mathrm{d}r)` and evaluate the derivatives at the given position of the cluster.


        Calculate the tidal tensor Tij=-d(Psi)(dxidxj)

        Parameters
        ----------
        R : float or Quantity
            Galactocentric radius
        z : float or Quantity
            height
        phi : float or Quantity, optional
            azimuth (default: 0.0)
        t : float or Quantity, optional
            time (default: 0.0)
        eigenval : bool, optional
            return eigenvalues if true (default: False)

        Returns
        -------
        Tidal Tensor

        Notes
        -----
        - 2018-03-21 - Written - Webb (UofT)


        Calculate the zero-velocity curve.

        Parameters
        ----------
        R : float or Quantity
            Galactocentric radius
        E : float or Quantity
            Energy
        Lz : float or Quantity
            Angular momentum
        phi : float or Quantity, optional
            azimuth (default: 0.0)
        t : float or Quantity, optional
            time (default: 0.0)

        Returns
        -------
        z : float or Quantity
            z such that Phi(R,z) + Lz/[2R^2] = E

        Notes
        -----
        - 2020-08-20 - Written - Bovy (UofT)


        Calculate the minimum and maximum radius for which the zero-velocity curve exists for this energy and angular momentum (R such that Phi(R,0) + Lz/[2R^2] = E)

        Parameters
        ----------
        E : float or Quantity
            Energy
        Lz : float or Quantity
            Angular momentum
        phi : float or Quantity, optional
            azimuth (default: 0.0)
        t : float or Quantity, optional
            time (default: 0.0)

        Returns
        -------
        Rmin, Rmax : float or Quantity
            Solutions R such that Phi(R,0) + Lz/[2R^2] = E

        Notes
        -----
        - 2020-08-20 - Written - Bovy (UofT)


    Evaluate a potential or sum of potentials.

    Parameters
    ----------
    Pot : Potential or list of Potential
        Potential or list of potentials (dissipative forces in such a list are ignored).
    R : float or Quantity
        Cylindrical Galactocentric distance.
    z : float or Quantity
        Distance above the plane.
    phi : float or Quantity, optional
        Azimuth (default: None).
    t : float or Quantity, optional
        Time (default: 0.0).
    dR : int, optional
        If set to a non-zero integer, return the dR derivative instead (default: 0).
    dphi : int, optional
        If set to a non-zero integer, return the dphi derivative instead (default: 0).

    Returns
    -------
    float or Quantity
        Potential or potential derivative.

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


    Evaluate the density corresponding to a potential or sum of potentials.

    Parameters
    ----------
    Pot : potential or list of potentials
        Dissipative forces in such a list are ignored.
    R : float or Quantity
        Cylindrical Galactocentric distance.
    z : float or Quantity
        Distance above the plane.
    phi : float or Quantity, optional
        Azimuth (default: None).
    t : float or Quantity, optional
        Time (default: 0.0).
    forcepoisson : bool, optional
        If True, calculate the density through the Poisson equation, even if an explicit expression for the density exists.

    Returns
    -------
    float or Quantity
        density

    Notes
    -----
    - 2010-08-08 - Written - Bovy (NYU)
    - 2013-12-28 - Added forcepoisson - Bovy (IAS)


    Evaluate the surface density for a potential or sum of potentials.

    Parameters
    ----------
    Pot : Potential or list of Potential
        Potential or list of potentials (dissipative forces in such a list are ignored).
    R : float or Quantity
        Cylindrical Galactocentric distance.
    z : float or Quantity
        Distance above the plane.
    phi : float or Quantity, optional
        Azimuth (default: None).
    t : float or Quantity, optional
        Time (default: 0.0).
    forcepoisson : bool, optional
        If True, calculate the surface density through the Poisson equation, even if an explicit expression for the surface density exists.

    Returns
    -------
    float or Quantity
        Surface density.

    Notes
    -----
    - 2018-08-20 - Written - Bovy (UofT)


    Calculate the mass enclosed either within a spherical shell with radius R or in the slab <R and between -z and z.

    Parameters
    ----------
    Pot : Potential or list of Potentials
        Potential or list of Potentials (dissipative forces in such a list are ignored).
    R : float or Quantity
        Cylindrical Galactocentric distance.
    z : float or Quantity, optional
        Vertical height up to which to integrate. Default is None.
    t : float or Quantity, optional
        Time. Default: 0.0.
    forceint : bool, optional
        If True, calculate the mass through integration of the density, even if an explicit expression for the mass exists. Default is False.

    Returns
    -------
    float or Quantity
        Mass enclosed within the spherical shell with radius R if z is None else mass in the slab <R and between -z and z.

    Notes
    -----
    - 2021-02-07 - Written - Bovy (UofT)
    - 2021-03-15 - Changed to integrate to spherical shell for z is None slab otherwise - Bovy (UofT)


    Evaluate the radial force F_R(R,z,phi,t) of a potential, force or a list of potentials/forces.

    Parameters
    ----------
    Pot : Potential, DissipativeForce or list of Potential or DissipativeForce instances
        A potential, dissipative force or a list of such objects.
    R : float or Quantity
        Cylindrical Galactocentric distance.
    z : float or Quantity
        Distance above the plane.
    phi : float or Quantity, optional
        Azimuth (default: None).
    t : float or Quantity, optional
        Time (default: 0.0).
    v : numpy.ndarray or Quantity, optional
        Current velocity in cylindrical coordinates. Required when including dissipative forces. Default is None.

    Returns
    -------
    F_R : float or Quantity
        Radial force F_R(R,z,phi,t).

    Notes
    -----
    - 2010-04-16 - Written - Bovy (NYU)
    - 2018-03-16 - Added velocity input for dissipative forces - Bovy (UofT)


    Evaluate the azimuthal torque due to a potential, force or a list of potentials/forces.

    Parameters
    ----------
    Pot : Potential, DissipativeForce or list of Potential or DissipativeForce instances
        A potential, dissipative force or a list of such objects.
    R : float or Quantity
        Cylindrical Galactocentric distance.
    z : float or Quantity
        Distance above the plane.
    phi : float or Quantity, optional
        Azimuth (default: None).
    t : float or Quantity, optional
        Time (default: 0.0).
    v : numpy.ndarray, optional
        Current velocity in cylindrical coordinates. Required when including dissipative forces. Default is None.

    Returns
    -------
    float or Quantity
        The azimuthal torque.

    Notes
    -----
    - 2010-04-16 - Written - Bovy (NYU)
    - 2018-03-16 - Added velocity input for dissipative forces - Bovy (UofT)


    Evaluate the vertical force at a given position due to a potential, force or a list of potentials/forces.

    Parameters
    ----------
    Pot : Potential, DissipativeForce or list of Potential or DissipativeForce instances
        A potential, dissipative force or a list of such objects.
    R : float or Quantity
        Cylindrical Galactocentric distance.
    z : float or Quantity
        Distance above the plane.
    phi : float or Quantity, optional
        Azimuth (default: None).
    t : float or Quantity, optional
        Time (default: 0.0).
    v : numpy.ndarray or Quantity, optional
        Current velocity in cylindrical coordinates. Required when including dissipative forces. Default is None.

    Returns
    -------
    float or Quantity
        The vertical force F_z(R,z,phi,t).

    Notes
    -----
    - 2010-04-16 - Written - Bovy (NYU)
    - 2018-03-16 - Added velocity input for dissipative forces - Bovy (UofT)


    Evaluate the radial force at a given position due to a potential, force or a list of potentials/forces.

    Parameters
    ----------
    Pot : Potential, DissipativeForce or list of Potential or DissipativeForce instances
        A potential, dissipative force or a list of such objects.
    R : float or Quantity
        Cylindrical Galactocentric distance.
    z : float or Quantity
        Distance above the plane.
    phi : float or Quantity, optional
        Azimuth (default: None).
    t : float or Quantity, optional
        Time (default: 0.0).
    v : numpy.ndarray or Quantity, optional
        Current velocity in cylindrical coordinates. Required when including dissipative forces. Default is None.

    Returns
    -------
    float or Quantity
        The radial force F_r(R,z,phi,t).

    Notes
    -----
    - 2016-06-10 - Written - Bovy (UofT)


    Evaluate the second (cylindrical) radial derivative of a potential or sum of potentials.

    Parameters
    ----------
    Pot : Potential or list of Potential instances
        A potential or list of potentials (dissipative forces in such a list are ignored).
    R : float or Quantity
        Cylindrical Galactocentric distance.
    z : float or Quantity
        Distance above the plane.
    phi : float or Quantity, optional
        Azimuth (default: None).
    t : float or Quantity, optional
        Time (default: 0.0).

    Returns
    -------
    float or Quantity
        The second (cylindrical) radial derivative d2Phi/d2R of the potential.

    Notes
    -----
    - 2012-07-25 - Written - Bovy (IAS)


    Evaluate the second vertical derivative of a potential or sum of potentials.

    Parameters
    ----------
    Pot : Potential or list of Potential instances
        A potential or list of potentials (dissipative forces in such a list are ignored).
    R : float or Quantity
        Cylindrical Galactocentric distance.
    z : float or Quantity
        Distance above the plane.
    phi : float or Quantity, optional
        Azimuth (default: None).
    t : float or Quantity, optional
        Time (default: 0.0).

    Returns
    -------
    float or Quantity
        The second vertical derivative d2Phi/d2z of the potential.

    Notes
    -----
    - 2012-07-25 - Written - Bovy (IAS)


    Evaluate the second derivative of the sum of potentials with respect to cylindrical Galactocentric distance and height.

    Parameters
    ----------
    Pot : Potential or list of Potential instances
        A potential or list of potentials (dissipative forces in such a list are ignored).
    R : float or Quantity
        Cylindrical Galactocentric distance.
    z : float or Quantity
        Distance above the plane.
    phi : float or Quantity, optional
        Azimuth (default: None).
    t : float or Quantity, optional
        Time (default: 0.0).

    Returns
    -------
    float or Quantity
        The second derivative d2Phi/dRdz of the sum of potentials with respect to cylindrical Galactocentric distance and height.

    Notes
    -----
    - 2013-08-28 - Written - Bovy (IAS)


    Evaluate the second azimuthal derivative of a potential or sum of potentials.

    Parameters
    ----------
    Pot : Potential or list of Potential instances
        A potential or list of potentials (dissipative forces in such a list are ignored).
    R : float or Quantity
        Cylindrical Galactocentric distance.
    z : float or Quantity
        Distance above the plane.
    phi : float or Quantity, optional
        Azimuth (default: None).
    t : float or Quantity, optional
        Time (default: 0.0).

    Returns
    -------
    float or Quantity
        The second azimuthal derivative d2Phi/d2phi of the potential.

    Notes
    -----
    - 2018-03-28 - Written - Bovy (UofT)


    Evaluate the second derivative of the sum of potentials with respect to cylindrical Galactocentric distance and azimuth.

    Parameters
    ----------
    Pot : Potential or list of Potential instances
        A potential or list of potentials (dissipative forces in such a list are ignored).
    R : float or Quantity
        Cylindrical Galactocentric distance.
    z : float or Quantity
        Distance above the plane.
    phi : float or Quantity, optional
        Azimuth (default: None).
    t : float or Quantity, optional
        Time (default: 0.0).

    Returns
    -------
    float or Quantity
        The second derivative d2Phi/dRdphi of the sum of potentials with respect to cylindrical Galactocentric distance and azimuth.

    Notes
    -----
    - 2014-06-30 - Written - Bovy (IAS)


    Evaluate the second derivative of the sum of potentials with respect to cylindrical azimuth and height.

    Parameters
    ----------
    Pot : Potential or list of Potential instances
        A potential or list of potentials (dissipative forces in such a list are ignored).
    R : float or Quantity
        Cylindrical Galactocentric distance.
    z : float or Quantity
        Distance above the plane.
    phi : float or Quantity, optional
        Azimuth (default: None).
    t : float or Quantity, optional
        Time (default: 0.0).

    Returns
    -------
    float or Quantity
        The second derivative d2Phi/dphidz of the sum of potentials with respect to cylindrical azimuth and height.

    Notes
    -----
    - 2021-04-30 - Written - Bovy (UofT)


    Evaluate the second (spherical) radial derivative of a potential or sum of potentials.

    Parameters
    ----------
    Pot : Potential or list of Potential instances
        A potential or list of potentials (dissipative forces in such a list are ignored).
    R : float or Quantity
        Cylindrical Galactocentric distance.
    z : float or Quantity
        Distance above the plane.
    phi : float or Quantity, optional
        Azimuth (default: None).
    t : float or Quantity, optional
        Time (default: 0.0).

    Returns
    -------
    float or Quantity
        The second (spherical) radial derivative d2Phi/d2r  of the potential.

    Notes
    -----
    - 2018-03-28 - Written - Bovy (UofT)


    Plot a set of potentials.

    Parameters
    ----------
    Pot : Potential or list of Potential instances
        Potential(s) to plot.
    rmin : float, optional
        Minimum R (can be Quantity). Default is 0.0.
    rmax : float, optional
        Maximum R (can be Quantity). Default is 1.5.
    nrs : int, optional
        Grid in R. Default is 21.
    zmin : float, optional
        Minimum z (can be Quantity). Default is -0.5.
    zmax : float, optional
        Maximum z (can be Quantity). Default is 0.5.
    nzs : int, optional
        Grid in z. Default is 21.
    phi : float, optional
        Azimuth to use for non-axisymmetric potentials. Default is None.
    t : float, optional
        Time to use to evaluate potential. Default is 0.0.
    xy : bool, optional
        If True, plot the potential in X-Y. Default is False.
    effective : bool, optional
        If True, plot the effective potential Phi + Lz^2/2/R^2. Default is False.
    Lz : float, optional
        Angular momentum to use for the effective potential when effective=True. Default is None.
    xrange : list, optional
        Minimum and maximum R values to plot. Default is None.
    yrange : list, optional
        Minimum and maximum z values to plot. Default is None.
    justcontours : bool, optional
        If True, just plot contours. Default is False.
    levels : array-like, optional
        Contours to plot. Default is None.
    ncontours : int, optional
        Number of contours when levels is None. Default is 21.
    cntrcolors : str or array-like, optional
        Colors of the contours (single color or array with length ncontours). Default is None.
    savefilename : str, optional
        Save to or restore from this savefile (pickle). Default is None.
    aspect : float, optional
        Aspect ratio of the plot. Default is None.
    **kwargs : dict, optional
            Any additional keyword arguments are passed to `galpy.util.plot.dens2d`.

    Returns
    -------
    galpy.util.plot.dens2d return value

    Notes
    -----
    - 2010-07-09 - Written by Bovy (NYU).
    - 2024-07-09 - Propagate keyword arguments to `galpy.util.plot.dens2d` - Bovy (UofT)
    - 2024-10-08 - Allow plotting in physical coordinates - Bovy (UofT)

    See Also
    --------
    galpy.util.plot.dens2d


    Plot the density of a set of potentials.

    Parameters
    ----------
    Pot : Potential or list of Potential instances
        Potential(s) to evaluate.
    rmin : float, optional
        Minimum R (can be Quantity). Default is 0.0.
    rmax : float, optional
        Maximum R (can be Quantity). Default is 1.5.
    nrs : int, optional
        Grid in R. Default is 21.
    zmin : float, optional
        Minimum z (can be Quantity). Default is -0.5.
    zmax : float, optional
        Maximum z (can be Quantity). Default is 0.5.
    nzs : int, optional
        Grid in z. Default is 21.
    phi : float, optional
        Azimuth to use for non-axisymmetric potentials. Default is None.
    t : float, optional
        Time to use to evaluate potential. Default is 0.0.
    xy : bool, optional
        If True, plot the density in X-Y. Default is False.
    ncontours : int, optional
        Number of contours. Default is 21.
    justcontours : bool, optional
        If True, just plot contours. Default is False.
    savefilename : str, optional
        Save to or restore from this savefile (pickle). Default is None.
    log : bool, optional
        If True, plot the log density. Default is False.
    aspect : float, optional
        Aspect ratio of the plot. Default is None.
    **kwargs : dict, optional
        Additional keyword arguments to pass to plot.dens2d.

    Returns
    -------
    galpy.util.plot.dens2d return value

    Notes
    -----
    - 2013-07-05 - Written - Bovy (IAS)
    - 2023-04-24 - Allow plotting in physical coordinates - Bovy (UofT)

    See Also
    --------
    galpy.util.plot.dens2d


    Plot the surface density of a set of potentials.

    Parameters
    ----------
    Pot : Potential or list of Potential instances
        Potential(s) for which to plot the surface density.
    xmin : float or Quantity
        Minimum x value. Default is -1.5.
    xmax : float or Quantity
        Maximum x value. Default is 1.5.
    nxs : int
        Number of grid points in x.
    ymin : float or Quantity
        Minimum y value. Default is -1.5.
    ymax : float or Quantity
        Maximum y value. Default is 1.5.
    nys : int
        Number of grid points in y.
    z : float or Quantity, optional
        Height between which to integrate the density (from -z to z). Default is numpy.inf.
    t : float, optional
        Time to use to evaluate potential. Default is 0.0.
    ncontours : int, optional
        Number of contours. Default is 21.
    justcontours : bool, optional
        If True, just plot contours. Default is False.
    aspect : float, optional
        Aspect ratio of the plot. Default is None.
    savefilename : str, optional
        Save to or restore from this savefile (pickle). Default is None.
    log : bool, optional
        If True, plot the log density. Default is False.
    **kwargs : dict, optional
        Additional keyword arguments to pass to plot.dens2d.

    Returns
    -------
    matplotlib plot
        Plot to output device.

    Notes
    -----
    - 2020-08-19 - Written - Bovy (UofT)


    Calculate the epicycle frequency at R in the potential Pot.

    Parameters
    ----------
    Pot : Potential instance or list thereof
        Potential instance or list thereof.
    R : float or Quantity
        Galactocentric radius.
    t : float or Quantity, optional
        Time (default: 0).

    Returns
    -------
    float or Quantity
        Epicycle frequency.

    Notes
    -----
    - 2012-07-25 - Written - Bovy (IAS)


    Calculate the vertical frequency at R in the potential Pot.

    Parameters
    ----------
    Pot : Potential instance or list thereof
        Potential instance or list thereof.
    R : float or Quantity
        Galactocentric radius.
    t : float or Quantity, optional
        Time (default: 0).

    Returns
    -------
    float or Quantity
        Vertical frequency.

    Notes
    -----
    - 2012-07-25 - Written - Bovy (IAS@MPIA)


    Calculate the potential flattening, defined as sqrt(fabs(z/R F_R/F_z))

    Parameters
    ----------
    Pot : Potential instance or list thereof
        Potential instance or list thereof.
    R : float or Quantity
        Galactocentric radius.
    z : float or Quantity
        Height.
    t : float or Quantity, optional
        Time (default: 0).

    Returns
    -------
    float or Quantity
        Flattening.

    Notes
    -----
    - 2012-09-13 - Written - Bovy (IAS)


    Calculate the terminal velocity at l in this potential.

    Parameters
    ----------
    Pot : Potential instance or list thereof
        Potential instance or list thereof.
    l : float or Quantity
        Galactic longitude [deg/rad; can be Quantity).
    t : float or Quantity, optional
        Time (default: 0).
    deg : bool, optional
        If True (default), l in deg.

    Returns
    -------
    float or Quantity
        Terminal velocity.

    Notes
    -----
    - 2013-05-31 - Written - Bovy (IAS)


    Calculate the radius of a circular orbit of Lz.

    Parameters
    ----------
    Pot : Potential instance or list thereof
        Potential instance or list thereof.
    lz : float or Quantity
        Angular momentum (can be Quantity).
    t : float or Quantity, optional
        Time (default: 0).

    Returns
    -------
    float or Quantity
        Radius.

    Notes
    -----
    - 2012-07-30 - Written - Bovy (IAS@MPIA)

    - An efficient way to call this function on many objects is provided as the Orbit method rguiding.

    See Also
    --------
    Orbit.rguiding


find a starting interval for rl


    Calculate the radius of a circular orbit with energy E.

    Parameters
    ----------
    Pot : Potential instance or list thereof
        Potential instance or list thereof.
    E : float or Quantity
        Energy.
    t : float, optional
        Time (default is 0.0).

    Returns
    -------
    radius : float
        Radius.

    Notes
    -----
    - 2022-04-06 - Written - Bovy (UofT)

    - An efficient way to call this function on many objects is provided as the Orbit method rE.

    See Also
    --------
    Orbit.rE


find a starting interval for rE


    Calculate the angular momentum of a circular orbit with energy E.

    Parameters
    ----------
    Pot : Potential instance or list thereof
        Potential instance or list thereof.
    E : float or Quantity
        Energy.
    t : float or Quantity, optional
        Time (default: 0.0).

    Returns
    -------
    float or Quantity
        Angular momentum of circular orbit with energy E

    Notes
    -----
    - 2022-04-06 - Written - Bovy (UofT)