Source-linked AI summary
galpy: A Python Library for Galactic Dynamics
Jo Bovy
TL;DR
Galactic-dynamics calculations require coordinated tools for potentials, orbit integration, action-angle coordinates, and distribution functions. galpy provides this framework, with axisymmetric action-angle approximations conserving actions to a few percent or better and angle errors of ≈10^-3 for a representative Milky Way orbit.
Problem
Galactic-dynamics software must coordinate distinct capabilities for gravitational potentials, orbit calculations, action-angle coordinates, and distribution functions.
Method
galpy combines modules for potentials, orbit integration, action-angle calculations, and distribution functions, supporting multiple numerical integrators and axisymmetric approximations.
Results
ActionAngleAdiabatic conserves radial and vertical actions to a few percent, while actionAngleStaeckel keeps action fluctuations below one percent and angle errors near 10^-3.
Takeaways & Limitations
galpy provides a practical, broadly organized toolkit for modeling galactic potentials, integrating orbits, and analyzing stellar dynamics.
Takeaways & Limitations
The current diskdf implementation supports only power-law or logarithmic potentials, including flat rotation curves.
Abstract
from arXiv · showhide
I describe the design, implementation, and usage of galpy, a Python package for galactic-dynamics calculations. At its core, galpy consists of a general framework for representing galactic potentials both in Python and in C (for accelerated computations); galpy functions, objects, and methods can generally take arbitrary combinations of these as arguments. Numerical orbit integration is supported with a variety of Runge-Kutta-type and symplectic integrators. For planar orbits, integration of the phase-space volume is also possible. galpy supports the calculation of action-angle coordinates and orbital frequencies for a given phase-space point for general spherical potentials, using state-of-the-art numerical approximations for axisymmetric potentials, and making use of a recent general approximation for any static potential. A number of different distribution functions (DFs) are also included in the current release; currently these consist of two-dimensional axisymmetric and non-axisymmetric disk DFs, a three-dimensional disk DF, and a DF framework for tidal streams. I provide several examples to illustrate the use of the code. I present a simple model for the Milky Way's gravitational potential consistent with the latest observations. I also numerically calculate the Oort functions for different tracer populations of stars and compare it to a new analytical approximation. Additionally, I characterize the response of a kinematically-warm disk to an elliptical m=2 perturbation in detail. Overall, galpy consists of about 54,000 lines, including 23,000 lines of code in the module, 11,000 lines of test code, and about 20,000 lines of documentation. The test suite covers 99.6% of the code. galpy is available at http://github.com/jobovy/galpy with extensive documentation available at http://galpy.readthedocs.org/en/latest .
2.1. Package structure
galpy is organized around interoperable subpackages for potentials, orbit integration, action–angle calculations, distribution functions, and utilities. Potential and Orbit objects provide the core infrastructure on which action–angle and distribution-function functionality builds.
- Package structure: galpy.potential provides general Potential subclasses and functions for representing gravitational potentials.Specific models, such as the NFW potential, are imported from this subpackage and form the basis of much galpy functionality.
- Package structure: The Orbit class supports flexible initialization, numerical integration, and evaluation of orbital characteristics through member functions.Orbit instances represent initial conditions and can be used by other galpy components.
- Package structure: galpy.actionAngle contains potential-specific classes for calculating actions, frequencies, and angles for specified orbits.These classes can be applied to Orbit instances in a chosen potential.
- Package structure: galpy.df provides distribution-function classes that typically depend on Potential and Orbit instances, and sometimes on action–angle instances.The included quasi-isothermal distribution function is an example of an action-based DF.
- Package structure: galpy.util includes plotting, coordinate-transformation, and unit-conversion utilities.Its coordinate routines cover transformations involving equatorial, Galactic, and Galactocentric coordinates.
3.1. General framework
galpy provides a general Potential framework that standardizes potential evaluation, force and derivative calculations, normalization, and composition from arbitrary lists of constituent potentials. Users can extend the framework with Python subclasses, while optional C implementations accelerate orbit integration and selected action–angle calculations.
- General Potential framework: Potential subclasses inherit general Potential, planarPotential, or linearPotential classes, whose methods provide shared evaluation and force functionality.Three-dimensional classes inherit Potential; planar and one-dimensional classes inherit planarPotential and linearPotential, respectively.
- Extending galpy: A new Python potential requires a subclass of galpy.potential.Potential with an amp parameter and methods defining its forces; advanced features require additional derivatives.Density can be implemented explicitly or computed from the Poisson equation when the relevant second derivatives are available.
- General Potential framework: Potential instances can be combined in arbitrary lists, with galpy summing each constituent’s potential, forces, and derivatives.Dedicated functions evaluate these quantities for lists of potentials.
- C implementations: C implementations are optional additions registered through hasC=True and are used to accelerate orbit integration and selected action–angle calculations.All potentials retain Python implementations because many galpy functions use Python Potential methods.
3.3. Axisymmetric potentials · 3.4. Non-axisymmetric potentials · 3.5. Example: Milky-Way-like potentials
galpy provides composable axisymmetric and non-axisymmetric potential models, including interpolation and time-dependent perturbations. It also offers MWPotential2014 as a convenient Milky-Way-like model fitted to dynamical constraints, with documented comparisons, structure, and limitations.
- 3.3. Axisymmetric potentials: galpy includes many three-dimensional axisymmetric potentials that can be combined into realistic galactic models.Some potentials are special cases of broader classes, including KeplerPotential and the Hernquist, Jaffe, and NFW models.
- 3.3. Axisymmetric potentials: interpRZPotential accelerates expensive axisymmetric evaluations by tabulating potentials, forces, derivatives, and related circular-velocity quantities on a grid for spline interpolation.Interpolated potentials can be used wherever Potential instances are accepted, including C-accelerated computations when configured with enable_c=True.
- 3.4. Non-axisymmetric potentials: galpy supplies two-dimensional non-axisymmetric perturbation models, including a general CosmphiDiskPotential with cos(mφ) dependence.These models primarily represent parametric perturbations to disk-galaxy potentials, and special cases are implemented in C.
- 3.4. Non-axisymmetric potentials: Time-dependent non-axisymmetric structure is represented with steady or transient logarithmic spirals and a rotating quadrupole bar potential.Spiral models can be grown gradually, while cos(mφ) perturbations use a Dehnen (2000) growth function controlled by tform and tsteady.
- 3.4. Non-axisymmetric potentials: MovingObjectPotential extends the non-axisymmetric framework to a moving object by combining an integrated Orbit instance with a specified mass.This can model the gravitational impact of objects such as molecular clouds on disk stellar orbits.
- 3.5. Example: Milky-Way-like potentials: MWPotential2014 is a simple, convenient Milky-Way gravitational-potential model fitted to dynamical data rather than intended as the best possible current model.It combines a power-law exponentially truncated bulge, a Miyamoto-Nagai disk, and an NFW dark-matter halo, with fitted component amplitudes and scale parameters.
- 3.5. Example: Milky-Way-like potentials: MWPotential2014 omits the Galactic-center supermassive black hole, which can instead be added as a KeplerPotential with mass 4 × 10^6 M⊙; it supersedes the older unfitted MWPotential.The model’s rotation curve, component masses, halo virial properties, and disk scale length are documented in the paper’s figures and table.
4.1. General framework
galpy provides a unified Orbit interface for integrating and characterizing orbits across dimensionalities from two through six, with specialized classes selected from the initial conditions. Its methods expose orbital properties in natural or physical units and can be extended to compute additional diagnostics such as Poincaré sections.
- Orbit framework: Orbit integration supports phase-space dimensionalities from two through six using multiple orbit flavors and integrators.Axisymmetric planar and three-dimensional orbits can assume angular-momentum conservation, while planarOrbit and FullOrbit retain the azimuthal angle without symmetry assumptions.
- Orbit framework: A general Orbit class hides the underlying orbit subclasses and determines the orbit type from the dimensionality of the supplied initial conditions.The implementation uses classes derived from OrbitTop, but users interact through the public Orbit interface.
- Orbit diagnostics: Orbit instances provide methods for accessing orbital characteristics and time dependence, with outputs available in physical coordinates when ro= and vo= scales are specified.If set during initialization, these scales are automatically applied to method outputs; otherwise they can be specified per method.
- Orbit diagnostics: Poincaré sections can be computed by extending galpy externally, although they are not currently supported directly by the package.The example demonstrates that the two displayed orbits have a third integral of motion in addition to energy and angular momentum.
4.2. Supported integrators
galpy provides eight orbit-integration methods through a uniform interface, including Python and accelerated C implementations of Runge–Kutta and symplectic schemes. The integrators generally maintain small energy errors over thousands of orbits, while phase-space-volume performance varies substantially across methods.
- Supported integrators: Eight integration methods are available through the integrate method’s method= keyword, including Python-based odeint and leapfrog implementations.odeint uses scipy’s lsoda solver, while leapfrog is a custom second-order symplectic integrator.
- Supported integrators: Six higher-order C integrators extend orbit integration to galpy potentials with C implementations, comprising three Runge–Kutta and three symplectic methods.The methods include rk4c, dopr54c, rk6c, leapfrog_c, a fourth-order Forest–Ruth scheme, and the sixth-order SI6A integrator.
- Energy conservation: 10−5 relative-energy errors are approached by odeint and rk4c after 2000 periods, while symplectic integrators avoid secular energy-error growth.For all integrators, energy errors remain small for thousands of orbits, and the reported errors are considered innocuous for phase-space ages of a few hundred orbital times.
- Phase-space volume: galpy can integrate phase-space volumes directly for two-dimensional orbits when the potential supplies second derivatives, supporting calculations for two-dimensional distribution functions.The Orbit method integrate_dxdv evolves (∆x, ∆v) rather than only (x, v).
- Phase-space volume: The fourth- and sixth-order Runge–Kutta methods show the best phase-space-volume conservation for the displayed orbit, whereas dopr54c and especially odeint deviate more rapidly.The phase-space-volume determinant should equal one; the comparison concerns the four non-symplectic integrators.
5.1. Generalities
galpy provides action–angle calculations through multiple approximation classes, with methods that progressively return actions, frequencies, and angles while minimizing redundant computation. These routines accept orbit instances or direct cylindrical phase-space coordinates, but do not currently invert action–angle coordinates to positions and velocities.
- Action–angle framework: Action–angle calculations are integral to galpy and support several approximations for different potential types.They are implemented in the galpy.actionAngle module and are used by some distribution functions.
- Action–angle framework: The actions, frequencies, and angles are returned through progressively broader methods: actions, actionsFreqs, and actionsFreqsAngles.This grouping minimizes unnecessary computations because frequencies require actions, while angles typically require frequencies.
- Inputs: All three basic action–angle methods accept phase-space positions supplied either as Orbit instances or directly in cylindrical Galactocentric coordinates.For an Orbit instance, the initial condition is used unless an integration time specifies an already-integrated phase-space position.
- Limitation: galpy currently lacks methods for calculating positions and velocities from action–angle coordinates in a specified potential.The available routines calculate action–angle quantities from phase-space positions, not the reverse transformation.
5.2. Isochrone and spherical potentials · 5.3. Action-angle coordinates for axisymmetric potentials
galpy implements action–angle coordinates and orbital frequencies analytically for the isochrone potential and numerically for spherical potentials. For axisymmetric potentials, it provides adiabatic and Stäckel approximations with different accuracy, computational requirements, and focal-length behavior.
- 5.2. Isochrone and spherical potentials: Isochrone action–angle coordinates and orbital frequencies are calculated analytically through the actionAngleIsochrone class.The class is initialized with a specific isochrone potential or its scale parameter.
- 5.2. Isochrone and spherical potentials: Spherical-potential action–angle coordinates are implemented in actionAngleSpherical using numerical integrals, without checking whether the supplied potential is spherical.Users must therefore avoid applying this class to axisymmetric potentials.
- 5.2. Isochrone and spherical potentials: Gaussian-quadrature integration through scipy’s integrate.fixed_quad is much faster than scipy’s integrate.quad for these numerical calculations.
- 5.3. Action-angle coordinates for axisymmetric potentials: The adiabatic approximation treats radial and vertical motion near the symmetry plane as decoupled oscillators, making it suitable for nearly circular orbits that remain near the plane.
- 5.3. Action-angle coordinates for axisymmetric potentials: The Stäckel approximation locally represents an axisymmetric potential with a prolate spheroidal focal length δ and computes actions, frequencies, and angles using a few one-dimensional numerical integrals.The method is implemented in actionAngleStaeckel and does not require explicitly fitting a Stäckel potential.
- 5.3. Action-angle coordinates for axisymmetric potentials: Both approximations have Python and C implementations for actions, but frequencies and angles are available only for actionAngleStaeckel in C with C-compatible potentials.C action calculations use Gaussian quadrature with 20 points, while interpRZPotential can provide a C-compatible interpolated potential.
- 5.3. Action-angle coordinates for axisymmetric potentials: For the tested MWPotential2014 orbit, actionAngleAdiabatic conserves radial and vertical actions to a few percent, whereas actionAngleStaeckel keeps action fluctuations below one percent.The angle evolution is also compared with the initial angle plus the linear frequency×time increase.
- 5.3. Action-angle coordinates for axisymmetric potentials: The Stäckel focal length δ is close to zero in approximately spherical central and outer regions, is δ ≈0.3 to 0.6 where the disk dominates, and often remains usable across nearby orbits.
5.4. Grid-based action-angle coordinates for axisymmetric potentials · 5.5. Action-angle coordinates for general static potentials
galpy accelerates axisymmetric action evaluations through interpolated grids tailored to adiabatic and Stäckel methods. For general static potentials, actionAngleIsochroneApprox derives coordinates from an auxiliary isochrone fit, conserving actions to better than 1 part in 10^-3 but excluding non-axisymmetric potentials.
- 5.4. Grid-based action-angle coordinates for axisymmetric potentials: Grid-based adiabatic and Stäckel methods tabulate actions for interpolation, speeding subsequent evaluations.The implementations are available as actionAngleAdiabaticGrid and actionAngleStaeckelGrid.
- 5.4. Grid-based action-angle coordinates for axisymmetric potentials: The adiabatic grid separates Jz over (R, Ez) from JR over (Lz, ER), reflecting each action’s approximate dependencies.The grids cover 0.01 ≤ R ≤ Rmax and 0.01 ≤ Lz ≤ vc(Rmax)Rmax.
- 5.4. Grid-based action-angle coordinates for axisymmetric potentials: The Stäckel implementation constructs a three-dimensional grid in (Lz, E, ψ) and interpolates separate ψ values for JR and Jz.New phase-space points are mapped to the grid using their angular momentum, energy, and inferred coordinate parameters.
- 5.4. Grid-based action-angle coordinates for axisymmetric potentials: Figure 20 demonstrates the actions along an orbit using direct and grid-interpolated adiabatic and Stäckel methods.The comparison covers both radial and vertical actions over five orbital periods.
- 5.4. Grid-based action-angle coordinates for axisymmetric potentials: In non-exact Stäckel galactic potentials, ψz is preferred for interpolating Jz because Ez more closely tracks the direct method’s third integral.ψR and ψz would coincide only for an exact Stäckel potential.
- 5.5. Action-angle coordinates for general static potentials: actionAngleIsochroneApprox computes general static-potential action–angle coordinates by fitting a generating function between auxiliary isochrone and target-potential coordinates.Actions, frequencies, and angles are obtained from this orbit-by-orbit auxiliary-potential construction.
- 5.5. Action-angle coordinates for general static potentials: 1 part in 10^-3: actions are conserved to better than this level for an MWPotential2014 orbit, while angle errors remain small for hundreds of periods.The simultaneous frequency and initial-angle fit over many orbital periods produces this behavior.
- 5.5. Action-angle coordinates for general static potentials: The actionAngleIsochroneApprox frequency-and-angle method is not implemented for non-axisymmetric potentials in the current galpy version.Its demonstrated application concerns static potentials and an axisymmetric MWPotential2014 orbit.
5.6. Example: Adiabatic invariance of the actions · 6.1. Two-dimensional distribution functions
The example shows that galpy preserves orbital actions during a smooth, adiabatic change between isochrone potentials. The disk-DF framework provides two-dimensional Shu and Dehnen models, correction procedures, kinematic diagnostics, and support for power-law or logarithmic potentials.
- 5.6. Example: Adiabatic invariance of the actions: Adiabatic evolution conserves the actions even though the energy, mean radius, and maximum height change during the potential transformation.The example uses TimeInterpPotential to smoothly change between two isochrone potentials.
- 6.1. Two-dimensional distribution functions: galpy includes two-dimensional Shu and Dehnen disk DFs alongside fully three-dimensional quasi-isothermal DFs.The Shu and Dehnen models are the two purely two-dimensional axisymmetric disk families described in this subsection.
- 6.1. Two-dimensional distribution functions: Shu and Dehnen DFs are steady-state, axisymmetric models using E and Lz, differing in how they warm a circular-orbit disk to include non-circular orbits.Both are implemented as subclasses of galpy.df.diskdf under galpy.df.
- 6.1. Two-dimensional distribution functions: The Shu DF evaluates its defining profiles at RL, the circular-orbit radius set by Lz, and is available as galpy.df.shudf.The formulation uses the rotational frequency, epicycle frequency, surface-density profile, radial-velocity-dispersion profile, and circular-orbit energy.
- 6.1. Two-dimensional distribution functions: The correction procedure iteratively adjusts scale profiles so the DF reproduces desired surface-density and radial-velocity-dispersion profiles.For the illustrated profiles, 20 iterations make the differences ΣDF/Σout and σR,DF/σR,out extremely small.
- 6.1. Two-dimensional distribution functions: galpy computes surface density, mean velocities, velocity dispersions, higher-order velocity moments, and the Oort functions A(R), B(R), C(R), and K(R).These quantities are obtained by integrating over the distribution function and related radial derivatives.
- 6.1. Two-dimensional distribution functions: The diskdf implementation supports only power-law or logarithmic potentials, including flat rotation curves, rather than arbitrary Potential instances.The paper characterizes this as a limitation because generalization to any Potential instance has not been implemented.
6.2. Example: Oort functions for different tracer populations of stars
galpy computes Oort functions for stellar tracer populations with varying radial-velocity dispersions and asymmetric drift. In the example, A varies linearly and strongly with asymmetric drift, while B is less affected and remains small under the fiducial model.
- 6.2. Example: Oort functions for different tracer populations of stars: The example computes A(R), B(R), and asymmetric drift at the solar radius for warm disk populations with different radial-velocity dispersions.The fiducial model uses an exponential surface-density profile with hR = R0/3, an exponential radial-velocity-dispersion profile with hσ = R0, and a flat rotation curve.
- 6.2. Example: Oort functions for different tracer populations of stars: For the power-law rotation curve, the circular-orbit Oort constants are A[σR(R0) = 0] = (1 −β)/2 and B[σR(R0) = 0] = −(1 + β)/2.The warm-population functions are compared with these constants as a function of asymmetric drift.
- 6.2. Example: Oort functions for different tracer populations of stars: Both A and B depend linearly on asymmetric drift, but A is much more affected by the population’s kinematic temperature than B.Changing the DF form or parameters affects B more strongly than A; hσ is the only parameter producing a large difference for A.
- 6.2. Example: Oort functions for different tracer populations of stars: The fiducial model predicts a one-to-one linear relation between ∆A and va, with ∆A negative and robust to DF changes except for hσ.These analytical predictions are borne out in Figure 24.
- 6.2. Example: Oort functions for different tracer populations of stars: For the fiducial model, ∆B vanishes in the simple approximation, so its actual small value depends on rotation-curve slope and scale length.The sign of ∆B can be positive or negative, and |∆B| < |∆A| when hσ < 2.
6.3. Three-dimensional distribution functions
galpy includes a three-dimensional quasi-isothermal disk distribution function that is steady-state, axisymmetric, and depends on all three orbital actions. The implementation supports arbitrary galactic potentials, action-angle methods, counter-rotation suppression, and calculations of DF-derived velocity moments.
- Three-dimensional distribution functions: galpy includes Binney’s improved quasi-isothermal DF as a steady-state, axisymmetric three-dimensional disk distribution function of (Jr, Lz, Jz).In an axisymmetric potential, Lz denotes the azimuthal action because it equals the z-component of angular momentum.
- Three-dimensional distribution functions: The qDF uses epicycle, circular, and vertical frequencies evaluated at the circular-orbit radius RL, with n, σR, and σz specified as free functions of RL.A tanh factor suppresses counter-rotating stars, and initialization can instead explicitly set the qDF to zero for them.
- Three-dimensional distribution functions: The quasiisothermaldf implementation works with any galpy Potential instance or list and uses supplied actionAngle subclasses for the required action-angle calculations.The actionAngleAdiabatic and actionAngleStaeckel methods, including gridded versions, are particularly useful for qDF disk orbits.
- Three-dimensional distribution functions: quasiisothermaldf provides methods for evaluating the qDF, marginalizing over velocity components, and computing density, mean velocities, and velocity dispersions.The implementation was used extensively in the analysis of Bovy et al. (2013), with example methods shown in Figure 25.
7.1. Methodology
galpy implements Dehnen’s method for evaluating the response of an initially axisymmetric stellar-disk distribution function to non-axisymmetric perturbations. The evolveddiskdf class computes the perturbed distribution function, its derivatives, and velocity moments, while currently restricting the axisymmetric models to power-law potentials and selected disk distribution functions.
- Methodology: Dehnen’s method evolves an initially axisymmetric, time-independent distribution function under non-axisymmetric perturbations to calculate the present-day distribution function.Liouville’s theorem provides the basis for evaluating the evolved distribution function along orbital trajectories.
- Methodology: The evolveddiskdf class implements this procedure using shudf or dehnendf as the initial distribution function and power-law models for the axisymmetric potential.These restrictions arise from the currently supported galpy.df.diskdfs and the class’s implementation.
- Methodology: Derivatives of the evolved distribution function are obtained through the chain rule, with orbit integration of a small phase-space volume computing the required trajectory derivatives.The initial distribution function’s derivatives are calculated directly from its functional form, while derivatives of the mapped coordinates are integrated using the dxdv Orbit method.
- Methodology: At fixed (R, φ), evolveddiskdf objects support grid evaluation over (vR, vT), enabling rapid calculation of velocity moments and Oort functions.This grid-based evaluation is a major difference from ordinary diskdf objects.
7.3. Response to a weak bar
The section demonstrates evolveddiskdf by modeling a stellar disk’s response to a weak, rotating Dehnen bar. The response is strongest near the outer Lindblad resonance, remains similar under rapid growth but develops spirality, and informs Milky Way velocity-field analyses.
- Model setup: The weak-bar experiment uses a rotating quadrupole with Rb set to 80% of corotation, a Dehnen DF, σR = 0.2 vc, Ωb = 1.9Ω0, α = 0.01, and a 25° bar angle.The initial disk has hR = R0/3 and hσ = R0 in a logarithmic background potential with vc(R) = v0.
- Adiabatic response: 0.04 v0 is the maximum radial-velocity response, compared with 0.03 v0 for rotational velocity, with both maxima near the outer Lindblad resonance at ROLR = 0.9 R0.The vertex deviation is typically ≲15°, with the largest values near the outer Lindblad resonance and R = 1.3 R0.
- Rapid-growth response: Rapid growth over two bar periods produces a response similar to adiabatic growth but induces spirality, especially in the radial-velocity response.The rapid-growth model is intended to mimic a more realistic bar-growth scenario.
- Observational relevance: The bar-response models help determine how non-axisymmetry influences stellar mean-velocity observations in the Milky Way.Both elliptical-disk and bar perturbations were used to estimate their effect on measurements of the Milky Way’s rotation curve.
8.1. Source code · 8.2. Automated testing and code coverage
galpy’s publicly developed codebase is supported by extensive documentation and an automated test suite spanning its core numerical, dynamical, distribution-function, and utility functionality. The suite is continuously integrated and achieves 99.6% coverage, with uncovered paths largely limited to rare or inaccessible cases.
- 8.1. Source code: galpy’s source code is public, hosted on GitHub, and developed without a private version through issue tracking and pull requests.Users are encouraged to report bugs through GitHub’s issue tracker, while contributors can copy the repository and merge changes through pull requests.
- 8.1. Source code: 23,000 lines of code comprise galpy, including about 16,750 Python lines and 6,000 C lines distributed across five major modules.The actionAngle, df, orbit, potential, and util modules each contain about 5,000 lines.
- 8.1. Source code: galpy’s documentation is generated with Sphinx and automatically rebuilt on Read the Docs after each GitHub push.The source contains about 14,000 documentation lines, supplemented by ≈5,500 lines of reStructured-Text tutorials and a 283-page PDF.
- 8.2. Automated testing and code coverage: The test suite uses nose and Travis CI to automatically run tests after pushes to the GitHub repository.This setup is intended to maintain code reliability and detect regressions as galpy is extended.
- 8.2. Automated testing and code coverage: 500 test functions contain about 11,000 lines of code and check about 20,000 assertions, concentrated mainly on potentials and orbit integration.All but 1,600 assertions concern potential and orbit-integration capabilities, including tests over large point grids.
- 8.2. Automated testing and code coverage: The tests validate forces, derivatives, Poisson consistency, conserved quantities, symplectic energy behavior, action-angle calculations, distribution-function moments, coordinate transformations, and code examples.Orbit tests include energy and Jacobi-integral conservation, while distribution-function tests compare moments and Oort functions with analytical predictions across multiple rotation curves.
- 8.2. Automated testing and code coverage: 99.6% of relevant code is covered, with 14,166 of 14,220 relevant lines tested.Uncovered lines concern special cases unlikely in practice or paths inaccessible through the user interface; plotting routines receive limited testing because meaningful testing is difficult.
APPENDIX
The appendix describes galpy’s coordinate-transformation utilities, covering positions, velocities, uncertainties, and conversions among equatorial, Galactic, and Galactocentric systems. It also gives a worked transformation example and reports complete test coverage for the coordinate functions.
- Coordinate transformations: galpy transforms positions and velocities among equatorial, Galactic spherical or rectangular, and Galactocentric rectangular or cylindrical coordinates.The transformations accept scalar or array inputs and use only numpy functions, making array operations very fast.
- Coordinate transformations: The utilities convert angles, distances, proper motions, and line-of-sight velocities while propagating proper-motion and velocity covariance matrices.Inputs use degrees or radians, kpc, mas yr−1, and km s−1, respectively.
- Worked example: A worked example converts observed equatorial data through Galactic and rectangular coordinates into Galactocentric cylindrical phase space using specified solar position and velocity.The example assumes the Sun is at (R,z) = (8,0.025) and reports the resulting cylindrical positions and velocities.
- Testing: 100 % test coverage is provided for the bovy_coords functions through 30 test functions and 272 individual test assertions.This coverage is reported for the coordinate-transformation functions discussed in the appendix.