coordinax
๐ Get Started#
coordinax enables working with coordinates and reference frames with JAX.
coordinax supports JAXโs main features:
JIT compilation (
jit())vectorization (
vmap(), etc.)auto-differentiation (
grad(),jacobian(),jax.hessian())GPU/TPU/multi-host acceleration
And best of all, coordinax doesnโt force you to use special unit-compatible re-exports of JAX libraries. You can use coordinax with existing JAX code, and with one simple decorator (quax.quaxify()), JAX will work with coordinax objects.
Installation#
pip install coordinax
uv add coordinax
To install the latest development version of coordinax directly from the GitHub repository, use pip:
uv add git+https://https://github.com/GalacticDynamics/coordinax.git@main
You can customize the branch by replacing main with any other branch name.
To build coordinax from source, clone the repository and install it with uv:
cd /path/to/parent
git clone https://https://github.com/GalacticDynamics/coordinax.git
cd coordinax
uv pip install -e . # editable mode
Quickstart#
The coordinax package has powerful tools for representing, using, and transforming coordinate objects, such as:
This functionality is organized into submodules available under the top-level coordinax namespace. You can import them directly, or for many objects use the coordinax.main namespace to access them.
>>> import coordinax
>>> import sys
>>> sorted(name.removeprefix("coordinax.")
... for name in sys.modules
... if name.startswith("coordinax.") and name.count(".") == 1)[1:]
['angles', 'api', 'astro', 'charts', 'curveframes', 'distances', 'frames', 'hypothesis', 'internal', 'interop', 'main', 'manifolds', 'representations', 'transforms', 'vectors']
We recommend importing as needed:
coordinax.mainascx: probably everything you need!coordinax.anglesascxa: further angle-specific functionality.coordinax.distancesascxd: further distance-specific functionality.coordinax.chartsascxc: chart-specific functionality.coordinax.framesascxf: frame-specific functionality.coordinax.manifoldsascxm: manifold-specific functionality.coordinax.representationsascxr: representation-specific functionality.coordinax.transformsascxt: transform-specific functionality.coordinax.vectorsascxv: vector-specific functionality.coordinax.astroascxastro: astronomy-specific functionality. Note that this package is an optional extra, so you may need to install it separately.coordinax.hypothesisascxst: property-based testing strategies forcoordinax. Note that this package is an optional extra, so you may need to install it separately.coordinax.interop.astropyascxapy: interoperability withastropy. Note that this package is an optional extra, so you may need to install it separately.
Angles and Distances#
coordinax is built on top of unxt, which provides support for quantity objects that represent a data array with an associated unit with the unxt.quantity.Quantity class. These Quantity objects can be used throughout coordinax, but coordinax also provides specific classes that offer additional functionality.
Letโs start with angles, which are represented by the Angle class. This class enforces that the inputted units have angular dimensions and provides some other useful utilities for working with angles. For example, the resulting Angle (a re-export of unxt.Angle) object can be wrapped to a specific range to conform to a branch cut (e.g., 0 to \(2\pi\) or \(-180^\circ\) to \(180^\circ\)).
>>> import coordinax.main as cx
>>> import unxt as u
>>> a = cx.Angle(370, "deg")
>>> a
Angle(370, 'deg')
>>> a.wrap_to(u.Q(0, "deg"), u.Q(360, "deg"))
Angle(10, 'deg')
Similarly, the Distance class represents distances in coordinax:
>>> d = cx.Distance(10, "kpc")
>>> d
Distance(10, 'kpc')
but other distance-like objects can be represented with the Parallax and DistanceModulus classes. These classes check that the units have distance dimensions, and they provide useful properties for converting between different distance representations.
>>> import coordinax.astro as cxastro
>>> import plum
>>> plum.convert(d, cxastro.Parallax)
Parallax(4.84813681e-10, 'rad')
>>> plum.convert(d, cxastro.DistanceModulus)
DistanceModulus(15., 'mag')
Ecosystem#
coordinaxโs Dependencies#
coordinaxโs Dependents#
galax: Galactic dynamics in JAX.