Spherical spline–interpolated potentials#

The SphericalSplinePotential class provides a flexible, spherically-symmetric potential model constructed from a 1D radial spline. Instead of hard-coding an analytic profile, the user supplies values of either potential energy, density, or enclosed mass on a set of radial knots.

This implementation requires GSL (the GNU Scientific Library) to be available at build/runtime. If Gala was built without GSL support, this class will not be usable.

Notes#

  • This potential uses a single class front-end that supports three input “value types”

    • density: The potential energy, mass enclosed, and gradients are computed by integrating the density.

    • mass (i.e. enclosed mass): The potential energy is computed by numerical integration and the density is obtained directly with derivatives of the splines.

    • potential: The enclosed mass, gradient, and density functions are obtained directly from spline interpolation.

  • Supports all GSL interpolation methods: “linear”, “polynomial”, “cspline” (default), “cspline_periodic”, “akima”, “akima_periodic”, and “steffen”. However note that some methods do not have smooth derivatives or second derivatives.

The implementation uses GSL spline routines to evaluate first and second derivatives where appropriate. For the supported interpolation methods, GSL provides finite derivatives:

  • Linear: piecewise-constant derivative (discontinuous at knots).

  • Cubic splines (cspline / cspline_periodic): continuous first and second derivatives.

  • Akima / akima_periodic: smooth first derivative designed to reduce overshoots.

  • Steffen: monotonic spline with continuous derivatives.

  • Polynomial: smooth derivatives within the domain.

Recommendations#

  1. If smoothness is important, use cspline. Cubic splines provide continuous first and second derivatives, which generally yield physically smoother densities when deriving them from potentials.

  2. Be mindful of endpoint behavior (inherited from GSL). The cubic spline implementation used here attempts to make the second derivative go to zero at the boundaries (i.e. for the end knots). This can introduce edge effects. A simple mitigation is to place knots beyond the radial range where you care about the physical model (i.e., make the knot grid slightly larger than the region you will evaluate). This reduces the influence of the boundary conditions in the region of interest.

  3. Use an appropriately dense knot grid in regions where the profile has high curvature (e.g., sharp features). Akima or steffen can be useful for reducing overshoot with sparse data, but these methods may produce less well-behaved higher derivatives.

  4. Validate by comparing diagnostics (e.g., the enclosed mass computed from the density vs the supplied mass profile) and by visual checks of the recovered density/gradients when you change interpolation method.

  5. For orbit modeling, it is generally better to supply mass profiles when possible (spline_value_type='mass') because dPhi/dr follows directly from M(r) and is less sensitive to high-frequency numerical noise in derivatives.

Examples#

Example 1: Create and evaluate a spline potential#

Create a mass-based spherical spline potential and evaluate it:

(Source code, png, pdf)

../_images/spherical-spline-1.png

Example 2: Make a SphericalSplinePotential from a density function#

The following example shows a more involved workflow: define a complex analytic density profile, evaluate it on a fine radial grid, build a SphericalSplinePotential with spline_value_type='density', and plot the resulting potential and recovered density. This is useful for quick visual experiments and for creating documentable figures in the Sphinx docs (via the matplotlib plot directive).

(Source code, png, pdf)

../_images/spherical-spline-2.png

Example 3: Effect of interpolation method (Akima vs cspline)#

This example constructs a potential by directly interpolating a potential-valued spline (spline_value_type='potential'). We then compare the density inferred from the potential using two different interpolation methods. Akima-style splines can produce piecewise-smooth first derivatives that sometimes appear ‘jagged’ in the second derivative (which is used to compute density), whereas cspline (cubic spline) tends to produce continuous second derivatives.

(Source code, png, pdf)

../_images/spherical-spline-3.png

API#

See: SphericalSplinePotential