unxts.interop.gala#
The gala package provides tools for Galactic dynamics. It is built on top of the astropy package and adds an additional units tool, the gala.units.UnitSystem class that can be used to convert between different unit systems.
unxts.interop.gala is the canonical location for gala integration, providing conversions between gala.units.UnitSystem and unxt.unitsystems.AbstractUnitSystem objects. This conversion is automatically enabled if unxts.interop.gala is installed. It is compatible with most versions of gala, but to ensure that compatible versions of gala and unxt are installed, the following installation extra is provided:
uv add "unxt[interop-gala]"
pip install "unxt[interop-gala]"
The following example demonstrates how to convert a gala unit system to a unxt unit system:
>>> import unxt
>>> import gala.units as gu
>>> gu.galactic # gala unit system
<UnitSystem (kpc, Myr, solMass, rad)>
>>> unxt.unitsystem(gu.galactic) # unxt unit system
unitsystem(kpc, Myr, solMass, rad)
Alternatively, the multiple-dispatch library on which unxt is built enables 2-way conversion.
>>> from plum import convert
>>> usys = convert(gu.galactic, unxt.AbstractUnitSystem)
>>> usys
unitsystem(kpc, Myr, solMass, rad)
>>> convert(usys, gu.UnitSystem)
<UnitSystem (kpc, Myr, solMass, rad)>
Public API#
unxts.interop.gala exposes two conversion functions:
convert_gala_unitsystem_to_unxt_unitsystemconvert_unxt_unitsystem_to_gala_unitsystem
These are plum.conversion_methods, registered with plumโs dispatch table as a side effect of importing unxts.interop.gala. Prefer plum.convert(usys, ...) (as shown above) over calling either function directly.
Install: pip install unxts.interop.gala